Use ModuleManager.BaseModule in more modules

This commit is contained in:
jesopo 2018-09-27 11:46:10 +01:00
parent f3d98d0e95
commit 8b0314b190
18 changed files with 39 additions and 82 deletions

View file

@ -1,17 +1,15 @@
#--require-config wordnik-api-key
import time
from src import Utils
from src import ModuleManager, Utils
URL_WORDNIK = "https://api.wordnik.com/v4/word.json/%s/definitions"
URL_WORDNIK_RANDOM = "https://api.wordnik.com/v4/words.json/randomWord"
RANDOM_DELAY_SECONDS = 3
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
self._last_called = 0
class Module(ModuleManager.BaseModule):
_last_called = 0
def _get_definition(self, word):
word = event["args"] if "args" in event else event

View file

@ -2,15 +2,12 @@
#--require-config google-search-id
import json
from src import Utils
from src import ModuleManager, Utils
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
URL_GOOGLESUGGEST = "http://google.com/complete/search"
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.google|g", usage="[search term]")
def google(self, event):
"""

View file

@ -1,15 +1,13 @@
#--require-config omdbapi-api-key
import json
from src import Utils
from src import ModuleManager, Utils
URL_OMDB = "http://www.omdbapi.com/"
URL_IMDBTITLE = "http://imdb.com/title/%s"
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "IMDb"
def __init__(self, bot, events, exports):
self.bot = bot
@Utils.hook("received.command.imdb", min_args=1, usage="<movie/tv title>")
def imdb(self, event):

View file

@ -1,13 +1,10 @@
import time
from src import Utils
from src import ModuleManager, Utils
SECONDS_MAX = Utils.SECONDS_WEEKS*8
SECONDS_MAX_DESCRIPTION = "8 weeks"
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.in", min_args=2, usage="<time> <message>")
def in_command(self, event):
"""

View file

@ -1,13 +1,10 @@
import re
from src import Utils
from src import ModuleManager, Utils
ISGD_API_URL = "https://is.gd/create.php"
REGEX_URL = re.compile("https?://", re.I)
class Module(object):
def __init__(self, bot, events, exports):
self.events = events
class Module(ModuleManager.BaseModule):
@Utils.hook("get.shortlink")
def shortlink(self, event):
url = event["url"]

View file

@ -1,9 +1,6 @@
from src import ModuleManager, Utils
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.loadmodule", min_args=1,
permission="load-module", usage="<module-name>")
def load(self, event):

View file

@ -1,6 +1,6 @@
#--ignore
import types, json
from src import Utils
from src import ModuleManager, Utils
def get_target(user):
return user.alias or user.nickname
@ -21,10 +21,8 @@ def del_setting(user, setting):
user.bot.database.del_user_setting(user.server.id, target,
setting)
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "Aliases"
def __init__(self, bot, events, exports):
self.bot = bot
@Utils.hook("new.user")
def new_user(self, event):

View file

@ -2,7 +2,7 @@ import collections, re, time
from datetime import datetime, date
from collections import Counter
from src import Utils
from src import ModuleManager, Utils
from suds.client import Client
from suds import WebFault
@ -14,16 +14,13 @@ from suds import WebFault
URL = 'https://lite.realtime.nationalrail.co.uk/OpenLDBSVWS/wsdl.aspx?ver=2016-02-16'
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "NR"
_client = None
PASSENGER_ACTIVITIES = ["U", "P", "R"]
COLOURS = [Utils.COLOR_LIGHTBLUE, Utils.COLOR_GREEN, Utils.COLOR_RED, Utils.COLOR_CYAN, Utils.COLOR_LIGHTGREY, Utils.COLOR_ORANGE]
def __init__(self, bot, events, exports):
self.bot = bot
self._client = None
@property
def client(self):
if self._client: return self._client

View file

@ -1,10 +1,7 @@
import datetime
from src import EventManager, Utils
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
from src import EventManager, ModuleManager, Utils
class Module(ModuleManager.BaseModule):
def print_line(self, event, line, channel=None):
timestamp = datetime.datetime.now().isoformat()
target = str(event["server"])

View file

@ -1,9 +1,6 @@
from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
self.exports = exports
from src import ModuleManager, Utils
class Module(ModuleManager.BaseModule):
def _set(self, settings, event, target):
settings_dict = dict([(setting["setting"], setting
) for setting in settings])

View file

@ -1,16 +1,14 @@
#--require-config soundcloud-api-key
import json, re, time
from src import Utils
from src import ModuleManager, Utils
URL_SOUNDCLOUD_TRACK = "http://api.soundcloud.com/tracks"
URL_SOUNDCLOUD_RESOLVE = "http://api.soundcloud.com/resolve"
REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "SoundCloud"
def __init__(self, bot, events, exports):
self.bot = bot
@Utils.hook("received.command.soundcloud|sc")
def soundcloud(self, event):

View file

@ -1,10 +1,7 @@
import time
from src import Utils
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
from src import ModuleManager, Utils
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.uptime")
def uptime(self, event):
"""

View file

@ -1,5 +1,5 @@
import collections, datetime, re
from src import Utils
from src import ModuleManager, Utils
URL_BUS = "https://api.tfl.gov.uk/StopPoint/%s/Arrivals"
URL_BUS_SEARCH = "https://api.tfl.gov.uk/StopPoint/Search/%s"
@ -18,11 +18,9 @@ URL_ROUTE = "https://api.tfl.gov.uk/Line/%s/Route/Sequence/all?excludeCrowding=T
PLATFORM_TYPES = ["Northbound", "Southbound", "Eastbound", "Westbound", "Inner Rail", "Outer Rail"]
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "TFL"
def __init__(self, bot, events, exports):
self.bot = bot
self.result_map = {}
result_map = {}
def vehicle_span(self, arrival_time, human=True):
vehicle_due_iso8601 = arrival_time

View file

@ -1,13 +1,10 @@
#--require-config bighugethesaurus-api-key
from src import Utils
from src import ModuleManager, Utils
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.synonym|antonym", min_args=1,
usage="<word> [type]")
def thesaurus(self, event):

View file

@ -5,16 +5,13 @@
import datetime, re, time, traceback
import twitter
from src import Utils
from src import ModuleManager, Utils
REGEX_TWITTERURL = re.compile(
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "Twitter"
def __init__(self, bot, events, exports):
self.bot = bot
self.events = events
def make_timestamp(self, s):
seconds_since = time.time() - datetime.datetime.strptime(s,

View file

@ -1,13 +1,10 @@
#--require-config openweathermap-api-key
from src import Utils
from src import ModuleManager, Utils
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
class Module(object):
def __init__(self, bot, events, exports):
self.bot = bot
class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.weather", min_args=1, usage="<location>")
def weather(self, event):
"""

View file

@ -1,13 +1,11 @@
#--require-config wolframalpha-api-key
import json
from src import Utils
from src import ModuleManager, Utils
URL_WA = "https://api.wolframalpha.com/v1/result"
class Module(object):
class Module(ModuleManager.BaseModule):
_name = "Wolfram|Alpha"
def __init__(self, bot, events, exports):
self.bot = bot
@Utils.hook("received.command.wolframalpha|wa", min_args=1, usage="<query>")
def wa(self, event):

View file

@ -22,7 +22,9 @@ class ModuleNotLoadedWarning(ModuleWarning):
class BaseModule(object):
def __init__(self, bot, events, exports):
pass
self.bot = bot
self.events = events
self.exports = exports
class ModuleManager(object):
def __init__(self, bot, events, exports, directory):