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))
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']))
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.")
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))
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))
async def create(self, ctx, ship: int, maxmembers: int, *, questname: str): """Creates a group.""" with self.lock: users = ReadFile('cogs/json/users.json') if ctx.message.author.id in users: file = ReadFile('cogs/json/matchmaking.json') try: id = file['groups'][-1]['id'] + 1 except Exception: id = 0 file['groups'].append({ "id": id, "quest": questname, "ship": ship, "owner": ctx.message.author.id, "members": [ctx.message.author.id], "maxmembers": maxmembers }) if not discord.utils.get(ctx.message.server.roles, name="Group {}".format(id)): await self.bot.create_role(ctx.message.server, name="Group {}".format(id)) await asyncio.sleep(1) await self.bot.add_roles( ctx.message.author, discord.utils.get(ctx.message.server.roles, name="Group {}".format(id))) everyone = discord.PermissionOverwrite(read_messages=False) mine = discord.PermissionOverwrite(read_messages=True, send_messages=True) await self.bot.create_channel( ctx.message.server, 'group-{}'.format(id), (ctx.message.server.default_role, everyone), (discord.utils.get(ctx.message.server.roles, name="Group {}".format(id)), mine)) WriteFile('cogs/json/matchmaking.json', file) message = "@here A group for ``{}`` on Ship {} has been created by ``{}``. Type ``!lfp join {}`` to join!".format( questname, ship, ctx.message.author.nick, id) await self.bot.send_message( discord.Object("174958246837223425"), message) else: await self.bot.say( "You are not registered! Type ``!help reg``.")
async def reg(self, ctx, *, playerID: str): """Register your Player ID and receive full access to the server""" with self.lock: file = ReadFile('cogs/json/users.json') file.update( {"{}".format(ctx.message.author.id): "{}".format(playerID)}) WriteFile('cogs/json/users.json', file) await self.bot.add_roles( ctx.message.author, discord.utils.get(ctx.message.server.roles, name="LFP")) await self.bot.say("{} Registered!".format( ctx.message.author.mention))
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``.")
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))