aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-27 12:08:07 +0100
committerGravatar jesopo2018-09-27 12:08:07 +0100
commit6eb8b1ba6d9aaaf7df42f3d705149f02b6a1b871 (patch)
treeece91b1c4d871d5d2b9a3f6319598e33aa13f93f /modules
parentUse ModuleManager.BaseModule in more modules (diff)
signature
Move all exports to @Utils.export calls
Diffstat (limited to 'modules')
-rw-r--r--modules/accept_invite.py12
-rw-r--r--modules/auto_mode.py10
-rw-r--r--modules/channel_op.py28
-rw-r--r--modules/check_urls.py26
-rw-r--r--modules/commands.py20
-rw-r--r--modules/ctcp.py13
-rw-r--r--modules/ducks.py26
-rw-r--r--modules/greeting.py10
-rw-r--r--modules/karma.py13
-rw-r--r--modules/lastfm.py11
-rw-r--r--modules/nickserv.py10
-rw-r--r--modules/sasl.py22
-rw-r--r--modules/sed.py20
-rw-r--r--modules/trakt.py10
-rw-r--r--modules/youtube.py15
15 files changed, 99 insertions, 147 deletions
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="<nickname> [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("(?<!\\\\)/")
REGEX_SED = re.compile("^s/")
-class Module(object):
- def __init__(self, bot, events, exports):
- self.events = events
-
- 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})
-
+@Utils.export("channelset", {"setting": "sed",
+ "help": "Disable/Enable sed in a channel",
+ "validate": Utils.bool_or_none})
+@Utils.export("channelset", {"setting": "sed-sender-only",
+ "help": "Disable/Enable sed only looking at the messages sent by the user",
+ "validate": Utils.bool_or_none})
+class Module(ModuleManager.BaseModule):
@Utils.hook("received.message.channel")
def channel_message(self, event):
sed_split = re.split(REGEX_SPLIT, event["message"], 3)
diff --git a/modules/trakt.py b/modules/trakt.py
index 81f9f00d..a902e9c1 100644
--- a/modules/trakt.py
+++ b/modules/trakt.py
@@ -1,16 +1,12 @@
#--require-config trakt-api-key
-from src import Utils
+from src import ModuleManager, Utils
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, exports):
- self.bot = bot
- exports.add("set", {"setting": "trakt",
- "help": "Set username on trakt.tv"})
-
+@Utils.export("set", {"setting": "trakt", "help": "Set username on trakt.tv"})
+class Module(ModuleManager.BaseModule):
@Utils.hook("received.command.nowwatching|nw", usage="[username]")
def now_watching(self, event):
"""
diff --git a/modules/youtube.py b/modules/youtube.py
index 10766c9c..9f5bdc77 100644
--- a/modules/youtube.py
+++ b/modules/youtube.py
@@ -1,7 +1,7 @@
#--require-config google-api-key
import re
-from src import Utils
+from src import ModuleManager, Utils
REGEX_YOUTUBE = re.compile(
"https?://(?:www.)?(?:youtu.be/|youtube.com/watch\?[\S]*v=)([\w\-]{11})",
@@ -16,15 +16,10 @@ URL_YOUTUBESHORT = "https://youtu.be/%s"
ARROW_UP = "▲"
ARROW_DOWN = "▼"
-class Module(object):
- def __init__(self, bot, events, exports):
- self.bot = bot
- self.events = events
-
- exports.add("channelset", {"setting": "auto-youtube",
- "help": "Disable/Enable automatically getting info from "
- "youtube URLs", "validate": Utils.bool_or_none})
-
+@Utils.export("channelset", {"setting": "auto-youtube",
+ "help": "Disable/Enable automatically getting info from youtube URLs",
+ "validate": Utils.bool_or_none})
+class Module(ModuleManager.BaseModule):
def get_video_page(self, video_id, part):
return Utils.get_url(URL_YOUTUBEVIDEO, get_params={"part": part,
"id": video_id, "key": self.bot.config["google-api-key"]},