added "poil au" feature
This commit is contained in:
parent
7e83820ed0
commit
28be8ea7d5
70
fouras.py
70
fouras.py
@ -1,12 +1,13 @@
|
|||||||
import discord
|
|
||||||
from discord.ext import tasks
|
from discord.ext import tasks
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import discord
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime, timedelta, timezone
|
|
||||||
import random
|
import random
|
||||||
from dotenv import load_dotenv
|
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
@ -20,6 +21,9 @@ token = os.getenv('DISCORD_TOKEN', "NO_TOKEN")
|
|||||||
|
|
||||||
client.riddles = []
|
client.riddles = []
|
||||||
client.answers = []
|
client.answers = []
|
||||||
|
client.rhyme_keys = {}
|
||||||
|
client.rhyme_strings = {}
|
||||||
|
client.cooldown = 0
|
||||||
client.ongoing_riddles = {}
|
client.ongoing_riddles = {}
|
||||||
|
|
||||||
def load_riddles():
|
def load_riddles():
|
||||||
@ -29,6 +33,30 @@ def load_riddles():
|
|||||||
client.answers = [line.strip() for line in a_file.readlines()]
|
client.answers = [line.strip() for line in a_file.readlines()]
|
||||||
print('Loaded {0} riddles'.format(len(client.riddles)))
|
print('Loaded {0} riddles'.format(len(client.riddles)))
|
||||||
|
|
||||||
|
def load_rhymes():
|
||||||
|
with open('rhymes.txt', 'r', encoding='utf-8') as f:
|
||||||
|
data = f.read()
|
||||||
|
|
||||||
|
keys_start = data.index('[KEYS]') + len('[KEYS]\n')
|
||||||
|
keys_end = data.index('[RHYMES]')
|
||||||
|
keys_data = data[keys_start:keys_end].split('\n')
|
||||||
|
keys = {}
|
||||||
|
for key_data in keys_data:
|
||||||
|
if key_data:
|
||||||
|
k, v = key_data.split(":")
|
||||||
|
keys[k] = v.split(',')
|
||||||
|
|
||||||
|
rhymes_start = data.index('[RHYMES]') + len('[RHYMES]\n')
|
||||||
|
rhymes_data = data[rhymes_start:].split('\n')
|
||||||
|
rhymes = {}
|
||||||
|
for rhyme_data in rhymes_data:
|
||||||
|
if rhyme_data:
|
||||||
|
k, v = rhyme_data.split(":")
|
||||||
|
rhymes[k] = v.split(',')
|
||||||
|
|
||||||
|
client.rhyme_keys = keys
|
||||||
|
client.rhyme_strings = rhymes
|
||||||
|
|
||||||
def new_riddle(channel, index):
|
def new_riddle(channel, index):
|
||||||
current_riddle = dict(index=index, nbClues=-1, riddle=client.riddles[index].strip(), answer=client.answers[index])
|
current_riddle = dict(index=index, nbClues=-1, riddle=client.riddles[index].strip(), answer=client.answers[index])
|
||||||
client.ongoing_riddles[channel] = current_riddle
|
client.ongoing_riddles[channel] = current_riddle
|
||||||
@ -78,9 +106,26 @@ def format_message(current_riddle):
|
|||||||
else:
|
else:
|
||||||
return "Énigme {0}:\n{1}".format(current_riddle['index'] + 1, formatted_riddle)
|
return "Énigme {0}:\n{1}".format(current_riddle['index'] + 1, formatted_riddle)
|
||||||
|
|
||||||
|
def get_last_word(ch:str)->str:
|
||||||
|
truncated = ch.split(None)[-1]
|
||||||
|
while True:
|
||||||
|
if len(truncated) == 1 or truncated[-1].isnumeric():
|
||||||
|
return False
|
||||||
|
if truncated[-1].isalpha() and truncated[-2].isalpha():
|
||||||
|
break
|
||||||
|
truncated = truncated[:-1]
|
||||||
|
return truncated
|
||||||
|
|
||||||
|
def poil_auquel(ch:str)->str:
|
||||||
|
for key in client.rhyme_keys:
|
||||||
|
if ch.endswith(tuple(client.rhyme_keys[key])):
|
||||||
|
return random.choice(client.rhyme_strings[key])
|
||||||
|
return ''
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
load_riddles()
|
load_riddles()
|
||||||
|
load_rhymes()
|
||||||
print('Logged in as {0.user}'.format(client))
|
print('Logged in as {0.user}'.format(client))
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
@ -121,8 +166,14 @@ async def on_message(message):
|
|||||||
await message.channel.send('Loaded {0} riddles'.format(len(client.riddles)))
|
await message.channel.send('Loaded {0} riddles'.format(len(client.riddles)))
|
||||||
return
|
return
|
||||||
|
|
||||||
if message_content == 'debug':
|
if message_content == 'about fouras':
|
||||||
|
author_user = await client.fetch_user(151626081458192384)
|
||||||
|
await message.channel.send(f"Ce bot a été développé par {author_user.mention}\nCode Source : https://gitlab.epicsparrow.com/Anselme/perefouras\nAjouter ce bot à votre serveur : https://discord.com/api/oauth2/authorize?client_id=1110208055171367014&permissions=274877975552&scope=bot")
|
||||||
|
return
|
||||||
|
|
||||||
|
if message_content == 'debug fouras':
|
||||||
dump = {}
|
dump = {}
|
||||||
|
dump['poil_au_cooldown'] = client.cooldown - time.time()
|
||||||
for key, value in client.ongoing_riddles.items():
|
for key, value in client.ongoing_riddles.items():
|
||||||
dump_channel = value
|
dump_channel = value
|
||||||
dump_channel.pop("message", None)
|
dump_channel.pop("message", None)
|
||||||
@ -167,6 +218,17 @@ async def on_message(message):
|
|||||||
if nbClues >= len(answer):
|
if nbClues >= len(answer):
|
||||||
finish_riddle(message.channel)
|
finish_riddle(message.channel)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
last_word = get_last_word(message_content)
|
||||||
|
if last_word:
|
||||||
|
poil = poil_auquel(message_content)
|
||||||
|
if poil and time.time() - client.cooldown > 0:
|
||||||
|
wait_time = random.randint(0, 900)
|
||||||
|
if bool(random.getrandbits(1)):
|
||||||
|
wait_time = random.randint(900, 10800)
|
||||||
|
client.cooldown = time.time() + wait_time
|
||||||
|
await message.channel.send(poil)
|
||||||
|
return
|
||||||
|
|
||||||
# Initialise le client
|
# Initialise le client
|
||||||
client.run(token)
|
client.run(token)
|
||||||
|
52
rhymes.txt
Normal file
52
rhymes.txt
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
[KEYS]
|
||||||
|
E:eu,eux
|
||||||
|
OUS:ous,ousse,ouce,ousses,ouces
|
||||||
|
US:us,+
|
||||||
|
OU:ou,où,oo
|
||||||
|
O:au,aux,o,os,oh,ho
|
||||||
|
OL:ol,ols,ole,oles,olle,ollesaul,auls
|
||||||
|
OUL:oule,oules,oul,ouls
|
||||||
|
ULVE:ulve,ulves
|
||||||
|
OR:or,ors,ore,ores,aur,aurs
|
||||||
|
IER:ier,iers,ierre,ierres,ayé
|
||||||
|
IEN:ien,iens,ient
|
||||||
|
ET:et,é,er,è,ait,ais,ai,ez,ied,ieds
|
||||||
|
OI:oi,oie,ois,oit,oa
|
||||||
|
AN:an,ant,ants,en,ment,ments
|
||||||
|
ESSE:esse,esses,aisse,aisses
|
||||||
|
EL:el,els,elle,elles,aile,ailes
|
||||||
|
ACHE:ache,ach,ash
|
||||||
|
IN:in
|
||||||
|
TON:ton,tons,thons,thons
|
||||||
|
ON:on,ont,onts,ons,ond,onds
|
||||||
|
OUILLE:ouille
|
||||||
|
ATTE:atte,ate,ates,attes,âte,âtes,blyat
|
||||||
|
A:a,à,ah,ha
|
||||||
|
I:i,is,it
|
||||||
|
U:u,hu,uh
|
||||||
|
[RHYMES]
|
||||||
|
A:Poil au bras.
|
||||||
|
E:Poil aux cheveux.
|
||||||
|
I:Poil à la vessie.,Poil au zizi.
|
||||||
|
O:Poil au dos.
|
||||||
|
U:Poil au cul.
|
||||||
|
US:Poil à l'anus.
|
||||||
|
ET:Poil au nez.,Poil aux pieds.
|
||||||
|
IER:Poil au derrière.
|
||||||
|
IEN:Poil de chien.
|
||||||
|
ACHE:Poil de moustache.
|
||||||
|
OU:Poil au cou.,Poil au genou.
|
||||||
|
ULVE:Poil à la vulve.
|
||||||
|
OL:Poil aux guiboles.
|
||||||
|
OUL:Poil à la moule.,Poil aux boules.
|
||||||
|
OR:Poil au corps.
|
||||||
|
IN:Poil aux mains.
|
||||||
|
TON:Poil au menton.
|
||||||
|
ON:Poil au fion.
|
||||||
|
OI:Poil aux doigts.
|
||||||
|
AN:Poil aux dents.
|
||||||
|
OUILLE:Poil aux couilles.
|
||||||
|
OUS:Poil au pouce.
|
||||||
|
ATTE:Poil à la chatte.
|
||||||
|
ESSE:Poil aux fesses.
|
||||||
|
EL:Poil aux aisselles.
|
Loading…
x
Reference in New Issue
Block a user