diff --git a/discordbot/__init__.py b/discordbot/__init__.py new file mode 100644 index 0000000..ba5f69d --- /dev/null +++ b/discordbot/__init__.py @@ -0,0 +1,28 @@ +import random +import discord +import os +import logging +import asyncio +from database.models import Humeur +from webapp import webapp + +class MyClient(discord.Client): + async def on_ready(self): + logging.info(f'Logged in as {self.user} (ID: {self.user.id})') + for c in self.get_all_channels() : + logging.info(f'{c.id} {c.name}') + self.loop.create_task(self.updateStatus()) + # await self.get_channel(1123512494468644984).send("essai en python") + + async def updateStatus(self): + humeur = random.choice(Humeur.query.all()) + if humeur != None: + logging.info(f'changement de status {humeur.text}') + await self.change_presence(status = discord.Status.online, activity = discord.CustomActivity(humeur.text)) + await asyncio.sleep(60) + +intents = discord.Intents.default() +client = MyClient(intents=intents) + +with webapp.app_context(): + client.run(os.getenv('TOKEN')) \ No newline at end of file diff --git a/run-web.py b/run-web.py index 23874e7..ccd87b9 100644 --- a/run-web.py +++ b/run-web.py @@ -1,4 +1,5 @@ from webapp import webapp +from discordbot import client if __name__ == '__main__': - webapp.run(debug=True) \ No newline at end of file + webapp.run(debug=True) \ No newline at end of file