give an Exports object (actually, ExportsContex object) to each module, to
facilitate things like !set and !channelset without using the events system
This commit is contained in:
parent
3ecd938de2
commit
8c6ab17e57
67 changed files with 172 additions and 151 deletions
44
Exports.py
Normal file
44
Exports.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
|
||||
class ExportsContext(object):
|
||||
def __init__(self, parent, context):
|
||||
self._parent = parent
|
||||
self.context = context
|
||||
|
||||
def add(self, setting, value):
|
||||
self._parent._context_add(self.context, setting, value)
|
||||
def get_all(self, setting):
|
||||
return self._parent.get_all(setting)
|
||||
|
||||
class Exports(object):
|
||||
def __init__(self):
|
||||
self._exports = {}
|
||||
self._context_exports = {}
|
||||
|
||||
def new_context(self, context):
|
||||
return ExportsContext(self, context)
|
||||
|
||||
def add(self, setting, value):
|
||||
self._add(None, setting, value)
|
||||
def _context_add(self, context, setting, value):
|
||||
self._add(context, setting, value)
|
||||
def _add(self, context, setting, value):
|
||||
if context == None:
|
||||
if not setting in self_exports:
|
||||
self._exports[setting] = []
|
||||
self._exports[setting].append(value)
|
||||
else:
|
||||
if not context in self._context_exports:
|
||||
self._context_exports[context] = {}
|
||||
if not setting in self._context_exports[context]:
|
||||
self._context_exports[context][setting] = []
|
||||
self._context_exports[context][setting].append(value)
|
||||
|
||||
def get_all(self, setting):
|
||||
return self._exports.get(setting, []) + sum([
|
||||
exports.get(setting, []) for exports in
|
||||
self._context_exports.values()], [])
|
||||
|
||||
def purge_context(self, context):
|
||||
if context in self._context_exports:
|
||||
del self._context_exports[context]
|
|
@ -1,6 +1,6 @@
|
|||
import os, select, sys, threading, time, traceback, uuid
|
||||
|
||||
import EventManager, IRCLineHandler, IRCServer, Logging
|
||||
import EventManager, Exports, IRCLineHandler, IRCServer, Logging
|
||||
import ModuleManager, Timer
|
||||
|
||||
class Bot(object):
|
||||
|
@ -14,7 +14,9 @@ class Bot(object):
|
|||
self.running = True
|
||||
self.poll = select.epoll()
|
||||
self._events = EventManager.EventHook(self)
|
||||
self.modules = ModuleManager.ModuleManager(self, self._events)
|
||||
self._exports = Exports.Exports()
|
||||
self.modules = ModuleManager.ModuleManager(self, self._events,
|
||||
self._exports)
|
||||
self.log = Logging.Log(self)
|
||||
self.line_handler = IRCLineHandler.LineHandler(self, self._events)
|
||||
self.timers = []
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import glob, imp, inspect, os, sys, uuid
|
||||
|
||||
class ModuleManager(object):
|
||||
def __init__(self, bot, events, directory="modules"):
|
||||
def __init__(self, bot, events, exports, directory="modules"):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
self.exports = exports
|
||||
self.directory = directory
|
||||
self.modules = {}
|
||||
self.waiting_requirement = {}
|
||||
|
@ -49,12 +50,12 @@ class ModuleManager(object):
|
|||
if not inspect.isclass(module.Module):
|
||||
raise ImportError("module '%s' has a Module attribute but it is not a class.")
|
||||
|
||||
event_context = str(uuid.uuid4())
|
||||
context = str(uuid.uuid4())
|
||||
module_object = module.Module(self.bot, self.events.new_context(
|
||||
event_context))
|
||||
context), self.exports.new_context(context))
|
||||
if not hasattr(module_object, "_name"):
|
||||
module_object._name = name.title()
|
||||
module_object._event_context = event_context
|
||||
module_object._context = context
|
||||
module_object._import_name = name
|
||||
|
||||
assert not module_object._name in self.modules, (
|
||||
|
@ -87,8 +88,9 @@ class ModuleManager(object):
|
|||
module = self.modules[name]
|
||||
del self.modules[name]
|
||||
|
||||
event_context = module._event_context
|
||||
self.events.purge_context(event_context)
|
||||
context = module._context
|
||||
self.events.purge_context(context)
|
||||
self.exports.purge_context(context)
|
||||
|
||||
del sys.modules[name]
|
||||
references = sys.getrefcount(module)
|
||||
|
|
|
@ -17,7 +17,7 @@ CHOICES = [
|
|||
]
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received.command.8ball").hook(
|
||||
self.decide,
|
||||
min_args=1,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("invite").hook(self.on_invite)
|
||||
|
||||
def on_invite(self, event):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("changenickname"
|
||||
).hook(self.change_nickname, permission="changenickname",
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="automode",
|
||||
help="Disable/Enable automode",
|
||||
validate=Utils.bool_or_none)
|
||||
exports.add("channelset", {"setting": "automode",
|
||||
"help": "Disable/Enable automode",
|
||||
"validate": Utils.bool_or_none})
|
||||
|
||||
events.on("channel").on("mode").hook(self.on_mode)
|
||||
events.on("received").on("join").hook(self.on_join)
|
||||
|
|
|
@ -2,7 +2,7 @@ import Utils
|
|||
|
||||
class Module(object):
|
||||
_name = "BTC"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("btc").hook(
|
||||
self.btc, help="Get the exchange rate of bitcoins",
|
||||
|
|
|
@ -7,7 +7,7 @@ URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
|
|||
REGEX_URL = re.compile("https?://", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
events.on("get").on("shortlink").hook(self.shortlink)
|
||||
|
|
|
@ -7,7 +7,7 @@ REGEX_BOOKID = re.compile("id=([\w\-]+)")
|
|||
|
||||
class Module(object):
|
||||
_name = "ISBN"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("isbn").hook(
|
||||
self.isbn, help="Get book information from a provided ISBN",
|
||||
|
|
|
@ -2,7 +2,7 @@ import Utils
|
|||
|
||||
class Module(object):
|
||||
_name = "Channel Op"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("kick", "k"
|
||||
).hook(self.kick, channel_only=True, require_mode="o",
|
||||
|
@ -40,21 +40,18 @@ class Module(object):
|
|||
events.on("received").on("message").on("channel").hook(
|
||||
self.highlight_spam)
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="highlight-spam-threshold",
|
||||
help="Set the number of nicknames in a message that "
|
||||
"qualifies as spam", validate=Utils.int_or_none)
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="highlight-spam-protection",
|
||||
help="Enable/Disable highlight spam protection",
|
||||
validate=Utils.bool_or_none)
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="highlight-spam-ban",
|
||||
help="Enable/Disable banning highlight spammers "
|
||||
"instead of just kicking", validate=Utils.bool_or_none)
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="ban-format",
|
||||
help="Set ban format ($n = nick, $u = username, $h = hostname)")
|
||||
exports.add("channelset", {"setting": "highlight-spam-threshold",
|
||||
"help": "Set the number of nicknames in a message that "
|
||||
"qualifies as spam", "validate": Utils.int_or_none})
|
||||
exports.add("channelset", {"setting": "highlight-spam-protection",
|
||||
"help": "Enable/Disable highlight spam protection",
|
||||
"validate": Utils.bool_or_none})
|
||||
exports.add("channelset", {"setting": "highlight-spam-ban",
|
||||
"help": "Enable/Disable banning highlight spammers "
|
||||
"instead of just kicking", "validate": Utils.bool_or_none})
|
||||
exports.add("channelset", {"setting": "ban-format",
|
||||
"help": "Set ban format ($n = nick, $u = username, "
|
||||
"$h = hostname)"})
|
||||
|
||||
def kick(self, event):
|
||||
target = event["args_split"][0]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received.numeric.001").hook(self.on_connect)
|
||||
events.on("self.join").hook(self.on_join)
|
||||
events.on("self.kick").hook(self.on_kick)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("preprocess").on("command").hook(self.preprocess_command)
|
||||
|
||||
|
|
|
@ -7,18 +7,17 @@ URL_VIRUSTOTAL = "https://www.virustotal.com/vtapi/v2/url/report"
|
|||
RE_URL = re.compile(r"https?://\S+", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
events.on("received.message.channel").hook(self.message)
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="check-urls",
|
||||
help="Enable/Disable automatically checking for malicious URLs",
|
||||
validate=Utils.bool_or_none)
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="check-urls-kick",
|
||||
help="Enable/Disable automatically kicking users that send "
|
||||
"malicious URLs", validate=Utils.bool_or_none)
|
||||
|
||||
exports.add("channelset", {"setting": "check-urls",
|
||||
"help": "Enable/Disable automatically checking for "
|
||||
"malicious URLs", "validate": Utils.bool_or_none})
|
||||
exports.add("channelset", {"setting": "check-urls-kick",
|
||||
"help": "Enable/Disable automatically kicking users that "
|
||||
"send malicious URLs", "validate": Utils.bool_or_none})
|
||||
|
||||
def message(self, event):
|
||||
match = RE_URL.search(event["message"])
|
||||
|
|
|
@ -26,7 +26,7 @@ THIRD_COLUMN = list(range(1, 37))[2::3]
|
|||
REGEX_STREET = re.compile("street([1-9]|1[0-2])$")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received.command.coins").hook(self.coins,
|
||||
help="Show how many coins you have")
|
||||
|
|
|
@ -45,7 +45,7 @@ class StdErr(Out):
|
|||
self.module_name, Utils.FONT_RESET)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
events.on("received").on("message").on("channel").hook(
|
||||
|
@ -60,9 +60,8 @@ class Module(object):
|
|||
events.on("received").on("command").on("more").hook(self.more,
|
||||
help="Get more output from the last command", skip_out=True)
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="command-prefix",
|
||||
help="Set the command prefix used in this channel")
|
||||
exports.add("channelset", {"setting": "command-prefix",
|
||||
"help": "Set the command prefix used in this channel"})
|
||||
|
||||
events.on("new").on("user", "channel").hook(self.new)
|
||||
events.on("send").on("stdout").hook(self.send_stdout)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("message").on("private").hook(
|
||||
self.private_message)
|
||||
|
|
|
@ -5,7 +5,7 @@ import Utils
|
|||
URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("define").hook(
|
||||
self.define, help="Define a provided term",
|
||||
|
|
|
@ -2,7 +2,7 @@ import random
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received.command.roll").hook(
|
||||
self.roll_dice,
|
||||
min_args=1,
|
||||
|
|
|
@ -2,7 +2,7 @@ import socket
|
|||
|
||||
class Module(object):
|
||||
_name = "DNS"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("dns").hook(
|
||||
self.dns, min_args=1,
|
||||
help="Get all addresses for a given hostname (IPv4/IPv6)",
|
||||
|
|
|
@ -14,7 +14,7 @@ DUCK_LIST = [
|
|||
]
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
|
||||
|
@ -33,10 +33,8 @@ class Module(object):
|
|||
"stats!")
|
||||
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="ducks-enabled",
|
||||
help="Toggles ducks!",
|
||||
validate=Utils.bool_or_none)
|
||||
exports.add("channelset", {"setting": "ducks-enabled",
|
||||
"help": "Toggle ducks!", "validate": Utils.bool_or_none})
|
||||
|
||||
events.on("received.numeric.366").hook(self.bootstrap)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ URL_GEOIP = "http://ip-api.com/json/%s"
|
|||
|
||||
class Module(object):
|
||||
_name = "GeoIP"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("geoip").hook(
|
||||
self.geoip, min_args=1,
|
||||
help="Get geoip data on a given IPv4/IPv6 address",
|
||||
|
|
|
@ -6,7 +6,7 @@ import Utils
|
|||
URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("google",
|
||||
"g").hook(self.google, help="Google feeling lucky",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import hashlib
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("hash"
|
||||
).hook(self.hash, min_args=2, help="Hash a string",
|
||||
|
|
|
@ -4,7 +4,7 @@ URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s"
|
|||
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("beenpwned").hook(
|
||||
self.beenpwned, min_args=1,
|
||||
help="Find out if a username, email or similar has appeared "
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class Module(object):
|
||||
_name = "IDs"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received.command.myid").hook(self.my_id,
|
||||
help="Show your user ID")
|
||||
events.on("received.command.channelid").hook(
|
||||
|
|
|
@ -8,7 +8,7 @@ URL_IMDBTITLE = "http://imdb.com/title/%s"
|
|||
|
||||
class Module(object):
|
||||
_name = "IMDb"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("imdb").hook(
|
||||
self.imdb, min_args=1,
|
||||
|
|
|
@ -5,7 +5,7 @@ SECONDS_MAX = Utils.SECONDS_WEEKS*8
|
|||
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("in").hook(
|
||||
self.in_command, min_args=2,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("numeric").on("001").hook(self.do_join)
|
||||
|
||||
def do_join(self, event):
|
||||
|
|
|
@ -5,7 +5,7 @@ REGEX_KARMA = re.compile("(.*)(\+{2,}|\-{2,})$")
|
|||
KARMA_DELAY_SECONDS = 3
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
events.on("new").on("user").hook(self.new_user)
|
||||
|
@ -19,10 +19,9 @@ class Module(object):
|
|||
min_args=1, help="Reset a specified karma to 0",
|
||||
usage="<target>")
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="karma-verbose",
|
||||
help="Disable/Enable automatically responding to karma changes",
|
||||
validate=Utils.bool_or_none)
|
||||
exports.add("channelset", {"setting": "karma-verbose",
|
||||
"help": "Disable/Enable automatically responding to "
|
||||
"karma changes", "validate": Utils.bool_or_none})
|
||||
|
||||
def new_user(self, event):
|
||||
event["user"].last_karma = None
|
||||
|
|
|
@ -5,12 +5,11 @@ import Utils
|
|||
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"set").assure_call(setting="lastfm",
|
||||
help="Set username on last.fm")
|
||||
exports.add("set", {"setting": "lastfm",
|
||||
"help": "Set username on last.fm"})
|
||||
|
||||
events.on("received").on("command").on("np",
|
||||
"listening", "nowplaying").hook(self.np,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received.command.loadmodule").hook(self.load,
|
||||
min_args=1, permission="load-module", help="Load a module",
|
||||
|
|
|
@ -22,7 +22,7 @@ def del_setting(user, setting):
|
|||
|
||||
class Module(object):
|
||||
_name = "Aliases"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("new").on("user").hook(self.new_user)
|
||||
events.on("received").on("nick").hook(self.nickname_change)
|
||||
|
|
|
@ -2,7 +2,7 @@ import base64
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("numeric").on("001"
|
||||
).hook(self.on_connect, priority=EventManager.PRIORITY_URGENT)
|
||||
events.on("received").on("command").on("setnickserv"
|
||||
|
|
|
@ -20,7 +20,7 @@ class Module(object):
|
|||
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):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self._client = None
|
||||
events.on("received").on("command").on("nrtrains"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("numeric").on("001").hook(
|
||||
self.on_connect, priority=EventManager.PRIORITY_URGENT)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ REQUIRES_IDENTIFY = ("You need to be identified to use that command "
|
|||
"(/msg %s register | /msg %s identify)")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("new").on("user").hook(self.new_user)
|
||||
events.on("preprocess").on("command").hook(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received.command.ping").hook(self.pong, help="Ping pong!")
|
||||
|
||||
def pong(self, event):
|
||||
|
|
|
@ -2,7 +2,7 @@ import datetime
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
|
||||
events.on("received").on("message").on("channel").hook(
|
||||
|
|
|
@ -55,7 +55,7 @@ QUOTES = {
|
|||
}
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("get.quit-quote").hook(self.quote)
|
||||
|
||||
def quote(self, event):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import random, time
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("quoteadd",
|
||||
"qadd").hook(self.quote_add, min_args=1,
|
||||
|
|
|
@ -2,7 +2,7 @@ import random, uuid
|
|||
|
||||
class Module(object):
|
||||
_name = "Random"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("random",
|
||||
"rand").hook(self.random, help="Get a random number",
|
||||
usage="[start] [end]")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import base64
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("preprocess.connect").hook(self.preprocess_connect)
|
||||
events.on("received.cap").hook(self.on_cap)
|
||||
|
|
|
@ -5,20 +5,18 @@ REGEX_SPLIT = re.compile("(?<!\\\\)/")
|
|||
REGEX_SED = re.compile("^s/")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
events.on("received").on("message").on("channel").hook(
|
||||
self.channel_message)
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="sed",
|
||||
help="Disable/Enable sed in a channel",
|
||||
validate=Utils.bool_or_none)
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="sed-sender-only",
|
||||
help="Disable/Enable sed only looking at the messages "
|
||||
"sent by the user", validate=Utils.bool_or_none)
|
||||
exports.add("channelset", {"setting": "sed",
|
||||
"help": "Disable/Enable sed in a channel",
|
||||
"validate": Utils.bool_or_none})
|
||||
exports.add("channelset", {"setting": "sed-sender-only",
|
||||
"help": "Disable/Enable sed only looking at the messages "
|
||||
"sent by the user", "validate": Utils.bool_or_none})
|
||||
|
||||
def channel_message(self, event):
|
||||
sed_split = re.split(REGEX_SPLIT, event["message"], 3)
|
||||
|
|
|
@ -2,7 +2,7 @@ import time
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("message").on("channel"
|
||||
).hook(self.channel_message)
|
||||
events.on("received").on("command").on("seen").hook(
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.settings = {}
|
||||
self.channel_settings = {}
|
||||
|
||||
events.on("postboot").on("configure").on("set").hook(
|
||||
self.postboot_set, replay=True)
|
||||
events.on("postboot").on("configure").on("channelset"
|
||||
).hook(self.postboot_channelset, replay=True)
|
||||
self.exports = exports
|
||||
|
||||
events.on("received").on("command").on("set").hook(
|
||||
self.set, help="Set a specified user setting",
|
||||
|
@ -31,23 +25,15 @@ class Module(object):
|
|||
help="Get a specified setting for the current channel",
|
||||
usage="<setting>", min_args=1, require_mode="o")
|
||||
|
||||
def _postboot_set(self, settings, event):
|
||||
settings[event["setting"]] = {}
|
||||
settings[event["setting"]]["validate"] = event.get(
|
||||
"validate", lambda s: s)
|
||||
settings[event["setting"]]["help"] = event.get("help",
|
||||
"")
|
||||
def postboot_set(self, event):
|
||||
self._postboot_set(self.settings, event)
|
||||
def postboot_channelset(self, event):
|
||||
self._postboot_set(self.channel_settings, event)
|
||||
|
||||
def _set(self, settings, event, target):
|
||||
settings_dict = dict([(setting["setting"], setting
|
||||
) for setting in settings])
|
||||
if len(event["args_split"]) > 1:
|
||||
setting = event["args_split"][0].lower()
|
||||
if setting in settings:
|
||||
if setting in settings_dict:
|
||||
value = " ".join(event["args_split"][1:])
|
||||
value = settings[setting]["validate"](value)
|
||||
value = settings_dict[setting].get("validate",
|
||||
lambda x: x)(value)
|
||||
if not value == None:
|
||||
target.set_setting(setting, value)
|
||||
event["stdout"].write("Saved setting")
|
||||
|
@ -59,12 +45,13 @@ class Module(object):
|
|||
event["stderr"].write("Please provide a value")
|
||||
else:
|
||||
event["stdout"].write("Available settings: %s" % (
|
||||
", ".join(settings.keys())))
|
||||
", ".join(settings_dict.keys())))
|
||||
def set(self, event):
|
||||
self._set(self.settings, event, event["user"])
|
||||
self._set(self.exports.get_all("set"), event, event["user"])
|
||||
|
||||
def channel_set(self, event):
|
||||
self._set(self.channel_settings, event, event["target"])
|
||||
self._set(self.exports.get_all("channelset"), event,
|
||||
event["target"])
|
||||
|
||||
def _get(self, event, setting, qualifier, value):
|
||||
if not value == None:
|
||||
|
|
|
@ -2,7 +2,7 @@ import signal
|
|||
import Config
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
signal.signal(signal.SIGINT, self.SIGINT)
|
||||
|
|
|
@ -9,7 +9,7 @@ REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
|
|||
|
||||
class Module(object):
|
||||
_name = "SoundCloud"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("soundcloud", "sc"
|
||||
).hook(self.soundcloud, help="Search SoundCloud")
|
||||
|
|
|
@ -4,7 +4,7 @@ import Utils
|
|||
URL_SPOTIFY = "https://api.spotify.com/v1/search"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("spotify").hook(
|
||||
self.spotify, help="Search for a track on spotify",
|
||||
min_args=1)
|
||||
|
|
|
@ -2,7 +2,7 @@ import time
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.boot_time = time.time()
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("uptime"
|
||||
|
|
|
@ -2,7 +2,7 @@ import random
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received.command.strax").hook(
|
||||
self.strax, help="Suggests a glorious method of battle for the glory of the Sontaran Empire, through IRC!")
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from threading import Thread
|
|||
class Module(Thread):
|
||||
_name = "telegram"
|
||||
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
key = bot.config.get("telegram-api-key")
|
||||
if not key: return
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ PLATFORM_TYPES = ["Northbound", "Southbound", "Eastbound", "Westbound", "Inner R
|
|||
|
||||
class Module(object):
|
||||
_name = "TFL"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.result_map = {}
|
||||
events.on("received").on("command").on("tflbus"
|
||||
|
|
|
@ -5,7 +5,7 @@ import Utils
|
|||
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("synonym",
|
||||
"antonym").hook(self.thesaurus, min_args=1,
|
||||
|
|
|
@ -4,7 +4,7 @@ import Utils
|
|||
REGEX_URL = re.compile("https?://\S+", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("title", "t").hook(
|
||||
self.title, help="Get the title of the provided or most "
|
||||
"recent URL.", usage="[URL]")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import EventManager
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("message").on("channel"
|
||||
).hook(self.channel_message,
|
||||
priority=EventManager.PRIORITY_MEDIUM)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("todo").hook(
|
||||
self.todo, help="Find out what's in your todo list",
|
||||
|
|
|
@ -6,15 +6,15 @@ URL_TRAKT = "https://api-v2launch.trakt.tv/users/%s/watching"
|
|||
URL_TRAKTSLUG = "https://trakt.tv/%s/%s"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("nowwatching",
|
||||
"nw").hook(self.now_watching,
|
||||
help="Get what you or another user is now watching "
|
||||
"on trakt.tv", usage="[username]")
|
||||
|
||||
events.on("postboot").on("configure").on("set"
|
||||
).assure_call(setting="trakt", help="Set username on trakt.tv")
|
||||
exports.add("set", {"setting": "trakt",
|
||||
"help": "Set username on trakt.tv"})
|
||||
|
||||
def now_watching(self, event):
|
||||
if event["args"]:
|
||||
|
|
|
@ -6,7 +6,7 @@ URL_LANGUAGES = "https://cloud.google.com/translate/docs/languages"
|
|||
REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("translate", "tr").hook(
|
||||
self.translate, help="Translate the provided phrase or the "
|
||||
"last line seen.", usage="[phrase]")
|
||||
|
|
|
@ -11,7 +11,7 @@ REGEX_TWITTERURL = re.compile(
|
|||
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("twitter", "tw"
|
||||
).hook(self.twitter, help="Find a tweet",
|
||||
|
|
|
@ -4,7 +4,7 @@ UPCITEMDB_URL = "https://api.upcitemdb.com/prod/trial/lookup"
|
|||
|
||||
class Module(object):
|
||||
_name = "UPC"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on(
|
||||
"upc", "ean", "gtin").hook(
|
||||
|
|
|
@ -5,7 +5,7 @@ URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
|
|||
REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
events.on("received").on("command").on("urbandictionary", "ud"
|
||||
).hook(self.ud, min_args=1,
|
||||
help="Get the definition of a provided term",
|
||||
|
|
|
@ -5,7 +5,7 @@ import Utils
|
|||
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("weather").hook(
|
||||
self.weather, min_args=1,
|
||||
|
|
|
@ -3,7 +3,7 @@ import Utils
|
|||
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("wiki", "wi"
|
||||
).hook(self.wikipedia, min_args=1)
|
||||
|
|
|
@ -6,7 +6,7 @@ URL_WA = "https://api.wolframalpha.com/v1/result"
|
|||
|
||||
class Module(object):
|
||||
_name = "Wolfram|Alpha"
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("command").on("wolframalpha", "wa"
|
||||
).hook(self.wa, min_args=1, help=
|
||||
|
|
|
@ -2,7 +2,7 @@ import time
|
|||
import Utils
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
events.on("received").on("message").on("channel"
|
||||
).hook(self.channel_message)
|
||||
|
|
|
@ -17,7 +17,7 @@ ARROW_UP = "▲"
|
|||
ARROW_DOWN = "▼"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot, events):
|
||||
def __init__(self, bot, events, exports):
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
events.on("received").on("command").on("yt", "youtube"
|
||||
|
@ -26,11 +26,9 @@ class Module(object):
|
|||
events.on("received").on("message").on("channel").hook(
|
||||
self.channel_message)
|
||||
|
||||
events.on("postboot").on("configure").on(
|
||||
"channelset").assure_call(setting="auto-youtube",
|
||||
help="Disable/Enable automatically getting info from youtube URLs",
|
||||
validate=Utils.bool_or_none)
|
||||
|
||||
exports.add("channelset", {"setting": "auto-youtube",
|
||||
"help": "Disable/Enable automatically getting info from "
|
||||
"youtube URLs", "validate": Utils.bool_or_none})
|
||||
|
||||
def get_video_page(self, video_id, part):
|
||||
return Utils.get_url(URL_YOUTUBEVIDEO, get_params={"part": part,
|
||||
|
|
Loading…
Reference in a new issue