async def terminate(self, ctx): self.user_id = str(ctx.author.id) if self.user_id not in self.bot.games.keys(): await ctx.send(Reply.not_in_game(self.user_id)) return game = self.bot.games[self.user_id] money = game.return_money(wrong_answer=False) time = self.bot.time - game.start await game.last_message.delete() save_player(str(game.user.id), money, time) del self.bot.games[self.user_id] await ctx.send(Reply.end_game(self.user_id, money))
async def on_reaction_add(self, reaction, user): answers_map = {'🇦': 'A', '🇧': 'B', '🇨': 'C', '🇩': 'D'} if str(user.id) in self.games.keys() and reaction.emoji in answers_map: player = str(user.id) game = self.games[player] game.answered = True # get the game of the player # await asyncio.sleep(0.5) answer = answers_map[reaction.emoji] # take the letter if game.correct_answer(answer): await self._right_answer(game.ctx) if game.question_level == 15: player_name = Reply.user_name(game.user.name, game.user.discriminator) money = game.question_amount_map[15] time = self.time - game.start await game.ctx.send(Gif.win) await game.ctx.send( f'<@{game.user.id}> жалко, че не са истински.') save_player(str(game.user.id), money, time) del self.games[player] return question_data = self.games[player].ask() game.last_embed = QuestionEmbed(**question_data) game.start_question = self.time game.last_question = question_data await game.last_message.edit(delete_after=5) game.last_message = await game.ctx.send( content=f'⏳ **Имаш {SECS} секунди**', embed=game.last_embed) await self._send_to_nick(game.last_question, game.right_answer) await game.last_message.add_reaction('🇦') await game.last_message.add_reaction('🇧') await game.last_message.add_reaction('🇨') await game.last_message.add_reaction('🇩') if game.waiting_friend_help: game.waiting_friend_help = False if game.waiting_audience_help: game.waiting_audience_help = False else: await self._wrong_answer(game.ctx) player_name = Reply.user_name(game.user.name, game.user.discriminator) money = game.return_money() time = self.time - game.start save_player(str(game.user.id), money, time) del self.games[player] await game.last_message.edit(delete_after=5) await game.ctx.send(Reply.end_game(player, money))
async def change_games_count(self): d = self.games.copy() for player_id in d: game = self.games[player_id] diff = self.time - game.start_question if diff == SECS - 5: await game.last_message.edit( content=f'⏳ **Остават ти 5 секунди!**', embed=game.last_embed) elif diff % 10 == 0: await game.last_message.edit( content=f'⏳ **Имаш {SECS - diff} секунди**', embed=game.last_embed) if self.time - game.start_question == SECS: await game.last_message.edit( content=f'⏳ **Изтече ти времето!**', embed=game.last_embed, delete_after=5) player = Reply.user_name(game.user.name, game.user.discriminator) money = game.return_money(wrong_answer=True) time = self.time - game.start save_player(str(game.user.id), money, time) await game.ctx.send(Reply.end_game(game.user.id, money)) del self.games[player_id] # check friends help if game.waiting_friend_help: user = self.get_user(int(game.helper_id)) if self.time - game.start_friend_help == 5: await game.friend_msg.edit( content=Reply.friend_help(user.name, 5)) if self.time - game.start_friend_help == 10: game.waiting_friend_help = False await game.friend_msg.edit( content=Reply.friend_help(user.name, 0)) await game.friend_msg.add_reaction(Emoji.clock) del self.helping_friends[game.helper_id] if not game.add_friend_reaction and \ not game.waiting_friend_help and \ game.start_friend_help: await game.friend_msg.add_reaction(Emoji.clock) game.add_friend_reaction = True try: del self.helping_friends[int(game.helper_id)] except: pass if game.waiting_audience_help: if self.time - game.start_audience_help == 5: await game.audience_msg.edit(content=Reply.audience_help(5) ) if self.time - game.start_audience_help == 10: audience_data = game.get_audience_votes() embed = AudienceEmbed(**audience_data) await game.audience_msg.edit(content=Reply.audience_help(0) ) await game.audience_channel.send(embed=embed) await game.audience_msg.add_reaction(Emoji.clock) game.waiting_audience_help = False if not game.add_audience_reaction and \ not game.waiting_audience_help and \ game.start_audience_help: await game.audience_msg.add_reaction(Emoji.clock) game.add_audience_reaction = True