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