diff --git a/modules/8ball.py b/modules/8ball.py index 60cdb261..1aa7df12 100644 --- a/modules/8ball.py +++ b/modules/8ball.py @@ -1,5 +1,5 @@ import random -from src import ModuleManager, Utils +from src import ModuleManager, utils CHOICES = [ "Definitely", @@ -19,7 +19,8 @@ CHOICES = [ "It is certain", "Naturally", "Reply hazy, try again later", - Utils.underline(Utils.color("DO NOT WASTE MY TIME", Utils.COLOR_RED)), + utils.irc.underline(utils.irc.color("DO NOT WASTE MY TIME", + utils.irc.COLOR_RED)), "Hmm... Could be!", "I'm leaning towards no", "Without a doubt", @@ -29,11 +30,11 @@ CHOICES = [ ] class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.8ball", min_args=1) + @utils.hook("received.command.8ball", min_args=1) def decide(selfs, event): """ :help: Ask the mystic 8ball a question! :usage: """ event["stdout"].write("You shake the magic ball... it " - "says " + Utils.bold(random.choice(CHOICES))) + "says " + utils.irc.bold(random.choice(CHOICES))) diff --git a/modules/accept_invite.py b/modules/accept_invite.py index b4bbb5ea..73434405 100644 --- a/modules/accept_invite.py +++ b/modules/accept_invite.py @@ -1,10 +1,10 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils -@Utils.export("serverset", {"setting": "accept-invites", +@utils.export("serverset", {"setting": "accept-invites", "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): if event["server"].is_own_nickname(event["target_user"].nickname): if event["server"].get_setting("accept-invites", True): diff --git a/modules/admin.py b/modules/admin.py index ac82dbcb..84ecad14 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -1,7 +1,7 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.changenickname", min_args=1) + @utils.hook("received.command.changenickname", min_args=1) def change_nickname(self, event): """ :help: Change my nickname @@ -11,7 +11,7 @@ class Module(ModuleManager.BaseModule): nickname = event["args_split"][0] event["server"].send_nick(nickname) - @Utils.hook("received.command.raw", min_args=1) + @utils.hook("received.command.raw", min_args=1) def raw(self, event): """ :help: Send a line of raw IRC data @@ -20,7 +20,7 @@ class Module(ModuleManager.BaseModule): """ event["server"].send(event["args"]) - @Utils.hook("received.command.part") + @utils.hook("received.command.part") def part(self, event): """ :help: Part from the current or given channel @@ -35,7 +35,7 @@ class Module(ModuleManager.BaseModule): event["stderr"].write("No channel provided") event["server"].send_part(target) - @Utils.hook("received.command.reconnect") + @utils.hook("received.command.reconnect") def reconnect(self, event): """ :help: Reconnect to the current network diff --git a/modules/auto_mode.py b/modules/auto_mode.py index ae233396..0fc11907 100644 --- a/modules/auto_mode.py +++ b/modules/auto_mode.py @@ -1,7 +1,7 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils -@Utils.export("channelset", {"setting": "automode", - "help": "Disable/Enable automode", "validate": Utils.bool_or_none}) +@utils.export("channelset", {"setting": "automode", + "help": "Disable/Enable automode", "validate": utils.bool_or_none}) class Module(ModuleManager.BaseModule): _name = "AutoMode" @@ -13,10 +13,10 @@ class Module(ModuleManager.BaseModule): channel.send_mode("+%s" % "".join(modes), " ".join([user.nickname for mode in modes])) - @Utils.hook("received.join") + @utils.hook("received.join") def on_join(self, event): self._check_modes(event["channel"], event["user"]) - @Utils.hook("received.account") + @utils.hook("received.account") def on_account(self, event): for channel in event["user"].channels: self._check_modes(channel, event["user"]) @@ -51,7 +51,7 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("Removed automode %s from '%s'" % ( mode_name, target_user.nickname)) - @Utils.hook("received.command.addop", min_args=1, channel_only=True) + @utils.hook("received.command.addop", min_args=1, channel_only=True) def add_op(self, event): """ :help: Add a user to the auto-mode list as an op @@ -59,7 +59,7 @@ class Module(ModuleManager.BaseModule): :require_mode: o """ self._add_mode(event, "o", "op") - @Utils.hook("received.command.removeop", min_args=1, channel_only=True) + @utils.hook("received.command.removeop", min_args=1, channel_only=True) def remove_op(self, event): """ :help: Remove a user from the auto-mode list as an op @@ -68,7 +68,7 @@ class Module(ModuleManager.BaseModule): """ self._remove_mode(event, "o", "op") - @Utils.hook("received.command.addvoice", min_args=1, channel_only=True) + @utils.hook("received.command.addvoice", min_args=1, channel_only=True) def add_voice(self, event): """ :help: Add a user to the auto-mode list as a voice @@ -76,7 +76,7 @@ class Module(ModuleManager.BaseModule): :require_mode: o """ self._add_mode(event, "v", "voice") - @Utils.hook("received.command.removevoice", min_args=1, channel_only=True) + @utils.hook("received.command.removevoice", min_args=1, channel_only=True) def remove_voice(self, event): """ :help: Remove a user from the auto-mode list as a voice diff --git a/modules/bitcoin.py b/modules/bitcoin.py index 07678d68..46c84596 100644 --- a/modules/bitcoin.py +++ b/modules/bitcoin.py @@ -1,16 +1,16 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): _name = "BTC" - @Utils.hook("received.command.btc") + @utils.hook("received.command.btc") def btc(self, event): """ :help: Get the exchange rate of bitcoins :usage: [currency] """ currency = (event["args"] or "USD").upper() - page = Utils.get_url("https://blockchain.info/ticker", + page = utils.http.get_url("https://blockchain.info/ticker", json=True) if page: if currency in page: diff --git a/modules/books.py b/modules/books.py index e3642198..6555c156 100644 --- a/modules/books.py +++ b/modules/books.py @@ -1,5 +1,5 @@ import json, re -from src import ModuleManager, Utils +from src import ModuleManager, utils URL_GOOGLEBOOKS = "https://www.googleapis.com/books/v1/volumes" URL_BOOKINFO = "https://books.google.co.uk/books?id=%s" @@ -9,7 +9,7 @@ class Module(ModuleManager.BaseModule): _name = "ISBN" def get_book(self, query, event): - page = Utils.get_url(URL_GOOGLEBOOKS, get_params={ + page = utils.http.get_url(URL_GOOGLEBOOKS, get_params={ "q": query, "country": "us"}, json=True) if page: if page["totalItems"] > 0: @@ -36,7 +36,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Failed to load results") - @Utils.hook("received.command.isbn", min_args=1) + @utils.hook("received.command.isbn", min_args=1) def isbn(self, event): """ :help: Get book information from a provided ISBN @@ -48,7 +48,7 @@ class Module(ModuleManager.BaseModule): isbn = isbn.replace("-", "") self.get_book("isbn:%s" % isbn, event) - @Utils.hook("received.command.book", min_args=1) + @utils.hook("received.command.book", min_args=1) def book(self, event): """ :help: Get book information from a provided title diff --git a/modules/bot_channel.py b/modules/bot_channel.py index c38f4e6f..2fe4e1fd 100644 --- a/modules/bot_channel.py +++ b/modules/bot_channel.py @@ -1,9 +1,9 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils -@Utils.export("serverset", {"setting": "bot-channel", +@utils.export("serverset", {"setting": "bot-channel", "help": "Set main channel"}) class Module(ModuleManager.BaseModule): - @Utils.hook("received.numeric.001") + @utils.hook("received.numeric.001") def do_join(self, event): event["server"].send_join(event["server"].get_setting("bot-channel", "#bitbot")) diff --git a/modules/channel_op.py b/modules/channel_op.py index 93c8101a..b2c1e3af 100644 --- a/modules/channel_op.py +++ b/modules/channel_op.py @@ -1,25 +1,25 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils class UserNotFoundException(Exception): pass class InvalidTimeoutException(Exception): pass -@Utils.export("channelset", {"setting": "highlight-spam-threshold", +@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", + "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", + "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", + "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" - @Utils.hook("timer.unban") + @utils.hook("timer.unban") def _timer_unban(self, event): server = self.bot.get_server(event["server_id"]) if server.has_channel(event["channel_name"]): @@ -33,7 +33,7 @@ class Module(ModuleManager.BaseModule): else: raise UserNotFoundException("That user is not in this channel") - @Utils.hook("received.command.kick|k", channel_only=True, min_args=1) + @utils.hook("received.command.kick|k", channel_only=True, min_args=1) def kick(self, event): """ :help: Kick a user from the current channel @@ -77,7 +77,7 @@ class Module(ModuleManager.BaseModule): event["target"].send_unban(target) return target - @Utils.hook("received.command.ban", channel_only=True, min_args=1) + @utils.hook("received.command.ban", channel_only=True, min_args=1) def ban(self, event): """ :help: Ban a user/hostmask from the current channel @@ -88,7 +88,7 @@ class Module(ModuleManager.BaseModule): event["args_split"][0]) def _temp_ban(self, event, accept_hostmask): - timeout = Utils.from_pretty_time(event["args_split"][1]) + timeout = utils.from_pretty_time(event["args_split"][1]) if not timeout: raise InvalidTimeoutException( "Please provided a valid time above 0 seconds") @@ -103,7 +103,7 @@ class Module(ModuleManager.BaseModule): self.bot.timers.add_persistent("unban", timeout, server_id=event["server"].id, channel_name=event["target"].name, hostmask=hostmask) - @Utils.hook("received.command.tempban|tb", channel_only=True, min_args=2) + @utils.hook("received.command.tempban|tb", channel_only=True, min_args=2) def temp_ban(self, event): """ :help: Temporarily ban someone from the current channel @@ -115,7 +115,7 @@ class Module(ModuleManager.BaseModule): except InvalidTimeoutException as e: event["stderr"].set_prefix("Tempban") event["stderr"].write(str(e)) - @Utils.hook("received.command.tempkickban|tkb", channel_only=True, + @utils.hook("received.command.tempkickban|tkb", channel_only=True, min_args=2) def temp_kick_ban(self, event): """ @@ -134,7 +134,7 @@ class Module(ModuleManager.BaseModule): except UserNotFoundException as e: event["stderr"].write(str(e)) - @Utils.hook("received.command.unban", channel_only=True, min_args=1) + @utils.hook("received.command.unban", channel_only=True, min_args=1) def unban(self, event): """ :help: Unban a user/hostmask from the current channel @@ -144,7 +144,7 @@ class Module(ModuleManager.BaseModule): self._ban(event["server"], event["target"], False, event["args_split"][0]) - @Utils.hook("received.command.kickban|kb", channel_only=True, min_args=1) + @utils.hook("received.command.kickban|kb", channel_only=True, min_args=1) def kickban(self, event): """ :help: Kick and ban a user from the current channel @@ -160,7 +160,7 @@ class Module(ModuleManager.BaseModule): event["stderr"].set_prefix("Kickban") event["stderr"].write(str(e)) - @Utils.hook("received.command.op", channel_only=True) + @utils.hook("received.command.op", channel_only=True) def op(self, event): """ :help: Op a user in the current channel @@ -170,7 +170,7 @@ class Module(ModuleManager.BaseModule): target = event["user"].nickname if not event["args_split"] else event[ "args_split"][0] event["target"].send_mode("+o", target) - @Utils.hook("received.command.deop", channel_only=True) + @utils.hook("received.command.deop", channel_only=True) def deop(self, event): """ :help: Remove op from a user in the current channel @@ -181,7 +181,7 @@ class Module(ModuleManager.BaseModule): "args_split"][0] event["target"].send_mode("-o", target) - @Utils.hook("received.command.voice", channel_only=True) + @utils.hook("received.command.voice", channel_only=True) def voice(self, event): """ :help: Voice a user in the current channel @@ -191,7 +191,7 @@ class Module(ModuleManager.BaseModule): target = event["user"].nickname if not event["args_split"] else event[ "args_split"][0] event["target"].send_mode("+v", target) - @Utils.hook("received.command.devoice", channel_only=True) + @utils.hook("received.command.devoice", channel_only=True) def devoice(self, event): """ :help: Remove voice from a user in the current channel @@ -202,7 +202,7 @@ class Module(ModuleManager.BaseModule): "args_split"][0] event["target"].send_mode("-v", target) - @Utils.hook("received.command.topic", min_args=1, channel_only=True) + @utils.hook("received.command.topic", min_args=1, channel_only=True) def topic(self, event): """ :help: Set the topic in the current channel @@ -210,7 +210,7 @@ class Module(ModuleManager.BaseModule): :require_mode: o """ event["target"].send_topic(event["args"]) - @Utils.hook("received.command.tappend", min_args=1, channel_only=True) + @utils.hook("received.command.tappend", min_args=1, channel_only=True) def tappend(self, event): """ :help: Append to the topic in the current channel @@ -219,7 +219,7 @@ class Module(ModuleManager.BaseModule): """ event["target"].send_topic(event["target"].topic + event["args"]) - @Utils.hook("received.message.channel") + @utils.hook("received.message.channel") def highlight_spam(self, event): if event["channel"].get_setting("highlight-spam-protection", False): nicknames = list(map(lambda user: user.nickname, @@ -238,7 +238,7 @@ class Module(ModuleManager.BaseModule): event["channel"].send_kick(event["user"].nickname, "highlight spam detected") - @Utils.hook("received.command.leave", channel_only=True) + @utils.hook("received.command.leave", channel_only=True) def leave(self, event): """ :help: Part me from the current channel diff --git a/modules/channel_save.py b/modules/channel_save.py index b352d0a6..3dfd08fb 100644 --- a/modules/channel_save.py +++ b/modules/channel_save.py @@ -1,7 +1,7 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.numeric.001") + @utils.hook("received.numeric.001") def on_connect(self, event): channels = event["server"].get_setting("autojoin", []) chan_keys = event["server"].get_setting("channel_keys", {}) @@ -20,7 +20,7 @@ class Module(ModuleManager.BaseModule): event["server"].send_join( ",".join(channels_sorted), ",".join(keys_sorted)) - @Utils.hook("self.join") + @utils.hook("self.join") def on_join(self, event): channels = event["server"].get_setting("autojoin", []) if not event["channel"].name in channels: @@ -33,10 +33,10 @@ class Module(ModuleManager.BaseModule): channels.remove(channel_name) server.set_setting("autojoin", channels) - @Utils.hook("self.part") + @utils.hook("self.part") def on_part(self, event): self._remove_channel(event["server"], event["channel"].name) - @Utils.hook("self.kick") + @utils.hook("self.kick") def on_kick(self, event): self._remove_channel(event["server"], event["channel"].name) diff --git a/modules/check_mode.py b/modules/check_mode.py index e364a4ab..f4922549 100644 --- a/modules/check_mode.py +++ b/modules/check_mode.py @@ -1,8 +1,8 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): - @Utils.hook("preprocess.command") + @utils.hook("preprocess.command") def preprocess_command(self, event): require_mode = event["hook"].get_kwarg("require_mode") if event["is_channel"] and require_mode: diff --git a/modules/check_urls.py b/modules/check_urls.py index 356fc13b..f63ac902 100644 --- a/modules/check_urls.py +++ b/modules/check_urls.py @@ -1,28 +1,28 @@ #--require-config virustotal-api-key import re -from src import ModuleManager, 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) -@Utils.export("channelset", {"setting": "check-urls", +@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", + "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", + "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}) + "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): match = RE_URL.search(event["message"]) if match and event["channel"].get_setting("check-urls", event["server"].get_setting("check-urls", False)): url = match.group(0) - page = Utils.get_url(URL_VIRUSTOTAL, get_params={ + page = utils.http.get_url(URL_VIRUSTOTAL, get_params={ "apikey": self.bot.config["virustotal-api-key"], "resource": url}, json=True) diff --git a/modules/coins.py b/modules/coins.py index a27755d3..c8012f69 100644 --- a/modules/coins.py +++ b/modules/coins.py @@ -1,5 +1,5 @@ import datetime, decimal, math, random, re, time -from src import Utils +from src import utils SIDES = {"heads": 0, "tails": 1} DEFAULT_REDEEM_DELAY = 600 # 600 seconds, 10 minutes @@ -36,7 +36,7 @@ class Module(object): bot.timers.add("coin-interest", INTEREST_INTERVAL, time.time()+until_next_hour) - @Utils.hook("received.command.coins") + @utils.hook("received.command.coins") def coins(self, event): """ :help: Show how many coins you have @@ -49,7 +49,7 @@ class Module(object): event["stdout"].write("%s has %s coin%s" % (target.nickname, "{0:.2f}".format(coins), "" if coins == 1 else "s")) - @Utils.hook("received.command.resetcoins", min_args=1) + @utils.hook("received.command.resetcoins", min_args=1) def reset_coins(self, event): """ :help: Reset a user's coins to 0 @@ -65,7 +65,7 @@ class Module(object): target.del_setting("coins") event["stdout"].write("Reset coins for %s" % target.nickname) - @Utils.hook("received.command.givecoins", min_args=1) + @utils.hook("received.command.givecoins", min_args=1) def give_coins(self, event): """ :help: Give coins to a user @@ -85,7 +85,7 @@ class Module(object): event["stdout"].write("Gave '%s' %s coins" % (target.nickname, str(coins))) - @Utils.hook("received.command.richest") + @utils.hook("received.command.richest") def richest(self, event): """ :help: Show the top 10 richest users @@ -98,7 +98,7 @@ class Module(object): top_10 = sorted(all_coins.keys()) top_10 = sorted(top_10, key=all_coins.get, reverse=True)[:10] - top_10 = ", ".join("%s (%s)" % (Utils.prevent_highlight( + top_10 = ", ".join("%s (%s)" % (utils.prevent_highlight( event["server"].get_user(nickname).nickname), "{0:.2f}".format( all_coins[nickname])) for nickname in top_10) event["stdout"].write("Richest users: %s" % top_10) @@ -106,7 +106,7 @@ class Module(object): def _redeem_cache(self, server, user): return "redeem|%s|%s@%s" % (server.id, user.username, user.hostname) - @Utils.hook("received.command.redeemcoins") + @utils.hook("received.command.redeemcoins") def redeem_coins(self, event): """ :help: Redeem your free coins @@ -129,12 +129,12 @@ class Module(object): else: time_left = self.bot.cache.until_expiration(cache) event["stderr"].write("Please wait %s before redeeming" % - Utils.to_pretty_time(math.ceil(time_left))) + utils.to_pretty_time(math.ceil(time_left))) else: event["stderr"].write( "You can only redeem coins when you have none") - @Utils.hook("received.command.flip", min_args=2, authenticated=True) + @utils.hook("received.command.flip", min_args=2, authenticated=True) def flip(self, event): """ :help: Bet on a coin flip @@ -178,7 +178,7 @@ class Module(object): event["user"].nickname, side_name, coin_bet_str, "" if coin_bet == 1 else "s")) - @Utils.hook("received.command.sendcoins", min_args=2, authenticated=True) + @utils.hook("received.command.sendcoins", min_args=2, authenticated=True) def send(self, event): """ :help: Send coins to another user @@ -230,7 +230,7 @@ class Module(object): event["user"].nickname, "{0:.2f}".format(send_amount), target_user.nickname)) - @Utils.hook("timer.coin-interest") + @utils.hook("timer.coin-interest") def interest(self, event): for server in self.bot.servers.values(): all_coins = server.get_all_user_settings( @@ -247,7 +247,7 @@ class Module(object): str(coins)) event["timer"].redo() - @Utils.hook("received.command.roulette", min_args=2, authenticated=True) + @utils.hook("received.command.roulette", min_args=2, authenticated=True) def roulette(self, event): """ :help: Spin a roulette wheel diff --git a/modules/commands.py b/modules/commands.py index 7ccd19cf..3660beb7 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -1,7 +1,7 @@ import re -from src import EventManager, ModuleManager, Utils +from src import EventManager, ModuleManager, utils -STR_MORE = "%s (more...)" % Utils.FONT_RESET +STR_MORE = "%s (more...)" % utils.irc.FONT_RESET STR_CONTINUED = "(...continued) " COMMAND_METHOD = "command-method" @@ -41,7 +41,7 @@ class Out(object): if self._msgid: tags["+draft/reply"] = self._msgid - prefix = Utils.FONT_RESET + "[%s] " % self.prefix() + prefix = utils.irc.FONT_RESET + "[%s] " % self.prefix() method = self._get_method() if method == "PRIVMSG": self.target.send_message(text, prefix=prefix, tags=tags) @@ -60,29 +60,31 @@ class Out(object): class StdOut(Out): def prefix(self): - return Utils.color(Utils.bold(self.module_name), Utils.COLOR_GREEN) + return utils.irc.color(utils.irc.bold(self.module_name), + utils.irc.COLOR_GREEN) class StdErr(Out): def prefix(self): - return Utils.color(Utils.bold("!"+self.module_name), Utils.COLOR_RED) + return utils.irc.color(utils.irc.bold("!"+self.module_name), + utils.irc.COLOR_RED) def _command_method_validate(s): if s.upper() in COMMAND_METHODS: return s.upper() -@Utils.export("channelset", {"setting": "command-prefix", +@utils.export("channelset", {"setting": "command-prefix", "help": "Set the command prefix used in this channel"}) -@Utils.export("serverset", {"setting": "command-prefix", +@utils.export("serverset", {"setting": "command-prefix", "help": "Set the command prefix used on this server"}) -@Utils.export("serverset", {"setting": "identity-mechanism", +@utils.export("serverset", {"setting": "identity-mechanism", "help": "Set the identity mechanism for this server"}) -@Utils.export("serverset", {"setting": "command-method", +@utils.export("serverset", {"setting": "command-method", "help": "Set the method used to respond to commands", "validate": _command_method_validate}) -@Utils.export("channelset", {"setting": "command-method", +@utils.export("channelset", {"setting": "command-method", "help": "Set the method used to respond to commands", "validate": _command_method_validate}) class Module(ModuleManager.BaseModule): - @Utils.hook("new.user|channel") + @utils.hook("new.user|channel") def new(self, event): if "user" in event: target = event["user"] @@ -165,7 +167,7 @@ class Module(ModuleManager.BaseModule): target.buffer.skip_next() event.eat() - @Utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW) + @utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW) def channel_message(self, event): command_prefix = event["channel"].get_setting("command-prefix", event["server"].get_setting("command-prefix", "!")) @@ -178,7 +180,7 @@ class Module(ModuleManager.BaseModule): command = event["message_split"][1].lower() self.message(event, command, 2) - @Utils.hook("received.message.private", priority=EventManager.PRIORITY_LOW) + @utils.hook("received.message.private", priority=EventManager.PRIORITY_LOW) def private_message(self, event): if event["message_split"]: command = event["message_split"][0].lower() @@ -189,7 +191,7 @@ class Module(ModuleManager.BaseModule): def _get_usage(self, hook): return hook.get_kwarg("usage", None) - @Utils.hook("received.command.help") + @utils.hook("received.command.help") def help(self, event): """ :help: Show help for a given command @@ -218,7 +220,7 @@ class Module(ModuleManager.BaseModule): help_available = sorted(help_available) event["stdout"].write("Commands: %s" % ", ".join(help_available)) - @Utils.hook("received.command.usage", min_args=1) + @utils.hook("received.command.usage", min_args=1) def usage(self, event): """ :help: Show the usage for a given command @@ -243,7 +245,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Unknown command '%s'" % command) - @Utils.hook("received.command.more", skip_out=True) + @utils.hook("received.command.more", skip_out=True) def more(self, event): """ :help: Show more output from the last command @@ -251,7 +253,7 @@ class Module(ModuleManager.BaseModule): if event["target"].last_stdout and event["target"].last_stdout.has_text(): event["target"].last_stdout.send() - @Utils.hook("received.command.ignore", min_args=1) + @utils.hook("received.command.ignore", min_args=1) def ignore(self, event): """ :help: Ignore commands from a given user @@ -266,7 +268,7 @@ class Module(ModuleManager.BaseModule): user.set_setting("ignore", True) event["stdout"].write("Now ignoring '%s'" % user.nickname) - @Utils.hook("received.command.unignore", min_args=1) + @utils.hook("received.command.unignore", min_args=1) def unignore(self, event): """ :help: Unignore commands from a given user @@ -280,14 +282,14 @@ class Module(ModuleManager.BaseModule): user.set_setting("ignore", False) event["stdout"].write("Removed ignore for '%s'" % user.nickname) - @Utils.hook("send.stdout") + @utils.hook("send.stdout") def send_stdout(self, event): stdout = StdOut(event["server"], event["module_name"], event["target"], event.get("msgid", None)) stdout.write(event["message"]).send() if stdout.has_text(): event["target"].last_stdout = stdout - @Utils.hook("send.stderr") + @utils.hook("send.stderr") def send_stderr(self, event): stderr = StdErr(event["server"], event["module_name"], event["target"], event.get("msgid", None)) diff --git a/modules/ctcp.py b/modules/ctcp.py index f720fd3a..f165b03d 100644 --- a/modules/ctcp.py +++ b/modules/ctcp.py @@ -1,11 +1,11 @@ import datetime -from src import ModuleManager, Utils +from src import ModuleManager, utils -@Utils.export("serverset", {"setting": "ctcp-responses", +@utils.export("serverset", {"setting": "ctcp-responses", "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): if event["message"][0] == "\x01" and event["message"][-1] == "\x01": if event["server"].get_setting("ctcp-responses", True): diff --git a/modules/database_backup.py b/modules/database_backup.py index ab8dc194..4f7e6395 100644 --- a/modules/database_backup.py +++ b/modules/database_backup.py @@ -1,5 +1,5 @@ import datetime, glob, os, shutil, time -from src import Utils +from src import utils BACKUP_INTERVAL = 60*60 # 1 hour BACKUP_COUNT = 5 @@ -14,7 +14,7 @@ class Module(object): bot.timers.add("database-backup", BACKUP_INTERVAL, time.time()+until_next_hour) - @Utils.hook("timer.database-backup") + @utils.hook("timer.database-backup") def backup(self, event): location = self.bot.database.location files = glob.glob("%s.*" % location) diff --git a/modules/define.py b/modules/define.py index dbd1e420..f0d696d0 100644 --- a/modules/define.py +++ b/modules/define.py @@ -1,7 +1,7 @@ #--require-config wordnik-api-key import time -from src import ModuleManager, Utils +from src import ModuleManager, utils URL_WORDNIK = "https://api.wordnik.com/v4/word.json/%s/definitions" URL_WORDNIK_RANDOM = "https://api.wordnik.com/v4/words.json/randomWord" @@ -12,14 +12,14 @@ class Module(ModuleManager.BaseModule): _last_called = 0 def _get_definition(self, word): - page = Utils.get_url(URL_WORDNIK % word, get_params={ + page = utils.http.get_url(URL_WORDNIK % word, get_params={ "useCanonical": "true", "limit": 1, "sourceDictionaries": "wiktionary", "api_key": self.bot.config[ "wordnik-api-key"]}, json=True) return page - @Utils.hook("received.command.define") + @utils.hook("received.command.define") def define(self, event): """ :help: Define a provided term @@ -40,7 +40,7 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Failed to load results") - @Utils.hook("received.command.randomword") + @utils.hook("received.command.randomword") def random_word(self, event): """ :help: Define a random word @@ -49,7 +49,7 @@ class Module(ModuleManager.BaseModule): RANDOM_DELAY_SECONDS): self._last_called = time.time() - page = Utils.get_url(URL_WORDNIK_RANDOM, get_params={ + page = utils.http.get_url(URL_WORDNIK_RANDOM, get_params={ "api_key":self.bot.config["wordnik-api-key"], "min_dictionary_count":1},json=True) if page and len(page): diff --git a/modules/dice.py b/modules/dice.py index ee93f570..26adca3e 100644 --- a/modules/dice.py +++ b/modules/dice.py @@ -1,10 +1,10 @@ import random -from src import ModuleManager, Utils +from src import ModuleManager, utils ERROR_FORMAT = "Incorrect format! Format must be [number]d[number], e.g. 1d20" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.roll", min_args=1) + @utils.hook("received.command.roll", min_args=1) def roll_dice(self, event): """ :help: Roll some dice, DND style! @@ -35,6 +35,5 @@ class Module(ModuleManager.BaseModule): total = sum(results) results = ', '.join(map(str, results)) - event["stdout"].write("Rolled " + Utils.bold(str_roll) + " for a total " - + "of " + Utils.bold(str(total)) - + ": " + results) + event["stdout"].write("Rolled %s for a total of %d: %s" % ( + str_roll, str(total), results)) diff --git a/modules/dns.py b/modules/dns.py index aa00b870..65f357e0 100644 --- a/modules/dns.py +++ b/modules/dns.py @@ -1,10 +1,10 @@ import socket -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): _name = "DNS" - @Utils.hook("received.command.dns", min_args=1) + @utils.hook("received.command.dns", min_args=1) def dns(self, event): """ :help: Get all addresses for a given hostname (IPv4/IPv6) diff --git a/modules/ducks.py b/modules/ducks.py index 296f6430..25b3c718 100644 --- a/modules/ducks.py +++ b/modules/ducks.py @@ -1,29 +1,29 @@ import random from operator import itemgetter from time import time -from src import EventManager, Utils +from src import EventManager, utils DUCK_TAIL = "・゜゜・。。・゜゜" DUCK_HEAD = ["\_o< ", "\_O< ", "\_0< ", "\_\u00f6< ", "\_\u00f8< ", "\_\u00f3< "] DUCK_MESSAGE = ["QUACK!", "FLAP FLAP!", "quack!", "squawk!"] DUCK_MESSAGE_RARE = ["beep boop!", "QUACK QUACK QUACK QUACK QUACK!!", "HONK!", - Utils.underline("I AM THE METAL DUCK")] + utils.irc.underline("I AM THE METAL DUCK")] 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", +@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", + "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", + "validate": utils.int_or_none}) +@utils.export("channelset", {"setting": "ducks-min-messages", "help": "Minimum messages between ducks spawning.", - "validate": Utils.int_or_none}) + "validate": utils.int_or_none}) class Module(object): def __init__(self, bot, events, exports): self.bot = bot @@ -32,7 +32,7 @@ class Module(object): for channel in server.channels.values(): self.bootstrap(channel) - @Utils.hook("new.channel") + @utils.hook("new.channel") def new_channel(self, event): self.bootstrap(event["channel"]) @@ -116,7 +116,7 @@ class Module(object): channel.send_kick(target, "You tried shooting a non-existent duck. Creepy!") - @Utils.hook("received.command.decoy") + @utils.hook("received.command.decoy") def duck_decoy(self, event): """ :help: Prepare a decoy duck @@ -175,7 +175,8 @@ class Module(object): if random.randint(1, 20) == 1: # rare! message = random.choice(DUCK_MESSAGE_RARE) - duck = Utils.color(Utils.bold(duck + message), Utils.COLOR_RED) + duck = utils.irc.color(utils.irc.bold(duck + message), + utils.irc.COLOR_RED) else: # not rare! duck += random.choice(DUCK_MESSAGE) @@ -191,7 +192,7 @@ class Module(object): else: game["duck_spawned"] = 1 - @Utils.hook("received.message.channel", + @utils.hook("received.message.channel", priority=EventManager.PRIORITY_MONITOR) def channel_message(self, event): if not event["channel"].get_setting("ducks-enabled", False): @@ -222,7 +223,7 @@ class Module(object): if self.should_generate_duck(event) == True: self.show_duck(event) - @Utils.hook("received.command.bef") + @utils.hook("received.command.bef") def befriend(self, event): """ :help: Befriend a duck @@ -252,15 +253,15 @@ class Module(object): channel.set_user_setting(uid, "ducks-befriended", total_befriended) msg = "Aww! %s befriended a duck! You've befriended %s ducks in %s!" \ - % (Utils.bold(nick), Utils.bold(total_befriended), - Utils.bold(channel.name)) + % (utils.irc.bold(nick), utils.irc.bold(total_befriended), + utils.irc.bold(channel.name)) event["stdout"].write(msg) self.clear_ducks(channel) event.eat() - @Utils.hook("received.command.bang") + @utils.hook("received.command.bang") def shoot(self, event): """ :help: Shoot a duck @@ -291,15 +292,15 @@ class Module(object): channel.set_user_setting(uid, "ducks-shot", total_shot) msg = "Pow! %s shot a duck! You've shot %s ducks in %s!" \ - % (Utils.bold(nick), Utils.bold(total_shot), - Utils.bold(channel.name)) + % (utils.irc.bold(nick), utils.irc.bold(total_shot), + utils.irc.bold(channel.name)) event["stdout"].write(msg) self.clear_ducks(channel) event.eat() - @Utils.hook("received.command.duckstats") + @utils.hook("received.command.duckstats") def duck_stats(self, event): """ :help: Show your duck stats @@ -338,13 +339,13 @@ class Module(object): cf = channel_friends msg = "%s ducks killed (%s in %s), and %s ducks befriended (%s in %s)" \ - % (Utils.bold(tp), Utils.bold(cp), Utils.bold(channel), - Utils.bold(tf), Utils.bold(cf), Utils.bold(channel)) + % (utils.irc.bold(tp), utils.irc.bold(cp), utils.irc.bold(channel), + utils.irc.bold(tf), utils.irc.bold(cf), utils.irc.bold(channel)) - event["stdout"].write(Utils.bold(nick) + ": " + msg) + event["stdout"].write(utils.irc.bold(nick) + ": " + msg) event.eat() - @Utils.hook("received.command.killers") + @utils.hook("received.command.killers") def duck_enemies(self, event): """ :help: Show the top duck shooters @@ -366,15 +367,15 @@ class Module(object): enemy_nicks.append(user) enemy_ducks.append(enemies) - sentence = Utils.bold("Duck Wranglers: ") + sentence = utils.irc.bold("Duck Wranglers: ") build = [] length = len(enemy_nicks) if len(enemy_nicks) < 8 else 8 for i in range(0, length): - nick = Utils.prevent_highlight(enemy_nicks[i]) + nick = utils.prevent_highlight(enemy_nicks[i]) build.append("%s (%s)" \ - % (Utils.bold(nick), + % (utils.irc.bold(nick), enemy_ducks[i])) sentence += ", ".join(build) @@ -382,7 +383,7 @@ class Module(object): event["stdout"].write(sentence) event.eat() - @Utils.hook("received.command.friends") + @utils.hook("received.command.friends") def duck_friends(self, event): """ :help: Show the top duck friends @@ -405,15 +406,15 @@ class Module(object): friend_nicks.append(user) friend_ducks.append(friends) - sentence = Utils.bold("Duck Friends: ") + sentence = utils.irc.bold("Duck Friends: ") length = len(friend_nicks) if len(friend_nicks) < 8 else 8 build = [] for i in range(0, length): - nick = Utils.prevent_highlight(friend_nicks[i]) + nick = utils.prevent_highlight(friend_nicks[i]) build.append("%s (%s)" \ - % (Utils.bold(nick), + % (utils.irc.bold(nick), friend_ducks[i]) ) diff --git a/modules/eval.py b/modules/eval.py index 72131f70..7e79311b 100644 --- a/modules/eval.py +++ b/modules/eval.py @@ -1,17 +1,17 @@ import socket -from src import ModuleManager, Utils +from src import ModuleManager, utils EVAL_URL = "https://eval.appspot.com/eval" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.eval", min_args=1) + @utils.hook("received.command.eval", min_args=1) def eval(self, event): """ :help: Evaluate a python statement :usage: """ try: - code, page = Utils.get_url(EVAL_URL, get_params={ + code, page = utils.http.get_url(EVAL_URL, get_params={ "statement": event["args"]}, code=True) except socket.timeout: event["stderr"].write("%s: eval timed out" % diff --git a/modules/geoip.py b/modules/geoip.py index 38cc6043..fed27083 100644 --- a/modules/geoip.py +++ b/modules/geoip.py @@ -1,17 +1,17 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils URL_GEOIP = "http://ip-api.com/json/%s" class Module(ModuleManager.BaseModule): _name = "GeoIP" - @Utils.hook("received.command.geoip", min_args=1) + @utils.hook("received.command.geoip", min_args=1) def geoip(self, event): """ :help: Get geoip data on a given IPv4/IPv6 address :usage: """ - page = Utils.get_url(URL_GEOIP % event["args_split"][0], + page = utils.http.get_url(URL_GEOIP % event["args_split"][0], json=True) if page: if page["status"] == "success": diff --git a/modules/google.py b/modules/google.py index e30e6cda..33dee523 100644 --- a/modules/google.py +++ b/modules/google.py @@ -2,13 +2,13 @@ #--require-config google-search-id import json -from src import ModuleManager, Utils +from src import ModuleManager, utils URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1" URL_GOOGLESUGGEST = "http://google.com/complete/search" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.google|g") + @utils.hook("received.command.google|g") def google(self, event): """ :help: Get first Google result for a given search term @@ -16,15 +16,15 @@ class Module(ModuleManager.BaseModule): """ phrase = event["args"] or event["target"].buffer.get() if phrase: - page = Utils.get_url(URL_GOOGLESEARCH, get_params={ + page = utils.http.get_url(URL_GOOGLESEARCH, get_params={ "q": phrase, "key": self.bot.config[ "google-api-key"], "cx": self.bot.config[ "google-search-id"], "prettyPrint": "true", "num": 1, "gl": "gb"}, json=True) if page: if "items" in page and len(page["items"]): - event["stdout"].write("(" + Utils.bold(phrase) + ") " \ - + page["items"][0]["link"]) + event["stdout"].write( + "(%s) %s" % (phrase, page["items"][0]["link"])) else: event["stderr"].write("No results found") else: @@ -32,21 +32,21 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No phrase provided") - @Utils.hook("received.command.suggest", usage="[phrase]") + @utils.hook("received.command.suggest", usage="[phrase]") def suggest(self, event): """ Get suggested phrases from Google """ phrase = event["args"] or event["target"].buffer.get() if phrase: - page = Utils.get_url(URL_GOOGLESUGGEST, get_params={ + page = utils.html.get_url(URL_GOOGLESUGGEST, get_params={ "output": "json", "client": "hp", "q": phrase}) if page: # google gives us jsonp, so we need to unwrap it. page = page.split("(", 1)[1][:-1] page = json.loads(page) suggestions = page[1] - suggestions = [Utils.strip_html(s[0]) for s in suggestions] + suggestions = [utils.html.strip_html(s[0]) for s in suggestions] if suggestions: event["stdout"].write("%s: %s" % (phrase, diff --git a/modules/greeting.py b/modules/greeting.py index bfc19fcd..2ac9660a 100644 --- a/modules/greeting.py +++ b/modules/greeting.py @@ -1,9 +1,9 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils -@Utils.export("channelset", {"setting": "greeting", +@utils.export("channelset", {"setting": "greeting", "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): greeting = event["channel"].get_setting("greeting", None) if greeting: diff --git a/modules/hash.py b/modules/hash.py index 04b2f99c..ba206105 100644 --- a/modules/hash.py +++ b/modules/hash.py @@ -1,8 +1,8 @@ import hashlib -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.hash", min_args=2) + @utils.hook("received.command.hash", min_args=2) def hash(self, event): """ :help: Hash a given string with a given algorithm diff --git a/modules/haveibeenpwned.py b/modules/haveibeenpwned.py index 62566823..3812dd58 100644 --- a/modules/haveibeenpwned.py +++ b/modules/haveibeenpwned.py @@ -1,18 +1,18 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s" URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.beenpwned", min_args=1) + @utils.hook("received.command.beenpwned", min_args=1) def beenpwned(self, event): """ :help: Find out if a username, email or similar has appeared in any hacked databases :usage: """ - page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True, - code=True) + page = utils.http.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], + json=True, code=True) if page: code, page = page if code == 200: diff --git a/modules/ids.py b/modules/ids.py index 8a71c7f5..59d1ca93 100644 --- a/modules/ids.py +++ b/modules/ids.py @@ -1,9 +1,9 @@ -from src import ModuleManager, Utils +from src import ModuleManager, utils class Module(ModuleManager.BaseModule): _name = "IDs" - @Utils.hook("received.command.myid") + @utils.hook("received.command.myid") def my_id(self, event): """ :help: Show your user ID @@ -11,7 +11,7 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("%s: %d" % (event["user"].nickname, event["user"].get_id())) - @Utils.hook("received.command.channelid", channel_only=True) + @utils.hook("received.command.channelid", channel_only=True) def channel_id(self, event): """ :help: Show the current channel's ID diff --git a/modules/imdb.py b/modules/imdb.py index a584a9e4..667a26f2 100644 --- a/modules/imdb.py +++ b/modules/imdb.py @@ -1,7 +1,7 @@ #--require-config omdbapi-api-key import json -from src import ModuleManager, Utils +from src import ModuleManager, utils URL_OMDB = "http://www.omdbapi.com/" URL_IMDBTITLE = "http://imdb.com/title/%s" @@ -9,13 +9,13 @@ URL_IMDBTITLE = "http://imdb.com/title/%s" class Module(ModuleManager.BaseModule): _name = "IMDb" - @Utils.hook("received.command.imdb", min_args=1) + @utils.hook("received.command.imdb", min_args=1) def imdb(self, event): """ :help: Search for a given title on IMDb :usage: """ - page = Utils.get_url(URL_OMDB, get_params={ + page = utils.http.get_url(URL_OMDB, get_params={ "t": event["args"], "apikey": self.bot.config["omdbapi-api-key"]}, json=True) diff --git a/modules/in.py b/modules/in.py index f237bee6..3a5ec19a 100644 --- a/modules/in.py +++ b/modules/in.py @@ -1,17 +1,17 @@ import time -from src import ModuleManager, Utils +from src import ModuleManager, utils -SECONDS_MAX = Utils.SECONDS_WEEKS*8 +SECONDS_MAX = utils.SECONDS_WEEKS*8 SECONDS_MAX_DESCRIPTION = "8 weeks" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.in", min_args=2) + @utils.hook("received.command.in", min_args=2) def in_command(self, event): """ :help: Set a reminder :usage: