async def on_command_error(self, ctx, error): if isinstance(error, errors.CommandInvokeError): if isinstance(error.original, MultipleVotesFound): await ctx.send( generate_message(MessageKey.MULTIPLE_VOTES_FOUND)) if isinstance(error.original, EmptyVoteFound): await ctx.send(generate_message(MessageKey.EMPTY_VOTE_FOUND))
def generate_status_embed(game_state): tally = game_state.data["tally"] voted_player_info = generate_message( MessageKey.POLL_STATUS_VOTED_PLAYER_INFO) return Embed( title=generate_message(MessageKey.POLL_STATUS_TITLE), description="\n".join([ voted_player_info.format(user=user, votes=votes) for user, votes in tally.items() ]), colour=Colour.blue(), timestamp=datetime.utcnow(), )
def generate_instruction_embed(user_ids): commands = "\n".join([ f"• `{bot.command_prefix}vote` <@{user_id}>" for user_id in user_ids ]) instruction = generate_message(MessageKey.POLL_INSTRUCTION_CONTENT) return Embed( title=generate_message(MessageKey.POLL_INSTRUCTION_TITLE), description=instruction.format( poll_duration=PollWorker.POLL_DURATION, commands=commands), colour=Colour.blue(), timestamp=datetime.utcnow(), )
async def handle_started_poll(self, game_state): self.started_poll = True embed = self.generate_instruction_embed(game_state.data["players"]) await self.poll_message.instruction.edit(content="", embed=embed) await self.poll_message.status.edit( content=generate_message(MessageKey.POLL_STARTED)) await asyncio.wait([self.poll_timer()], return_when=asyncio.FIRST_COMPLETED)
async def poll_timer(self): second = self.POLL_DURATION poll_timer_message = generate_message(MessageKey.POLL_TIMER) while second > 0: await self.poll_message.timer.edit( content=poll_timer_message.format(second=second)) await asyncio.sleep(1) second -= 1
def generate_result_embed(game_state, embed_color): if game_state.status == Status.NO_VOTES_SUBMITTED: description = generate_message( MessageKey.POLL_RESULT_NO_VOTES_SUBMITTED) else: tally = game_state.data["tally"] voted_player_info = generate_message( MessageKey.POLL_RESULT_VOTED_PLAYER_INFO) total_alive_players = len(game_state.data["players"]) description = "\n".join([ voted_player_info.format(user=user, votes=votes) for user, votes in tally.items() ]) result_info = generate_message(MessageKey.POLL_RESULT_INFO) description += "\n\n" + result_info.format( total_alive_players=total_alive_players) return Embed( title=generate_message(MessageKey.POLL_RESULT_TITLE), description=description, colour=embed_color, timestamp=datetime.utcnow(), )
async def initiate_poll_message(self): instruction = await self.ctx.send( generate_message(MessageKey.POLL_GENERATING_PROCESS)) timer = await self.ctx.send("\u200b") status = await self.ctx.send("\u200b") self.poll_message = PollMessage(instruction, timer, status)