mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 06:40:35 +01:00
Resoudre les probleme des 2 thread bloquant
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import random
|
||||
import discord
|
||||
import os
|
||||
# import os
|
||||
import logging
|
||||
import asyncio
|
||||
from database.models import Humeur
|
||||
from webapp import webapp
|
||||
from database.models import Configuration, Humeur
|
||||
|
||||
class DiscordBot(discord.Client):
|
||||
async def on_ready(self):
|
||||
@@ -15,14 +15,20 @@ class DiscordBot(discord.Client):
|
||||
# await self.get_channel(1123512494468644984).send("essai en python")
|
||||
|
||||
async def updateStatus(self):
|
||||
# from database.models import Humeur
|
||||
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)
|
||||
|
||||
def begin(self) :
|
||||
with webapp.app_context():
|
||||
token = Configuration.query.filter_by(key='discord_token').first()
|
||||
if token :
|
||||
self.run(token.value)
|
||||
else :
|
||||
logging.error('pas de token on ne lance pas discord')
|
||||
|
||||
intents = discord.Intents.default()
|
||||
bot = DiscordBot(intents=intents)
|
||||
|
||||
with webapp.app_context():
|
||||
bot.run(os.getenv('TOKEN'))
|
||||
Reference in New Issue
Block a user