countdown-bot

A Discord bot that runs countdown games and generates analytics
git clone https://git.ashermorgan.net/countdown-bot/
Log | Files | Refs | README

commit 538303cba7f359197b73f9b0c07abfd1f07fe739
parent 26cc223b5d4ac873da653f62f38d9e65d11b59e8
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date:   Fri, 22 Jan 2021 14:26:35 -0800

Improve help command output.

Diffstat:
Mbot.py | 55++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/bot.py b/bot.py @@ -226,7 +226,11 @@ async def on_message(obj): @bot.command() -async def progress(ctx): +async def contributors(ctx): + """ + Get information about countdown contributors + """ + # Get messages if (ctx.channel.id in channels): countdown = countdowns[str(ctx.channel.id)] @@ -242,23 +246,22 @@ async def progress(ctx): # Create plot plt.close() - plt.title("Countdown Progress") - plt.xlabel("Time") - plt.ylabel("Progress") - plt.gcf().autofmt_xdate() + plt.title("Countdown Contributors") # Add data to graph - x = [countdown.messages[0].timestamp] + [x["time"] for x in stats["progress"]] - y = [0] + [x["progress"] for x in stats["progress"]] - plt.plot(x, y) + x = [x["author"] for x in stats["contributors"]] + y = [x["contributors"] for x in stats["contributors"]] + plt.pie(y, labels=x, autopct="%1.1f%%", startangle = 90) # Save graph plt.savefig(tmp.name) file = discord.File(tmp.name, filename="image.png") # Create embed - embed=discord.Embed(title="Countdown Progress") - embed.description = f"{stats['start'] - stats['current']} / {stats['start']} ({round(stats['percentage'], 2)}%)" + embed=discord.Embed(title="Countdown Contributors") + embed.description = "" + for i in range(0, len(x)): + embed.description += f"**{i + 1}.** `{x[i]}` ({y[i]})\n" embed.set_image(url="attachment://image.png") # Send embed @@ -273,7 +276,11 @@ async def progress(ctx): @bot.command() -async def contributors(ctx): +async def progress(ctx): + """ + Get information about countdown progress + """ + # Get messages if (ctx.channel.id in channels): countdown = countdowns[str(ctx.channel.id)] @@ -289,22 +296,23 @@ async def contributors(ctx): # Create plot plt.close() - plt.title("Countdown Contributors") + plt.title("Countdown Progress") + plt.xlabel("Time") + plt.ylabel("Progress") + plt.gcf().autofmt_xdate() # Add data to graph - x = [x["author"] for x in stats["contributors"]] - y = [x["contributors"] for x in stats["contributors"]] - plt.pie(y, labels=x, autopct="%1.1f%%", startangle = 90) + x = [countdown.messages[0].timestamp] + [x["time"] for x in stats["progress"]] + y = [0] + [x["progress"] for x in stats["progress"]] + plt.plot(x, y) # Save graph plt.savefig(tmp.name) file = discord.File(tmp.name, filename="image.png") # Create embed - embed=discord.Embed(title="Countdown Contributors") - embed.description = "" - for i in range(0, len(x)): - embed.description += f"**{i + 1}**. `{x[i]}` ({y[i]})\n" + embed=discord.Embed(title="Countdown Progress") + embed.description = f"{stats['start'] - stats['current']} / {stats['start']} ({round(stats['percentage'], 2)}%)" embed.set_image(url="attachment://image.png") # Send embed @@ -321,9 +329,18 @@ async def contributors(ctx): # Command aliases @bot.command() async def c(ctx): + """ + Alias for !count contributors + """ + await contributors(ctx) + @bot.command() async def p(ctx): + """ + Alias for !count progress + """ + await progress(ctx)