Use ModuleManager.BaseModule in more modules
This commit is contained in:
parent
f3d98d0e95
commit
8b0314b190
18 changed files with 39 additions and 82 deletions
|
@ -1,17 +1,15 @@
|
||||||
#--require-config wordnik-api-key
|
#--require-config wordnik-api-key
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
URL_WORDNIK = "https://api.wordnik.com/v4/word.json/%s/definitions"
|
URL_WORDNIK = "https://api.wordnik.com/v4/word.json/%s/definitions"
|
||||||
URL_WORDNIK_RANDOM = "https://api.wordnik.com/v4/words.json/randomWord"
|
URL_WORDNIK_RANDOM = "https://api.wordnik.com/v4/words.json/randomWord"
|
||||||
|
|
||||||
RANDOM_DELAY_SECONDS = 3
|
RANDOM_DELAY_SECONDS = 3
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
_last_called = 0
|
||||||
self.bot = bot
|
|
||||||
self._last_called = 0
|
|
||||||
|
|
||||||
def _get_definition(self, word):
|
def _get_definition(self, word):
|
||||||
word = event["args"] if "args" in event else event
|
word = event["args"] if "args" in event else event
|
||||||
|
|
|
@ -2,15 +2,12 @@
|
||||||
#--require-config google-search-id
|
#--require-config google-search-id
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
|
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
|
||||||
URL_GOOGLESUGGEST = "http://google.com/complete/search"
|
URL_GOOGLESUGGEST = "http://google.com/complete/search"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.google|g", usage="[search term]")
|
@Utils.hook("received.command.google|g", usage="[search term]")
|
||||||
def google(self, event):
|
def google(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
#--require-config omdbapi-api-key
|
#--require-config omdbapi-api-key
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
URL_OMDB = "http://www.omdbapi.com/"
|
URL_OMDB = "http://www.omdbapi.com/"
|
||||||
URL_IMDBTITLE = "http://imdb.com/title/%s"
|
URL_IMDBTITLE = "http://imdb.com/title/%s"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "IMDb"
|
_name = "IMDb"
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.imdb", min_args=1, usage="<movie/tv title>")
|
@Utils.hook("received.command.imdb", min_args=1, usage="<movie/tv title>")
|
||||||
def imdb(self, event):
|
def imdb(self, event):
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import time
|
import time
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
SECONDS_MAX = Utils.SECONDS_WEEKS*8
|
SECONDS_MAX = Utils.SECONDS_WEEKS*8
|
||||||
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.in", min_args=2, usage="<time> <message>")
|
@Utils.hook("received.command.in", min_args=2, usage="<time> <message>")
|
||||||
def in_command(self, event):
|
def in_command(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import re
|
import re
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
ISGD_API_URL = "https://is.gd/create.php"
|
ISGD_API_URL = "https://is.gd/create.php"
|
||||||
REGEX_URL = re.compile("https?://", re.I)
|
REGEX_URL = re.compile("https?://", re.I)
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.events = events
|
|
||||||
|
|
||||||
@Utils.hook("get.shortlink")
|
@Utils.hook("get.shortlink")
|
||||||
def shortlink(self, event):
|
def shortlink(self, event):
|
||||||
url = event["url"]
|
url = event["url"]
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.loadmodule", min_args=1,
|
@Utils.hook("received.command.loadmodule", min_args=1,
|
||||||
permission="load-module", usage="<module-name>")
|
permission="load-module", usage="<module-name>")
|
||||||
def load(self, event):
|
def load(self, event):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#--ignore
|
#--ignore
|
||||||
import types, json
|
import types, json
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
def get_target(user):
|
def get_target(user):
|
||||||
return user.alias or user.nickname
|
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,
|
user.bot.database.del_user_setting(user.server.id, target,
|
||||||
setting)
|
setting)
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Aliases"
|
_name = "Aliases"
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("new.user")
|
@Utils.hook("new.user")
|
||||||
def new_user(self, event):
|
def new_user(self, event):
|
||||||
|
|
|
@ -2,7 +2,7 @@ import collections, re, time
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
from suds.client import Client
|
from suds.client import Client
|
||||||
from suds import WebFault
|
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'
|
URL = 'https://lite.realtime.nationalrail.co.uk/OpenLDBSVWS/wsdl.aspx?ver=2016-02-16'
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "NR"
|
_name = "NR"
|
||||||
|
_client = None
|
||||||
|
|
||||||
PASSENGER_ACTIVITIES = ["U", "P", "R"]
|
PASSENGER_ACTIVITIES = ["U", "P", "R"]
|
||||||
COLOURS = [Utils.COLOR_LIGHTBLUE, Utils.COLOR_GREEN, Utils.COLOR_RED, Utils.COLOR_CYAN, Utils.COLOR_LIGHTGREY, Utils.COLOR_ORANGE]
|
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
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if self._client: return self._client
|
if self._client: return self._client
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
from src import EventManager, Utils
|
from src import EventManager, ModuleManager, Utils
|
||||||
|
|
||||||
class Module(object):
|
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
|
class Module(ModuleManager.BaseModule):
|
||||||
def print_line(self, event, line, channel=None):
|
def print_line(self, event, line, channel=None):
|
||||||
timestamp = datetime.datetime.now().isoformat()
|
timestamp = datetime.datetime.now().isoformat()
|
||||||
target = str(event["server"])
|
target = str(event["server"])
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(object):
|
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.exports = exports
|
|
||||||
|
|
||||||
|
class Module(ModuleManager.BaseModule):
|
||||||
def _set(self, settings, event, target):
|
def _set(self, settings, event, target):
|
||||||
settings_dict = dict([(setting["setting"], setting
|
settings_dict = dict([(setting["setting"], setting
|
||||||
) for setting in settings])
|
) for setting in settings])
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
#--require-config soundcloud-api-key
|
#--require-config soundcloud-api-key
|
||||||
|
|
||||||
import json, re, time
|
import json, re, time
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
URL_SOUNDCLOUD_TRACK = "http://api.soundcloud.com/tracks"
|
URL_SOUNDCLOUD_TRACK = "http://api.soundcloud.com/tracks"
|
||||||
URL_SOUNDCLOUD_RESOLVE = "http://api.soundcloud.com/resolve"
|
URL_SOUNDCLOUD_RESOLVE = "http://api.soundcloud.com/resolve"
|
||||||
REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
|
REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "SoundCloud"
|
_name = "SoundCloud"
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.soundcloud|sc")
|
@Utils.hook("received.command.soundcloud|sc")
|
||||||
def soundcloud(self, event):
|
def soundcloud(self, event):
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import time
|
import time
|
||||||
from src import Utils
|
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.uptime")
|
@Utils.hook("received.command.uptime")
|
||||||
def uptime(self, event):
|
def uptime(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import collections, datetime, re
|
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 = "https://api.tfl.gov.uk/StopPoint/%s/Arrivals"
|
||||||
URL_BUS_SEARCH = "https://api.tfl.gov.uk/StopPoint/Search/%s"
|
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"]
|
PLATFORM_TYPES = ["Northbound", "Southbound", "Eastbound", "Westbound", "Inner Rail", "Outer Rail"]
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "TFL"
|
_name = "TFL"
|
||||||
def __init__(self, bot, events, exports):
|
result_map = {}
|
||||||
self.bot = bot
|
|
||||||
self.result_map = {}
|
|
||||||
|
|
||||||
def vehicle_span(self, arrival_time, human=True):
|
def vehicle_span(self, arrival_time, human=True):
|
||||||
vehicle_due_iso8601 = arrival_time
|
vehicle_due_iso8601 = arrival_time
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
#--require-config bighugethesaurus-api-key
|
#--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"
|
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.synonym|antonym", min_args=1,
|
@Utils.hook("received.command.synonym|antonym", min_args=1,
|
||||||
usage="<word> [type]")
|
usage="<word> [type]")
|
||||||
def thesaurus(self, event):
|
def thesaurus(self, event):
|
||||||
|
|
|
@ -5,16 +5,13 @@
|
||||||
|
|
||||||
import datetime, re, time, traceback
|
import datetime, re, time, traceback
|
||||||
import twitter
|
import twitter
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
REGEX_TWITTERURL = re.compile(
|
REGEX_TWITTERURL = re.compile(
|
||||||
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
|
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Twitter"
|
_name = "Twitter"
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
self.events = events
|
|
||||||
|
|
||||||
def make_timestamp(self, s):
|
def make_timestamp(self, s):
|
||||||
seconds_since = time.time() - datetime.datetime.strptime(s,
|
seconds_since = time.time() - datetime.datetime.strptime(s,
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
#--require-config openweathermap-api-key
|
#--require-config openweathermap-api-key
|
||||||
|
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
|
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.weather", min_args=1, usage="<location>")
|
@Utils.hook("received.command.weather", min_args=1, usage="<location>")
|
||||||
def weather(self, event):
|
def weather(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#--require-config wolframalpha-api-key
|
#--require-config wolframalpha-api-key
|
||||||
import json
|
import json
|
||||||
from src import Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
URL_WA = "https://api.wolframalpha.com/v1/result"
|
URL_WA = "https://api.wolframalpha.com/v1/result"
|
||||||
|
|
||||||
class Module(object):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Wolfram|Alpha"
|
_name = "Wolfram|Alpha"
|
||||||
def __init__(self, bot, events, exports):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@Utils.hook("received.command.wolframalpha|wa", min_args=1, usage="<query>")
|
@Utils.hook("received.command.wolframalpha|wa", min_args=1, usage="<query>")
|
||||||
def wa(self, event):
|
def wa(self, event):
|
||||||
|
|
|
@ -22,7 +22,9 @@ class ModuleNotLoadedWarning(ModuleWarning):
|
||||||
|
|
||||||
class BaseModule(object):
|
class BaseModule(object):
|
||||||
def __init__(self, bot, events, exports):
|
def __init__(self, bot, events, exports):
|
||||||
pass
|
self.bot = bot
|
||||||
|
self.events = events
|
||||||
|
self.exports = exports
|
||||||
|
|
||||||
class ModuleManager(object):
|
class ModuleManager(object):
|
||||||
def __init__(self, bot, events, exports, directory):
|
def __init__(self, bot, events, exports, directory):
|
||||||
|
|
Loading…
Reference in a new issue