From 43701f1a53e49008eeb5ce75a8221389ace7f2ec Mon Sep 17 00:00:00 2001 From: ddorn Date: Sun, 26 Apr 2020 22:22:15 +0200 Subject: [PATCH] :sparkles: add a way to spawn a shell to debug also can show partial tirages --- tfjm-discord-bot.py | 28 +++++++++++++++++++--- tirages.yaml | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 tirages.yaml diff --git a/tfjm-discord-bot.py b/tfjm-discord-bot.py index 8663314..315276b 100644 --- a/tfjm-discord-bot.py +++ b/tfjm-discord-bot.py @@ -1,11 +1,13 @@ #!/bin/python import asyncio +import code import os import random import sys import traceback from collections import defaultdict, namedtuple from pathlib import Path +from pprint import pprint from typing import Dict, Type import discord @@ -39,7 +41,7 @@ TIRAGES_FILE = Path(__file__).parent / "tirages.yaml" def in_passage_order(teams, round=0): - return sorted(teams, key=lambda team: team.passage_order[round], reverse=True) + return sorted(teams, key=lambda team: team.passage_order[round] or 0, reverse=True) class TfjmError(Exception): @@ -202,14 +204,15 @@ class Tirage(yaml.YAMLObject): records = [ Record( team.name, - team.accepted_problems[round][0], + (team.accepted_problems[round] or "- None")[0], f"k = {team.coeff(round)} ", ) for team in in_passage_order(self.teams, round) ] msg += f"\n\n**{ROUND_NAMES[round].capitalize()}**:\n" - msg += table.format(*records[round]) + "\n" + code.interact(local=locals()) + msg += table.format(*records) + "\n" for team in self.teams: msg += team.details(round) @@ -625,6 +628,7 @@ async def abort_draw_cmd(ctx): @bot.command(name="draw-skip", aliases=["skip"]) +@commands.has_role(CNO_ROLE) async def draw_skip(ctx, *teams): channel = ctx.channel.id tirages[channel] = tirage = Tirage(ctx, channel, teams) @@ -750,6 +754,24 @@ async def show_cmd(ctx: Context, arg: str): await tirage.show(ctx) +@bot.command() +@commands.has_role(CNO_ROLE) +async def interrupt_cmd(ctx): + 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 + def _show(o): + print(*dir(o), sep="\n") + + code.interact(local={**globals(), **locals()}) + + await ctx.send("Tout va mieux !") + + @bot.event async def on_command_error(ctx: Context, error, *args, **kwargs): if isinstance(error, commands.CommandInvokeError): diff --git a/tirages.yaml b/tirages.yaml new file mode 100644 index 0000000..14d1132 --- /dev/null +++ b/tirages.yaml @@ -0,0 +1,57 @@ +&id001 ! +channel: 703310860365594624 +phase: !!python/object:__main__.TirageOrderPhase + name: des tirages + order_name: tirage_order + reverse: false + round: 0 + tirage: *id001 +teams: +- ! + accepted_problems: + - null + - null + drawn_problem: null + mention: <@&703923322483900426> + name: AAA + passage_order: + - null + - null + rejected: + - !!set {} + - !!set {} + tirage_order: + - null + - null +- ! + accepted_problems: + - null + - null + drawn_problem: null + mention: <@&703923681931296831> + name: BBB + passage_order: + - null + - null + rejected: + - !!set {} + - !!set {} + tirage_order: + - null + - null +- ! + accepted_problems: + - null + - null + drawn_problem: null + mention: <@&703923724465733632> + name: CCC + passage_order: + - null + - null + rejected: + - !!set {} + - !!set {} + tirage_order: + - null + - null