示例#1
0
async def create_cc(bot,
                    name,
                    owner,
                    people,
                    hidden=False,
                    category=None,
                    announce=True):
    # people should contain owner
    if owner not in people and owner is not None:
        people.append(owner)

    guild = fetch_guild(bot)
    if category is None:
        category = await fetch_a_category(bot)
    if category is None: raise errors.NoSuchChannel()

    overwrites = get_overwrites(guild, people, owner)
    channel = await guild.create_text_channel(name,
                                              overwrites=overwrites,
                                              category=category)

    if announce:
        people_mentions = [p.mention for p in people]
        random.shuffle(people_mentions)

        if hidden:
            msg = "A new CC has been created!\n**Members:**\n{}".format(
                "\n".join(people_mentions))
        else:
            msg = "{} has created a new CC!\n**Members:**\n{}".format(
                owner.mention, "\n".join(people_mentions))
        await channel.send(msg)
示例#2
0
def get_all_alive(bot):
    guild = fetch_guild(bot)
    alive = []
    for p in Player.select():
        m = guild.get_member(p.discord_id)
        if is_participant(m):
            alive.append(p)
    return alive
示例#3
0
async def fetch_a_category(bot):
    ids = fetch_cc_category_ids()
    guild = fetch_guild(bot)
    for catid in ids:
        cat = guild.get_channel(catid)
        if cat is None:
            CCCategory.get(discord_id=catid).delete_instance()
            continue  # clean up and skip if it no longer exists
        if len(cat.text_channels) < 30:
            return cat
            break
    return await create_new_category(bot)
示例#4
0
async def format_poll_output(bot, reactions, errs):
    guild = fetch_guild(bot)
    res_ret = []
    for emoji, people in reactions.items():
        option_player_id = Player.get(emoji=emoji).discord_id
        option_player_mention = guild.get_member(option_player_id).mention
        if len(people) == 0:
            voters = "*No one!*"
        else:
            voters = ", ".join(p.mention for p in people)
        res_ret.append("({count}) {opt} : {voters}".format(
            opt=option_player_mention, voters=voters, count=len(people)))
    return ("Results:\n" + "\n".join(res_ret) + "\n" + "\n".join(errs))
示例#5
0
    async def add(self, ctx, *who: PlayerConverter):
        """Add players to the kill queue.

        They must all be participants.
        """
        guild = fetch_guild(self.bot)
        participant = guild.get_role(conf['ids'].getint("participant"))
        if any(not participant in m.roles for m in who):
            await ctx.send(
                ":warning: One or more of those people are not participants!")
            return
        KillQEntry.insert_many([{"discord_id": p.id} for p in who]).execute()
        await ctx.send(
            ":white_check_mark: {} people added to kill queue!".format(
                len(who)))
示例#6
0
async def close_poll(bot, pollid):
    guild = fetch_guild(bot)
    poll = Poll.get_or_none(id=pollid)
    if poll is None:
        raise errors.NoSuchPoll()

    # get emojis to members, with self removed
    reactions = await get_raw_reactions(bot, poll, guild.me)

    # process the reactions
    processed_reactions, errs = await process_reactions(reactions)

    # format output
    s = await format_poll_output(bot, processed_reactions, errs)

    # delete the poll
    poll.delete_instance(recursive=True)
    return s
示例#7
0
    async def start_game(self, ctx):
        """Assigns the participant role to all players and changes game phase.

        This is equivalent to manually assigning the Participant role to all
        signed up players, then doing `{PREFIX}gamephase set GAME`.
        """
        if not everyone_has_a_role():
            await ctx.send(
                ":warning: We can't start yet, not everyone has a role!")
            return
        guild = fetch_guild(self.bot)
        participant = guild.get_role(conf['ids'].getint("participant"))
        for p in Player.select():
            m = guild.get_member(p.discord_id)
            await m.add_roles(participant)
            await ctx.send("{} is now a participant...".format(m.mention))
        set_game_phase(GamePhases.GAME)
        await ctx.send("Set game phase to `GAME` ({})".format(
            GamePhases.GAME.value))
示例#8
0
 async def list_signedup(self, ctx, mention=False):
     if not is_gamemaster(ctx.author) and mention:
         mention = False
     guild = fetch_guild(self.bot)
     players = list(Player.select())
     count = len(players)
     if count == 0:
         await ctx.send("No one has signed up yet!")
     else:
         if mention:
             await ctx.send("*Total: {} players*\n".format(count) +
                            "\n".join("{} - {}".format(
                                p.emoji,
                                guild.get_member(p.discord_id).mention)
                                      for p in players))
         else:
             await ctx.send("*Total: {} players*\n".format(count) +
                            "\n".join("{} - {}".format(
                                p.emoji,
                                guild.get_member(p.discord_id).display_name)
                                      for p in players))
示例#9
0
    async def killall(self, ctx):
        """Kill everyone in the current Kill Queue.

        Each person in the Kill Queue will have their participant role removed and the dead role added.
        The Kill Queue will then be cleared.
        """
        guild = fetch_guild(self.bot)
        participant = guild.get_role(conf['ids'].getint("participant"))
        dead = guild.get_role(conf['ids'].getint("dead"))
        to_kill = list(KillQEntry.select())
        if len(to_kill) == 0:
            await ctx.send(":warning: The Kill Queue is empty!")
            return

        if await confirm(
                ctx, "All the above people will be killed by this command."):
            for e in to_kill:
                member = guild.get_member(e.discord_id)
                await member.remove_roles(participant)
                await member.add_roles(dead)
                await ctx.send("Killed <@{}>".format(e.discord_id))
            KillQEntry.delete().execute()
            await ctx.send("The Kill Queue has been cleared.")
示例#10
0
 def __init__(self, bot):
     self.bot=bot
     self.guild = fetch_guild(self.bot)
示例#11
0
async def create_new_category(bot):
    guild = fetch_guild(bot)
    cat = await guild.create_category_channel("More CCs rename me")
    CCCategory.create(discord_id=cat.id)
    return cat