From 5fd9c0ca7932a3bbfc8ac9e2383a177f0ae023b7 Mon Sep 17 00:00:00 2001 From: Georgios Atheridis Date: Fri, 25 Mar 2022 08:09:24 +0200 Subject: [PATCH] added an example --- examples/account1/message_interpreter.py | 49 ++++++++++++++++++++++++ examples/account1/scam.py | 6 +++ examples/account1/spam.py | 7 ++++ examples/account1/tools/raid.py | 18 +++++++++ 4 files changed, 80 insertions(+) create mode 100644 examples/account1/message_interpreter.py create mode 100644 examples/account1/scam.py create mode 100644 examples/account1/spam.py create mode 100644 examples/account1/tools/raid.py diff --git a/examples/account1/message_interpreter.py b/examples/account1/message_interpreter.py new file mode 100644 index 0000000..23a3fd0 --- /dev/null +++ b/examples/account1/message_interpreter.py @@ -0,0 +1,49 @@ +from aptbot.bot import Bot, Message, Commands +import os +import importlib +import importlib.util +from importlib import reload +import traceback + +import tools.raid +reload(tools.raid) + + +PATH = os.path.dirname(os.path.realpath(__file__)) + +commands = [ + c for c in os.listdir(PATH) if os.path.isfile(os.path.join(PATH, c)) +] +commands.remove(os.path.split(__file__)[1]) +specs = {} +for command in commands: + if command.split('.')[0]: + specs[command.split('.')[0]] = ( + importlib.util.spec_from_file_location( + f"{command.split('.')[0]}", + os.path.join(PATH, command) + ) + ) + +modules = {} +for command in specs: + modules[command] = importlib.util.module_from_spec(specs[command]) + if specs[command] and specs[command].loader: + try: + specs[command].loader.exec_module(modules[command]) + except Exception as e: + print() + print(traceback.format_exc()) + print(f"Problem Loading Module: {e}") + + +def main(bot: Bot, message: Message): + prefix = '?' + command = message.value.split(' ')[0] + if message.command == Commands.PRIVMSG and command.startswith(prefix): + try: + modules[command[1:]].main(bot, message) + except KeyError: + pass + + tools.raid.raid(bot, message) diff --git a/examples/account1/scam.py b/examples/account1/scam.py new file mode 100644 index 0000000..7988365 --- /dev/null +++ b/examples/account1/scam.py @@ -0,0 +1,6 @@ +from aptbot.bot import Message, Commands, Bot + + +def main(bot: Bot, message: Message): + msg = message.nick + " you have been scammed KEKW" + bot.send_privmsg(message.channel, msg) diff --git a/examples/account1/spam.py b/examples/account1/spam.py new file mode 100644 index 0000000..6c3e49f --- /dev/null +++ b/examples/account1/spam.py @@ -0,0 +1,7 @@ +from aptbot.bot import Message, Commands, Bot + + +def main(bot: Bot, message: Message): + msg = ' '.join(message.value.split(' ')[1:]) + msg = (msg + ' ') * 10 + bot.send_privmsg(message.channel, msg) diff --git a/examples/account1/tools/raid.py b/examples/account1/tools/raid.py new file mode 100644 index 0000000..f16eb16 --- /dev/null +++ b/examples/account1/tools/raid.py @@ -0,0 +1,18 @@ +from aptbot.bot import Bot, Message, Commands + + +def raid(bot: Bot, message: Message): + if message.command == Commands.USERNOTICE: + if message.tags["msg-id"] == "raid": + raider_name = message.tags["msg-param-displayName"] + raider_login = message.tags["msg-param-login"] + raider_id = message.tags["user-id"] + raider_game = "" + if raider_id: + raider_channel_info = "channel info here" + viewers = message.tags["msg-param-viewerCount"] + viewers = f"{viewers} viewer" if viewers == "1" else f"{viewers} viewers" + msg_reply = f"POGGERS {raider_name} has raided {message.channel} with {viewers}!!! Why don\'t you check them out at https://twitch.tv/{raider_login}" + if raider_game: + msg_reply += f' they were just playing {raider_game}.' + bot.send_privmsg(message.channel, msg_reply) -- 2.30.2