From 2680f4be036da3d83a4638963144cf99e35da5f3 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Date: Wed, 5 Jun 2019 23:15:44 +0100 Subject: [PATCH] Initial commit --- .gitignore | 124 +++++++++++++++++++++++++ GitHub/README.md | 1 + GitHub/__init__.py | 72 +++++++++++++++ GitHub/config.py | 56 ++++++++++++ GitHub/local/__init__.py | 1 + GitHub/plugin.py | 77 ++++++++++++++++ GitHub/test.py | 38 ++++++++ Inquisicao/README.md | 1 + Inquisicao/__init__.py | 72 +++++++++++++++ Inquisicao/config.py | 56 ++++++++++++ Inquisicao/local/__init__.py | 1 + Inquisicao/plugin.py | 172 +++++++++++++++++++++++++++++++++++ Inquisicao/test.py | 38 ++++++++ Kernel/README.md | 1 + Kernel/__init__.py | 72 +++++++++++++++ Kernel/config.py | 56 ++++++++++++ Kernel/local/__init__.py | 1 + Kernel/plugin.py | 68 ++++++++++++++ Kernel/test.py | 38 ++++++++ Maria/README.md | 1 + Maria/__init__.py | 72 +++++++++++++++ Maria/config.py | 56 ++++++++++++ Maria/doc-conf/doc.conf | 9 ++ Maria/local/__init__.py | 1 + Maria/plugin.py | 115 +++++++++++++++++++++++ Maria/test.py | 38 ++++++++ requirements.txt | 4 + 27 files changed, 1241 insertions(+) create mode 100644 .gitignore create mode 100644 GitHub/README.md create mode 100644 GitHub/__init__.py create mode 100644 GitHub/config.py create mode 100644 GitHub/local/__init__.py create mode 100644 GitHub/plugin.py create mode 100644 GitHub/test.py create mode 100644 Inquisicao/README.md create mode 100644 Inquisicao/__init__.py create mode 100644 Inquisicao/config.py create mode 100644 Inquisicao/local/__init__.py create mode 100644 Inquisicao/plugin.py create mode 100644 Inquisicao/test.py create mode 100644 Kernel/README.md create mode 100644 Kernel/__init__.py create mode 100644 Kernel/config.py create mode 100644 Kernel/local/__init__.py create mode 100644 Kernel/plugin.py create mode 100644 Kernel/test.py create mode 100644 Maria/README.md create mode 100644 Maria/__init__.py create mode 100644 Maria/config.py create mode 100644 Maria/doc-conf/doc.conf create mode 100644 Maria/local/__init__.py create mode 100644 Maria/plugin.py create mode 100644 Maria/test.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0c219b --- /dev/null +++ b/.gitignore @@ -0,0 +1,124 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/GitHub/README.md b/GitHub/README.md new file mode 100644 index 0000000..0d70f05 --- /dev/null +++ b/GitHub/README.md @@ -0,0 +1 @@ +GitHub rss commit reader diff --git a/GitHub/__init__.py b/GitHub/__init__.py new file mode 100644 index 0000000..f4b1af1 --- /dev/null +++ b/GitHub/__init__.py @@ -0,0 +1,72 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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. + +### + +""" +GitHub: GitHub rss commit reader +""" + +import sys +import supybot +from supybot import world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "" + +__author__ = supybot.Author('Pedro de Oliveira', 'falso', + 'falsovsky@gmail.com') + +# 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/GitHub/config.py b/GitHub/config.py new file mode 100644 index 0000000..4c969ad --- /dev/null +++ b/GitHub/config.py @@ -0,0 +1,56 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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('GitHub') +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('GitHub', True) + + +GitHub = conf.registerPlugin('GitHub') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(GitHub, 'someConfigVariableName', +# registry.Boolean(False, _("""Help for someConfigVariableName."""))) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/GitHub/local/__init__.py b/GitHub/local/__init__.py new file mode 100644 index 0000000..e86e97b --- /dev/null +++ b/GitHub/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/GitHub/plugin.py b/GitHub/plugin.py new file mode 100644 index 0000000..fdcdb1e --- /dev/null +++ b/GitHub/plugin.py @@ -0,0 +1,77 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 +from supybot.commands import * +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('GitHub') +except ImportError: + # Placeholder that allows to run the plugin on a bot + # without the i18n module + _ = lambda x: x +import datetime +import requests +import atoma +import timeago + + +class GitHub(callbacks.Plugin): + """GitHub rss commit reader""" + + def __parse_rss(self, url): + response = requests.get(url) + + if response: + feed = atoma.parse_atom_bytes(response.content) + message = "{}: {} by {} {}".format( + feed.title.value, + feed.entries[0].title.value, + feed.entries[0].authors[0].name, + timeago.format(feed.entries[0].updated, datetime.datetime.now(datetime.timezone.utc)) + ) + else: + message = response.status_code + + return message + + def last(self, irc, msg, args, atom_url): + """ + + Returns the last commit message from the specified atom url. + """ + irc.reply(self.__parse_rss(atom_url), prefixNick=False) + last = wrap(last, ['httpUrl']) + + +Class = GitHub + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/GitHub/test.py b/GitHub/test.py new file mode 100644 index 0000000..69c9b50 --- /dev/null +++ b/GitHub/test.py @@ -0,0 +1,38 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 GitHubTestCase(PluginTestCase): + plugins = ('GitHub',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Inquisicao/README.md b/Inquisicao/README.md new file mode 100644 index 0000000..f3a4d62 --- /dev/null +++ b/Inquisicao/README.md @@ -0,0 +1 @@ +Client for Inquisicao diff --git a/Inquisicao/__init__.py b/Inquisicao/__init__.py new file mode 100644 index 0000000..5da9287 --- /dev/null +++ b/Inquisicao/__init__.py @@ -0,0 +1,72 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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. + +### + +""" +Inquisicao: Client for Inquisicao +""" + +import sys +import supybot +from supybot import world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "" + +__author__ = supybot.Author('Pedro de Oliveira', 'falso', + 'falsovsky@gmail.com') + +# 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/Inquisicao/config.py b/Inquisicao/config.py new file mode 100644 index 0000000..1310d86 --- /dev/null +++ b/Inquisicao/config.py @@ -0,0 +1,56 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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('Inquisicao') +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('Inquisicao', True) + + +Inquisicao = conf.registerPlugin('Inquisicao') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(Inquisicao, 'someConfigVariableName', +# registry.Boolean(False, _("""Help for someConfigVariableName."""))) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Inquisicao/local/__init__.py b/Inquisicao/local/__init__.py new file mode 100644 index 0000000..e86e97b --- /dev/null +++ b/Inquisicao/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/Inquisicao/plugin.py b/Inquisicao/plugin.py new file mode 100644 index 0000000..6fd1b4d --- /dev/null +++ b/Inquisicao/plugin.py @@ -0,0 +1,172 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 +from supybot.commands import * +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('Inquisicao') +except ImportError: + # Placeholder that allows to run the plugin on a bot + # without the i18n module + _ = lambda x: x +from urllib.parse import urlencode +import json +import re +import requests + +class Inquisicao(callbacks.Plugin): + """Client for Inquisicao""" + + def __init__(self, irc): + self.__parent = super(Inquisicao, self) + self.__parent.__init__(irc) + self.__truncate = 380 # max chars + + def __truncate_unicode_to_byte_limit(self, src, byte_limit, encoding='utf-8'): + """Ripado daqui: https://stackoverflow.com/a/24839091""" + return src.encode(encoding)[:byte_limit].decode(encoding, 'ignore') + + def __format_message(self, data, search): + """Devolve uma string bonita sobre o processo""" + + result = "" + extra = "crime" + shown = 0 + + # Se for pesquisa, mostra o registo actual / total + if search: + result = "[%d/%d] " % ( + data['next'] - 1 if data['next'] else data['total'], + data['total']) + data = data['message'] + + # Titulo + result = "%s%s" % (result, data['titulo']) + + # Printa o Crime se existir, e incrementa o shown + if data['crime']: + result = "%s | Crime: %s" % (result, data['crime']) + shown = shown + 1 + # Printa a Sentença se existir, e incrementa o shown + if data['sentenca']: + result = u"%s | Sentença: %s" % (result, data['sentenca']) + shown = shown + 1 + + # Se printou menos de 2 registos + if shown < 2: + # Se tiver "Notas" e "Outros dados" + if data['notas'] and data['outros']: + # Ver qual deles é maior e printa. + # Define a variavel "extra" com o valor da chave que foi + # extra-printada, para ser utilizada em caso de pesquisa + if len(data['notas']) > len(data['outros']): + result = "%s | Notas: %s" % (result, data['notas']) + extra = "notas" + else: + result = "%s | Outros dados: %s" % (result, data['outros']) + extra = "outros" + # Senão printa as Notas + elif data['notas']: + result = "%s | Notas: %s" % (result, data['notas']) + extra = "notas" + # Ou os Outros dados + elif data['outros']: + result = "%s | Outros dados: %s" % (result, data['outros']) + extra = "outros" + + # Se for pesquisa + if search: + # Verifica se o match é o mesmo que algum dos items já printados + # Estou a comparar duas vezes com o Crime quando o "extra" não é definido + if (data['crime'] != data['match']['value'] and + data['sentenca'] != data['match']['value'] and + data[extra] != data['match']['value']): + + # Printa o match + result = "%s | %s: %s" % ( + result, + data['match']['key'], + data['match']['value']) + + # Remover newlines e espaços duplicados + result = result.replace("\r\n", " ") + result = result.replace("\n", " ") + result = re.sub(' +', ' ', result) + + original = result + result = self.__truncate_unicode_to_byte_limit(original, self.__truncate) + + # Se a foi cortada, adiciona os ... + if original != result: + result = result + u"…" + + # Adiciona o short url + result = "%s | %s" % (result, data['url']) + + return result + + def __do_request(self, action, arguments): + baseurl = "https://inquisicao.deadbsd.org/api/" + response = requests.get(baseurl + action + "?" + urlencode(arguments)) + return json.loads(response.content.decode('utf-8')) + + def find(self, irc, msg, args, text, position): + """ [position] + + Returns the matched proccess with "text" at "position". + """ + data = self.__do_request('adcautelam', + { + 'key': text, + 'page': position + }) + + if not data: + irc.reply("Not found", prefixNick=False) + return + + irc.reply(self.__format_message(data, True), prefixNick=False) + find = wrap(find, ['anything', optional('int', default=0)]) + + def random(self, irc, msg, args): + """takes no arguments + + Returns a random proccess. + """ + data = self.__do_request('degredo', {}) + irc.reply(self.__format_message(data, False), prefixNick=False) + random = wrap(random) + + +Class = Inquisicao + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/Inquisicao/test.py b/Inquisicao/test.py new file mode 100644 index 0000000..403eb58 --- /dev/null +++ b/Inquisicao/test.py @@ -0,0 +1,38 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 InquisicaoTestCase(PluginTestCase): + plugins = ('Inquisicao',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Kernel/README.md b/Kernel/README.md new file mode 100644 index 0000000..ad64323 --- /dev/null +++ b/Kernel/README.md @@ -0,0 +1 @@ +Get latest kernel versions diff --git a/Kernel/__init__.py b/Kernel/__init__.py new file mode 100644 index 0000000..21d70d5 --- /dev/null +++ b/Kernel/__init__.py @@ -0,0 +1,72 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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. + +### + +""" +Kernel: Get latest kernel versions +""" + +import sys +import supybot +from supybot import world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "" + +__author__ = supybot.Author('Pedro de Oliveira', 'falso', + 'falsovsky@gmail.com') + +# 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/Kernel/config.py b/Kernel/config.py new file mode 100644 index 0000000..2d1c4e0 --- /dev/null +++ b/Kernel/config.py @@ -0,0 +1,56 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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('Kernel') +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('Kernel', True) + + +Kernel = conf.registerPlugin('Kernel') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(Kernel, 'someConfigVariableName', +# registry.Boolean(False, _("""Help for someConfigVariableName."""))) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Kernel/local/__init__.py b/Kernel/local/__init__.py new file mode 100644 index 0000000..e86e97b --- /dev/null +++ b/Kernel/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/Kernel/plugin.py b/Kernel/plugin.py new file mode 100644 index 0000000..4403da8 --- /dev/null +++ b/Kernel/plugin.py @@ -0,0 +1,68 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 +from supybot.commands import * +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('Kernel') +except ImportError: + # Placeholder that allows to run the plugin on a bot + # without the i18n module + _ = lambda x: x +import json +import requests + +class Kernel(callbacks.Plugin): + """Get latest kernel versions""" + + def __linus(self): + response = requests.get("https://www.kernel.org/releases.json") + data = json.loads(response.content.decode('utf-8')) + + output = "" + for release in data['releases']: + output += "{}: {}, ".format(release['moniker'], release['version']) + + return output[:-2] + + def latest(self, irc, msg, args): + """takes no arguments + + Returns the latest Linux Kernel version. + """ + irc.reply(self.__linus(), prefixNick=False) + latest = wrap(latest) + + +Class = Kernel + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/Kernel/test.py b/Kernel/test.py new file mode 100644 index 0000000..af67775 --- /dev/null +++ b/Kernel/test.py @@ -0,0 +1,38 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 KernelTestCase(PluginTestCase): + plugins = ('Kernel',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Maria/README.md b/Maria/README.md new file mode 100644 index 0000000..8a739dc --- /dev/null +++ b/Maria/README.md @@ -0,0 +1 @@ +MariaWeb client diff --git a/Maria/__init__.py b/Maria/__init__.py new file mode 100644 index 0000000..876c689 --- /dev/null +++ b/Maria/__init__.py @@ -0,0 +1,72 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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. + +### + +""" +Maria: MariaWeb client +""" + +import sys +import supybot +from supybot import world + +# Use this for the version of this plugin. You may wish to put a CVS keyword +# in here if you're keeping the plugin in CVS or some similar system. +__version__ = "" + +__author__ = supybot.Author('Pedro de Oliveira', 'falso', + 'falsovsky@gmail.com') + +# 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/Maria/config.py b/Maria/config.py new file mode 100644 index 0000000..edb0f48 --- /dev/null +++ b/Maria/config.py @@ -0,0 +1,56 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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('Maria') +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('Maria', True) + + +Maria = conf.registerPlugin('Maria') +# This is where your configuration variables (if any) should go. For example: +# conf.registerGlobalValue(Maria, 'someConfigVariableName', +# registry.Boolean(False, _("""Help for someConfigVariableName."""))) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/Maria/doc-conf/doc.conf b/Maria/doc-conf/doc.conf new file mode 100644 index 0000000..aad1931 --- /dev/null +++ b/Maria/doc-conf/doc.conf @@ -0,0 +1,9 @@ + +supybot.directories.data: doc-data +supybot.directories.conf: doc-conf +supybot.directories.log: doc-logs +supybot.log.stdout: False +supybot.log.level: DEBUG +supybot.log.format: %(levelname)s %(message)s +supybot.log.plugins.individualLogfiles: False +supybot.databases: sqlite anydbm cdb flat pickle diff --git a/Maria/local/__init__.py b/Maria/local/__init__.py new file mode 100644 index 0000000..e86e97b --- /dev/null +++ b/Maria/local/__init__.py @@ -0,0 +1 @@ +# Stub so local is a module, used for third-party modules diff --git a/Maria/plugin.py b/Maria/plugin.py new file mode 100644 index 0000000..6af0caa --- /dev/null +++ b/Maria/plugin.py @@ -0,0 +1,115 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 +from supybot.commands import * +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('Maria') +except ImportError: + # Placeholder that allows to run the plugin on a bot + # without the i18n module + _ = lambda x: x +from urllib.parse import urlencode +import json +import requests + +class Maria(callbacks.Plugin): + """MariaWeb client""" + + def __init__(self, irc): + self.__parent = super(Maria, self) + self.__parent.__init__(irc) + + def __format_message(self, data): + return "{} - #{} - {} [{}]".format( + data['message']['text'], + data['message']['user'], + data['message']['datetime'], + data['message']['magazine'][:1].lower() + ) + + def __do_request(self, action, arguments): + baseurl = "https://maria.deadbsd.org/api/" + response = requests.get(baseurl + action + "?" + urlencode(arguments)) + return json.loads(response.content.decode('utf-8')) + + def latest(self, irc, msg, args, position): + """[position] + + Returns the last message, or last + position. + """ + data = self.__do_request('latest', {'position': position}) + + if data['next'] > 0: + irc.reply("{} found 'maria latest {}' for the next one".format( + data['total'], + data['next'] + ), prefixNick=False) + irc.reply(self.__format_message(data), prefixNick=False) + latest = wrap(latest, [optional('int', default=0)]) + + def find(self, irc, msg, args, text, position): + """ [position] + + Returns the matched message with "text" at "position". + """ + data = self.__do_request('find', + { + 'text': text, + 'position': position + }) + + if 'error' in data: + irc.reply(data['error'], prefixNick=False) + return + + if data['next'] > 0: + irc.reply("{} found. 'maria find {} {}' for the next one".format( + data['total'], + text, + data['next'] + ), prefixNick=False) + irc.reply(self.__format_message(data), prefixNick=False) + find = wrap(find, ['anything', optional('int', default=0)]) + + def random(self, irc, msg, args): + """takes no arguments + + Returns a random message. + """ + data = self.__do_request('random', {}) + irc.reply(self.__format_message(data), prefixNick=False) + random = wrap(random) + +Class = Maria + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/Maria/test.py b/Maria/test.py new file mode 100644 index 0000000..6278667 --- /dev/null +++ b/Maria/test.py @@ -0,0 +1,38 @@ +### +# Copyright (c) 2019, Pedro de Oliveira +# 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 MariaTestCase(PluginTestCase): + plugins = ('Maria',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..226e792 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +atoma==0.0.15 +limnoria==2019.2.23 +requests==2.22.0 +timeago==1.0.10 \ No newline at end of file