summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatrixAeria <upezu@student.kit.edu>2020-10-19 21:13:57 +0200
committerNatrixAeria <upezu@student.kit.edu>2020-10-19 21:13:57 +0200
commite3ed83db59b70c26ec057f4462fef8d56da03365 (patch)
treea5c18e813328228b84ec25d3bb81695904b85b82
parent65c20596192ddc93e78d577de8cdb503a2de2224 (diff)
Add scoreboard
-rw-r--r--bot.py8
-rw-r--r--commands.py41
-rw-r--r--config.py5
3 files changed, 28 insertions, 26 deletions
diff --git a/bot.py b/bot.py
index 303333e..1ef8bec 100644
--- a/bot.py
+++ b/bot.py
@@ -206,13 +206,13 @@ class Cupido(commands.Bot):
channel = self.get_dm_channel(member)
name = self.get_username(vote)
if vote.id in self.tutors:
- self.score_map[member.id] += config.SUCCESS_POINTS
- text = config.SUCCESS_TEXT.format(tutor=name, points=self.score_map[member.id])
+ self.score_map[member] += config.SUCCESS_POINTS
+ text = config.SUCCESS_TEXT.format(tutor=name, points=self.score_map[member])
color = discord.Colour.green()
title = config.SUCCESS_TITLE
else:
- self.score_map[member.id] += config.FAILIURE_POINTS
- text = config.FAILIURE_TEXT.format(user=name, points=self.score_map[member.id])
+ self.score_map[member] += config.FAILIURE_POINTS
+ text = config.FAILIURE_TEXT.format(user=name, points=self.score_map[member])
color = discord.Colour.red()
title = config.FAILIURE_TITLE
embed = discord.Embed(title=title, type="rich", description=text, colour=color)
diff --git a/commands.py b/commands.py
index 62046f6..a422e26 100644
--- a/commands.py
+++ b/commands.py
@@ -4,6 +4,7 @@ import random
import config
+import discord
from discord.ext import commands
@@ -15,8 +16,8 @@ async def await_n(it) -> List[Any]:
return [task.result() for task in done]
-async def answer(ctx: commands.Context, msg: str):
- await ctx.send(f'{ctx.author.mention} {msg}')
+async def answer(ctx: commands.Context, msg: str, *args, **kwargs):
+ await ctx.send(f'{ctx.author.mention} {msg}', *args, **kwargs)
@commands.command(help='display this help message', aliases=('hepl', 'h', '?'))
@@ -48,22 +49,6 @@ async def destroy(ctx: commands.Context):
ctx.bot.pair_channels = []
-def fac(n):
- i = 1
- for z in range(2, n+1):
- i *= z
- return i
-
-
-def n_th_permutation(n, lst):
- nlst = [None for _ in lst]
- indexes = list(range(len(lst)))
- for i in lst:
- n, index = divmod(n, len(indexes))
- nlst[indexes.pop(index)] = i
- return nlst
-
-
def round_up_div(a, b):
a, b = divmod(a, b)
return a+1 if b else a
@@ -107,7 +92,7 @@ async def shuffle(ctx: commands.Context, channel_size=2):
group.append(tutors.pop())
for _ in range(count - tutor_count):
for i, member in enumerate(normals):
- if any(frozenset((member.id, other.id)) in ctx.bot.oldgroups for other in group):
+ if any((frozenset((member.id, other.id)) in ctx.bot.oldgroups) for other in group):
continue
group.append(normals.pop(i))
break
@@ -123,7 +108,7 @@ async def shuffle(ctx: commands.Context, channel_size=2):
for member1 in group:
for member2 in group:
if member1 != member2:
- ctx.bot.oldgroups.add(frozenset((member1, member2)))
+ ctx.bot.oldgroups.add(frozenset((member1.id, member2.id)))
random.shuffle(futures)
for group in groups:
@@ -151,7 +136,7 @@ async def stop(ctx: commands.Context, cancel_loop=True):
async def loop_cycle(ctx, t):
- if not await shuffle(ctx):
+ if not await shuffle(ctx, 3):
return False
await asyncio.sleep(t)
await ctx.bot.update_scores(ctx.guild)
@@ -227,5 +212,19 @@ async def list(ctx: commands.Context):
else:
await answer(ctx, 'there is no tutor :/')
+@commands.command(
+ help='get the scoreboard',
+ aliases=('scores', 'score', 'points')
+)
+async def scoreboard(ctx: commands.Context):
+ text = config.SCOREBOARD_TEXT
+ scores = [i for i in ctx.bot.score_map.items()]
+ scores = sorted(scores, reverse=True, key=lambda i: i[1])
+ for n, (member, score) in enumerate(scores):
+ if score > 0:
+ text += f'\n {n+1}. {ctx.bot.get_username(member)} hat {score} Punkt{"" if score == 1 else "e"}'
+ embed = discord.Embed(title=config.SCOREBOARD_TITLE, type="rich", description=text, colour=discord.Colour.purple())
+ await ctx.send(embed=embed)
+
bot_commands = [cmd for cmd in locals().values() if isinstance(cmd, commands.Command)]
diff --git a/config.py b/config.py
index d6c223d..84ba673 100644
--- a/config.py
+++ b/config.py
@@ -23,7 +23,7 @@ DEFAULT_LOOP_COUNT = 3
EMOJI_POOL = ['๐Ÿ‘พ', '๐Ÿค–', '๐Ÿ‘ป', '๐Ÿฆง', '๐Ÿด', '๐ŸŽฎ', '๐ŸŽท', '๐Ÿ˜ˆ', '๐Ÿฆ„', '๐Ÿฎ', '๐ŸŒป', '๐Ÿ˜', '๐Ÿ•', '๐Ÿฆ‰']
PANEL_TITLE = 'Wer ist Tutor?'
PANEL_TEXT = '''
-Wenn **du** der Meinung bist, dass du gerade mit einem **Tutor** sprichst,
+Wenn du der Meinung bist, dass du gerade mit einem Tutor sprichst,
dann stimme jetzt mit einem der entsprechenden Emojis unten ab:
'''
@@ -43,3 +43,6 @@ Vielleicht ja beim nรคchsten Mal ๐Ÿ˜Ž
** -> +{FAILIURE_POINTS} points <- **
๐Ÿช™ Du hast nun **{{points}}** Punkte ๐Ÿช™
'''
+
+SCOREBOARD_TITLE = 'Scoreboard'
+SCOREBOARD_TEXT = 'Hier siehst du, wer wie viele Punkte hat:'