コード例 #1
0
    async def vote(self, ctx):
        # TODO combine vote and submitvote using self.bot.wait_for
        try:
            poll = self.polls[str(ctx.channel.id)]
        except KeyError:
            await ctx.author.send(text.no_poll_in_channel)
            await ctx.message.delete()
            return

        account_age = (datetime.now(timezone.utc) -
                       ctx.author.created_at.replace(tzinfo=timezone.utc)).days

        if poll.check_if_voted(str(ctx.author.id)):
            await ctx.author.send(text.already_voted)

        elif account_age < constants.voting_age_days:
            await ctx.author.send(
                text.account_age(account_age, constants.voting_age_days))

        elif poll.started is False:
            await ctx.channel.send(text.poll_not_started)

        elif poll.ended is True:
            await ctx.channel.send(text.poll_already_ended)

        else:
            await ctx.author.send(poll.get_vote_text())
            await ctx.author.send(poll.get_submitballot_template())

        await ctx.message.delete()
コード例 #2
0
    async def submitballot(self, ctx, channel_id, *args):
        try:
            poll = self.polls[channel_id]
        except KeyError:
            await ctx.author.send(text.cant_find_poll)
            return

        account_age = (datetime.now(timezone.utc) -
                       ctx.author.created_at.replace(tzinfo=timezone.utc)).days

        if poll.check_if_voted(str(ctx.author.id)):
            await ctx.author.send(text.already_voted)

        elif account_age < constants.voting_age_days:
            await ctx.author.send(
                text.account_age(account_age, constants.voting_age_days))

        elif poll.started is False:
            await ctx.channel.send(text.poll_not_started)

        elif poll.ended is True:
            await ctx.channel.send(text.poll_already_ended)

        elif not poll.check_valid_ballot(args):
            await ctx.author.send("bad ballot")

        else:
            await ctx.author.send(text.confirm_vote + "\n" +
                                  poll.confirm_vote_text(args))

            def check(m):
                return m.author == ctx.author\
                    and m.channel == ctx.channel

            reply = None
            while (reply is None or not (reply.content.lower() == "yes"
                                         or reply.content.lower() == "no")):
                try:
                    reply = await self.bot.wait_for('message',
                                                    timeout=120,
                                                    check=check)
                except TimeoutError:
                    await ctx.author.send(text.timeout)
                    return
            if reply.content.lower() == "yes":
                print("\n\n" + str(args) + "\n\n")
                poll.submit_vote(str(ctx.author.id), ctx.author.name, args)
                self.save_one(channel_id)
                await ctx.author.send(text.vote_processed)
            else:
                await ctx.author.send(text.vote_not_processed)
                return
コード例 #3
0
    async def vote(self, ctx):
        # TODO combine vote and submitvote using self.bot.wait_for
        try:
            poll = self.polls[str(ctx.channel.id)]
        except KeyError:
            await ctx.author.send(text.no_poll_in_channel)
            await ctx.message.delete()
            return

        account_age = (datetime.now(timezone.utc) -
                       ctx.author.created_at.replace(tzinfo=timezone.utc)).days

        server_join_date = ctx.author.joined_at.replace(tzinfo=timezone.utc)
        bad_hardcoded_date = datetime.fromisoformat(
            "2021-11-22 03:59:59.000000+00:00")

        server_join_ok = server_join_date < bad_hardcoded_date

        if poll.check_if_voted(str(ctx.author.id)):
            await ctx.author.send(text.already_voted)

        elif account_age < constants.voting_age_days:
            await ctx.author.send(
                text.account_age(account_age, constants.voting_age_days))

        elif not server_join_ok:
            await ctx.author.send(text.not_in_server_long_enough)

        elif poll.started is False:
            await ctx.channel.send(text.poll_not_started)

        elif poll.ended is True:
            await ctx.channel.send(text.poll_already_ended)

        else:
            await ctx.author.send(poll.get_vote_text())
            await ctx.author.send(poll.get_submitballot_template())

        await ctx.message.delete()