]>
Commit | Line | Data |
---|---|---|
cf400e09 JR |
1 | # Erebus IRC bot - Author: Erebus Team |
2 | # vim: fileencoding=utf-8 | |
bac69af4 | 3 | # nitterize twitter links |
cf400e09 JR |
4 | # This file is released into the public domain; see http://unlicense.org/ |
5 | ||
6 | # module info | |
7 | modinfo = { | |
8 | 'author': 'Erebus Team', | |
9 | 'license': 'public domain', | |
10 | 'compatible': [0], # compatible module API versions | |
9de26fbb | 11 | 'depends': ['urls'], # other modules required to work properly? |
cf400e09 JR |
12 | 'softdeps': [], # modules which are preferred but not required |
13 | } | |
14 | ||
15 | # preamble | |
16 | import modlib | |
17 | lib = modlib.modlib(__name__) | |
18 | modstart = lib.modstart | |
19 | modstop = lib.modstop | |
20 | ||
21 | # module code | |
22 | import re | |
d4541fa9 | 23 | re_findtwitter = re.compile(r"""https?://(?:www\.)?(?:twitter|x)\.com/([-./_a-z0-9]+)""", re.I) |
cf400e09 JR |
24 | |
25 | @lib.hooknum("PRIVMSG") | |
26 | def privmsg_hook(bot, line): | |
27 | pieces = line.split(None, 3) | |
28 | chan = pieces[2] | |
366accf8 | 29 | if chan[0] != "#": return |
cf400e09 | 30 | msg = pieces[3][1:] |
366accf8 | 31 | |
cf400e09 JR |
32 | replaced = "" |
33 | for mo in re_findtwitter.finditer(msg): | |
3c63ef05 | 34 | replaced += re_findtwitter.sub(bot.parent.cfg.get('nitterize', 'instance', 'https://nitter.net') + r"\1", mo.group(0)) + " " |
cf400e09 | 35 | if replaced: |
9de26fbb JR |
36 | bot.msg(chan, replaced) |
37 | titles = lib.mod('urls').process_line(replaced) | |
38 | lib.mod('urls').send_response(bot, chan, titles) | |
2412ad6e JR |
39 | |
40 | @lib.hook(glevel=lib.STAFF, needchan=False) | |
41 | @lib.argsEQ(1) | |
42 | def setnitter(bot, user, chan, realtarget, *args): | |
3c63ef05 JR |
43 | newnitter = args[0] |
44 | if newnitter[-1] != "/": | |
45 | newnitter += "/" | |
46 | bot.parent.cfg.set('nitterize', 'instance', newnitter) | |
47 | return 'Done' |