Exemplo n.º 1
0
    async def remove(self, ctx, groupID: int, *, membername: str):
        """Remove a member from a group."""

        if ctx.message.author.id in admins:
            with self.lock:
                file = ReadFile('cogs/json/matchmaking.json')
                id = SearchGroup(groupID)

                try:
                    member = SearchMember(membername)

                    await self.bot.remove_roles(
                        ctx.message.server.get_member(member),
                        discord.utils.get(ctx.message.server.roles,
                                          name="Group {}".format(id)))
                    file['groups'][id]['members'].remove(member)
                    WriteFile('cogs/json/matchmaking.json', file)

                    await self.bot.say(
                        "{} Member ``{}`` removed from the ``{}`` group.".
                        format(ctx.message.author.mention, membername,
                               file['groups'][id]['quest']))
                except Exception as e:
                    await self.bot.say(
                        "{} Member ``{}`` not found in the ``{}`` group.".
                        format(ctx.message.author.mention, membername,
                               file['groups'][id]['quest']))
Exemplo n.º 2
0
    async def remove(self, ctx, member: str):
        """Removes a selected member from a group. GROUP OWNER ONLY"""

        with self.lock:
            file = ReadFile('cogs/json/matchmaking.json')
            index = SearchGroup(id)

            if ctx.message.author.id == file['groups'][index]['owner']:
                try:
                    await self.bot.remove_roles(
                        ctx.message.server.get_member(member),
                        discord.utils.get(ctx.message.server.roles,
                                          name="Group {}".format(id)))
                    file['groups'][index]['members'].remove(member)
                    WriteFile('cogs/json/matchmaking.json', file)

                    await self.bot.say(
                        "{} Member ``{}`` removed from the ``{}`` group.".
                        format(ctx.message.author.mention, member,
                               file['groups'][index]['quest']))
                except Exception as e:
                    await self.bot.say(
                        "{} Member ``{}`` not found in the ``{}`` group.".
                        format(ctx.message.author.mention, member,
                               file['groups'][index]['quest']))
            else:
                await self.bot.say(
                    "{} You are not the owner of the group.".format(
                        ctx.message.author.mention))
Exemplo n.º 3
0
    async def finish(self, ctx, groupID: int):
        """Finishes a group."""

        if ctx.message.author.id in admins:
            with self.lock:
                try:
                    index = SearchGroup(groupID)
                    file = ReadFile('cogs/json/matchmaking.json')

                    server = ctx.message.server
                    for user in file['groups'][index]['members']:
                        await self.bot.remove_roles(
                            server.get_member(user),
                            discord.utils.get(server.roles,
                                              name="Group {}".format(groupID)))

                    await self.bot.delete_channel(
                        discord.utils.get(server.channels,
                                          name="group-{}".format(groupID)))
                    await self.bot.delete_role(
                        server,
                        discord.utils.get(server.roles,
                                          name="Group {}".format(groupID)))

                    file['groups'].pop(index)

                    WriteFile('cogs/json/matchmaking.json', file)
                except:
                    await self.bot.say("Something went wrong.")
Exemplo n.º 4
0
    async def leave(self, ctx):
        """Leaves the selected group."""

        with self.lock:
            if ctx.message.channel.name.startswith('group'):
                groupID = ctx.message.channel.name.split('-')[1]
                file = ReadFile('cogs/json/matchmaking.json')
                index = SearchGroup(int(groupID))

                #print(file['groups'][groupID]['owner'])
                #print(file['groups'][index]['owner'])

                if ctx.message.author.id in file['groups'][index]['members']:
                    await self.bot.remove_roles(
                        ctx.message.author,
                        discord.utils.get(ctx.message.server.roles,
                                          name="Group {}".format(groupID)))

                    file['groups'][index]['members'].remove(
                        ctx.message.author.id)

                    WriteFile('cogs/json/matchmaking.json', file)

                    await self.bot.say(
                        "{} You have been removed from the ``{}`` group.".
                        format(ctx.message.author.mention,
                               file['groups'][index]['quest']))
                else:
                    await self.bot.say("{} You are not in that group.".format(
                        ctx.message.author.mention))
            else:
                await self.bot.say(
                    "{} Group commands must be used in a group channel.".
                    format(ctx.message.author.mention))
Exemplo n.º 5
0
    async def finish(self, ctx):
        with self.lock:
            if ctx.message.channel.name.startswith('group'):
                id = ctx.message.channel.name.split('-')[1]

                index = SearchGroup(int(id))
                file = ReadFile('cogs/json/matchmaking.json')

                if ctx.message.author.id == file['groups'][index]['owner']:
                    server = self.bot.get_server("80900839538962432")
                    for user in file['groups'][index]['members']:
                        await self.bot.remove_roles(
                            server.get_member(user),
                            discord.utils.get(ctx.message.server.roles,
                                              name="Group {}".format(id)))

                    await self.bot.delete_channel(
                        discord.utils.get(ctx.message.server.channels,
                                          name="group-{}".format(id)))
                    await self.bot.delete_role(
                        server,
                        discord.utils.get(ctx.message.server.roles,
                                          name="Group {}".format(id)))

                    file['groups'].pop(index)

                    WriteFile('cogs/json/matchmaking.json', file)
                else:
                    await self.bot.say(
                        "{} Only the group owner can finish the quest.".format(
                            ctx.message.author.mention))
            else:
                await self.bot.say(
                    "{} Group commands must be used in a group channel.".
                    format(ctx.message.author.mention))
Exemplo n.º 6
0
    async def join(self, ctx, id: int):
        """Joins a group."""

        with self.lock:
            users = ReadFile('cogs/json/users.json')
            if ctx.message.author.id in users:
                try:
                    file = ReadFile('cogs/json/matchmaking.json')
                    index = SearchGroup(id)

                    if ctx.message.author.id not in file['groups'][index][
                            'members']:
                        try:
                            await self.bot.add_roles(
                                ctx.message.author,
                                discord.utils.get(ctx.message.server.roles,
                                                  name="Group {}".format(id)))
                            file['groups'][index]['members'].append(
                                ctx.message.author.id)
                            WriteFile('cogs/json/matchmaking.json', file)

                            await self.bot.say(
                                "{} Joined the ``{}`` group, owned by ``{}``.".
                                format(ctx.message.author.mention,
                                       file['groups'][index]['quest'],
                                       users[file['groups'][index]['owner']]))

                        except Exception as e:
                            await self.bot.say(
                                "{} Could not find the requested group. Please check the #group-board channel."
                                .format(ctx.message.author.mention))
                    else:
                        await self.bot.say(
                            "{} You are already in that group.".format(
                                ctx.message.author.mention))
                except:
                    await self.bot.say(
                        "{} Could not find a group with that ID. Check #groups-board for the right ID."
                        .format(ctx.message.author.mention))
            else:
                await self.bot.say(
                    "You are not registered! Type ``!help reg``.")
Exemplo n.º 7
0
    async def leave(self, ctx, id: int):
        """Leaves the selected group."""

        with self.lock:
            file = ReadFile('cogs/json/matchmaking.json')
            index = SearchGroup(id)

            if ctx.message.author.id in file['groups'][index]['members']:
                await self.bot.remove_roles(
                    ctx.message.author,
                    discord.utils.get(ctx.message.server.roles,
                                      name="Group {}".format(id)))

                file['groups'][index]['members'].remove(ctx.message.author.id)

                WriteFile('cogs/json/matchmaking.json', file)

                await self.bot.say(
                    "{} You have been removed from the ``{}`` group.".format(
                        ctx.message.author.mention,
                        file['groups'][id]['quest']))
            else:
                await self.bot.say("{} You are not in that group.".format(
                    ctx.message.author.mention))