Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,50 @@ | ||
from plugin import Plugin | ||
|
||
class Urls(Plugin): | ||
def help_text(self, bot): | ||
|
||
def help_text(self, bot): | ||
return (bot.translate("url_help") + "\n" + bot.translate("url_help2")) | ||
|
||
def on_msg(self, bot, user_nick, host, channel, message): | ||
if bot.httpregex.search(message.lower()) is not None: | ||
urls = bot.geturlsfrommsg(message) | ||
for url in urls: | ||
title = bot.sanitize(bot.geturltitle(url)) | ||
if title == "": | ||
title = url | ||
if message.lower().startswith('!private') or message.lower().startswith('!pr'): | ||
def on_msg(self, bot, user_nick, host, channel, message): | ||
ms = message.lower() | ||
|
||
if bot.httpregex.search(ms) is None: | ||
return False | ||
|
||
# extract list of arrays from message | ||
urls = bot.geturlsfrommsg(message) | ||
|
||
# loop through all items | ||
for url in urls: | ||
|
||
# fetch html <title> element | ||
title = bot.sanitize(bot.geturltitle(url)) | ||
|
||
# Check if link can be added to wiki | ||
if not ms.startswith('!private') and not ms.startswith('!pr') and not ms.startswith('!nsfw'): | ||
|
||
# Set proper wikititle | ||
if title == "": | ||
title = url | ||
|
||
# call bot and paste to wiki | ||
bot.get_plugin("MediaWiki").wikiupdate(wikititle, url) | ||
|
||
# If empty title, dont paste to irc | ||
if title == "": | ||
continue | ||
|
||
# check if private link | ||
if ms.startswith('!private') or ms.startswith('!pr'): | ||
bot.send_message(channel, "[private] " + "Title: {title}".format(title=title), user_nick) | ||
elif message.lower().startswith('!nsfw'): | ||
|
||
# check if link was marked as nsfw from sender | ||
elif ms.startswith('!nsfw'): | ||
bot.send_message(channel, "[nsfw] " + "Title: {title}".format(title=title), user_nick) | ||
else: | ||
|
||
# send title to | ||
else: | ||
bot.send_message(channel, "Title: {title}".format(title=title), user_nick) | ||
print bot.get_plugin("MediaWiki").wikiupdate(title, url) | ||
|
||
|
||
|