Ajout premières commandes
This commit is contained in:
parent
9c2012467f
commit
10eab70e22
2 changed files with 57 additions and 0 deletions
45
src/main.py
Normal file
45
src/main.py
Normal file
|
@ -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()
|
12
src/modules/utils.py
Normal file
12
src/modules/utils.py
Normal file
|
@ -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 !")
|
Loading…
Reference in a new issue