Add logging
This commit is contained in:
parent
dafbabe0b8
commit
db695b0805
1 changed files with 43 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
import pickle
|
import pickle
|
||||||
import random
|
import random
|
||||||
import tomllib
|
import tomllib
|
||||||
|
@ -9,6 +10,9 @@ from .ai import AIBot
|
||||||
|
|
||||||
description = """BotBotBot"""
|
description = """BotBotBot"""
|
||||||
|
|
||||||
|
logger = logging.getLogger("botbotbot")
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
with open("config.toml", "rb") as config_file:
|
with open("config.toml", "rb") as config_file:
|
||||||
config = tomllib.load(config_file)
|
config = tomllib.load(config_file)
|
||||||
|
|
||||||
|
@ -24,7 +28,7 @@ Ta réponse doit être une seule phrase.
|
||||||
TA RÉPONSE DOIT ÊTRE EN FRANÇAIS !!!"""
|
TA RÉPONSE DOIT ÊTRE EN FRANÇAIS !!!"""
|
||||||
aibot = AIBot(
|
aibot = AIBot(
|
||||||
config.get("mistral_api_key"),
|
config.get("mistral_api_key"),
|
||||||
model="open-mixtral-8x7b",
|
model="open-mixtral-8x22b",
|
||||||
system_message=system_prompt,
|
system_message=system_prompt,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,10 +46,11 @@ shuffle_tasks = set()
|
||||||
|
|
||||||
@bot.listen("on_ready")
|
@bot.listen("on_ready")
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f"We have logged in as {bot.user}")
|
logger.info(f"We have logged in as {bot.user}")
|
||||||
|
|
||||||
|
|
||||||
async def reply(message):
|
async def reply(message):
|
||||||
|
logger.info(f"Reply to {message.author}")
|
||||||
mention = random.choices(
|
mention = random.choices(
|
||||||
[f"<@{message.author.id}>", "@everyone", "@here"], weights=(98, 1, 1)
|
[f"<@{message.author.id}>", "@everyone", "@here"], weights=(98, 1, 1)
|
||||||
)[0]
|
)[0]
|
||||||
|
@ -61,7 +66,7 @@ async def reply(message):
|
||||||
|
|
||||||
|
|
||||||
async def ai_reply(message):
|
async def ai_reply(message):
|
||||||
print("Running AI")
|
logger.info(f"AI Reply to {message.author}")
|
||||||
prompt = message.clean_content
|
prompt = message.clean_content
|
||||||
if prompt == "" and message.embeds:
|
if prompt == "" and message.embeds:
|
||||||
prompt = message.embeds[0].description
|
prompt = message.embeds[0].description
|
||||||
|
@ -86,6 +91,7 @@ async def on_message(message):
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.author != bot.user and bot.user in message.mentions:
|
if message.author != bot.user and bot.user in message.mentions:
|
||||||
|
logger.info(f"{message.author} metion")
|
||||||
await random.choice((reply, react))(message)
|
await random.choice((reply, react))(message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -101,38 +107,45 @@ async def on_message(message):
|
||||||
@bot.listen("on_reaction_add")
|
@bot.listen("on_reaction_add")
|
||||||
async def add_more_reaction(reaction, user):
|
async def add_more_reaction(reaction, user):
|
||||||
if random.random() < 50 / 100:
|
if random.random() < 50 / 100:
|
||||||
|
logger.info(f"Copy reaction from {user}")
|
||||||
await reaction.message.add_reaction(reaction.emoji)
|
await reaction.message.add_reaction(reaction.emoji)
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_message_edit")
|
@bot.listen("on_message_edit")
|
||||||
async def react_message_edit(before, after):
|
async def react_message_edit(before, after):
|
||||||
if after.author != bot.user and random.random() < 50 / 100:
|
if after.author != bot.user and random.random() < 50 / 100:
|
||||||
|
logger.info(f"React to edit from {after.author}")
|
||||||
await after.add_reaction("👀")
|
await after.add_reaction("👀")
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_message")
|
@bot.listen("on_message")
|
||||||
async def rando_shuffle(message):
|
async def rando_shuffle(message):
|
||||||
if not message.flags.ephemeral and random.random() < 5 / 100 and message.guild:
|
if not message.flags.ephemeral and random.random() < 5 / 100 and message.guild:
|
||||||
|
logger.info(f"Message shuffle after message from {message.author}")
|
||||||
await try_shuffle(message.guild)
|
await try_shuffle(message.guild)
|
||||||
|
|
||||||
|
|
||||||
def save_wordlist():
|
def save_wordlist():
|
||||||
|
logger.info("Saving updated wordlist")
|
||||||
with open("wordlist.pickle", "wb") as word_file:
|
with open("wordlist.pickle", "wb") as word_file:
|
||||||
pickle.dump(word_list, word_file)
|
pickle.dump(word_list, word_file)
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(name="bibl", guild_ids=guild_ids, description="Ajouter une phrase")
|
@bot.slash_command(name="bibl", guild_ids=guild_ids, description="Ajouter une phrase")
|
||||||
async def bibl(ctx, phrase):
|
async def bibl(ctx, phrase):
|
||||||
|
logger.info(f"BIBL {ctx.author} {phrase}")
|
||||||
word_list.append(phrase)
|
word_list.append(phrase)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="BIBL", description=phrase, color=discord.Colour.green()
|
title="BIBL", description=phrase, color=discord.Colour.green()
|
||||||
)
|
)
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
save_wordlist()
|
save_wordlist()
|
||||||
|
logger.info("FIN BIBL")
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(name="tabl", guild_ids=guild_ids, description="Lister les phrases")
|
@bot.slash_command(name="tabl", guild_ids=guild_ids, description="Lister les phrases")
|
||||||
async def tabl(ctx):
|
async def tabl(ctx):
|
||||||
|
logger.info(f"TABL {ctx.author}")
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="TABL", description="\n".join(word_list), color=discord.Colour.green()
|
title="TABL", description="\n".join(word_list), color=discord.Colour.green()
|
||||||
)
|
)
|
||||||
|
@ -141,6 +154,7 @@ async def tabl(ctx):
|
||||||
|
|
||||||
@bot.slash_command(name="enle", guild_ids=guild_ids, description="Enlever une phrase")
|
@bot.slash_command(name="enle", guild_ids=guild_ids, description="Enlever une phrase")
|
||||||
async def enle(ctx, phrase):
|
async def enle(ctx, phrase):
|
||||||
|
logger.info(f"ENLE {ctx.author} {phrase}")
|
||||||
try:
|
try:
|
||||||
word_list.remove(phrase)
|
word_list.remove(phrase)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -148,12 +162,14 @@ async def enle(ctx, phrase):
|
||||||
title="ERRE ENLE", description=phrase, color=discord.Colour.red()
|
title="ERRE ENLE", description=phrase, color=discord.Colour.red()
|
||||||
)
|
)
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
|
logger.info("ERRE ENLE")
|
||||||
else:
|
else:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="ENLE", description=f"~~{phrase}~~", color=discord.Colour.green()
|
title="ENLE", description=f"~~{phrase}~~", color=discord.Colour.green()
|
||||||
)
|
)
|
||||||
await ctx.respond(embed=embed, ephemeral=True, delete_after=delay)
|
await ctx.respond(embed=embed, ephemeral=True, delete_after=delay)
|
||||||
save_wordlist()
|
save_wordlist()
|
||||||
|
logger.info("FIN ENLE")
|
||||||
|
|
||||||
|
|
||||||
async def try_shuffle(guild):
|
async def try_shuffle(guild):
|
||||||
|
@ -167,7 +183,7 @@ async def try_shuffle(guild):
|
||||||
|
|
||||||
|
|
||||||
async def shuffle_nicks(guild):
|
async def shuffle_nicks(guild):
|
||||||
print("ALEA")
|
logger.info("Shuffle")
|
||||||
members = guild.members
|
members = guild.members
|
||||||
members.remove(guild.owner)
|
members.remove(guild.owner)
|
||||||
|
|
||||||
|
@ -175,45 +191,61 @@ async def shuffle_nicks(guild):
|
||||||
|
|
||||||
random.shuffle(nicks)
|
random.shuffle(nicks)
|
||||||
for member, nick in zip(members, nicks):
|
for member, nick in zip(members, nicks):
|
||||||
print(member, nick)
|
logger.info(member, nick)
|
||||||
await member.edit(nick=nick)
|
await member.edit(nick=nick)
|
||||||
print("FIN ALEA")
|
logger.info("Shuffle done")
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(name="alea", guild_ids=guild_ids, description="Modifier les pseudos")
|
@bot.slash_command(name="alea", guild_ids=guild_ids, description="Modifier les pseudos")
|
||||||
async def alea(ctx):
|
async def alea(ctx):
|
||||||
|
logger.info(f"ALEA {ctx.author}")
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
if await try_shuffle(ctx.guild):
|
if await try_shuffle(ctx.guild):
|
||||||
embed = discord.Embed(title="ALEA", color=discord.Colour.green())
|
embed = discord.Embed(title="ALEA", color=discord.Colour.green())
|
||||||
await ctx.respond(embed=embed, ephemeral=True, delete_after=delay)
|
await ctx.respond(embed=embed, ephemeral=True, delete_after=delay)
|
||||||
|
logger.info("FIN ALEA")
|
||||||
else:
|
else:
|
||||||
embed = discord.Embed(title="ERRE ALEA", color=discord.Colour.red())
|
embed = discord.Embed(title="ERRE ALEA", color=discord.Colour.red())
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
|
logger.info("ERRE ALEA")
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_voice_state_update")
|
@bot.listen("on_voice_state_update")
|
||||||
async def voice_random_nicks(member, before, after):
|
async def voice_random_nicks(member, before, after):
|
||||||
if before.channel is None and random.random() < 5 / 100:
|
if before.channel is None and random.random() < 5 / 100:
|
||||||
|
logger.info(f"Voice shuffle from {member}")
|
||||||
await try_shuffle(member.guild)
|
await try_shuffle(member.guild)
|
||||||
|
|
||||||
|
logger.debug("Voice state update")
|
||||||
|
logger.debug(before.channel)
|
||||||
|
logger.debug(after.channel)
|
||||||
|
if after.channel:
|
||||||
|
logger.debug(after.channel.members)
|
||||||
if (
|
if (
|
||||||
before.channel is None
|
before.channel is None
|
||||||
and after.channel is not None
|
and after.channel is not None
|
||||||
and random.random() < 5 / 100
|
and random.random() < 5 / 100
|
||||||
and bot not in after.channel.members
|
and bot not in after.channel.members
|
||||||
):
|
):
|
||||||
|
logger.info(f"Voice connect from {member}")
|
||||||
|
source = await discord.FFmpegOpusAudio.from_probe("assets/allo.ogg")
|
||||||
|
|
||||||
await asyncio.sleep(random.randrange(60))
|
await asyncio.sleep(random.randrange(60))
|
||||||
vo = await after.channel.connect()
|
vo = await after.channel.connect()
|
||||||
source = await discord.FFmpegOpusAudio.from_probe("assets/allo.ogg")
|
|
||||||
|
await asyncio.sleep(random.randrange(10))
|
||||||
vo.play(source)
|
vo.play(source)
|
||||||
|
|
||||||
await asyncio.sleep(random.randrange(60))
|
await asyncio.sleep(random.randrange(60))
|
||||||
await vo.disconnect()
|
await vo.disconnect()
|
||||||
|
logger.info("Voice disconnect")
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
name="indu", guild_ids=guild_ids, description="Poser une question à MistralAI"
|
name="indu", guild_ids=guild_ids, description="Poser une question à MistralAI"
|
||||||
)
|
)
|
||||||
async def indu(ctx, prompt):
|
async def indu(ctx, prompt):
|
||||||
|
logger.info(f"INDU {ctx.author} {prompt}")
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
res_stream = aibot.get_response_stream(prompt)
|
res_stream = aibot.get_response_stream(prompt)
|
||||||
|
|
||||||
|
@ -232,12 +264,14 @@ async def indu(ctx, prompt):
|
||||||
|
|
||||||
embed.color = None
|
embed.color = None
|
||||||
await message.edit(embed=embed)
|
await message.edit(embed=embed)
|
||||||
|
logger.info("FIN INDU")
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
name="chan", guild_ids=guild_ids, description="Donner de nouveaux pseudos"
|
name="chan", guild_ids=guild_ids, description="Donner de nouveaux pseudos"
|
||||||
)
|
)
|
||||||
async def chan(ctx, file: discord.Attachment):
|
async def chan(ctx, file: discord.Attachment):
|
||||||
|
logger.info(f"CHAN {ctx.author}")
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
|
||||||
members = ctx.guild.members
|
members = ctx.guild.members
|
||||||
|
@ -251,13 +285,14 @@ async def chan(ctx, file: discord.Attachment):
|
||||||
|
|
||||||
random.shuffle(nicks)
|
random.shuffle(nicks)
|
||||||
for member, nick in zip(members, nicks):
|
for member, nick in zip(members, nicks):
|
||||||
print(member, nick)
|
logger.info(member, nick)
|
||||||
await member.edit(nick=nick)
|
await member.edit(nick=nick)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="CHAN", description="\n".join(nicks), color=discord.Colour.green()
|
title="CHAN", description="\n".join(nicks), color=discord.Colour.green()
|
||||||
)
|
)
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
|
logger.info("FIN CHAN")
|
||||||
|
|
||||||
|
|
||||||
bot.run(config.get("token"))
|
bot.run(config.get("token"))
|
||||||
|
|
Loading…
Reference in a new issue