2020-04-27 08:05:17 +00:00
|
|
|
#!/bin/python
|
|
|
|
import code
|
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
import discord
|
|
|
|
from discord.ext import commands
|
|
|
|
from discord.ext.commands import Context
|
|
|
|
|
2020-04-27 10:28:30 +00:00
|
|
|
from src.cogs import TfjmHelpCommand
|
2020-04-27 08:05:17 +00:00
|
|
|
from src.constants import *
|
|
|
|
from src.errors import TfjmError, UnwantedCommand
|
|
|
|
|
2020-04-27 10:28:30 +00:00
|
|
|
bot = commands.Bot("!", help_command=TfjmHelpCommand())
|
2020-04-27 08:05:17 +00:00
|
|
|
|
2020-04-27 09:43:16 +00:00
|
|
|
# Variable globale qui contient les tirages.
|
|
|
|
tirages = {}
|
2020-04-27 08:05:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
|
|
|
print(f"{bot.user} has connected to Discord!")
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(
|
|
|
|
name="choose",
|
2020-04-27 10:28:30 +00:00
|
|
|
usage='choix1 choix2 "choix 3"...',
|
2020-04-27 08:05:17 +00:00
|
|
|
aliases=["choice", "choix", "ch"],
|
|
|
|
)
|
|
|
|
async def choose(ctx: Context, *args):
|
2020-04-27 10:28:30 +00:00
|
|
|
"""
|
|
|
|
Choisit une option parmi tous les arguments.
|
2020-04-27 08:05:17 +00:00
|
|
|
|
2020-04-27 10:28:30 +00:00
|
|
|
Pour les options qui contiennent une espace,
|
|
|
|
il suffit de mettre des guillemets (`"`) autour.
|
|
|
|
"""
|
2020-04-27 08:05:17 +00:00
|
|
|
|
2020-04-27 10:28:30 +00:00
|
|
|
choice = random.choice(args)
|
|
|
|
await ctx.send(f"J'ai choisi... **{choice}**")
|
2020-04-27 08:05:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name="interrupt")
|
2020-04-27 10:35:02 +00:00
|
|
|
@commands.has_role(Role.DEV)
|
2020-04-27 08:05:17 +00:00
|
|
|
async def interrupt_cmd(ctx):
|
2020-04-27 10:28:30 +00:00
|
|
|
"""
|
|
|
|
:warning: Ouvre une console là où un @dev m'a lancé. :warning:
|
|
|
|
|
|
|
|
A utiliser en dernier recours:
|
|
|
|
- le bot sera inactif pendant ce temps.
|
|
|
|
- toutes les commandes seront executées à sa reprise.
|
|
|
|
"""
|
|
|
|
|
2020-04-27 08:05:17 +00:00
|
|
|
await ctx.send(
|
|
|
|
"J'ai été arrêté et une console interactive a été ouverte là où je tourne. "
|
|
|
|
"Toutes les commandes rateront tant que cette console est ouverte.\n"
|
|
|
|
"Soyez rapides, je déteste les opérations à coeur ouvert... :confounded:"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Utility function
|
|
|
|
|
|
|
|
local = {
|
|
|
|
**globals(),
|
|
|
|
**locals(),
|
|
|
|
"pprint": pprint,
|
|
|
|
"_show": lambda o: print(*dir(o), sep="\n"),
|
|
|
|
"__name__": "__console__",
|
|
|
|
"__doc__": None,
|
|
|
|
}
|
|
|
|
|
|
|
|
code.interact(banner="Ne SURTOUT PAS FAIRE Ctrl+C !\n(TFJM² debugger)", local=local)
|
|
|
|
await ctx.send("Tout va mieux !")
|
|
|
|
|
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_command_error(ctx: Context, error, *args, **kwargs):
|
|
|
|
if isinstance(error, commands.CommandInvokeError):
|
|
|
|
if isinstance(error.original, UnwantedCommand):
|
|
|
|
await ctx.message.delete()
|
|
|
|
author: discord.Message
|
|
|
|
await ctx.author.send(
|
|
|
|
"J'ai supprimé ton message:\n> "
|
|
|
|
+ ctx.message.clean_content
|
|
|
|
+ "\nC'est pas grave, c'est juste pour ne pas encombrer "
|
|
|
|
"le chat lors du tirage."
|
|
|
|
)
|
|
|
|
await ctx.author.send("Raison: " + error.original.msg)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
msg = str(error.original) or str(error)
|
|
|
|
traceback.print_tb(error.original.__traceback__, file=sys.stderr)
|
|
|
|
else:
|
|
|
|
msg = str(error)
|
|
|
|
|
|
|
|
print(repr(error), dir(error), file=sys.stderr)
|
|
|
|
await ctx.send(msg)
|
|
|
|
|
|
|
|
|
2020-04-27 09:43:16 +00:00
|
|
|
bot.load_extension("src.cogs.tirages")
|
2020-04-27 12:46:04 +00:00
|
|
|
bot.load_extension("src.cogs.teams")
|
2020-04-27 09:43:16 +00:00
|
|
|
|
|
|
|
|
2020-04-27 08:05:17 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
bot.run(TOKEN)
|