class AddToTeam: def __init__(self, channel, author, message, users): self.channel = channel self.author = author self.users = users self.team_name = message self.api = Api() async def apply(self): role = get(self.author.roles, name=self.team_name) if role is None and not self.author.top_role.permissions.administrator: await self.channel.send("You are not in this team") return elif self.author.top_role.permissions.administrator: role = get(self.channel.guild.roles, name=self.team_name) if role is None: await self.channel.send("This team does not exists") return for user in self.users: try: user_info = self.api.get_user_info(user.id, 'team_name') if user_info == "": self.api.add_member_to_team(user.id, self.team_name) await user.add_roles(role) await self.channel.send("%s has joined the team!" % user.name) await user.send("You have joined the team %s!" % self.team_name) else: await self.channel.send("The user %s has a team already" % user.name) except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR) as e: await self.channel.send(e.message)
class ChangeTeamName: def __init__(self, channel, author, message, client): self.channel = channel self.guild = get_bits_server(client) self.author = author self.new_name = message self.api = Api() async def apply(self): try: old_name = self.api.get_user_info(self.author.id, 'team_name') role = get(self.author.roles, name=old_name) if role is None: await self.channel.send("Sync error. Contact an organizer") return if get(self.guild.roles, name=self.new_name) is not None: await self.channel.send( "There is already a team with name: %s" % self.new_name) return text_channel = get(self.guild.text_channels, name=old_name) voice_channel = get(self.guild.voice_channels, name=old_name) await role.edit(name=self.new_name) await text_channel.edit(name=self.new_name) await voice_channel.edit(name=self.new_name) self.api.change_team_name(self.author.id, self.new_name) await self.channel.send("Team name changed!") except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR) as e: await self.channel.send(e.message)
def __init__(self, channel, author, message, user, client): self.channel = channel self.author = author self.user = user self.team_name = message self.guild = get_bits_server(client) self.api = Api()
class CreateTeam: def __init__(self, channel, author, message, user, client): self.channel = channel self.author = author self.user = user self.team_name = message self.guild = get_bits_server(client) self.api = Api() async def apply(self): if get(self.author.roles, name=DISCORD_ORGANIZER_ROLE_NAME) is None: await self.channel.send( "You have no permissions to create a new team. Contact an organizer" ) return try: user_info = self.api.get_user_info(self.user.id, 'team_name') if user_info == "": self.api.create_new_team(self.user.id, self.team_name) team_role = await create_channel_rol(self.guild, self.team_name) await self.user.add_roles(team_role) await self.channel.send("Team created!") else: await self.channel.send("This user has a team already") except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR) as e: await self.channel.send(e.message)
class CreateAllTeams: def __init__(self, channel, author, client): self.channel = channel self.author = author self.guild = get_bits_server(client) self.api = Api() async def apply(self): # Check if has Admin permission on Top Role if not self.author.top_role.permissions.administrator: await self.channel.send( "You have no permissions to execute this command") return try: all_users = self.api.get_all_users() all_teams = [ e['team_name'].lower() for e in all_users if e['team_name'].lower() != "" ] unique_teams = list(set(all_teams)) for team in unique_teams: # Check if role does exist on Discord Server. if get(self.guild.roles, name=team) is not None: await self.channel.send("Team %s was already created!" % team) else: # create role await create_channel_rol(self.guild, team) await self.channel.send("Team %s created!" % team) sleep(1) except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR) as e: await self.channel.send(e.message)
class AddSticker: def __init__(self, channel, author, message, user): self.channel = channel self.author = author self.user = user self.sticker_name = message self.api = Api() async def apply(self): if get(self.author.roles, name=DISCORD_ORGANIZER_ROLE_NAME) is None: await self.channel.send("You have no permissions to add stickers") return try: self.api.add_sticker(self.user.id, self.sticker_name) await self.channel.send('Sticker %s added!' % self.sticker_name) except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR) as e: await self.channel.send(e.message)
class User: def __init__(self, member, client): self.guild = get_bits_server(client) self.user = member self.api = Api() # Check in user + add roles async def save(self): try: response = self.api.check_in(self.user.id) type_role = get(self.guild.roles, name=response['type']) team_role = get(self.guild.roles, name=response['team_name'].lower()) if type_role is not None: await self.user.add_roles(type_role) if team_role is not None: await self.user.add_roles(team_role) except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR): await self.user.send("Sync error. Contact an organizer") async def apply(self, channel, user): if get(user.roles, name=DISCORD_ORGANIZER_ROLE_NAME) is None: await channel.send("You have no permissions. Contact an organizer") return try: response = self.api.check_in(self.user.id) type_role = get(self.guild.roles, name=response['type']) team_role = get(self.guild.roles, name=response['team_name'].lower()) if type_role is not None: await self.user.add_roles(type_role) if team_role is not None: await self.user.add_roles(team_role) except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR): await channel.send("Sync error. Contact an organizer")
class GetUserInfo: def __init__(self, channel, author, user): self.channel = channel self.author = author self.user = user self.api = Api() async def apply(self): if get(self.author.roles, name=DISCORD_ORGANIZER_ROLE_NAME) is None: await self.channel.send("You have no permissions to see the required information") return try: info = self.api.get_user_info(self.user.id, 'all') await self.author.send(json.dumps(info, indent=1)) except (self.api.USER_NOT_FOUND, self.api.BAD_REQUEST, self.api.SERVER_ERROR) as e: await self.channel.send(e.message)
def __init__(self, channel, author, user): self.channel = channel self.author = author self.user = user self.api = Api()
def __init__(self, member, client): self.guild = get_bits_server(client) self.user = member self.api = Api()
def __init__(self, channel, author, message, user): self.channel = channel self.author = author self.user = user self.sticker_name = message self.api = Api()
def __init__(self, channel, author, message, users): self.channel = channel self.author = author self.users = users self.team_name = message self.api = Api()
def __init__(self, channel, author, client): self.channel = channel self.author = author self.guild = get_bits_server(client) self.api = Api()