]>
jfr.im git - erebus.git/blob - modules/nitterize.py
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/
10 'author': 'Erebus Team',
11 'license': 'public domain',
12 'compatible': [0], # compatible module API versions
13 'depends': [], # other modules required to work properly?
14 'softdeps': [], # modules which are preferred but not required
19 lib
= modlib
.modlib(__name__
)
20 modstart
= lib
.modstart
25 re_findtwitter
= re
.compile(r
"""https?://(?:www\.)?(?:twitter|x)\.com/([-./_a-z0-9]+)""", re
.I
)
27 @lib.hooknum("PRIVMSG")
28 def privmsg_hook(bot
, line
):
29 pieces
= line
.split(None, 3)
31 if chan
[0] != "#": return
35 for mo
in re_findtwitter
.finditer(msg
):
36 replaced
+= re_findtwitter
.sub(bot
.parent
.cfg
.get('nitterize', 'instance', 'https://nitter.net') + r
"\1", mo
.group(0)) + " "
38 bot
.msg(chan
, "%s" % (replaced
))
40 @lib.hook(glevel
=lib
.STAFF
, needchan
=False)
42 def setnitter(bot
, user
, chan
, realtarget
, *args
):
44 if newnitter
[-1] != "/":
46 bot
.parent
.cfg
.set('nitterize', 'instance', newnitter
)