async def status(self, msg): """ Called when the status command is invoked. """ embed = discord.Embed(title="Kwiss: question {}/{}".format( self.quizapi.current_question_index() + 1, len(self.quizapi))) embed.add_field(name="Category", value=self.quizapi.category_name(self.category)) embed.add_field(name="Difficulty", value=Difficulty.human_readable(self.difficulty)) embed.add_field(name="Mode", value="Points (Everyone answers)") embed.add_field(name="Initiated by", value=get_best_username(Storage().get(self.plugin), self.requester)) status = ":arrow_forward: Running" if self.state == Phases.REGISTERING: status = ":book: Signup phase" # status = ":pause_button: Paused" embed.add_field(name="Status", value=status) if self.ranked: embed.add_field(name="Ranked", value=":memo:") if self.debug: embed.add_field(name="Debug mode", value=":beetle:") if self.gecki: embed.add_field(name="Gecki", value="I'm in! 😍") await self.channel.send(embed=embed)
async def end(self): embed = self.score.embed() winners = [get_best_username(Storage().get(self.plugin), x) for x in self.score.winners()] # Übergangslösung points = self.score.points() for user in points: self.plugin.update_ladder(user, points[user]) msgkey = "quiz_end" if len(winners) > 1: msgkey = "quiz_end_pl" elif len(winners) == 0: msgkey = "quiz_end_no_winner" winners = utils.format_andlist(winners, ands=Lang.lang(self.plugin, "and"), emptylist=Lang.lang(self.plugin, "nobody")) msg = Lang.lang(self.plugin, msgkey, winners) if msg is None: await self.channel.send(embed=embed) elif embed is None: await self.channel.send(msg) else: await self.channel.send(msg, embed=embed) self.plugin.end_quiz(self.channel)
async def end(self): embed = self.score.embed() winners = [get_best_username(Storage().get(self.plugin), x) for x in self.score.winners()] msgkey = "quiz_end" if len(winners) > 1: msgkey = "quiz_end_pl" elif len(winners) == 0: msgkey = "quiz_end_no_winner" winners = utils.format_andlist(winners, ands=Lang.lang(self.plugin, "and"), emptylist=Lang.lang(self.plugin, "nobody")) msg = Lang.lang(self.plugin, msgkey, winners) if msg is None: await self.channel.send(embed=embed) elif embed is None: await self.channel.send(msg) else: await self.channel.send(msg, embed=embed) if self.ranked: for player in self.registered_participants: self.plugin.update_ladder(player, self.score.calc_points(player)) self.plugin.end_quiz(self.channel)
def embed(self, end=False, sort_by_points=False): embed = discord.Embed(title=Lang.lang(self.plugin, "results_title")) ladder = self.ladder(sort_by_points=sort_by_points) place = 0 for i in range(len(ladder)): user = ladder[i] if i == 0 or self._score[user] < self._score[ladder[i - 1]]: place += 1 # embed name = "**#{}** {}".format( place, get_best_username(Storage().get(self.plugin), user)) value = "Correct answers: {}".format(self._score[user]) if len(self) > 1: value = "{}\nScore: {}".format(value, self.calc_points(user)) embed.add_field(name=name, value=value) i += 1 if len(ladder) == 0: if end: embed.add_field(name="Nobody has scored!", value=" ") else: embed.add_field(name="**#1** Geckarbot", value="I won! :)") return embed
async def cmd_ladder(self, ctx, *args): if len(args) != 1: await ctx.message.add_reaction(Lang.CMDERROR) return embed = discord.Embed() entries = {} for uid in Storage().get(self)["ladder"]: member = discord.utils.get(ctx.guild.members, id=uid) points = Storage().get(self)["ladder"][uid] if points not in entries: entries[points] = [member] else: entries[points].append(member) values = [] keys = sorted(entries.keys(), reverse=True) place = 0 for el in keys: for user in entries[el]: values.append("**#{}:** {} - {}".format( place, el, get_best_username(Storage().get(self), user))) if len(values) == 0: await ctx.send("So far, nobody is on the ladder.") return embed.add_field(name="Ladder:", value="\n".join(values)) await ctx.send(embed=embed)
async def eval(self): """ Is called when the question is over. Evaluates scores and cancels the timer. :return: """ self.plugin.logger.debug("Ending question") # End timeout timer if self.current_question_timer is not None: try: self.current_question_timer.cancel() except utils.HasAlreadyRun: self.plugin.logger.warning("This should really, really not happen.") self.current_question_timer = None else: # We ran into a timeout and need to give that function time to communicate this fact await asyncio.sleep(1) if self.current_reaction_listener is not None: self.current_reaction_listener.unregister() question = self.quizapi.current_question() # Normalize answers for el in self.registered_participants: if len(self.registered_participants[el]) != 1: self.registered_participants[el] = None else: self.registered_participants[el] = self.registered_participants[el][0] # Increment scores correctly_answered = [] for user in self.registered_participants: if question.check_answer(self.registered_participants[user], emoji=True): correctly_answered.append(user) for user in correctly_answered: self.score.increase(user, self.current_question, totalcorr=len(correctly_answered)) correct = [get_best_username(Storage().get(self.plugin), el) for el in correctly_answered] correct = utils.format_andlist(correct, Lang.lang(self.plugin, "and"), Lang.lang(self.plugin, "nobody")) if self.config["emoji_in_pose"]: ca = question.correct_answer_emoji else: ca = question.correct_answer_letter await self.channel.send(Lang.lang(self.plugin, "points_question_done", ca, correct)) # Reset answers list for user in self.registered_participants: self.registered_participants[user] = [] await asyncio.sleep(self.config["question_cooldown"]) self.state = Phases.QUESTION
async def status(self, msg): embed = discord.Embed(title="Kwiss: question {}/{}".format( self.quizapi.current_question_index() + 1, len(self.quizapi))) embed.add_field(name="Category", value=self.quizapi.category_name(self.category)) embed.add_field(name="Difficulty", value=Difficulty.human_readable(self.difficulty)) embed.add_field(name="Mode", value="Rush (Winner takes it all)") embed.add_field(name="Initiated by", value=get_best_username(Storage().get(self.plugin), self.requester)) status = ":arrow_forward: Running" # status = ":pause_button: Paused" embed.add_field(name="Status", value=status) if self.debug: embed.add_field(name="Debug mode", value=":beetle:") await msg.add_reaction(Lang.CMDSUCCESS) await self.channel.send(embed=embed)
async def eval(self): """ Is called when the question is over. Evaluates scores and cancels the timer. :return: """ self.plugin.logger.debug("Ending question") question = self.quizapi.current_question() # Increment score self.score.increase(self.last_author, question) await self.channel.send(Lang.lang(self.plugin, "correct_answer", get_best_username(Storage().get(self.plugin), self.last_author), question.correct_answer_letter)) await asyncio.sleep(self.config["question_cooldown"]) self.state = Phases.QUESTION
async def about_to_start(self): """ ABOUTTOSTART -> QUESTION; ABOUTTOSTART -> ABORT """ self.plugin.logger.debug("Ending the registering phase") abort = False if len(self.registered_participants) == 0: abort = True if abort: embed, msg = self.plugin.end_quiz(self.channel) self.channel.send(msg, embed=embed) return else: for user in self.registered_participants: self.score.add_participant(user) embed = discord.Embed(title=Lang.lang(self.plugin, "quiz_phase")) value = "\n".join([get_best_username(Storage().get(self.plugin), el, mention=True) for el in self.registered_participants]) embed.add_field(name="Participants:", value=value) await self.channel.send(embed=embed) await asyncio.sleep(10) self.state = Phases.QUESTION
def havent_answered_hr(self): return [get_best_username(Storage().get(self.plugin), el) for el in self.registered_participants if len(self.registered_participants[el]) != 1]