1
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

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

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

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

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

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

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

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

@ -9,7 +9,7 @@ from nemubot.exception import IMException
from nemubot.hooks import hook from nemubot.hooks import hook
from nemubot.tools.web import getURLContent, striphtml 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/' BASEURL_NIST = 'https://nvd.nist.gov/vuln/detail/'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -6,7 +6,7 @@ import urllib
from nemubot.exception import IMException from nemubot.exception import IMException
from nemubot.tools.web import getJSON 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_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" URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?da=2&domainName=%%s&outputFormat=json&userName=%s&password=%s"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -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.
#

@ -20,7 +20,7 @@ class _ModuleContext:
self.module = module self.module = module
if module is not None: 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: else:
self.module_name = "" self.module_name = ""

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