summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratyush Desai2021-06-19 16:08:43 +0530
committerPratyush Desai2021-06-19 16:08:43 +0530
commitc44b03e2aeb949db26de1f6dad4fe1e79cd529fc (patch)
tree04116cf354fcc17eb2e82daaec444d39b74000be
downloadsnoparser-c44b03e2aeb949db26de1f6dad4fe1e79cd529fc.tar.gz
snoparser-c44b03e2aeb949db26de1f6dad4fe1e79cd529fc.tar.bz2
snoparser-c44b03e2aeb949db26de1f6dad4fe1e79cd529fc.zip
Initial commit
-rw-r--r--README.md1
-rw-r--r--__init__.py71
-rw-r--r--config.py56
-rw-r--r--local/__init__.py1
-rw-r--r--plugin.py140
-rw-r--r--test.py38
6 files changed, 307 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7812442
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+Parses the Server Notices from ErgoIRCd
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..9251fb3
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,71 @@
+###
+# Copyright (c) 2021, mogad0n
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+"""
+SnoParser: Parses the Server Notices from ErgoIRCd
+"""
+
+import sys
+import supybot
+from supybot import world
+
+# Use this for the version of this plugin.
+__version__ = ""
+
+# XXX Replace this with an appropriate author or supybot.Author instance.
+__author__ = supybot.authors.unknown
+
+# This is a dictionary mapping supybot.Author instances to lists of
+# contributions.
+__contributors__ = {}
+
+# This is a url where the most recent plugin package can be downloaded.
+__url__ = ''
+
+from . import config
+from . import plugin
+if sys.version_info >= (3, 4):
+ from importlib import reload
+else:
+ from imp import reload
+# In case we're being reloaded.
+reload(config)
+reload(plugin)
+# Add more reloads here if you add third-party modules and want them to be
+# reloaded when this plugin is reloaded. Don't forget to import them as well!
+
+if world.testing:
+ from . import test
+
+Class = plugin.Class
+configure = config.configure
+
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/config.py b/config.py
new file mode 100644
index 0000000..29d7ba8
--- /dev/null
+++ b/config.py
@@ -0,0 +1,56 @@
+###
+# Copyright (c) 2021, mogad0n
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+from supybot import conf, registry
+try:
+ from supybot.i18n import PluginInternationalization
+ _ = PluginInternationalization('SnoParser')
+except:
+ # Placeholder that allows to run the plugin on a bot
+ # without the i18n module
+ _ = lambda x: x
+
+
+def configure(advanced):
+ # This will be called by supybot to configure this module. advanced is
+ # a bool that specifies whether the user identified themself as an advanced
+ # user or not. You should effect your configuration by manipulating the
+ # registry as appropriate.
+ from supybot.questions import expect, anything, something, yn
+ conf.registerPlugin('SnoParser', True)
+
+
+SnoParser = conf.registerPlugin('SnoParser')
+# This is where your configuration variables (if any) should go. For example:
+# conf.registerGlobalValue(SnoParser, 'someConfigVariableName',
+# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
+
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/local/__init__.py b/local/__init__.py
new file mode 100644
index 0000000..e86e97b
--- /dev/null
+++ b/local/__init__.py
@@ -0,0 +1 @@
+# Stub so local is a module, used for third-party modules
diff --git a/plugin.py b/plugin.py
new file mode 100644
index 0000000..580166c
--- /dev/null
+++ b/plugin.py
@@ -0,0 +1,140 @@
+###
+# Copyright (c) 2021, mogad0n
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+from supybot import utils, plugins, ircutils, callbacks, ircdb, conf, log, world, ircmsgs
+from supybot.commands import *
+try:
+ from supybot.i18n import PluginInternationalization
+ _ = PluginInternationalization('SnoParser')
+except ImportError:
+ # Placeholder that allows to run the plugin on a bot
+ # without the i18n module
+ _ = lambda x: x
+
+import re
+import os
+import sys
+import time
+
+class SnoParser(callbacks.Plugin):
+ """Parses the Server Notices from ErgoIRCd"""
+ threaded = True
+
+ def doNotice(self, irc, msg):
+ (target, text) = msg.args
+ if target == irc.nick:
+
+ # server notices CONNECT, KILL, XLINE
+
+ text = ircutils.stripFormatting(text)
+ if 'CONNECT' in text:
+ connregex = "^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$"
+ couple = re.match(connregex, text)
+ nickname = couple.group(1)
+ username = couple.group(2)
+ host = couple.group(3)
+ ip = couple.group(4)
+ realname = couple.group(5)
+ ip_seen = 0
+ nick_seen = 0
+ DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen}
+ repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}"
+ self._sendSnotice(irc, msg, repl)
+ if 'XLINE' in text and 'temporary' in text:
+ xlineregex = "^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$"
+ couple = re.match(xlineregex, text)
+ who = couple.group(1)
+ who_operator = couple.group(2)
+ duration = couple.group(3)
+ which_line = couple.group(4)
+ host_or_ip = couple.group(5)
+ DictFromSnotice = {'notice': 'tempban', 'who': who, 'operator': who_operator, 'duration': duration, 'type': which_line, 'target': host_or_ip}
+ repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']}\x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {DictFromSnotice['who']} \x02BannedByOper:\x0F {DictFromSnotice['operator']} \x02Duration:\x0F {DictFromSnotice['duration']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Nick:\x0F {DictFromSnotice['target']}"
+ self._sendSnotice(irc, msg, repl)
+ # WHY THE FUCK IS IT elif ??
+ elif 'XLINE' in text and 'temporary' not in text and 'removed' not in text:
+ perm_xline_regex = "^-XLINE- (.+) \[(.+)\] added (D-Line|K-Line) for (.+)$"
+ couple = re.match(perm_xline_regex, text)
+ who = couple.group(1)
+ who_operator = couple.group(2)
+ which_line = couple.group(3)
+ host_or_ip = couple.group(4)
+ DictFromSnotice = {'notice': 'Permaban', 'who': who, 'operator': who_operator, 'type': which_line, 'target': host_or_ip}
+ repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {DictFromSnotice['who']} \x02BannedByOper:\x0F {DictFromSnotice['operator']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Host/IP:\x0F {DictFromSnotice['target']}"
+ self._sendSnotice(irc, msg, repl)
+ elif 'XLINE' in text and 'removed' in text:
+ unxlineregex = "^-XLINE- (.+) removed (D-Line|K-Line) for (.+)$"
+ couple = re.match(unxlineregex, text)
+ who = couple.group(1)
+ which_line = couple.group(2)
+ host_or_ip = couple.group(3)
+ DictFromSnotice = {'notice': 'unxline', 'who': who, 'type': which_line, 'target': host_or_ip}
+ repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303 :=D\x0F \x02UnbannedBy:\x0F {DictFromSnotice['who']} \x02XLINE type:\x0F {DictFromSnotice['type']} \x02Host/IP:\x0F {DictFromSnotice['target']}"
+ self._sendSnotice(irc, msg, repl)
+ if 'KILL' in text:
+ killregex = "^-KILL- (.+) \[(.+)\] killed (\d) clients with a (KLINE|DLINE) \[(.+)\]$"
+ couple = re.match(killregex, text)
+ who = couple.group(1)
+ who_operator = couple.group(2)
+ clients = couple.group(3)
+ which_line = couple.group(4)
+ nick = couple.group(5)
+ DictFromSnotice = {'notice': 'kill', 'who': who, 'operator': who_operator, "client": clients, 'type': which_line, 'nick': nick}
+ repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303☠\x0F \x02KilledBy:\x0F {DictFromSnotice['who']} \x02KilledByOper:\x0F {DictFromSnotice['operator']} \x02NumofClientsAffected:\x0F {DictFromSnotice['client']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Nick:\x0F {DictFromSnotice['nick']}"
+ self._sendSnotice(irc, msg, repl)
+ if 'NICK' in text and 'changed nickname to' in text:
+ nickregex = "^-NICK- (.+) changed nickname to (.+)$"
+ couple = re.match(nickregex, text)
+ old_nick = couple.group(1)
+ new_nick = couple.group(2)
+ DictFromSnotice = {'notice': 'nick change', 'old_nick': old_nick, 'new_nick': new_nick}
+ repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} ==> {DictFromSnotice['old_nick']} changed their nick to {DictFromSnotice['new_nick']}"
+ self._sendSnotice(irc, msg, repl)
+ if 'QUIT' in text and 'exited' in text:
+ quitregex = "^-QUIT- (.+) exited the network$"
+ couple = re.match(quitregex, text)
+ nick = couple.group(1)
+ repl = f"\x02\x1FNOTICE: quit nick: {nick} has exited the network"
+ self._sendSnotice(irc, msg, repl)
+ # -ACCOUNT- Client [<redacted-hostmask>] registered account [<redacted>] from IP <redacted>
+ # -ACCOUNT- Operator [<redacted>] registered account [<redacted>] with SAREGISTER
+ if 'ACCOUNT' in text and 'logged into account' in text:
+ accregex = "^-ACCOUNT- "
+
+
+
+ def _sendSnotice(self, irc, msg, repl):
+ irc.queueMsg(msg=ircmsgs.IrcMsg(command='PRIVMSG',
+ args=('#snotices', repl)))
+
+Class = SnoParser
+
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..d6fa395
--- /dev/null
+++ b/test.py
@@ -0,0 +1,38 @@
+###
+# Copyright (c) 2021, mogad0n
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+from supybot.test import *
+
+
+class SnoParserTestCase(PluginTestCase):
+ plugins = ('SnoParser',)
+
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: