summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatrixAeria <upezu@student.kit.edu>2020-10-20 01:53:06 +0200
committerNatrixAeria <upezu@student.kit.edu>2020-10-20 01:53:06 +0200
commitd25246962ff3ae1d269411e8ceb4ba4f539405d5 (patch)
treebf0585c751939036149fe0ed5466bab38c494562
parent9b472f1af089439e0a8cac67635392214213cea1 (diff)
Rework the score system
-rw-r--r--bot.py28
-rw-r--r--commands.py25
-rw-r--r--config.py38
3 files changed, 72 insertions, 19 deletions
diff --git a/bot.py b/bot.py
index 72753dd..71635cb 100644
--- a/bot.py
+++ b/bot.py
@@ -21,10 +21,13 @@ class Cupido(commands.Bot):
self.reaction_map = {}
self.vote_map = {}
self.read_file()
- self.score_map = dd(lambda: 0)
+ self.reset_scoreboard()
self.oldgroups = set()
self.admin_channel = admin_channel
+ def reset_scoreboard(self):
+ self.score_map = dd(lambda: 0)
+
def read_file(self):
try:
with open(config.TUTOR_FILE_PATH, 'r') as f:
@@ -63,10 +66,11 @@ class Cupido(commands.Bot):
async def create_voice_channel(self, ctx, name, category=None):
channel = await ctx.guild.create_voice_channel(
- config.LOBBY_CHANNEL_NAME,
+ name,
category=self.meta_channel,
)
await channel.set_permissions(ctx.guild.default_role, **config.CHANNEL_PERMISSIONS)
+ await channel.set_permissions(self.user, **config.BOT_PERMISSIONS)
return channel
async def create_lobby(self, ctx):
@@ -141,6 +145,7 @@ class Cupido(commands.Bot):
embed = discord.Embed(title=config.PANEL_TITLE, type="rich", description=text, colour=discord.Colour.purple())
msg = await channel.send(embed=embed)
await await_n(map(msg.add_reaction, emojis))
+ self.vote_map[user.id] = None
return msg
async def destroy_pair_channels(self, ctx, meta_channel):
@@ -209,12 +214,25 @@ class Cupido(commands.Bot):
self.vote_map = {}
async def update_score(self, member):
- if member.id in self.tutors or member.id not in self.vote_map or self.vote_map[member.id] is None:
+ if member.id in self.tutors or member.id not in self.vote_map:
return
vote = self.vote_map[member.id]
channel = self.get_dm_channel(member)
- name = self.get_username(vote)
- if vote.id in self.tutors:
+ name = None if vote is None else self.get_username(vote)
+ tutorset = set(self.tutors)
+ possible_votes = self.reaction_map[member.id].values()
+ tutors = {tutor for tutor in possible_votes if tutor.id in tutorset}
+ if vote is None and tutors:
+ self.score_map[member] += config.PASS_BAD_POINTS
+ text = config.PASS_BAD_TEXT.format(points=self.score_map[member], tutor=', '.join(self.get_username(tutor) for tutor in tutors))
+ color = discord.Colour.red()
+ title = config.PASS_BAD_TITLE
+ elif vote is None:
+ self.score_map[member] += config.PASS_GOOD_POINTS
+ text = config.PASS_GOOD_TEXT.format(points=self.score_map[member])
+ color = discord.Colour.green()
+ title = config.PASS_GOOD_TITLE
+ elif vote.id in self.tutors:
self.score_map[member] += config.SUCCESS_POINTS
text = config.SUCCESS_TEXT.format(tutor=name, points=self.score_map[member])
color = discord.Colour.green()
diff --git a/commands.py b/commands.py
index a804469..44bc340 100644
--- a/commands.py
+++ b/commands.py
@@ -21,17 +21,17 @@ async def answer(ctx: commands.Context, msg: str, *args, **kwargs):
def is_admin_channel(ctx: commands.Context):
- print(ctx.message.channel,ctx.bot.admin_channel, ctx.message.channel == ctx.bot.admin_channel)
return ctx.message.channel.id == ctx.bot.admin_channel
@commands.command(help='display this help message', aliases=('hepl', 'h', '?'))
async def help(ctx: commands.Context):
command_doc = '\n'.join(
- f' * {config.COMMAND_PREFIX}{c.name:15} - {c.help}'
+ f' โ€ข {config.COMMAND_PREFIX}{c.name:15} - {c.help}'
for c in ctx.bot.commands)
- await answer(ctx, f'''```
-{config.HELP_TEXT}\nThese are all available commands:\n{command_doc}```''')
+ doc = f'{config.HELP_TEXT}\nThese are all available commands:\n{command_doc}'
+ embed = discord.Embed(title="Hilfe", type="rich", description=doc, colour=discord.Colour.purple())
+ await answer(ctx, '', embed=embed)
@commands.command(help='create a new lobby', aliases=('create', 'inti', 'craete', 'cretae', 'c', 'i', '+'))
@@ -144,8 +144,8 @@ async def stop(ctx: commands.Context, cancel_loop=True):
await ctx.bot.destroy_pair_channels(ctx, meta_channel)
-async def loop_cycle(ctx, t):
- if not await shuffle(ctx, 3):
+async def loop_cycle(ctx, t, g):
+ if not await shuffle(ctx, g):
return False
await asyncio.sleep(t)
await ctx.bot.update_scores(ctx.guild)
@@ -157,7 +157,7 @@ async def loop_cycle(ctx, t):
help=f'repeat "shuffle" and "stop" <n> (default: {config.DEFAULT_LOOP_COUNT}) times and <t>'
f' (default: {config.DEFAULT_LOOP_TIME}) seconds',
aliases=('repeat', 'shuffleloop'))
-async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFAULT_LOOP_TIME):
+async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFAULT_LOOP_TIME, g=3):
if not is_admin_channel(ctx): return
try:
n, t = int(n), int(t)
@@ -166,7 +166,7 @@ async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFA
return
await answer(ctx, f'repeat shuffling {n} times and each {t} seconds')
for _ in range(n):
- result = await ctx.bot.await_coroutine(loop_cycle(ctx, t))
+ result = await ctx.bot.await_coroutine(loop_cycle(ctx, t, g))
message = {
'cancelled': 'cancelled loop command',
'already running': 'cannot start loop, another task is running...'
@@ -239,5 +239,14 @@ async def scoreboard(ctx: commands.Context):
embed = discord.Embed(title=config.SCOREBOARD_TITLE, type="rich", description=text, colour=discord.Colour.purple())
await ctx.send(embed=embed)
+@commands.command(
+ help='reset the scoreboard',
+ aliases=(),
+)
+async def reset(ctx: commands.Context):
+ if is_admin_channel(ctx):
+ ctx.bot.reset_scoreboard()
+ await answer(ctx, 'resetted the scoreboard')
+
bot_commands = [cmd for cmd in locals().values() if isinstance(cmd, commands.Command)]
diff --git a/config.py b/config.py
index 4703448..b5b4c72 100644
--- a/config.py
+++ b/config.py
@@ -9,7 +9,7 @@ GAME_STATUS = 'dich aus'
HELP_TEXT = f'''{NAME.title()} - your partner for getting shuffled.
{NAME.title()} is a discord bot to get to know your people.
-This software is open-source <https://git.kobert.dev/lovefinderrz.git/>!
+This software is open-source https://git.kobert.dev/lovefinderrz.git/
'''
CATEGORY_CHANNEL_NAME = 'KENNENLERNEN'
@@ -27,20 +27,42 @@ Wenn du der Meinung bist, dass du gerade mit einem Tutor sprichst,
dann stimme jetzt mit einem der entsprechenden Emojis unten ab:
'''
-SUCCESS_POINTS = 1
-SUCCESS_TITLE = 'Du bist ein Sieger!'
+SUCCESS_POINTS = 3
+SUCCESS_TITLE = 'Ertappt!'
SUCCESS_TEXT = f'''
Du hast einen Tutor entlarvt ({{tutor}})!! ๐Ÿฅณ๐Ÿ‘
-** -> +{SUCCESS_POINTS} points <- **
+** -> +{SUCCESS_POINTS} Punkte <- **
+๐Ÿช™ Du hast nun **{{points}}** Punkte ๐Ÿช™
+'''
+
+PASS_GOOD_POINTS = 1
+PASS_GOOD_TITLE = 'Schรถn!'
+PASS_GOOD_TEXT = f'''
+Es war kein Tutor unter euch! ๐Ÿ‘
+Du hast fรผr niemanden abgestimmt,
+und damit lagst du auch im Recht.
+Daher:
+** -> +{PASS_GOOD_POINTS} Punkt <- **
+๐Ÿช™ Du hast nun **{{points}}** Punkte ๐Ÿช™
+'''
+
+PASS_BAD_POINTS = 0
+PASS_BAD_TITLE = 'Schade'
+PASS_BAD_TEXT = f'''
+Es war kein Tutor unter euch! ๐Ÿ‘
+Du hast fรผr niemanden abgestimmt,
+doch folgende Personen waren
+Tutoren: {{tutor}}
+** -> +{PASS_BAD_POINTS} Punkt <- **
๐Ÿช™ Du hast nun **{{points}}** Punkte ๐Ÿช™
'''
FAILIURE_POINTS = 0
-FAILIURE_TITLE = 'Schade'
+FAILIURE_TITLE = 'Schade ๐Ÿ˜”'
FAILIURE_TEXT = f'''
Schade. {{user}} war kein Tutor ๐Ÿ˜”
Vielleicht ja beim nรคchsten Mal ๐Ÿ˜Ž
-** -> +{FAILIURE_POINTS} points <- **
+** -> +{FAILIURE_POINTS} Punkte <- **
๐Ÿช™ Du hast nun **{{points}}** Punkte ๐Ÿช™
'''
@@ -53,3 +75,7 @@ CHANNEL_PERMISSIONS = {
'move_members': False,
'mute_members': False,
}
+BOT_PERMISSIONS = {
+ 'move_members': True,
+ 'mute_members': True,
+}