From 6eb8b1ba6d9aaaf7df42f3d705149f02b6a1b871 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 27 Sep 2018 12:08:07 +0100 Subject: Move all exports to @Utils.export calls --- modules/accept_invite.py | 12 +++++------- modules/auto_mode.py | 10 ++++------ modules/channel_op.py | 28 +++++++++++++--------------- modules/check_urls.py | 26 +++++++++++--------------- modules/commands.py | 20 ++++++++------------ modules/ctcp.py | 13 +++++-------- modules/ducks.py | 26 +++++++++++--------------- modules/greeting.py | 10 ++++------ modules/karma.py | 13 +++++-------- modules/lastfm.py | 11 +++-------- modules/nickserv.py | 10 ++++------ modules/sasl.py | 22 ++++++++++------------ modules/sed.py | 20 ++++++++------------ modules/trakt.py | 10 +++------- modules/youtube.py | 15 +++++---------- 15 files changed, 99 insertions(+), 147 deletions(-) (limited to 'modules') diff --git a/modules/accept_invite.py b/modules/accept_invite.py index e9b2add9..b4bbb5ea 100644 --- a/modules/accept_invite.py +++ b/modules/accept_invite.py @@ -1,11 +1,9 @@ -from src import Utils - -class Module(object): - def __init__(self, bot, events, exports): - exports.add("serverset", {"setting": "accept-invites", - "help": "Set whether I accept invites on this server", - "validate": Utils.bool_or_none}) +from src import ModuleManager, Utils +@Utils.export("serverset", {"setting": "accept-invites", + "help": "Set whether I accept invites on this server", + "validate": Utils.bool_or_none}) +class Module(ModuleManager.BaseModule): @Utils.hook("received.invite") def on_invite(self, event): if event["server"].is_own_nickname(event["target_user"].nickname): diff --git a/modules/auto_mode.py b/modules/auto_mode.py index 08648ca3..d1851a58 100644 --- a/modules/auto_mode.py +++ b/modules/auto_mode.py @@ -1,11 +1,9 @@ -from src import Utils +from src import ModuleManager, Utils -class Module(object): +@Utils.export("channelset", {"setting": "automode", + "help": "Disable/Enable automode", "validate": Utils.bool_or_none}) +class Module(ModuleManager.BaseModule): _name = "AutoMode" - def __init__(self, bot, events, exports): - exports.add("channelset", {"setting": "automode", - "help": "Disable/Enable automode", - "validate": Utils.bool_or_none}) def _check_modes(self, channel, user): identified_account = user.get_identified_account() diff --git a/modules/channel_op.py b/modules/channel_op.py index 13f9df5a..81d00075 100644 --- a/modules/channel_op.py +++ b/modules/channel_op.py @@ -1,20 +1,18 @@ -from src import Utils +from src import ModuleManager, Utils -class Module(object): +@Utils.export("channelset", {"setting": "highlight-spam-threshold", + "help": "Set the number of nicknames in a message that qualifies as spam", + "validate": Utils.int_or_none}) +@Utils.export("channelset", {"setting": "highlight-spam-protection", + "help": "Enable/Disable highlight spam protection", + "validate": Utils.bool_or_none}) +@Utils.export("channelset", {"setting": "highlight-spam-ban", + "help": "Enable/Disable banning highlight spammers " + "instead of just kicking", "validate": Utils.bool_or_none}) +@Utils.export("channelset", {"setting": "ban-format", + "help": "Set ban format ($n = nick, $u = username, $h = hostname)"}) +class Module(ModuleManager.BaseModule): _name = "Channel Op" - def __init__(self, bot, events, exports): - 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)"}) @Utils.hook("received.command.kick|k", channel_only=True, require_mode="o", usage=" [reason]", min_args=1) diff --git a/modules/check_urls.py b/modules/check_urls.py index b0438ec8..356fc13b 100644 --- a/modules/check_urls.py +++ b/modules/check_urls.py @@ -1,25 +1,21 @@ #--require-config virustotal-api-key import re -from src import Utils +from src import ModuleManager, Utils 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, exports): - self.bot = bot - self.events = events - exports.add("channelset", {"setting": "check-urls", - "help": "Enable/Disable automatically checking for " - "malicious URLs", "validate": Utils.bool_or_none}) - exports.add("serverset", {"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}) - +@Utils.export("channelset", {"setting": "check-urls", + "help": "Enable/Disable automatically checking for malicious URLs", + "validate": Utils.bool_or_none}) +@Utils.export("serverset", {"setting": "check-urls", + "help": "Enable/Disable automatically checking for malicious URLs", + "validate": Utils.bool_or_none}) +@Utils.export("channelset", {"setting": "check-urls-kick", + "help": "Enable/Disable automatically kicking users that " + "send malicious URLs", "validate": Utils.bool_or_none}) +class Module(ModuleManager.BaseModule): @Utils.hook("received.message.channel") def message(self, event): match = RE_URL.search(event["message"]) diff --git a/modules/commands.py b/modules/commands.py index 3bc2604f..c60876c3 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -1,5 +1,5 @@ import re -from src import EventManager, Utils +from src import EventManager, ModuleManager, Utils STR_MORE = "%s (more...)" % Utils.FONT_RESET STR_CONTINUED = "(...continued) " @@ -43,17 +43,13 @@ class StdErr(Out): def prefix(self): return Utils.color(Utils.bold(self.module_name), Utils.COLOR_RED) -class Module(object): - def __init__(self, bot, events, exports): - self.events = events - - exports.add("channelset", {"setting": "command-prefix", - "help": "Set the command prefix used in this channel"}) - exports.add("serverset", {"setting": "command-prefix", - "help": "Set the command prefix used on this server"}) - exports.add("serverset", {"setting": "identity-mechanism", - "help": "Set the identity mechanism for this server"}) - +@Utils.export("channelset", {"setting": "command-prefix", + "help": "Set the command prefix used in this channel"}) +@Utils.export("serverset", {"setting": "command-prefix", + "help": "Set the command prefix used on this server"}) +@Utils.export("serverset", {"setting": "identity-mechanism", + "help": "Set the identity mechanism for this server"}) +class Module(ModuleManager.BaseModule): @Utils.hook("new.user|channel") def new(self, event): if "user" in event: diff --git a/modules/ctcp.py b/modules/ctcp.py index efb855fb..f720fd3a 100644 --- a/modules/ctcp.py +++ b/modules/ctcp.py @@ -1,13 +1,10 @@ import datetime -from src import Utils - -class Module(object): - def __init__(self, bot, events, exports): - self.bot = bot - exports.add("serverset", {"setting": "ctcp-responses", - "help": "Set whether I respond to CTCPs on this server", - "validate": Utils.bool_or_none}) +from src import ModuleManager, Utils +@Utils.export("serverset", {"setting": "ctcp-responses", + "help": "Set whether I respond to CTCPs on this server", + "validate": Utils.bool_or_none}) +class Module(ModuleManager.BaseModule): @Utils.hook("received.message.private") def private_message(self, event): if event["message"][0] == "\x01" and event["message"][-1] == "\x01": diff --git a/modules/ducks.py b/modules/ducks.py index 56f495c8..84e22942 100644 --- a/modules/ducks.py +++ b/modules/ducks.py @@ -13,24 +13,20 @@ DUCK_MESSAGE_RARE = ["beep boop!", "QUACK QUACK QUACK QUACK QUACK!!", "HONK!", DUCK_MINIMUM_MESSAGES = 10 DUCK_MINIMUM_UNIQUE = 3 - +@Utils.export("channelset", {"setting": "ducks-enabled", + "help": "Toggle ducks!", "validate": Utils.bool_or_none}) +@Utils.export("channelset", {"setting": "ducks-kick", + "help": "Should the bot kick if there's no duck?", + "validate": Utils.bool_or_none}) +@Utils.export("channelset", {"setting": "ducks-min-unique", + "help": "Minimum unique users required to talk before a duck spawns.", + "validate": Utils.int_or_none}) +@Utils.export("channelset", {"setting": "ducks-min-messages", + "help": "Minimum messages between ducks spawning.", + "validate": Utils.int_or_none}) class Module(object): def __init__(self, bot, events, exports): self.bot = bot - exports.add("channelset", {"setting": "ducks-enabled", - "help": "Toggle ducks!", "validate": Utils.bool_or_none}) - - exports.add("channelset", {"setting": "ducks-kick", - "help": "Should the bot kick if there's no duck?", - "validate": Utils.bool_or_none}) - - exports.add("channelset", {"setting": "ducks-min-unique", - "help": "Minimum unique users required to talk before a " - "duck spawns.", "validate": Utils.int_or_none}) - - exports.add("channelset", {"setting": "ducks-min-messages", - "help": "Minimum messages between ducks spawning.", - "validate": Utils.int_or_none}) for server in self.bot.servers.values(): for channel in server.channels.values(): diff --git a/modules/greeting.py b/modules/greeting.py index 4cf8fa22..bfc19fcd 100644 --- a/modules/greeting.py +++ b/modules/greeting.py @@ -1,10 +1,8 @@ -from src import Utils - -class Module(object): - def __init__(self, bot, events, exports): - exports.add("channelset", {"setting": "greeting", - "help": "Set a greeting to send to users when they join"}) +from src import ModuleManager, Utils +@Utils.export("channelset", {"setting": "greeting", + "help": "Set a greeting to send to users when they join"}) +class Module(ModuleManager.BaseModule): @Utils.hook("received.join") def join(self, event): greeting = event["channel"].get_setting("greeting", None) diff --git a/modules/karma.py b/modules/karma.py index 350e32fa..7191a90e 100644 --- a/modules/karma.py +++ b/modules/karma.py @@ -1,16 +1,13 @@ import re, time -from src import EventManager, Utils +from src import EventManager, ModuleManager, Utils REGEX_KARMA = re.compile("^(.*[^-+])[-+]*(\+{2,}|\-{2,})$") KARMA_DELAY_SECONDS = 3 -class Module(object): - def __init__(self, bot, events, exports): - self.events = events - exports.add("channelset", {"setting": "karma-verbose", - "help": "Disable/Enable automatically responding to " - "karma changes", "validate": Utils.bool_or_none}) - +@Utils.export("channelset", {"setting": "karma-verbose", + "help": "Disable/Enable automatically responding to karma changes", + "validate": Utils.bool_or_none}) +class Module(ModuleManager.BaseModule): @Utils.hook("new.user") def new_user(self, event): event["user"].last_karma = None diff --git a/modules/lastfm.py b/modules/lastfm.py index ddeefc6b..d02abd6f 100644 --- a/modules/lastfm.py +++ b/modules/lastfm.py @@ -1,18 +1,13 @@ #--require-config lastfm-api-key from datetime import datetime, timezone -from src import Utils +from src import ModuleManager, Utils URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/" -class Module(object): +@Utils.export("set", {"setting": "lastfm", "help": "Set last.fm username"}) +class Module(ModuleManager.BaseModule): _name = "last.fm" - def __init__(self, bot, events, exports): - self.bot = bot - self.events = events - - exports.add("set", {"setting": "lastfm", - "help": "Set username on last.fm"}) @Utils.hook("received.command.np|listening|nowplaying", usage="[username]") def np(self, event): diff --git a/modules/nickserv.py b/modules/nickserv.py index 8816a26a..2bceba0c 100644 --- a/modules/nickserv.py +++ b/modules/nickserv.py @@ -1,11 +1,9 @@ import base64 -from src import EventManager, Utils - -class Module(object): - def __init__(self, bot, events, exports): - exports.add("serverset", {"setting": "nickserv-password", - "help": "Set the nickserv password for this server"}) +from src import EventManager, ModuleManager, Utils +@Utils.export("serverset", {"setting": "nickserv-password", + "help": "Set the nickserv password for this server"}) +class Module(ModuleManager.BaseModule): @Utils.hook("received.numeric.001", priority=EventManager.PRIORITY_URGENT) def on_connect(self, event): nickserv_password = event["server"].get_setting( diff --git a/modules/sasl.py b/modules/sasl.py index cbebb31e..ebe305b9 100644 --- a/modules/sasl.py +++ b/modules/sasl.py @@ -1,18 +1,16 @@ import base64 -from src import Utils +from src import ModuleManager, Utils -class Module(object): - def __init__(self, bot, events, exports): - exports.add("serverset", {"setting": "sasl", - "help": "Set the sasl username/password for this server", - "validate": self._validate}) - - def _validate(self, s): - mechanism = s - if " " in s: - mechanism, arguments = s.split(" ", 1) - return {"mechanism": mechanism, "args": arguments} +def _validate(self, s): + mechanism = s + if " " in s: + mechanism, arguments = s.split(" ", 1) + return {"mechanism": mechanism, "args": arguments} +@Utils.export("serverset", {"setting": "sasl", + "help": "Set the sasl username/password for this server", + "validate": _validate}) +class Module(ModuleManager.BaseModule): @Utils.hook("received.cap.ls") def on_cap(self, event): has_sasl = "sasl" in event["capabilities"] diff --git a/modules/sed.py b/modules/sed.py index bae45656..f377daf1 100644 --- a/modules/sed.py +++ b/modules/sed.py @@ -1,20 +1,16 @@ import re, traceback -from src import Utils +from src import ModuleManager, Utils REGEX_SPLIT = re.compile("(?