Move all exports to @Utils.export calls

This commit is contained in:
jesopo 2018-09-27 12:08:07 +01:00
parent 8b0314b190
commit 6eb8b1ba6d
15 changed files with 99 additions and 147 deletions

View file

@ -1,11 +1,9 @@
from src import Utils from src import ModuleManager, Utils
class Module(object): @Utils.export("serverset", {"setting": "accept-invites",
def __init__(self, bot, events, exports):
exports.add("serverset", {"setting": "accept-invites",
"help": "Set whether I accept invites on this server", "help": "Set whether I accept invites on this server",
"validate": Utils.bool_or_none}) "validate": Utils.bool_or_none})
class Module(ModuleManager.BaseModule):
@Utils.hook("received.invite") @Utils.hook("received.invite")
def on_invite(self, event): def on_invite(self, event):
if event["server"].is_own_nickname(event["target_user"].nickname): if event["server"].is_own_nickname(event["target_user"].nickname):

View file

@ -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" _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): def _check_modes(self, channel, user):
identified_account = user.get_identified_account() identified_account = user.get_identified_account()

View file

@ -1,20 +1,18 @@
from src import Utils from src import ModuleManager, Utils
class Module(object): @Utils.export("channelset", {"setting": "highlight-spam-threshold",
_name = "Channel Op" "help": "Set the number of nicknames in a message that qualifies as spam",
def __init__(self, bot, events, exports): "validate": Utils.int_or_none})
exports.add("channelset", {"setting": "highlight-spam-threshold", @Utils.export("channelset", {"setting": "highlight-spam-protection",
"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", "help": "Enable/Disable highlight spam protection",
"validate": Utils.bool_or_none}) "validate": Utils.bool_or_none})
exports.add("channelset", {"setting": "highlight-spam-ban", @Utils.export("channelset", {"setting": "highlight-spam-ban",
"help": "Enable/Disable banning highlight spammers " "help": "Enable/Disable banning highlight spammers "
"instead of just kicking", "validate": Utils.bool_or_none}) "instead of just kicking", "validate": Utils.bool_or_none})
exports.add("channelset", {"setting": "ban-format", @Utils.export("channelset", {"setting": "ban-format",
"help": "Set ban format ($n = nick, $u = username, " "help": "Set ban format ($n = nick, $u = username, $h = hostname)"})
"$h = hostname)"}) class Module(ModuleManager.BaseModule):
_name = "Channel Op"
@Utils.hook("received.command.kick|k", channel_only=True, @Utils.hook("received.command.kick|k", channel_only=True,
require_mode="o", usage="<nickname> [reason]", min_args=1) require_mode="o", usage="<nickname> [reason]", min_args=1)

View file

@ -1,25 +1,21 @@
#--require-config virustotal-api-key #--require-config virustotal-api-key
import re import re
from src import Utils from src import ModuleManager, Utils
URL_VIRUSTOTAL = "https://www.virustotal.com/vtapi/v2/url/report" 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): @Utils.export("channelset", {"setting": "check-urls",
def __init__(self, bot, events, exports): "help": "Enable/Disable automatically checking for malicious URLs",
self.bot = bot "validate": Utils.bool_or_none})
self.events = events @Utils.export("serverset", {"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}) @Utils.export("channelset", {"setting": "check-urls-kick",
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 " "help": "Enable/Disable automatically kicking users that "
"send malicious URLs", "validate": Utils.bool_or_none}) "send malicious URLs", "validate": Utils.bool_or_none})
class Module(ModuleManager.BaseModule):
@Utils.hook("received.message.channel") @Utils.hook("received.message.channel")
def message(self, event): def message(self, event):
match = RE_URL.search(event["message"]) match = RE_URL.search(event["message"])

View file

@ -1,5 +1,5 @@
import re import re
from src import EventManager, Utils from src import EventManager, ModuleManager, Utils
STR_MORE = "%s (more...)" % Utils.FONT_RESET STR_MORE = "%s (more...)" % Utils.FONT_RESET
STR_CONTINUED = "(...continued) " STR_CONTINUED = "(...continued) "
@ -43,17 +43,13 @@ class StdErr(Out):
def prefix(self): def prefix(self):
return Utils.color(Utils.bold(self.module_name), Utils.COLOR_RED) return Utils.color(Utils.bold(self.module_name), Utils.COLOR_RED)
class Module(object): @Utils.export("channelset", {"setting": "command-prefix",
def __init__(self, bot, events, exports):
self.events = events
exports.add("channelset", {"setting": "command-prefix",
"help": "Set the command prefix used in this channel"}) "help": "Set the command prefix used in this channel"})
exports.add("serverset", {"setting": "command-prefix", @Utils.export("serverset", {"setting": "command-prefix",
"help": "Set the command prefix used on this server"}) "help": "Set the command prefix used on this server"})
exports.add("serverset", {"setting": "identity-mechanism", @Utils.export("serverset", {"setting": "identity-mechanism",
"help": "Set the identity mechanism for this server"}) "help": "Set the identity mechanism for this server"})
class Module(ModuleManager.BaseModule):
@Utils.hook("new.user|channel") @Utils.hook("new.user|channel")
def new(self, event): def new(self, event):
if "user" in event: if "user" in event:

View file

@ -1,13 +1,10 @@
import datetime import datetime
from src import Utils from src import ModuleManager, Utils
class Module(object): @Utils.export("serverset", {"setting": "ctcp-responses",
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", "help": "Set whether I respond to CTCPs on this server",
"validate": Utils.bool_or_none}) "validate": Utils.bool_or_none})
class Module(ModuleManager.BaseModule):
@Utils.hook("received.message.private") @Utils.hook("received.message.private")
def private_message(self, event): def private_message(self, event):
if event["message"][0] == "\x01" and event["message"][-1] == "\x01": if event["message"][0] == "\x01" and event["message"][-1] == "\x01":

View file

@ -13,24 +13,20 @@ DUCK_MESSAGE_RARE = ["beep boop!", "QUACK QUACK QUACK QUACK QUACK!!", "HONK!",
DUCK_MINIMUM_MESSAGES = 10 DUCK_MINIMUM_MESSAGES = 10
DUCK_MINIMUM_UNIQUE = 3 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): class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot 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 server in self.bot.servers.values():
for channel in server.channels.values(): for channel in server.channels.values():

View file

@ -1,10 +1,8 @@
from src import Utils from src import ModuleManager, Utils
class Module(object): @Utils.export("channelset", {"setting": "greeting",
def __init__(self, bot, events, exports):
exports.add("channelset", {"setting": "greeting",
"help": "Set a greeting to send to users when they join"}) "help": "Set a greeting to send to users when they join"})
class Module(ModuleManager.BaseModule):
@Utils.hook("received.join") @Utils.hook("received.join")
def join(self, event): def join(self, event):
greeting = event["channel"].get_setting("greeting", None) greeting = event["channel"].get_setting("greeting", None)

View file

@ -1,16 +1,13 @@
import re, time import re, time
from src import EventManager, Utils from src import EventManager, ModuleManager, Utils
REGEX_KARMA = re.compile("^(.*[^-+])[-+]*(\+{2,}|\-{2,})$") REGEX_KARMA = re.compile("^(.*[^-+])[-+]*(\+{2,}|\-{2,})$")
KARMA_DELAY_SECONDS = 3 KARMA_DELAY_SECONDS = 3
class Module(object): @Utils.export("channelset", {"setting": "karma-verbose",
def __init__(self, bot, events, exports): "help": "Disable/Enable automatically responding to karma changes",
self.events = events "validate": Utils.bool_or_none})
exports.add("channelset", {"setting": "karma-verbose", class Module(ModuleManager.BaseModule):
"help": "Disable/Enable automatically responding to "
"karma changes", "validate": Utils.bool_or_none})
@Utils.hook("new.user") @Utils.hook("new.user")
def new_user(self, event): def new_user(self, event):
event["user"].last_karma = None event["user"].last_karma = None

View file

@ -1,18 +1,13 @@
#--require-config lastfm-api-key #--require-config lastfm-api-key
from datetime import datetime, timezone from datetime import datetime, timezone
from src import Utils from src import ModuleManager, Utils
URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/" 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" _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]") @Utils.hook("received.command.np|listening|nowplaying", usage="[username]")
def np(self, event): def np(self, event):

View file

@ -1,11 +1,9 @@
import base64 import base64
from src import EventManager, Utils from src import EventManager, ModuleManager, Utils
class Module(object): @Utils.export("serverset", {"setting": "nickserv-password",
def __init__(self, bot, events, exports):
exports.add("serverset", {"setting": "nickserv-password",
"help": "Set the nickserv password for this server"}) "help": "Set the nickserv password for this server"})
class Module(ModuleManager.BaseModule):
@Utils.hook("received.numeric.001", priority=EventManager.PRIORITY_URGENT) @Utils.hook("received.numeric.001", priority=EventManager.PRIORITY_URGENT)
def on_connect(self, event): def on_connect(self, event):
nickserv_password = event["server"].get_setting( nickserv_password = event["server"].get_setting(

View file

@ -1,18 +1,16 @@
import base64 import base64
from src import Utils from src import ModuleManager, Utils
class Module(object): def _validate(self, s):
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 mechanism = s
if " " in s: if " " in s:
mechanism, arguments = s.split(" ", 1) mechanism, arguments = s.split(" ", 1)
return {"mechanism": mechanism, "args": arguments} 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") @Utils.hook("received.cap.ls")
def on_cap(self, event): def on_cap(self, event):
has_sasl = "sasl" in event["capabilities"] has_sasl = "sasl" in event["capabilities"]

View file

@ -1,20 +1,16 @@
import re, traceback import re, traceback
from src import Utils from src import ModuleManager, Utils
REGEX_SPLIT = re.compile("(?<!\\\\)/") REGEX_SPLIT = re.compile("(?<!\\\\)/")
REGEX_SED = re.compile("^s/") REGEX_SED = re.compile("^s/")
class Module(object): @Utils.export("channelset", {"setting": "sed",
def __init__(self, bot, events, exports):
self.events = events
exports.add("channelset", {"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", @Utils.export("channelset", {"setting": "sed-sender-only",
"help": "Disable/Enable sed only looking at the messages " "help": "Disable/Enable sed only looking at the messages sent by the user",
"sent by the user", "validate": Utils.bool_or_none}) "validate": Utils.bool_or_none})
class Module(ModuleManager.BaseModule):
@Utils.hook("received.message.channel") @Utils.hook("received.message.channel")
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)

View file

@ -1,16 +1,12 @@
#--require-config trakt-api-key #--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_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): @Utils.export("set", {"setting": "trakt", "help": "Set username on trakt.tv"})
def __init__(self, bot, events, exports): class Module(ModuleManager.BaseModule):
self.bot = bot
exports.add("set", {"setting": "trakt",
"help": "Set username on trakt.tv"})
@Utils.hook("received.command.nowwatching|nw", usage="[username]") @Utils.hook("received.command.nowwatching|nw", usage="[username]")
def now_watching(self, event): def now_watching(self, event):
""" """

View file

@ -1,7 +1,7 @@
#--require-config google-api-key #--require-config google-api-key
import re import re
from src import Utils from src import ModuleManager, Utils
REGEX_YOUTUBE = re.compile( REGEX_YOUTUBE = re.compile(
"https?://(?:www.)?(?:youtu.be/|youtube.com/watch\?[\S]*v=)([\w\-]{11})", "https?://(?:www.)?(?:youtu.be/|youtube.com/watch\?[\S]*v=)([\w\-]{11})",
@ -16,15 +16,10 @@ URL_YOUTUBESHORT = "https://youtu.be/%s"
ARROW_UP = "" ARROW_UP = ""
ARROW_DOWN = "" ARROW_DOWN = ""
class Module(object): @Utils.export("channelset", {"setting": "auto-youtube",
def __init__(self, bot, events, exports): "help": "Disable/Enable automatically getting info from youtube URLs",
self.bot = bot "validate": Utils.bool_or_none})
self.events = events class Module(ModuleManager.BaseModule):
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): 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,
"id": video_id, "key": self.bot.config["google-api-key"]}, "id": video_id, "key": self.bot.config["google-api-key"]},