|
2 | 2 |
|
3 | 3 | class Urls(Plugin):
|
4 | 4 |
|
5 |
| -def help_text(self, bot): |
6 |
| - return (bot.translate("url_help") + "\n" + bot.translate("url_help2")) |
| 5 | + def help_text(self, bot): |
| 6 | + return (bot.translate("url_help") + "\n" + bot.translate("url_help2")) |
7 | 7 |
|
8 |
| -def on_msg(self, bot, user_nick, host, channel, message): |
9 |
| - ms = message.lower() |
| 8 | + def on_msg(self, bot, user_nick, host, channel, message): |
| 9 | + ms = message.lower() |
10 | 10 |
|
11 |
| - if bot.httpregex.search(ms) is None: |
12 |
| - return False |
| 11 | + if bot.httpregex.search(ms) is None: |
| 12 | + return False |
13 | 13 |
|
14 |
| - # extract list of arrays from message |
15 |
| - urls = bot.geturlsfrommsg(message) |
| 14 | + # extract list of arrays from message |
| 15 | + urls = bot.geturlsfrommsg(message) |
16 | 16 |
|
17 |
| - # loop through all items |
18 |
| - for url in urls: |
| 17 | + # loop through all items |
| 18 | + for url in urls: |
19 | 19 |
|
20 |
| - # fetch html <title> element |
21 |
| - title = bot.sanitize(bot.geturltitle(url)) |
| 20 | + # fetch html <title> element |
| 21 | + title = bot.sanitize(bot.geturltitle(url)) |
22 | 22 |
|
23 |
| - # Check if link can be added to wiki |
24 |
| - if not ms.startswith('!private') and not ms.startswith('!pr') and not ms.startswith('!nsfw'): |
| 23 | + # Check if link can be added to wiki |
| 24 | + if not ms.startswith('!private') and not ms.startswith('!pr') and not ms.startswith('!nsfw'): |
25 | 25 |
|
26 |
| - # Set proper wikititle |
27 |
| - if title == "": |
28 |
| - title = url |
| 26 | + # Set proper wikititle |
| 27 | + if title == "": |
| 28 | + wikititle = url |
| 29 | + else: |
| 30 | + wikititle = title |
29 | 31 |
|
30 |
| - # call bot and paste to wiki |
31 |
| - bot.get_plugin("MediaWiki").wikiupdate(wikititle, url) |
| 32 | + # call bot and paste to wiki |
| 33 | + bot.get_plugin("MediaWiki").wikiupdate(wikititle, url) |
32 | 34 |
|
33 |
| - # If empty title, dont paste to irc |
34 |
| - if title == "": |
35 |
| - continue |
| 35 | + # If empty title, dont paste to irc |
| 36 | + if title == "": |
| 37 | + continue |
36 | 38 |
|
37 |
| - # check if private link |
38 |
| - if ms.startswith('!private') or ms.startswith('!pr'): |
39 |
| - bot.send_message(channel, "[private] " + "Title: {title}".format(title=title), user_nick) |
| 39 | + # check if private link |
| 40 | + if ms.startswith('!private') or ms.startswith('!pr'): |
| 41 | + bot.send_message(channel, "[private] " + "Title: {title}".format(title=title), user_nick) |
40 | 42 |
|
41 |
| - # check if link was marked as nsfw from sender |
42 |
| - elif ms.startswith('!nsfw'): |
43 |
| - bot.send_message(channel, "[nsfw] " + "Title: {title}".format(title=title), user_nick) |
| 43 | + # check if link was marked as nsfw from sender |
| 44 | + elif ms.startswith('!nsfw'): |
| 45 | + bot.send_message(channel, "[nsfw] " + "Title: {title}".format(title=title), user_nick) |
44 | 46 |
|
45 |
| - # send title to |
46 |
| - else: |
47 |
| - bot.send_message(channel, "Title: {title}".format(title=title), user_nick) |
| 47 | + # send title to |
| 48 | + else: |
| 49 | + bot.send_message(channel, "Title: {title}".format(title=title), user_nick) |
48 | 50 |
|
49 | 51 |
|
50 | 52 |
|
0 commit comments