1
0
Fork 0

Virtualy move all nemubot modules into nemubot.module.* hierarchy, to avoid conflict with system/vendor modules

This commit is contained in:
nemunaire 2017-08-27 18:22:53 +02:00
parent 45fe5b2156
commit f60de818f2
53 changed files with 75 additions and 67 deletions

View File

@ -12,7 +12,7 @@ from nemubot.message import Command
from nemubot.tools.human import guess
from nemubot.tools.xmlparser.node import ModuleState
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -13,7 +13,7 @@ from nemubot.tools.countdown import countdown_format
from nemubot.tools.date import extractDate
from nemubot.tools.xmlparser.node import ModuleState
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -4,12 +4,11 @@
from datetime import datetime, timezone
from nemubot import context
from nemubot.event import ModuleEvent
from nemubot.hooks import hook
from nemubot.tools.countdown import countdown_format
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -7,7 +7,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.message import Command, DirectAsk, Text
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -11,7 +11,7 @@ from nemubot.hooks import hook
from nemubot.tools import web
from nemubot.tools.web import striphtml
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -6,7 +6,7 @@ from bs4 import BeautifulSoup
from nemubot.hooks import hook
from nemubot.tools.web import getURLContent, striphtml
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools.web import getURLContent, striphtml
from more import Response
from nemubot.module.more import Response
BASEURL_NIST = 'https://nvd.nist.gov/vuln/detail/'

View File

@ -8,7 +8,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -14,7 +14,7 @@ import dns.resolver
from nemubot.exception import IMException
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
# MODULE INTERFACE ####################################################

View File

@ -7,7 +7,7 @@ import capstone
from nemubot.exception import IMException
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -12,7 +12,7 @@ from nemubot.tools.countdown import countdown_format, countdown
from nemubot.tools.date import extractDate
from nemubot.tools.xmlparser.node import ModuleState
from more import Response
from nemubot.module.more import Response
def help_full ():

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.message import Command, Text
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -11,7 +11,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -1,7 +1,7 @@
from nemubot.hooks import hook
from nemubot.exception import IMException
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
import json
nemubotversion = 3.4

View File

@ -8,7 +8,7 @@ import os
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -11,7 +11,7 @@ from nemubot.tools import web
nemubotversion = 3.4
from more import Response
from nemubot.module.more import Response
# MEDIAWIKI REQUESTS ##################################################

View File

@ -8,7 +8,7 @@ import re
from nemubot.exception import IMException
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
from . import isup
from . import page

View File

@ -12,7 +12,7 @@ from nemubot.tools.xmlparser.node import ModuleState
logger = logging.getLogger("nemubot.module.networking.watchWebsite")
from more import Response
from nemubot.module.more import Response
from . import page

View File

@ -6,7 +6,7 @@ import urllib
from nemubot.exception import IMException
from nemubot.tools.web import getJSON
from more import Response
from nemubot.module.more import Response
URL_AVAIL = "https://www.whoisxmlapi.com/whoisserver/WhoisService?cmd=GET_DN_AVAILABILITY&domainName=%%s&outputFormat=json&username=%s&password=%s"
URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?da=2&domainName=%%s&outputFormat=json&userName=%s&password=%s"

View File

@ -12,7 +12,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
from nemubot.tools.feed import Feed, AtomEntry

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -8,7 +8,7 @@ from nemubot import context
from nemubot.exception import IMException
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
DB = None

View File

@ -4,7 +4,7 @@
from nemubot.exception import IMException
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
from nextstop import ratp

View File

@ -10,7 +10,7 @@ from nemubot.tools import web
nemubotversion = 3.4
from more import Response
from nemubot.module.more import Response
def help_full():

View File

@ -9,7 +9,7 @@ from nemubot import context
from nemubot.exception import IMException
from nemubot.hooks import hook
from more import Response
from nemubot.module.more import Response
# MODULE INTERFACE ####################################################

View File

@ -12,7 +12,7 @@ from nemubot.tools import web
nemubotversion = 4.0
from more import Response
from nemubot.module.more import Response
def help_full():

View File

@ -11,7 +11,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -10,7 +10,7 @@ from nemubot.hooks import hook
nemubotversion = 3.4
from more import Response
from nemubot.module.more import Response
def help_full():

View File

@ -16,7 +16,7 @@ from nemubot.tools.xmlparser.node import ModuleState
nemubotversion = 3.4
from more import Response
from nemubot.module.more import Response
def load(context):
context.data.setIndex("name", "phone")

View File

@ -10,7 +10,7 @@ from nemubot.tools.xmlparser.node import ModuleState
from .pyaspell import Aspell
from .pyaspell import AspellError
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -10,7 +10,7 @@ import re
from nemubot.hooks import hook
from nemubot.exception import IMException
from nemubot.tools.web import getURLContent, getJSON
from more import Response
from nemubot.module.more import Response
# POSTAGE SERVICE PARSERS ############################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -8,7 +8,7 @@ from nemubot.tools.web import getJSON
nemubotversion = 4.0
from more import Response
from nemubot.module.more import Response
URL_TPBAPI = None

View File

@ -8,7 +8,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# GLOBALS #############################################################

View File

@ -8,7 +8,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# MODULE CORE #########################################################

View File

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -10,8 +10,8 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
import mapquest
from nemubot.module.more import Response
from nemubot.module import mapquest
# GLOBALS #############################################################

View File

@ -11,11 +11,11 @@ from nemubot.hooks import hook
from nemubot.tools import web
from nemubot.tools.xmlparser.node import ModuleState
import mapquest
from nemubot.module import mapquest
nemubotversion = 4.0
from more import Response
from nemubot.module.more import Response
URL_DSAPI = "https://api.darksky.net/forecast/%s/%%s,%%s?lang=%%s&units=%%s"

View File

@ -10,8 +10,8 @@ from nemubot.tools.xmlparser.node import ModuleState
nemubotversion = 3.4
from more import Response
from networking.page import headers
from nemubot.module.more import Response
from nemubot.module.networking.page import headers
PASSWD_FILE = None
# You can get one with: curl -b "sessionid=YOURSESSIONID" 'https://accounts.cri.epita.net/api/users/' > users.json

View File

@ -10,7 +10,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
from more import Response
from nemubot.module.more import Response
# LOADING #############################################################

View File

@ -15,7 +15,7 @@ from nemubot.tools.xmlparser.node import ModuleState
nemubotversion = 3.4
from more import Response
from nemubot.module.more import Response
API_URL="http://worldcup.sfg.io/%s"

View File

@ -4,7 +4,7 @@ import re, json, subprocess
from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools.web import _getNormalizedURL, getURLContent
from more import Response
from nemubot.module.more import Response
"""Get information of youtube videos"""

View File

@ -153,7 +153,7 @@ def main():
context.modules_configuration[mod.name] = mod
if mod.autoload:
try:
__import__(mod.name)
__import__("nemubot.module." + mod.name)
except:
logger.exception("Exception occurs when loading module"
" '%s'", mod.name)
@ -164,7 +164,7 @@ def main():
if args.module:
for module in args.module:
__import__(module)
__import__("nemubot.module." + module)
if args.socketfile:
from nemubot.server.socket import UnixSocketListener

View File

@ -97,18 +97,19 @@ class Bot(threading.Thread):
def _help_msg(msg):
"""Parse and response to help messages"""
from more import Response
from nemubot.module.more import Response
res = Response(channel=msg.to_response)
if len(msg.args) >= 1:
if msg.args[0] in self.modules and self.modules[msg.args[0]]() is not None:
if hasattr(self.modules[msg.args[0]](), "help_full"):
hlp = self.modules[msg.args[0]]().help_full()
if "nemubot.module." + msg.args[0] in self.modules and self.modules["nemubot.module." + msg.args[0]]() is not None:
mname = "nemubot.module." + msg.args[0]
if hasattr(self.modules[mname](), "help_full"):
hlp = self.modules[mname]().help_full()
if isinstance(hlp, Response):
return hlp
else:
res.append_message(hlp)
else:
res.append_message([str(h) for s,h in self.modules[msg.args[0]]().__nemubot_context__.hooks], title="Available commands for module " + msg.args[0])
res.append_message([str(h) for s,h in self.modules[mname]().__nemubot_context__.hooks], title="Available commands for module " + msg.args[0])
elif msg.args[0][0] == "!":
from nemubot.message.command import Command
for h in self.treater._in_hooks(Command(msg.args[0][1:])):

View File

@ -29,16 +29,16 @@ class ModuleFinder(Finder):
self.add_module = add_module
def find_module(self, fullname, path=None):
# Search only for new nemubot modules (packages init)
if path is None:
if path is not None and fullname.startswith("nemubot.module."):
module_name = fullname.split(".", 2)[2]
for mpath in self.modules_paths:
if os.path.isfile(os.path.join(mpath, fullname + ".py")):
if os.path.isfile(os.path.join(mpath, module_name + ".py")):
return ModuleLoader(self.add_module, fullname,
os.path.join(mpath, fullname + ".py"))
elif os.path.isfile(os.path.join(os.path.join(mpath, fullname), "__init__.py")):
os.path.join(mpath, module_name + ".py"))
elif os.path.isfile(os.path.join(os.path.join(mpath, module_name), "__init__.py")):
return ModuleLoader(self.add_module, fullname,
os.path.join(
os.path.join(mpath, fullname),
os.path.join(mpath, module_name),
"__init__.py"))
return None
@ -53,17 +53,17 @@ class ModuleLoader(SourceFileLoader):
def _load(self, module, name):
# Add the module to the global modules list
self.add_module(module)
logger.info("Module '%s' successfully loaded.", name)
logger.info("Module '%s' successfully imported from %s.", name.split(".", 2)[2], self.path)
return module
# Python 3.4
def exec_module(self, module):
super(ModuleLoader, self).exec_module(module)
super().exec_module(module)
self._load(module, module.__spec__.name)
# Python 3.3
def load_module(self, fullname):
module = super(ModuleLoader, self).load_module(fullname)
module = super().load_module(fullname)
return self._load(module, module.__name__)

View File

@ -0,0 +1,7 @@
#
# This directory aims to store nemubot core modules.
#
# Custom modules should be placed into a separate directory.
# By default, this is the directory modules in your current directory.
# Use the --modules-path argument to define a custom directory for your modules.
#

View File

@ -20,7 +20,7 @@ class _ModuleContext:
self.module = module
if module is not None:
self.module_name = module.__spec__.name if hasattr(module, "__spec__") else module.__name__
self.module_name = (module.__spec__.name if hasattr(module, "__spec__") else module.__name__).replace("nemubot.module.", "")
else:
self.module_name = ""

View File

@ -69,6 +69,7 @@ setup(
'nemubot.hooks.keywords',
'nemubot.message',
'nemubot.message.printer',
'nemubot.module',
'nemubot.server',
'nemubot.server.message',
'nemubot.tools',