Exemplo n.º 1
0
    async def takedown(self, context, student_id: int, *post):
        post = ' '.join(post)
        if not post:
            await context.send(
                'You must supply the user to stand down and the post you are standing them down from, '
                f'usage: `{helpers.PREFIX}takedown <STUDENT NUMBER> <POST>`')
            return
        matching_posts = helpers.match_post(post)
        if not matching_posts:
            await context.send(
                'Looks like that post isn\'t available for this election, '
                f'use `{helpers.PREFIX}posts` to see the posts up for election`'
            )
            return
        post = matching_posts[0]

        if student_id not in helpers.standing[post]:
            await context.send(
                'Looks like this user isn\'t standing for this post')
            return

        helpers.email_secretary(str(helpers.standing[post][student_id][0]),
                                post,
                                stood_down=True)
        del helpers.standing[post][student_id]

        helpers.save_standing()

        helpers.log(
            f'{student_id} has been stood down from standing for {post}')
        await context.send(
            f'{student_id} has been stood down from running for {post}')
Exemplo n.º 2
0
    async def delete(self, context, *, post):
        def check(msg):
            return msg.author == context.author and msg.channel == context.channel

        matching_posts = helpers.match_post(post)
        if not matching_posts:
            await context.send(f'{post} doesn\'t exist')
            return

        post = matching_posts[0]

        if helpers.standing[post].items():
            if not (len(helpers.standing[post]) == 1
                    and helpers.standing[post][0]):
                await context.send(
                    f'Members are already running for {post}, would you like to delete it? [(y)es/(n)o]'
                )
                while True:
                    msg = await self.bot.wait_for('message',
                                                  check=check,
                                                  timeout=60)
                    if msg.content.lower() in ['y', 'yes']:
                        break
                    elif msg.content.lower() in ['n', 'no']:
                        await context.send('Delete cancelled')
                        return
                    else:
                        await context.send(
                            'I didn\'t understand that, please answer (y)es or (n)o'
                        )

        helpers.standing.pop(post)
        await context.send(f'{post} deleted')
        return
Exemplo n.º 3
0
    async def standdown(self, context, *post):
        post = ' '.join(post)
        if not post:
            await context.send(
                f'Must supply the post you are standing down from, usage: `{helpers.PREFIX}standdown <POST>`'
            )
            return
        matching_posts = helpers.match_post(post)
        if not matching_posts:
            await context.send(
                'Looks like that post isn\'t available for this election, '
                f'use `{helpers.PREFIX}posts` to see the posts up for election`'
            )
            return
        post = matching_posts[0]

        author = context.author.id

        if helpers.registered_members[author] not in helpers.standing[post]:
            await context.send('Looks like you weren\'t standing for this post'
                               )
            return

        helpers.email_secretary(str(
            helpers.standing[post][helpers.registered_members[author]][0]),
                                post,
                                stood_down=True)
        del helpers.standing[post][helpers.registered_members[author]]

        helpers.save_standing()

        helpers.log(
            f'{helpers.registered_members[author]} has stood down from standing for {post}'
        )
        await context.send(f'You have stood down from running for {post}')
Exemplo n.º 4
0
    async def rename(self, context, old_post, new_post):
        matching_posts = helpers.match_post(old_post)
        if not matching_posts:
            await context.send(f'{old_post} doesn\'t exist')
            return

        helpers.standing[new_post] = helpers.standing.pop(matching_posts[0])

        helpers.save_standing()

        helpers.log(
            f'The post of {matching_posts[0]} has been renamed to {new_post}')
        await context.send(
            f'The post of {matching_posts[0]} has been renamed to {new_post}')
Exemplo n.º 5
0
    async def setup(self, context, *post):
        post = ' '.join(post)
        matching_posts = helpers.match_post(post)
        if matching_posts:
            await context.send(f'{post} already exists')
            return

        helpers.standing[post] = {
            0: (Candidate('RON (Re-Open Nominations)'), '*****@*****.**', 42)
        }

        helpers.save_standing()

        helpers.log(f'The post of {post} has been created')
        await context.send(f'The post of {post} has been created')
Exemplo n.º 6
0
    async def begin(self, context, *post):
        post = ' '.join(post)
        if not post:
            await context.send(
                'Must supply the post/referendum title you are starting the vote for, usage:'
                f'`{helpers.PREFIX}begin <POST/TITLE>`')
            return
        matching_posts = helpers.match_post(post)
        type = 'POST'
        if not matching_posts:
            matching_posts = helpers.match_referendum(post)
            type = 'REFERENDUM'
            if not matching_posts:
                await context.send(
                    'Looks like that post/referendum isn\'t available for this election, '
                    f'use `{helpers.PREFIX}posts` to see the posts up for election or '
                    f'or use `{helpers.PREFIX}referenda` to see the referenda that will be voted upon'
                )
                return

        async with helpers.current_live_post_lock.writer_lock:
            if helpers.current_live_post:
                await context.send(
                    'You can\'t start a new vote until the last one has finished'
                )
                return
            post = matching_posts[0]

            helpers.current_live_post = (type, post)
        helpers.log(f'Voting has now begun for: {post}')

        if type == 'POST':
            await self.distribute_all_post_ballots(post)

            await context.send(
                f'Voting has now begun for: {post}\n'
                'All registered voters will have just received a message from me. '
                'Please vote by reacting to the candidates listed in your DMs where '
                ':one: is your top candidate, :two: is your second top candidate, etc. '
                'You do not need to put a ranking in for every candidate')
        else:
            await self.distribute_all_referenda_ballots(post)

            await context.send(
                f'Voting has now begun for: {post}\n'
                'All registered voters will have just received a message from me. Please vote by '
                'reacting :ballot_box_with_check: to either the \'For\' or \'Against\' message '
                'in your DMs')
Exemplo n.º 7
0
    async def list_candidates(self, context, *post):
        if not helpers.standing:
            await context.send('There are currently no posts set up in this election')
            return

        post = ' '.join(post)

        output_str = ''
        if post:
            matching_posts = helpers.match_post(post)
            if matching_posts:
                post = matching_posts[0]
                candidates = [(str(candidate), discordid) for candidate, _, discordid in helpers.standing[post].values()]
                random.shuffle(candidates)
                output_str += f'Candidates standing for {post}:\n'
                for candidate in candidates:
                    if candidate[1] == 42:
                        output_str += f' - {candidate[0]}\n'
                    else:
                        output_str += f' - {candidate[0]} - {(await self.bot.fetch_user(candidate[1])).display_name}\n'
                output_str += '--------\n'
            else:
                output_str = ('Looks like that post isn\'t in this election, '
                              f'use `{helpers.PREFIX}posts` to see the posts up for election`')
        else:
            for post in helpers.standing:
                candidates = [(str(candidate), discordid) for candidate, _, discordid in helpers.standing[post].values()]
                random.shuffle(candidates)
                output_str += f'Candidates standing for {post}:\n'
                for candidate in candidates:
                    if candidate[1] == 42:
                        output_str += f' - {candidate[0]}\n'
                    else:
                        output_str += f' - {candidate[0]} - {(await self.bot.fetch_user(candidate[1])).display_name}\n'
                output_str += '--------\n'

        if output_str:
            await context.send(output_str)
Exemplo n.º 8
0
    async def stand(self, context, *input):
        if not input:
            await context.send(
                'Must supply the post you are running for and a valid email address, '
                f'usage:`{helpers.PREFIX}stand <POST> <EMAIL>`')
            return
        email = input[-1]
        post = ' '.join(input[:-1])
        if not post:
            await context.send(
                'Must supply the post you are running for and a valid email address, '
                f'usage:`{helpers.PREFIX}stand <POST> <EMAIL>`')
            return
        if '@' not in email:
            await context.send(
                'Must supply the post you are running for and a valid email address, '
                f'usage:`{helpers.PREFIX}stand <POST> <EMAIL>`')
            return

        matching_posts = helpers.match_post(post)
        if not matching_posts:
            await context.send(
                'Looks like that post isn\'t available for this election, '
                f'use `{helpers.PREFIX}posts` to see the posts up for election'
            )
            return
        post = matching_posts[0]
        async with helpers.current_live_post_lock.reader_lock:
            if helpers.current_live_post:
                if post == helpers.current_live_post[1]:
                    await context.send(
                        f'I\'m afraid voting for {post} has already begun, you cannot stand for this post'
                    )
                    return

            author = context.author.id
            members = helpers.get_members()

            output_str = 'Error'
            if author in helpers.registered_members:
                if [
                        i for i in helpers.standing[post]
                        if i == helpers.registered_members[author]
                ]:
                    output_str = (
                        f'It looks like you, {members[helpers.registered_members[author]]} are already '
                        f'standing for the position of: {post}')
                else:
                    helpers.standing[post][
                        helpers.registered_members[author]] = (Candidate(
                            members[helpers.registered_members[author]]),
                                                               email, author)
                    output_str = (
                        f'Congratulations {members[helpers.registered_members[author]]}, '
                        f'you are now standing for the position of {post}. If you no longer wish to stand, you '
                        f'can send `{helpers.PREFIX}standdown {post}`\n\n'
                        'Now you\'ll need to prepare a 2 minute speech to be given in the election call.\n'
                        f'If you have any questions please contact the secretary {helpers.SECRETARY_NAME}'
                        f'({helpers.SECRETARY_EMAIL}), or someone else on the committee.\n'
                        'If you can\'t make it to the actual election call, you must get in touch with the '
                        'secretary ASAP to sort out alternative arrangements.')
                    helpers.log(
                        f'{context.author.name}({helpers.registered_members[author]}) is now standing for {post}'
                    )
                    helpers.email_secretary(
                        members[helpers.registered_members[author]], post)
            else:
                output_str = (
                    'Looks like you\'re not registered yet, '
                    f'please register using `{helpers.PREFIX}register <STUDENT NUMBER>`'
                )
                helpers.log(
                    f'{context.author.name} has failed to stand for {post} because they are not registered'
                )

        helpers.save_standing()
        await context.send(output_str)