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