Enhance VoiceBot with random phrase generation and presence updates based on selected words
This commit is contained in:
parent
f2464e57f7
commit
1de2ffb2b6
3 changed files with 22757 additions and 4 deletions
22735
assets/mots.txt
Normal file
22735
assets/mots.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -94,9 +94,6 @@ class ChaosBot:
|
|||
|
||||
async def on_ready(self) -> None:
|
||||
logger.info(f"We have logged in as {self.bot.user}")
|
||||
emo = discord.PartialEmoji.from_str("🥑")
|
||||
activity = discord.CustomActivity("Génère du chaos", emoji=emo)
|
||||
await self.bot.change_presence(activity=activity)
|
||||
|
||||
def run(self) -> None:
|
||||
if not isinstance(tk := self.config.get("token"), str):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import pathlib
|
||||
import random
|
||||
|
||||
import discord
|
||||
|
@ -26,6 +27,8 @@ class VoiceBot:
|
|||
self.aibot = aibot
|
||||
self.guild_ids = guild_ids
|
||||
|
||||
self.mots = pathlib.Path("assets/mots.txt").read_text().split("\n")
|
||||
|
||||
def init_events(self) -> None:
|
||||
self.bot.add_listener(self.on_voice_state_update, "on_voice_state_update")
|
||||
self.bot.add_listener(self.shuffle, "on_voice_state_update")
|
||||
|
@ -46,10 +49,25 @@ class VoiceBot:
|
|||
if guild is None:
|
||||
continue
|
||||
|
||||
mot = random.choice(self.mots)
|
||||
if self.aibot is not None:
|
||||
status = self.aibot.answer(
|
||||
f"Dis une phrase aléatoire et originale avec le mot {mot}."
|
||||
)
|
||||
activity = discord.CustomActivity(status)
|
||||
await self.bot.change_presence(activity=activity)
|
||||
|
||||
if random.random() < 50 / 100:
|
||||
logger.info("Random connect.")
|
||||
voice_chan = random.choice(guild.voice_channels)
|
||||
await self.connect_voice(voice_chan)
|
||||
if not voice_chan.status and self.aibot is not None:
|
||||
mot = random.choice(self.mots)
|
||||
await voice_chan.set_status(
|
||||
self.aibot.answer(
|
||||
f"Dis une phrase aléatoire et originale avec le mot {mot}."
|
||||
)
|
||||
)
|
||||
else:
|
||||
logger.info("Random disconnect.")
|
||||
await self.disconnect_voice(guild)
|
||||
|
@ -79,7 +97,10 @@ class VoiceBot:
|
|||
|
||||
script = None
|
||||
if self.aibot is not None and random.random() < 20 / 100:
|
||||
script = self.aibot.answer("Dis un truc aléatoire et original.")
|
||||
mot = random.choice(self.mots)
|
||||
script = self.aibot.answer(
|
||||
f"Dis une phrase aléatoire et originale avec le mot {mot}."
|
||||
)
|
||||
if script is None:
|
||||
script = random.choice(
|
||||
[
|
||||
|
|
Loading…
Add table
Reference in a new issue