further improvement
This commit is contained in:
parent
984897c51e
commit
03d41b4104
15
main.py
15
main.py
@ -1,14 +1,5 @@
|
|||||||
from discord.ext import tasks
|
|
||||||
from datetime import datetime, timedelta, timezone
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import discord
|
import discord
|
||||||
import os
|
|
||||||
import asyncio
|
|
||||||
import random
|
|
||||||
import re
|
|
||||||
import json
|
|
||||||
import time
|
|
||||||
import unidecode
|
|
||||||
|
|
||||||
from modules.base import BaseModule
|
from modules.base import BaseModule
|
||||||
from modules import FourasModule, RhymesModule
|
from modules import FourasModule, RhymesModule
|
||||||
@ -49,11 +40,13 @@ async def on_message(message):
|
|||||||
message.author == client.user and message.channel in client.ongoing_riddles
|
message.author == client.user and message.channel in client.ongoing_riddles
|
||||||
): # need to move a part of that block in FourasModule
|
): # need to move a part of that block in FourasModule
|
||||||
current_riddle = client.ongoing_riddles[message.channel]
|
current_riddle = client.ongoing_riddles[message.channel]
|
||||||
if not ("message" in current_riddle):
|
if "message" not in current_riddle:
|
||||||
current_riddle["message"] = message
|
current_riddle["message"] = message
|
||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(message.channel, (discord.DMChannel, discord.TextChannel, discord.Thread)):
|
if isinstance(
|
||||||
|
message.channel, (discord.DMChannel, discord.TextChannel, discord.Thread)
|
||||||
|
):
|
||||||
for m in client.modules:
|
for m in client.modules:
|
||||||
await m.handle_message(message)
|
await m.handle_message(message)
|
||||||
|
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
from .fouras import FourasModule
|
from .fouras import FourasModule
|
||||||
from .rhymes import RhymesModule
|
from .rhymes import RhymesModule
|
||||||
|
|
||||||
|
ALL = [FourasModule, RhymesModule]
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
ENCODING = "utf-8"
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
ENCODING = "utf-8"
|
||||||
|
|
||||||
|
|
||||||
class BaseModule:
|
class BaseModule:
|
||||||
_client = None
|
_client = None
|
||||||
@ -19,4 +20,6 @@ class BaseModule:
|
|||||||
dm_channel = await self._client.fetch_channel(channel.id)
|
dm_channel = await self._client.fetch_channel(channel.id)
|
||||||
return "[DM={0}]".format(dm_channel.recipient.name)
|
return "[DM={0}]".format(dm_channel.recipient.name)
|
||||||
else:
|
else:
|
||||||
return "[Server={0}] => [Channel={1}]".format(channel.guild.name, channel.name)
|
return "[Server={0}] => [Channel={1}]".format(
|
||||||
|
channel.guild.name, channel.name
|
||||||
|
)
|
||||||
|
@ -5,6 +5,19 @@ import time
|
|||||||
import json
|
import json
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
API_URL = "".join(
|
||||||
|
[
|
||||||
|
"https://discord.com/api/oauth2/authorize?",
|
||||||
|
"client_id=1110208055171367014&permissions=274877975552&scope=bot",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
ABOUT = """
|
||||||
|
Ce bot a été développé par {user}
|
||||||
|
Code Source : https://gitlab.epicsparrow.com/Anselme/perefouras
|
||||||
|
Ajouter ce bot à votre serveur : {url}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class FourasModule(BaseModule):
|
class FourasModule(BaseModule):
|
||||||
def load(self):
|
def load(self):
|
||||||
@ -83,7 +96,8 @@ class FourasModule(BaseModule):
|
|||||||
await message.channel.send(self.new_riddle(message.channel, index))
|
await message.channel.send(self.new_riddle(message.channel, index))
|
||||||
else:
|
else:
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
f"Numéro d'énigme invalide, merci de saisir un numéro entre 1 et {len(self._client.riddles)}"
|
"Numéro d'énigme invalide, merci de saisir un numéro ",
|
||||||
|
f"entre 1 et {len(self._client.riddles)}",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if message_content == "fouras":
|
if message_content == "fouras":
|
||||||
@ -101,16 +115,14 @@ class FourasModule(BaseModule):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if message_content == "about fouras":
|
if message_content == "about fouras":
|
||||||
author_user = await self.client.fetch_user(151626081458192384)
|
author_user = await self._client.fetch_user(151626081458192384)
|
||||||
await message.channel.send(
|
await message.channel.send(ABOUT.format(user=author_user.mention, url=API_URL))
|
||||||
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
|
return
|
||||||
|
|
||||||
if message_content == "debug fouras":
|
if message_content == "debug fouras":
|
||||||
dump = {}
|
dump = {}
|
||||||
cooldowns = {}
|
cooldowns = {}
|
||||||
for key, value in self.client.cooldown.items():
|
for key, value in self._client.cooldown.items():
|
||||||
channel_name = await self.get_channel_name(key)
|
channel_name = await self.get_channel_name(key)
|
||||||
cooldowns[channel_name] = value - time.time()
|
cooldowns[channel_name] = value - time.time()
|
||||||
dump["poil_au_cooldown"] = cooldowns
|
dump["poil_au_cooldown"] = cooldowns
|
||||||
@ -132,7 +144,10 @@ class FourasModule(BaseModule):
|
|||||||
if unidecode(answer.lower()) in unidecode(message_content):
|
if unidecode(answer.lower()) in unidecode(message_content):
|
||||||
current_riddle["solver"] = message.author
|
current_riddle["solver"] = message.author
|
||||||
|
|
||||||
await message.channel.send(f"Bravo {message.author.mention} ! La réponse était bien `{answer}`.")
|
await message.channel.send(
|
||||||
|
f"Bravo {message.author.mention} ! ",
|
||||||
|
f"La réponse était bien `{answer}`.",
|
||||||
|
)
|
||||||
await current_riddle["message"].edit(content=self.format_message(current_riddle))
|
await current_riddle["message"].edit(content=self.format_message(current_riddle))
|
||||||
self.finish_riddle(message.channel)
|
self.finish_riddle(message.channel)
|
||||||
return
|
return
|
||||||
|
@ -1,38 +1,18 @@
|
|||||||
from .base import BaseModule
|
from .base import BaseModule
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
|
|
||||||
RHYMES_FILE = "rhymes.txt"
|
RHYMES_FILE = "rhymes.txt"
|
||||||
|
|
||||||
|
|
||||||
class RhymesModule(BaseModule):
|
class RhymesModule(BaseModule):
|
||||||
rhymes_keys: dict = {}
|
rhymes: dict = {}
|
||||||
rhyme_strings: dict = {}
|
|
||||||
cooldown: dict = {}
|
cooldown: dict = {}
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
with open(RHYMES_FILE, "r", encoding="utf-8") as f:
|
with open("rhymes.json", "r") as f:
|
||||||
data = f.read()
|
self.rhymes = json.load(f)
|
||||||
|
|
||||||
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(",")
|
|
||||||
|
|
||||||
self.rhyme_keys = keys
|
|
||||||
self.rhyme_strings = rhymes
|
|
||||||
|
|
||||||
def get_last_word(self, ch: str) -> str:
|
def get_last_word(self, ch: str) -> str:
|
||||||
truncated = ch
|
truncated = ch
|
||||||
@ -45,9 +25,9 @@ class RhymesModule(BaseModule):
|
|||||||
return truncated
|
return truncated
|
||||||
|
|
||||||
def poil_auquel(self, ch: str) -> str:
|
def poil_auquel(self, ch: str) -> str:
|
||||||
for key in self.rhyme_keys:
|
for key in self.rhymes:
|
||||||
if ch.endswith(tuple(self.rhyme_keys[key])):
|
if ch.endswith(tuple(self.rhymes[key]["keys"])):
|
||||||
return random.choice(self.rhyme_strings[key])
|
return random.choice(self.rhymes[key]["rhymes"])
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
async def handle_message(self, message):
|
async def handle_message(self, message):
|
||||||
|
18
parser_txt_to_json.py
Normal file
18
parser_txt_to_json.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
with open("rhymes.txt", "r") as f:
|
||||||
|
key = ""
|
||||||
|
res = {}
|
||||||
|
lines = [line.strip("\n") for line in f.readlines()]
|
||||||
|
for line in lines:
|
||||||
|
if line == "[KEYS]":
|
||||||
|
key = "keys"
|
||||||
|
elif line == "[RHYMES]":
|
||||||
|
key = "rhymes"
|
||||||
|
else:
|
||||||
|
k, v = line.split(":")
|
||||||
|
res.setdefault(k, {})[key] = v.split(",")
|
||||||
|
|
||||||
|
|
||||||
|
with open("rhymes.json", "w") as f:
|
||||||
|
json.dump(res, f, indent=2, ensure_ascii=False)
|
290
rhymes.json
Normal file
290
rhymes.json
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
{
|
||||||
|
"E": {
|
||||||
|
"keys": [
|
||||||
|
"eu",
|
||||||
|
"eux"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux cheveux."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OUS": {
|
||||||
|
"keys": [
|
||||||
|
"ous",
|
||||||
|
"ousse",
|
||||||
|
"ouce",
|
||||||
|
"ousses",
|
||||||
|
"ouces"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au pouce."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"US": {
|
||||||
|
"keys": [
|
||||||
|
"us",
|
||||||
|
"+"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil à l'anus."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OU": {
|
||||||
|
"keys": [
|
||||||
|
"ou",
|
||||||
|
"où",
|
||||||
|
"oo"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au cou.",
|
||||||
|
"Poil au genou."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"O": {
|
||||||
|
"keys": [
|
||||||
|
"au",
|
||||||
|
"aux",
|
||||||
|
"o",
|
||||||
|
"os",
|
||||||
|
"oh",
|
||||||
|
"ho"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au dos."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OL": {
|
||||||
|
"keys": [
|
||||||
|
"ol",
|
||||||
|
"ols",
|
||||||
|
"ole",
|
||||||
|
"oles",
|
||||||
|
"olle",
|
||||||
|
"ollesaul",
|
||||||
|
"auls"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux guiboles."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OUL": {
|
||||||
|
"keys": [
|
||||||
|
"oule",
|
||||||
|
"oules",
|
||||||
|
"oul",
|
||||||
|
"ouls"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil à la moule.",
|
||||||
|
"Poil aux boules."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ULVE": {
|
||||||
|
"keys": [
|
||||||
|
"ulve",
|
||||||
|
"ulves"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil à la vulve."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OR": {
|
||||||
|
"keys": [
|
||||||
|
"or",
|
||||||
|
"ors",
|
||||||
|
"ore",
|
||||||
|
"ores",
|
||||||
|
"aur",
|
||||||
|
"aurs"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au corps."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"IER": {
|
||||||
|
"keys": [
|
||||||
|
"ier",
|
||||||
|
"iers",
|
||||||
|
"ierre",
|
||||||
|
"ierres",
|
||||||
|
"ayé"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au derrière."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"IEN": {
|
||||||
|
"keys": [
|
||||||
|
"ien",
|
||||||
|
"iens",
|
||||||
|
"ient"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil de chien."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ET": {
|
||||||
|
"keys": [
|
||||||
|
"et",
|
||||||
|
"é",
|
||||||
|
"er",
|
||||||
|
"è",
|
||||||
|
"ait",
|
||||||
|
"ais",
|
||||||
|
"ai",
|
||||||
|
"ez",
|
||||||
|
"ied",
|
||||||
|
"ieds"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au nez.",
|
||||||
|
"Poil aux pieds."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OI": {
|
||||||
|
"keys": [
|
||||||
|
"oi",
|
||||||
|
"oie",
|
||||||
|
"ois",
|
||||||
|
"oit",
|
||||||
|
"oa"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux doigts."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"AN": {
|
||||||
|
"keys": [
|
||||||
|
"an",
|
||||||
|
"ant",
|
||||||
|
"ants",
|
||||||
|
"en",
|
||||||
|
"ment",
|
||||||
|
"ments"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux dents. "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ESSE": {
|
||||||
|
"keys": [
|
||||||
|
"esse",
|
||||||
|
"esses",
|
||||||
|
"aisse",
|
||||||
|
"aisses"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux fesses."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"EL": {
|
||||||
|
"keys": [
|
||||||
|
"el",
|
||||||
|
"els",
|
||||||
|
"elle",
|
||||||
|
"elles",
|
||||||
|
"aile",
|
||||||
|
"ailes"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux aisselles."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ACHE": {
|
||||||
|
"keys": [
|
||||||
|
"ache",
|
||||||
|
"ach",
|
||||||
|
"ash"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil de moustache."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"IN": {
|
||||||
|
"keys": [
|
||||||
|
"in"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux mains."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"TON": {
|
||||||
|
"keys": [
|
||||||
|
"ton",
|
||||||
|
"tons",
|
||||||
|
"thons",
|
||||||
|
"thons"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au menton."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ON": {
|
||||||
|
"keys": [
|
||||||
|
"on",
|
||||||
|
"ont",
|
||||||
|
"onts",
|
||||||
|
"ons",
|
||||||
|
"ond",
|
||||||
|
"onds"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au fion."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OUILLE": {
|
||||||
|
"keys": [
|
||||||
|
"ouille",
|
||||||
|
"ouilles"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil aux couilles."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ATTE": {
|
||||||
|
"keys": [
|
||||||
|
"atte",
|
||||||
|
"ate",
|
||||||
|
"ates",
|
||||||
|
"attes",
|
||||||
|
"âte",
|
||||||
|
"âtes",
|
||||||
|
"blyat"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil à la chatte."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"A": {
|
||||||
|
"keys": [
|
||||||
|
"a",
|
||||||
|
"à",
|
||||||
|
"ah",
|
||||||
|
"ha"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au bras."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"I": {
|
||||||
|
"keys": [
|
||||||
|
"i",
|
||||||
|
"is",
|
||||||
|
"it"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil à la vessie.",
|
||||||
|
"Poil au zizi."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"U": {
|
||||||
|
"keys": [
|
||||||
|
"u",
|
||||||
|
"hu",
|
||||||
|
"uh"
|
||||||
|
],
|
||||||
|
"rhymes": [
|
||||||
|
"Poil au cul."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user