From 10eab70e223d0703f9bcf658fc78661ff8e7738c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 27 Jul 2021 02:29:13 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20premi=C3=A8res=20commandes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/modules/utils.py | 12 ++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/main.py create mode 100644 src/modules/utils.py diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..760d5af --- /dev/null +++ b/src/main.py @@ -0,0 +1,45 @@ +from twitchio.ext import commands +from os import environ, listdir +from dotenv import load_dotenv +from sys import exit + +path = 'todo.txt' + +def load(variables): + """Load env variables""" + keys = {} + load_dotenv() + for var in variables: + try: + keys[var] = environ[var] + except KeyError: + print(f"Please set the environment variable {var} (.env file supported)") + exit(1) + + return keys + +class Bot(commands.Bot): + def __init__(self): + self.keys = load(["ACCESS_TOKEN", "PREFIX"]) + super().__init__(token=self.keys["ACCESS_TOKEN"], prefix=self.keys["PREFIX"], initial_channels=['mylloon']) + + async def event_ready(self): + print(f'Logged in on {self.nick}') + + async def event_message(self, message): + if message.echo: # Messages with echo set to True are messages sent by the bot + return + + # Print the contents of our message to console... + if not message.content.startswith(self.keys["PREFIX"]): + print(f"{message.author.name}: {message.content}") + + await self.handle_commands(message) # Let the bot know we want to handle and invoke our commands + +client = Bot() + +for file in listdir("modules"): + if file.endswith(".py") and file.startswith("-") == False: + client.load_module(f"modules.{file[:-3]}") + +client.run() diff --git a/src/modules/utils.py b/src/modules/utils.py new file mode 100644 index 0000000..a40e152 --- /dev/null +++ b/src/modules/utils.py @@ -0,0 +1,12 @@ +from twitchio.ext import commands + +def prepare(bot: commands.Bot): + bot.add_cog(Utils(bot)) + +class Utils(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command() + async def discord(self, ctx: commands.Context): + await ctx.send(f"Rejoins mon Discord !")