--- /dev/null
+# Erebus IRC bot - Author: Erebus Team
+# vim: fileencoding=utf-8
+# module for 's/regex/replacement/' style correction
+# warning: arbitrary regex's are generally capable of various DoS attacks on CPU/memory usage. use with caution.
+# see for usage examples: https://github.com/zonidjan/erebus/commit/d7e9802778477f1faa26a03078cb1b3c018a5e5c
+# This file is released into the public domain; see http://unlicense.org/
+
+# module info
+modinfo = {
+ 'author': 'Erebus Team',
+ 'license': 'public domain',
+ 'compatible': [0], # compatible module API versions
+ 'depends': [], # other modules required to work properly?
+ 'softdeps': [], # modules which are preferred but not required
+}
+
+# preamble
+import modlib
+lib = modlib.modlib(__name__)
+modstart = lib.modstart
+modstop = lib.modstop
+
+# module code
+import re
+from collections import namedtuple
+re_findtwitter = re.compile(r"""https?://(?:www\.)?(?:twitter|x)\.com/([-.a-z0-9/]+)""", re.I)
+
+@lib.hooknum("PRIVMSG")
+def privmsg_hook(bot, line):
+ pieces = line.split(None, 3)
+ chan = pieces[2]
+ msg = pieces[3][1:]
+ replaced = ""
+ for mo in re_findtwitter.finditer(msg):
+ replaced += re_findtwitter.sub(r"https://nitter.projectsegfau.lt/\1", mo.group(0)) + " "
+ if replaced:
+ bot.msg(chan, "%s" % (replaced))