def change_catergory(self, event, channel): """ This command is used to change the games cetegory. Usage: `update gc [ChannelID]` """ guild = Guild.using_id(event.guild.id) if isinstance(channel, int): if guild.games_category == channel: return event.msg.reply( '`Error:` New games category matches the current games category.' ) else: guild.games_category = channel guild.save() new_channel = event.guild.channels[channel] return event.msg.reply( 'Updated the games category to **{name}** (`{id}`)'.format( name=new_channel.name, id=new_channel.id)) else: if guild.games_category == channel.id: return event.msg.reply( '`Error:` New games category matches the current games category.' ) else: guild.games_category = channel.id guild.save() return event.msg.reply( 'Updated the games category to **{name}** (`{id}`)'.format( name=channel.name, id=channel.id))
def update_spectators(self, event, role, mode=None): """ This command is used to update the spectator roles. Usage: `change addspec/rvmspec [Role Name or Role ID]` """ if role.isdigit(): role = int(role) arg_role = self.get_role(event, role) if not arg_role: return event.msg.reply( '`Error:` Role not found, please check ID/Name and try again.') guild = Guild.using_id(event.guild.id) if arg_role.id in guild.spectator_roles and mode == 'add': return event.msg.reply( '`Error:` That role is already labled as a spectator.') if arg_role.id not in guild.spectator_roles and mode == 'rvm': return event.msg.reply( '`Error:` That role is not labled as a spectator.') if mode == 'add': guild.spectator_roles.append(arg_role.id) guild.save() return event.msg.reply( 'Added role **{name}** (`{id}`) as a spectator.'.format( name=arg_role.name, id=arg_role.id)) if mode == 'rvm': guild.spectator_roles.remove(arg_role.id) guild.save() return event.msg.reply( 'Removed role **{name}** (`{id}`) as a spectator.'.format( name=arg_role.name, id=arg_role.id))
def list_settings(self, event): settings_msg = """ __**Prefix**__: {prefix} __**Referee Role**__: {rr} __**Games Category**__: {gc} __**Spectator Roles**__: {sr} """ settings = Guild.using_id(event.guild.id) games_category = None if settings.games_category: games_category = event.guild.channels.get(settings.games_category) spectator_roles = [] if len(settings.spectator_roles) > 0: for x in settings.spectator_roles: spectator_roles.append('<@&{}>'.format(x)) embed = MessageEmbed() # embed.color = 0xFF0000 embed.add_field(name='General Settings', value=settings_msg.format( prefix=settings.prefix, rr='{}'.format('`None`' if settings.referee_role == None else '<@&' + str(settings.referee_role) + '>'), gc='{} (`{}`)'.format(games_category.name, games_category.id) if settings.games_category else '`None`', sr='{}'.format('`None`' if len(spectator_roles) == 0 else ', '.join(spectator_roles)) )) embed.add_field(name='Enabled Games', value='{}'.format(''.join(settings.enabled_games_emotes())), inline=True) embed.add_field(name='Disabled Games', value='{}'.format(''.join(settings.disabled_games_emotes())), inline=True) embed.set_footer(text='Go get help with settings, do {}help settings'.format(settings.prefix), icon=self.state.me.get_avatar_url()) return event.msg.reply('', embed=embed)
def update_games(self, event, game, mode=None): """ This command is used to enable/disable games. Usage: `games enable/disable [Game]` Current Games: **Connect 4**, **Uno**, **TicTacToe**, **HangMan** """ game_types = { "uno": 1 << 0, #Uno 'c4': 1 << 1, #Connect4 'ttt': 1 << 2, #TicTacToe 'hm': 1 << 3, #Hangman # '2048': 1 << 4, #2048 # 'trivia': 1 << 5, #Trivia } game_name = game_checker(game) if game_name == None: return event.msg.reply('`Error`: Game not found.') guild = Guild.using_id(event.guild.id) if mode == 'enable': listed = guild.check_if_listed(game_name, 'enabled') if listed: return event.msg.reply('`Error`: Game is already enabled.') else: guild.enabled_games = guild.enabled_games + game_types[game_name] guild.save() return event.msg.reply('Game has been enabled!') if mode == 'disable': listed = guild.check_if_listed(game_name, 'disabled') if listed: return event.msg.reply('`Error`: Game is already disabled.') else: guild.enabled_games = guild.enabled_games - game_types[game_name] guild.save() return event.msg.reply('Game has been disabled!')
def start(cls, event, game_channel, players, game_type): guild = Guild.using_id(event.guild.id) game = cls.create( guild_id=event.guild.id, game_channel=game_channel, players=[x.id for x in players], type_=game_type, ) if guild.log_channel and guild.logs_enabled: embed = MessageEmbed() embed.title = 'Game Ended!' player_list = [] for x in players: player_list.append('`*` {x} | `{x.id}`'.format(x=x)) game_info = [ '**Game**: {}'.format(num_str.get(game_type)), '**Channel**: <#{channel}> (`{channel}`)'.format( channel=game.game_channel), '**ID**: {}'.format(game.id) ] embed.add_field(name='Players »', value='\n'.join(player_list)) embed.add_field(name='Game Info »', value='\n'.join(game_info)) embed.set_footer(text='Started By {}'.format(event.author), icon_url=event.author.get_avatar_url()) embed.timestamp = datetime.utcnow().isoformat() event.guild.channels.get(guild.log_channel)\ .send_message(embed=embed) return game
def create_channels(self, players): guild_obj = Guild.using_id(self.guild.id) channels = [] for player in players: channel_name = "uno-{}-{}".format(self.game_id, player.user) channel_name = channel_name.replace('#', '-') channel = self.guild.create_channel(parent_id=guild_obj.games_category, name=channel_name, channel_type=ChannelType.GUILD_TEXT) self.update_permissions(channel, guild_obj, player) player.message = channel.send_message("Game starting...") channels.append(channel) return channels
def create_channel(self, player): guild_obj = Guild.using_id(self.guild.id) channel_name = "{}-Hangman".format(player) channel_name = channel_name.replace('#', '-') channel_name = channel_name.replace('#', '-') channel = self.guild.create_channel( parent_id=guild_obj.games_category, name=channel_name, channel_type=ChannelType.GUILD_TEXT) self.update_permissions(channel, guild_obj) return channel
def fresh_start(self, event, guild_id): new_guild = Guild.create( guild_id=guild_id, owner_id=event.guild.owner_id, prefix="+", games_catergory=None, spectator_roles=[], enabled_games=0, referee_role=None, role_allow_startgames=None, booster_perks=False, ) return new_guild
def change_prefix(self, event, prefix): """ This command is used to change the bot's prefix. Usage: `update prefix *insert prefix here*` Example: `update prefix !` """ guild = Guild.using_id(event.guild.id) if guild.prefix == prefix: return event.msg.reply('`Error:` New prefix matches the current prefix.') else: guild.prefix = prefix guild.save() return event.msg.reply('Prefix has been updated to `{}`!'.format(guild.prefix))
def func(*args, **kwargs): guild = None try: guild.db = Guild.select().where(Guild.guild_id == kwargs.pop('gid')).get() except Guild.DoesNotExist: return 'Invalid Guild', 404 try: guild.disco = currentapp.discord.api.guilds_get(kwargs.pop('gid')) except APIException return 'Invalid Guild', 404 return f(guild, *args, **kwargs)
def create_channel(self, players): guild_obj = Guild.using_id(self.guild.id) channel_name = "{}_vs_{}".format(self.red_player.user_object, self.blue_player.user_object) channel_name = channel_name.replace('#', '-') channel_name = channel_name.replace('#', '-') channel = self.guild.create_channel( parent_id=guild_obj.games_category, name=channel_name, channel_type=ChannelType.GUILD_TEXT) self.update_permissions(channel, guild_obj) return channel
def update_referee(self, event, role): """ This command is used to change the referee role. Usage: `update ref [Role Name or Role ID]` """ if role.isdigit(): role = int(role) new_role = self.get_role(event, role) if not new_role: return event.msg.reply('`Error:` Role not found, please check ID/Name and try again.') guild = Guild.using_id(event.guild.id) if guild.referee_role == new_role.id: return event.msg.reply('`Error:` New referee role matches the current referee role.') else: guild.referee_role = new_role.id guild.save() return event.msg.reply('Updated the referee role to **{name}** (`{id}`)'.format(name=new_role.name, id=new_role.id))
def end_connect_four(var): game_data = var game = Games.with_id(game_data.id) game.winner = game_data.winner game.turn_count = game_data.turns game.ended = True game.save() guild = Guild.using_id(game_data.guild.id) board = game_data.game_board.get_final() for x in range(4): board = board[:board.rfind('\n')] if guild.log_channel and guild.logs_enabled: embed = MessageEmbed() embed.title = 'Game Ended!' player_list = [] players = [game_data.guild.members.get(x) for x in game_data.players] for x in players: player_list.append('`*` {x} | `{x.id}`'.format(x=x)) game_info = [ '**Game**: {}'.format(num_str.get(1)), '**Total Turns**: {}'.format(game.turn_count), '**ID**: {}'.format(game.id) ] embed.add_field(name='Players »', value='\n'.join(player_list)) embed.add_field(name='Game Info »', value='\n'.join(game_info)) embed.set_footer(text='The Winner Is {}'.format( game_data.guild.members.get(game_data.winner).user), icon_url=game_data.guild.members.get( game_data.winner).user.get_avatar_url()) embed.timestamp = datetime.utcnow().isoformat() game_data.guild.channels.get(guild.log_channel)\ .send_message(embed=embed) bembed = MessageEmbed() bembed.description = board bembed.title = 'Game Board' game_data.guild.channels.get(guild.log_channel)\ .send_message(embed=bembed)
def logs(self, event, channel=None, mode=None): """ This command is used to change the Game Logs settings. Usage: `update logs enable/disable/channel [ChannelID, Mention, Name]` """ guild = Guild.using_id(event.guild.id) if mode == 'enable': guild.logs_enabled = True guild.save() return event.msg.reply( '<{}> Logs have been enabled!'.format(YES_EMOJI)) if mode == 'disable': guild.logs_enabled = False guild.save() return event.msg.reply( '<{}> Logs have been disabled!'.format(YES_EMOJI)) if mode == 'setchannel': if isinstance(channel, int): if guild.log_channel == channel: return event.msg.reply( '`Error:` New logs channel matches the current logs channel.' ) else: guild.log_channel = channel guild.save() new_channel = event.guild.channels[channel] return event.msg.reply( 'Updated the logs channel to **{name}** (`{id}`)'. format(name=new_channel.name, id=new_channel.id)) else: if guild.log_channel == channel.id: return event.msg.reply( '`Error:` New logs channel matches the current logs channel.' ) else: guild.log_channel = channel.id guild.save() return event.msg.reply( 'Updated the logs channel to **{name}** (`{id}`)'. format(name=channel.name, id=channel.id))
def on_message_create(self, event): if event.message.channel.type == ChannelType.DM: return if event.message.author.bot: return user_obj, created = Users.get_or_create(id=event.message.author.id) perms = event.message.channel.get_permissions(self.state.me) if not perms.can(Permissions.SEND_MESSAGES): return event.bot_admin = event.message.author.id in TEMP_BOT_ADMINS event.user_level = 0 has_admin = False new_setup = False guild = None if event.message.guild: try: guild = Guild.using_id(event.guild.id) except Guild.DoesNotExist: guild = self.fresh_start(event, event.guild.id) new_setup = True if len(event.message.member.roles) > 0: for x in event.message.member.roles: role = event.message.guild.roles.get(x) if role.permissions.can(Permissions.ADMINISTRATOR): event.user_level = 100 has_admin = True if guild.referee_role: if not has_admin and guild.referee_role in event.message.member.roles: event.user_level = 50 if event.message.author.bot: return if not event.message.content.startswith( guild.prefix ) and event.message.mentions and self.state.me.id in event.message.mentions: content = event.message.without_mentions content = content.replace(' ', '', -1) if 'prefix' in content.lower(): return event.channel.send_message('Prefix: `{}`'.format( guild.prefix)) else: pass # Grab the list of commands commands = list( self.bot.get_commands_for_message(False, {}, guild.prefix, event.message)) # Used for cmd cooldowns user_ignores_cooldowns = self.cooldown_check(event.message.author.id) # Sorry, nothing to see here :C if not len(commands): return for command, match in commands: if command.name == 'settings' and len(commands) > 1: continue needed_level = 0 if command.level: needed_level = command.level cooldown = 0 if hasattr(command.plugin, 'game'): if not guild.check_if_listed(game_checker(command.plugin.game), 'enabled'): return if command.level == -1 and not event.bot_admin: return if not event.bot_admin and event.user_level < needed_level: continue try: command_event = CommandEvent(command, event.message, match) command_event.bot_admin = event.bot_admin command_event.user_level = event.user_level command_event.db_user = user_obj command_event.db_guild = guild if command.args: if len(command_event.args) < command.args.required_length: self.dis_cmd_help(command, command_event, event, guild) return command.plugin.execute(command_event) except: self.log.exception('Command error:') return event.reply('It seems that an error has occured! :(') if new_setup: event.message.reply( 'Hey! I\'ve noticed that I\'m new to the server and have no config, please check out `{}settings` to edit and setup the bot.' .format(guild.prefix)) return