def is_in_servers(*server_ids): def predicate(ctx): server = ctx.message.server if server is None: return False return server.id in server_ids return commands.check(predicate)
def can_embed(): """Command requires embed links permissions to display it's contents.""" def predicate(ctx: context.NabCtx): if not ctx.bot_permissions.embed_links: raise errors.CannotEmbed() return True return commands.check(predicate)
def is_owner(): def predicate(ctx): if ctx.author.id == config.owner_id: return True else: raise owner_only return commands.check(predicate)
def is_in_guilds(*guild_ids): def predicate(ctx): guild = ctx.guild if guild is None: return False return guild.id in guild_ids return commands.check(predicate)
def is_nsfw_channel(): def predicate(ctx): if not isinstance(ctx.channel, discord.DMChannel) and ctx.channel.is_nsfw(): return True else: raise not_nsfw_channel return commands.check(predicate)
def is_support(): def predicate(ctx): if ctx.author.id in config.support_ids or ctx.author.id in config.dev_ids or ctx.author.id == config.owner_id: return True else: raise support_only return commands.check(predicate)
def has_permissions(**permissions): def predicate(ctx): if all(getattr(ctx.channel.permissions_for(ctx.author), name, None) == value for name, value in permissions.items()): return True else: raise no_permission return commands.check(predicate)
def is_guild_owner(): def predicate(ctx): if ctx.author.id == ctx.guild.owner_id: return True else: raise not_guild_owner return commands.check(predicate)
def in_server(server_id): """Commands decorator adding a check which makes the command available from the given server only.""" def predicate(ctx): server = ctx.message.server return server is not None and server.id == server_id return commands.check(predicate)
def custom_perms(**perms): def predicate(ctx): # Return true if this is a private channel, we'll handle that in the registering of the command if ctx.message.channel.is_private: return True # Get the member permissions so that we can compare member_perms = ctx.message.author.permissions_in(ctx.message.channel) # Next, set the default permissions if one is not used, based on what was passed # This will be overriden later, if we have custom permissions required_perm = discord.Permissions.none() for perm, setting in perms.items(): setattr(required_perm, perm, setting) try: server_settings = config.cache.get('server_settings').values required_perm_value = [x for x in server_settings if x['server_id'] == ctx.message.server.id][0]['permissions'][ctx.command.qualified_name] required_perm = discord.Permissions(required_perm_value) except (TypeError, IndexError, KeyError): pass # Now just check if the person running the command has these permissions return member_perms >= required_perm predicate.perms = perms return commands.check(predicate)
def recruiter_or_permissions(**perms): def predicate(ctx): server = ctx.message.server recruiter_role = settings.get_server_recruiter(server).lower() return role_or_permissions(ctx, lambda r: r.name.lower() == recruiter_role, **perms) return commands.check(predicate)
def setting_command(): """Local check that provides a custom message when used on PMs.""" async def predicate(ctx): if ctx.guild is None: raise commands.NoPrivateMessage("Settings can't be modified on private messages.") return True return commands.check(predicate)
def admin_or_permissions(**perms): def predicate(ctx): server = ctx.message.server admin_role = ctx.bot.settings.get_server_admin(server) return role_or_permissions(ctx, lambda r: r.name.lower() == admin_role.lower(), **perms) return commands.check(predicate)
def is_admin(): def predicate(ctx): return ( ctx.message.author.id == config["GENERAL"]["adminID"] or ctx.message.author.id == config["GENERAL"]["adminID2"] ) return commands.check(predicate)
def owner_only(): """Command can only be executed by the bot owner.""" async def predicate(ctx): res = await is_owner(ctx) if not res: raise errors.UnathorizedUser("You are not allowed to use this command.") return True return commands.check(predicate)
def server_admin_only(): """Command can only be executed by a server administrator.""" async def predicate(ctx): res = await check_guild_permissions(ctx, {'administrator': True}) or await is_owner(ctx) if res: return True raise errors.UnathorizedUser("You need Administrator permission to use this command.") return commands.check(predicate)
def developer(): def wrapper(ctx): with open('data/devs.json') as f: devs = json.load(f) if ctx.author.id in devs: return True raise commands.MissingPermissions('You cannot use this command because you are not a developer.') return commands.check(wrapper)
def mod_or_permissions(**perms): def predicate(ctx): server = ctx.message.server mod_role = settings.get_server_mod(server).lower() admin_role = settings.get_server_admin(server).lower() return role_or_permissions(ctx, lambda r: r.name.lower() in (mod_role,admin_role), **perms) return commands.check(predicate)
def server_mod_only(): """Command can only be used by users with manage guild permissions.""" async def predicate(ctx): res = await check_guild_permissions(ctx, {'manage_guild': True}) or await is_owner(ctx) if res: return True raise errors.UnathorizedUser("You need Manage Server permissions to use this command.") return commands.check(predicate)
def is_owner(warn=True): def check(ctx, warn): owner = is_owner_check(ctx.message) if not owner and warn: print(ctx.message.author.name + " à essayer d'executer " + ctx.message.content + " sur le serveur " + ctx.message.guild.name) return owner owner = commands.check(lambda ctx: check(ctx, warn)) return owner
def check_permissions(**perms): def pred(ctx): msg = ctx.message ch = msg.channel author = msg.author resolved = ch.permissions_for(author) return all(getattr(resolved, name, None) == value for name, value in perms.items()) return check(pred)
def requires_starboard(): def predicate(ctx): ctx.guild_id = ctx.message.server.id ctx.starboard_db = ctx.cog.stars_db.get(ctx.guild_id, {}) ctx.starboard_channel = ctx.bot.get_channel(ctx.starboard_db.get('channel')) if ctx.starboard_channel is None: raise StarboardError("\N{WARNING SIGN} Starboard channel not found.") return True return commands.check(predicate)
def is_council_lite_or_higher(): def pred(ctx): server = ctx.message.server if server is None or server.id != BLOB_GUILD_ID: return False council_lite = discord.utils.find(lambda r: r.id == COUNCIL_LITE_ID, server.roles) return ctx.message.author.top_role >= council_lite return commands.check(pred)
def has_permissions(**perms): """Command can only be used if the user has the provided permissions.""" async def pred(ctx): ret = await check_permissions(ctx, perms) if not ret: raise commands.MissingPermissions(perms) return True return commands.check(pred)
def is_random(): # for testing stuff """ Checks if user requesting a command is Extra_Random, if not command will not execute Usage: wrapper of command """ def predicate(ctx): return ctx.message.author.id == "92562410493202432" return commands.check(predicate)
def is_moderator(): def _is_moderator(ctx): if ctx.guild is None: return False member = ctx.guild.get_member(ctx.author.id) perms = ctx.channel.permissions_for(member) return (ctx.author.id == ctx.bot.owner_id ) or perms.kick_members or perms.ban_members return commands.check(_is_moderator)
def is_idiotech(): """ Checks if user requesting a command is Idiotech, if not command will not execute Usage: wrapper of command """ def predicate(ctx): return ctx.message.author.id == "176291669254209539" return commands.check(predicate)
def is_scream(): """ Checks if user requesting a command is iScrE4m, if not command will not execute Usage: wrapper of command """ def predicate(ctx): return ctx.message.author.id == "132577770046750720" return commands.check(predicate)
def has_permissions(**perms): def predicate(ctx): member = perms.get("member", ctx.message.author) if ctx.message.author == ctx.message.server.owner: return True channel = ctx.message.channel resolved = channel.permissions_for(member) return all(getattr(resolved, name, None) == value for name, value in perms.items()) return commands.check(predicate)
def server_mod_or_perms(**permissions): def predicate(ctx): if not ctx.guild: return True mod_role_name = read_data_entry(ctx.guild.id, "mod-role") mod = discord.utils.get(ctx.author.roles, name=mod_role_name) if mod or permissions and all(getattr(ctx.channel.permissions_for(ctx.author), name, None) == value for name, value in permissions.items()): return True else: raise no_permission return commands.check(predicate)
def is_developer(): async def predicate(ctx): return ctx.author.id == ID.user.developer return commands.check(predicate)
def is_bot_admin(): async def predicate(ctx): return ctx.author.id in botconfig["bot_admins"] return commands.check(predicate)
def is_dev(): return commands.check(is_dev_check)
class SupportService(commands.Cog): def __init__(self, bot): self.bot = bot @commands.group() @commands.check(is_public) @commands.bot_has_guild_permissions(administrator=True, manage_messages=True) @commands.check_any(commands.has_guild_permissions(administrator=True), commands.check(is_overwatch), commands.check(is_community_owner)) async def support(self, ctx): try: await ctx.message.delete() except Exception: pass if ctx.invoked_subcommand is None: title = '__Available commands under ***Support*** category!__' description = 'Support System was designed to allow community owners collection of support' \ ' requests to one channel and respond to users. Bellow are availabale commands' value = [{'name': f'{bot_setup["command"]} support set_channel <discord channel>', 'value': "Sets the channel where requested support tickets will be sent"}, {'name': f'{bot_setup["command"]} support on', 'value': "Sets the support service ON"}, {'name': f'{bot_setup["command"]} support off ', 'value': "Sets support service off"} ] await custom_message.embed_builder(ctx=ctx, title=title, description=description, data=value) @support.command() @commands.check(is_support_registered) async def set_channel(self, ctx, chn: TextChannel): try: await ctx.message.delete() except Exception: pass if sup_sys_mng.modify_channel(community_id=ctx.message.guild.id, channel_id=int(chn.id), channel_name=f'{chn}'): info_embed = Embed(title='__Support System Message__', description='You have successfully set channel to listen for ticket supports.', colour=Colour.green()) info_embed.set_thumbnail(url=self.bot.user.avatar_url) info_embed.add_field(name='Channel Name', value=f'{chn}', inline=False) info_embed.add_field(name='Channel ID', value=f'{chn.id}', inline=False) info_embed.add_field(name=':warning: Notice :warning: ', value='If you will delete channel which is assigned to listen for ' 'support messages, it wont work, and you will need to set different channel', inline=False) info_embed.add_field(name='How to create support ticket', value=f'commands ticket issue') await ctx.author.send(embed=info_embed) else: message = f'There has been system backend error. Please try again later! We apologize for inconvinience' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) @support.command() @commands.check(is_support_registered) @commands.check(check_if_support_channel_registered) async def on(self, ctx): try: await ctx.message.delete() except Exception: pass if sup_sys_mng.turn_on_off(community_id=ctx.message.guild.id, direction=1): title = '__System Message__' message = f'You have turned ON support ticket service successfully. Members can now create ' \ f'ticket by executing command {bot_setup["command"]} ticket <message>' await custom_message.system_message(ctx=ctx, color_code=0, message=message, destination=1, sys_msg_title=title) else: message = f'There has been system backend error while trying to turn support service ON. ' \ f'Please try again later! We apologize for inconvinience' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) @support.command() @commands.check(is_support_registered) @commands.check(check_if_support_channel_registered) async def off(self, ctx): try: await ctx.message.delete() except Exception: pass if sup_sys_mng.turn_on_off(community_id=int(ctx.message.guild.id), direction=0): title = '__System Message__' message = 'You have turned OFF automtic jail system and profanity successfully.' \ ' Your members can get crazy' await custom_message.system_message(ctx=ctx, color_code=0, message=message, destination=1, sys_msg_title=title) else: message = f'There was a backend error. Please try again later or contact one of the administrators ' \ f'on the community. We apologize for inconvinience' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) @set_channel.error async def set_channel_error(self, ctx, error): if isinstance(error, commands.CheckFailure): message = f'You have not registered community yet into ***SUPPORT*** system. Please first ' \ f'execute ***{bot_setup["command"]}service register support***' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) elif isinstance(error, commands.MissingRequiredArgument): message = f'You did not provide all required arguments. Command structure is {bot_setup["command"]} ' \ f'support set_channel <#discord.TextChannel>.' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) elif isinstance(error, commands.BadArgument): message = f'You have provide wrong argument for channel part. Channel needs to be tagged with' \ f' #chanelName and a Text Channel Type. Command structure is {bot_setup["command"]} support set_channel <#discord.TextChannel>.' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) else: title = '__:bug: Found__' message = f'Bug has been found while executing command and {self.bot.user} service team has been' \ f' automatically notified. We apologize for inconvinience!' await custom_message.system_message(ctx, message=message, color_code=1, destination=1, sys_msg_title=title) dest = await self.bot.fetch_user(user_id=int(360367188432912385)) await custom_message.bug_messages(ctx=ctx, error=error, destination=dest) @on.error async def on_error(self, ctx, error): if isinstance(error, commands.CheckFailure): message = f'You either have not registered community for ***SUPPORT*** system --> ' \ f'execute {bot_setup["command"]}service register support\n or have not set destination' \ f' where tickets wil be sent {bot_setup["command"]} support set_channel <#discord.TextChannel> ' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) else: title = '__:bug: Found__' message = f'Bug has been found while executing command and {self.bot.user} service ' \ f'team has been automatically notified. We apologize for inconvinience!' await custom_message.system_message(ctx, message=message, color_code=1, destination=1, sys_msg_title=title) dest = await self.bot.fetch_user(user_id=int(360367188432912385)) await custom_message.bug_messages(ctx=ctx, error=error, destination=dest) @off.error async def off_error(self, ctx, error): if isinstance(error, commands.CheckFailure): message = f'You either have not registered community for ***SUPPORT*** system --> ' \ f'execute {bot_setup["command"]}service register support\n or have not set destination ' \ f'where tickets wil be sent {bot_setup["command"]} support set_channel <#discord.TextChannel> ' await custom_message.system_message(ctx, message=message, color_code=1, destination=1) else: title = '__:bug: Found__' message = f'Bug has been found while executing command and {self.bot.user} service team has been ' \ f'automatically notified. We apologize for inconvinience!' await custom_message.system_message(ctx, message=message, color_code=1, destination=1, sys_msg_title=title) dest = await self.bot.fetch_user(user_id=int(360367188432912385)) await custom_message.bug_messages(ctx=ctx, error=error, destination=dest)
def decorator(check): def predicate(ctx): return in_pm(ctx) return commands.check(predicate)
def sudo(): def predicate(ctx): return sudoer(ctx) return commands.check(predicate)
def owner(): def predicate(ctx): return bot_owner(ctx) return commands.check(predicate)
def has_permissions(*, check=all, **perms): """ discord.Commands method to check if author has permissions """ async def pred(ctx): return await check_permissions(ctx, perms, check=check) return commands.check(pred)
def is_owner(): return commands.check(lambda ctx: ctx.author.id == 300396755193954306)
def isOwner(): # for decorators async def predicate(ctx): return ctx.bot.isOwner(ctx) return commands.check(predicate)
def check_channel(): """restrict the bot to respond in the "bot-commands" channel only""" def predicate(ctx, *args, **kwargs): return str(ctx.channel) == "bot-commands" return commands.check(predicate)
def is_dj(): def predicate(ctx): return getattr(ctx.player, "dj", None) == ctx.author return commands.check(predicate)
def is_in_guilds(*guild_keys): """Only allow this command on certain guilds""" async def predicate(ctx): return get_guild_key(ctx.guild) in guild_keys return commands.check(predicate)
def admin_check(): # check if the user is an admin def predicate(ctx): return ctx.message.author.server_permissions.administrator return commands.check(predicate)
def is_dev(): """For limiting commands to developers (reloads and such)""" def predicate(ctx): return ctx.message.author.id in settings.devs return commands.check(predicate)
def vote(action): async def predicate(ctx): if ctx.author == ctx.player.dj: return True if action == "skip": text = _( "{user} wants to skip a track. React if you agree. **{current}/{total}** voted for it!" ) elif action == "pause_resume": text = _( "{user} wants to pause/resume the player. React if you agree. **{current}/{total}** voted for it!" ) elif action == "stop": text = _( "{user} wants to stop playback. React if you agree. **{current}/{total}** voted for it!" ) elif action == "volume": text = _( "{user} wants to change the volume. React if you agree. **{current}/{total}** voted for it!" ) elif action == "loop": text = _( "{user} wants to toggle repeating. React if you agree. **{current}/{total}** voted for it!" ) elif action == "equalizer": text = _( "{user} wants to change the equalizer. React if you agree. **{current}/{total}** voted for it!" ) members = [ m for m in ctx.bot.get_channel(int(ctx.player.channel_id)).members if m != ctx.guild.me ] accepted = {ctx.author} needed = int(len(members) / 2) + 1 msg = await ctx.send( text.format(user=ctx.author.mention, current=len(accepted), total=needed)) def check(r, u): return (u in members and u not in accepted and str(r.emoji) == "\U00002705" and r.message.id == msg.id) await msg.add_reaction("\U00002705") while len(accepted) < needed: try: r, u = await ctx.bot.wait_for("reaction_add", check=check, timeout=10) except asyncio.TimeoutError: raise VoteDidNotPass() accepted.add(u) await msg.edit(content=text.format( user=ctx.author.mention, current=len(accepted), total=needed)) await msg.delete() await ctx.send(_("Vote passed!")) return True return commands.check(predicate)
def is_not_locked(): def predicate(ctx): return (not getattr(ctx.player, "locked", False) or getattr(ctx.player, "dj", None) == ctx.author) return commands.check(predicate)
def is_me(): def predicate(ctx): return ctx.message.author.id == Constants.owner_id return commands.check(predicate)
def has_permissions(*, check=all, **perms): async def pred(ctx): return await check_permissions(ctx, perms, check=check) return commands.check(pred)
def is_vip_server(): async def pred(ctx): return ctx.author.guild.id == 601052758929309736 return commands.check(pred)
def get_player(): def predicate(ctx): ctx.player = ctx.bot.wavelink.get_player(ctx.guild.id, cls=Player) return True return commands.check(predicate)
def isBotPerson(): def predicate(ctx): return ctx.message.author.id in [195587810131050496] return commands.check(predicate)
def is_owner(): return commands.check(is_owner_check)
def requires_admin(): """Decorator for commands that require to be an admin""" async def predicate(ctx: Context): return ctx.author.id in admins return check(predicate)
"""Checks for a user to be in a class line.""" async def predicate(ctx: Context) -> bool: async with ctx.bot.pool.acquire() as conn: ret = await conn.fetchval( 'SELECT class FROM profile WHERE "user"=$1;', ctx.author.id ) if (check := ctx.bot.in_class_line(ret, class_)) and class_ == "Ranger": ctx.pet_data = await conn.fetchrow( 'SELECT * FROM pets WHERE "user"=$1;', ctx.author.id ) if not check: raise WrongClass(class_) return True return commands.check(predicate) def is_nothing(ctx: Context) -> bool: """Checks for a user to be human and not taken cv yet.""" if ctx.character_data["race"] == "Human" and ctx.character_data["cv"] == -1: return True return False def has_god() -> "_CheckDecorator": """Checks for a user to have a god.""" async def predicate(ctx: Context) -> bool: if not hasattr(ctx, "character_data"): ctx.character_data = await ctx.bot.pool.fetchrow(
def is_bot_guy(): async def predicate(ctx): return ctx.author.id == BOT_GUY return commands.check(predicate)
def is_gm() -> "_CheckDecorator": async def predicate(ctx: Context) -> bool: return ctx.author.id in ctx.bot.config.game_masters return commands.check(predicate)
def is_sticker_admin(): return commands.check(is_sticker_admin_check)
def is_idle(): async def predicate(ctx: commands.Context): return await (ctx.bot.map.get_player(ctx.author.id)).is_traveling() return commands.check(predicate)
- !tournament-submissions-list - View your submissions Please note that I will only respond to submission-related commands if sent in a DM; do not attempt to submit a solution file in a public channel, for obvious reasons. Finally, it hopefully goes without saying, but please do not deliberately DDOS me or submit an excessive number of non-scoring solutions. I'm just a small bot trying to make my way in the world with naught but a raspberry pi and limited SD card space! """, allowed_mentions=discord.AllowedMentions(users=False) ) # Don't actually ping me def _no_dm(ctx): """Check for dis-allowing a command from being run in a DM.""" return ctx.message.guild is not None no_dm = commands.check(_no_dm) @bot.command(name='run', aliases=['r', 'score', 'validate', 'check']) @no_dm async def run(ctx): """Run/validate the attached solution file. Must be a Community Edition export. """ assert len( ctx.message.attachments) == 1, "Expected one attached solution file!" soln_bytes = await ctx.message.attachments[0].read() try: soln_str = soln_bytes.decode("utf-8") except UnicodeDecodeError as e: