class invites: async def command(client, message, channel:ChannelBase=None): guild = message.channel.guild if channel is None: if not guild.cached_permissions_for(client).can_manage_guild: await client.message_create(message.channel, 'I dont have enough permission, to request the invites.') return invites = await client.invite_get_guild(guild) else: if not channel.cached_permissions_for(client).can_manage_channel: await client.message_create(message.channel, 'I dont have enough permission, to request the invites.') return invites = await client.invite_get_channel(channel) pages=[Embed(description=chunk) for chunk in pchunkify(invites,write_parents=False)] await Pagination(client, message.channel,pages,120.) category = 'ADMINISTRATION' checks = [checks.has_guild_permissions(Permission().update_by_keys(manage_channel=True), handler=permission_check_handler)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('invites', ( 'I can list you the invites of the guild.\n' f'Usage: `{prefix}invites <channel>`\n' 'If `channel` is passed, I ll check the invites only at that channel.' ), color=ADMINISTRATION_COLOR).add_footer( 'Guild only! You must have manage_channel permission to use this command.')
class reaction_clear: async def command(client, message, message_id:int): while True: if not message.channel.cached_permissions_for(client).can_manage_messages: content='I have no permissions to execute this command at the channel.' break try: target_message = await client.message_get(message.channel, message_id) except DiscordException: content = 'Could not find that message.' break await client.reaction_clear(target_message) content = 'Done, pat me now!' break message = await client.message_create(message.channel, content) await sleep(30., KOKORO) await client.message_delete(message) category = 'ADMINISTRATION' checks=[checks.has_permissions(Permission().update_by_keys(manage_messages=True), handler=permission_check_handler)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('reaction_clear', ( 'Do you want me to remvoe all the reactions from a message?\n' f'Usage: `{prefix}reaction_clear *message_id*`' ), color=ADMINISTRATION_COLOR).add_footer( 'Guild only! You must have manage messages permission to invoke this command.!')
class message_pure: async def command(client, message, message_id: int, channel: Converter('channel', default_code='message.channel')): if not channel.cached_permissions_for(client).can_read_message_history: await client.message_create( message.channel, 'I am unable to read the messages at the specified channel.') return try: data = await client.http.message_get(channel.id, message_id) except DiscordException as err: await client.message_create(message.channel, repr(err)) return await Pagination(client, message.channel, [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ]) category = 'UTILITY' checks = [ checks.has_permissions(Permission().update_by_keys(administrator=True)) ] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed( 'message_pure', ('If you want, I show the pure json representing a message.\n' f'Usage: `{prefix}message_pure *message_id* <channel>`\n' 'By default `channel` is the channel, where you used the command.' ), color=UTILITY_COLOR).add_footer('Guild only! Administrator only!')
class logs: async def command(client, message, guild:'guild'=None, user:User=None, event_name: str=''): if guild is None: guild = message.guild if guild is None: await client.message_create(message.channel, 'Cannot default to current guild. The command was not called from a guild.') return if not guild.cached_permissions_for(client).can_view_audit_logs: await client.message_create(message.channel, 'I have no permissions at the guild, to request audit logs.') return while True: if not event_name: event=None break try: event = AuditLogEvent.INSTANCES[int(event_name)] break except (KeyError, ValueError): pass try: event = getattr(AuditLogEvent, event_name.upper()) break except AttributeError: pass event = None break with client.keep_typing(message.channel): iterator = client.audit_log_iterator(guild,user,event) await iterator.load_all() logs = iterator.transform() await Pagination(client, message.channel, [Embed(description=chunk) for chunk in pchunkify(logs)]) category = 'ADMINISTRATION' checks=[checks.has_guild_permissions(Permission().update_by_keys(view_audit_logs=True), handler=permission_check_handler)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('logs', ( 'I can list you the audit logs of the guild.\n' f'Usage: `{prefix}logs <guild> <user> <event>`\n' 'Both `user` and `event` is optional.\n' '`user` is the user, who executed the logged oprations.\n' 'The `event` is the internal value or name of the type of the ' 'operation.' ), color=ADMINISTRATION_COLOR).add_footer( 'Guild only!')
class auto_pyramid: async def command(client, message, emoji:Emoji, size:int): while True: if size < 2: error_message = 'That is pretty small. OOF' elif size > 23: error_message = 'That is HUGE! Thats what she said...' else: break await client.message_create(message.channel, error_message) return should_check_external = (emoji.is_custom_emoji() and (emoji.guild is not message.guild)) available_clients = [] channel = message.channel for client_ in channel.clients: permissions = channel.cached_permissions_for(client_) if not permissions.can_send_messages: continue if not client_.can_use_emoji(emoji): continue if should_check_external and (not permissions.can_use_external_emojis): continue available_clients.append(client_) if len(available_clients) < 2: await client.message_create(message.channel,f'There need to be at least 2 client at the channel, who can ' f'build a pyramid, meanwhile there is only {len(available_clients)}') return for client_, count in zip(cycle(available_clients), chain(range(1,size),range(size,0,-1))): await client_.message_create(channel, ' '.join(emoji.as_emoji for _ in range(count))) checks = [checks.has_guild_permissions(Permission().update_by_keys(manage_messages=True))] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('execute',( 'Creates a pyramid!\n' f'Usage: `{prefix}auto-pyramid <emoji> <size>`' ), color=SATORI_HELP_COLOR).add_footer( 'Guild only! You must have manage messages permission to use it.') async def parser_failure_handler(client, message, command, content, args): embed = await command.description(client, message) await Closer(client, message.channel, embed)
class invite_create: async def command(client, message, content): user = message.author invite_ = None if content == 'perma': if client.is_owner(user) or user is message.guild.owner: invite_ = await client.vanity_invite(message.guild) if invite_ is None: max_age = 0 max_use = 0 else: await client.message_create(message.channel, 'You must be the owner of the guild, to create a permanent invite.') return else: max_age = 21600 max_use = 1 try: if invite_ is None: invite_ = await client.invite_create_pref(message.guild, max_age, max_use) except DiscordException as err: content = repr(err) except ValueError as err: content = err.args[0] else: if invite_ is None: content = 'I do not have enought permission to create invite from the guild\'s prefered channel.' else: content = f'Here is your invite, dear:\n\n{invite_.url}' channel = await client.channel_private_create(user) try: await client.message_create(channel, content) except DiscordException as err: if err.code == ERROR_CODES.cannot_send_message_to_user: await client.message_create(message.channel, 'You have DM disabled, could not send the invite.') category = 'ADMINISTRATION' checks = [checks.owner_or_has_guild_permissions(Permission().update_by_keys(create_instant_invite=True), handler=permission_check_handler)] async def description(client, message): guild = message.channel.guild user = message.author if guild is None: full = False else: if user == guild.owner: full = True else: full = False if not full: full = client.is_owner(user) prefix = client.command_processer.get_prefix_for(message) if full: content = ( 'I create an invite for you, to this guild.\n' f'Usage: `{prefix}invite-create (perma)`\n' 'By passing `perma` after the command, I ll create for you, my dear A permanent invite to the guild.' ) else: content=( 'I create an invite for you, to this guild.\n' f'Usage: `{prefix}invite-create`' ) return Embed('create-invite', content, color=ADMINISTRATION_COLOR).add_footer( 'Guild only. You must have `create instant invite` permission to invoke this command.')
class emoji_role: async def command(client, message, emoji:Emoji, *roles:'role'): permissions = message.channel.cached_permissions_for(client) if (not permissions.can_manage_emojis) or (not permissions.can_add_reactions): await client.message_create(message.channel, embed = Embed(description='I have no permissions to edit emojis, or to add reactions.')) return roles = sorted(roles) roles_ = emoji.roles embed = Embed().add_author(emoji.url, emoji.name) if (roles_ is None) or (not roles_): role_text = '*none*' else: role_text = ', '.join([role.mention for role in roles_]) embed.add_field('Roles before:', role_text) if (not roles): role_text = '*none*' else: role_text = ', '.join([role.mention for role in roles]) embed.add_field('Roles after:', role_text) message = await client.message_create(message.channel, embed=embed) for emoji_ in ROLE_EMOJI_EMOJIS: await client.reaction_add(message, emoji_) try: event = await wait_for_reaction(client, message, _role_emoji_emoji_checker(message.guild), 300.) except TimeoutError: emoji_ = ROLE_EMOJI_CANCEL else: emoji_ = event.emoji if message.channel.cached_permissions_for(client).can_manage_messages: try: await client.reaction_clear(message) except BaseException as err: if isinstance(err, ConnectionError): # no internet return if isinstance(err, DiscordException): if err.code in ( ERROR_CODES.invalid_access, # client removed ERROR_CODES.unknown_message, # message deleted ERROR_CODES.invalid_permissions, # permissions changed meanwhile ): return raise if emoji_ is ROLE_EMOJI_OK: try: await client.emoji_edit(emoji, roles=roles) except DiscordException as err: footer = repr(err) else: footer = 'Emoji edited succesfully.' elif emoji_ is ROLE_EMOJI_CANCEL: footer = 'Emoji edit cancelled' else: #should not happen return embed.add_footer(footer) await client.message_edit(message, embed=embed) name = 'emoji-role' category = 'ADMINISTRATION' checks = [checks.has_permissions(Permission().update_by_keys(administrator=True), handler=permission_check_handler)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('emoji-role', ( 'Edits the emoji for which roles is available for.\n' f'Usage: `{prefix}emoji-role *emoji* <role_1> <role_2> ...`\n' ), color=ADMINISTRATION_COLOR).add_footer( 'Guild only. You must have adminsitartor permission to execute this command')
class bans: async def command(client, message): guild = message.channel.guild if (guild is None): return if not guild.cached_permissions_for(client).can_ban_users: await client.message_create(message.channel, embed = Embed( description = 'I have no permissions at the guild.', color=ADMINISTRATION_COLOR)) return ban_data = await client.guild_bans(guild) if not ban_data: await client.message_create(message.channel, 'None') return embeds = [] maintext = f'Guild bans for {guild.name} {guild.id}:' limit = len(ban_data) index = 0 while True: field_count = 0 embed_length = len(maintext) embed = Embed(title=maintext) embeds.append(embed) while True: user, reason = ban_data[index] if reason is None: reason = 'Not defined.' name = f'{user:f} {user.id}' embed_length += len(reason)+len(name) if embed_length > 5900: break embed.add_field(name,reason) field_count += 1 if field_count == 25: break index +=1 if index == limit: break if index == limit: break index = 0 field_count = 0 embed_ln = len(embeds) result = [] while True: embed = embeds[index] index +=1 embed.add_footer(f'Page: {index}/{embed_ln}. Bans {field_count+1}-{field_count+len(embed.fields)}/{limit}') field_count += len(embed.fields) result.append(embed) if index == embed_ln: break await Pagination(client, message.channel, result) category = 'ADMINISTRATION' checks = [checks.has_guild_permissions(Permission().update_by_keys(ban_users=True), handler=permission_check_handler)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('bans', ( 'I ll show you the banned users at the guild.\n' f'Usage: `{prefix}bans`' ), color=ADMINISTRATION_COLOR).add_footer( 'Guild only. You must have `ban user` permission to ' 'invoke this command.')
async def send_wait_delete(client, message, text, delay=SECOND_DELAY): """ Sends the given data and deletes it after the seconds given defaults to 10 """ msg = await client.message_create(message, text) await sleep(delay) await client.message_delete(message, msg) #HANDLER async def NO_PERMISSION_HANDLER(client, message, command, check): to_send = embed_template( user=message.author, titles='Permission Denied', descript=f"You must have the `" f"{' '.join(permission_name.replace('_',' ') for permission_name in check.permissions)}" f"` permission to use `{command}` command") send_wait_delete(client, message, to_send) #CHECKS CHECK_MANAGE_GUILD = checks.has_guild_permissions( Permission().update_by_keys(manage_guild=True), handler=NO_PERMISSION_HANDLER, )
new = self for name, value in kwargs.items(): shift = BEHAVIOUR_FLAG_KEYS[name] if value: new = new | (1 << shift) else: if (new >> shift) & 1: new = new ^ (1 << shift) return type(self)(new) def __repr__(self): return f'{self.__class__.__name__}({int.__repr__(self)})' AUTO_REACT_ROLE_REQUIRED_PERMISSIONS = Permission().update_by_keys( manage_messages=True, manage_roles=True) async def create_auto_react_role(client, message, target_message: MESSAGE_CONVERTER): channel = target_message.channel guild = channel.guild if guild is None: await client.message_create( message.channel, 'The given message do not belongs to a guild.') return if (message.guild is not message.guild) and (not guild.permissions_for( message.author).can_administrator): await client.mesage_create( message.channel,
text = f'Joined channel: {channel.name}.' break await client.message_create(message.channel, text) async def party_is_over_description(client,message): prefix = client.command_processer.get_prefix_for(message) return Embed('party-is-over',( 'Should I mark the talking party as done?\n' f'Usage: `{prefix}party-is-over`' ), color=MAIN_VOICE_COLOR).add_footer( 'Administartor only!') @VOICE_COMMANDS_MAIN(description=party_is_over_description, checks=[ checks.has_guild_permissions(Permission().update_by_keys(administrator=True)), checks.client_has_guild_permissions(Permission().update_by_keys(move_users=True)) ], aliases=['partyisover']) async def party_is_over(client, message): guild = message.guild if guild is None: return while True: voice_client = client.voice_client_for(message) if voice_client is None: text = 'I don\'t see any parties arround me.' break Task(voice_client.disconnect(), KOKORO)
class auto_pyramid_u: async def command(client, message, emoji:Emoji, size:int): while True: if size < 2: error_message = 'That is pretty small. OOF' elif size > 23: error_message = 'That is HUGE! Thats what she said...' else: break await client.message_create(message.channel, error_message) return if emoji.is_custom_emoji() and (emoji.managed or (emoji.roles is not None) or (emoji.guild is not message.guild)): await client.message_create(message.channel, 'No managed, limited to role or outer custom emojis are allowed.') return channel = message.channel if not channel.cached_permissions_for(client).can_manage_webhooks: await client.message_create(channel, 'I need manage webhooks permission to execute this command.') return webhooks = await client.webhook_get_channel(channel) for webhook in webhooks: if webhook.type is WebhookType.bot: executor_webhook = webhook break else: executor_webhook = None if (executor_webhook is None): executor_webhook = await client.webhook_create(channel, 'auto-pyramider') users = list(message.guild.users.values()) selected_users = [] needed_users = (size<<1) - 1 user_count = len(users) while True: if user_count == 0: break if needed_users == 0: break user = users.pop(randint(0, user_count-1)) user_count -= 1 if user.is_bot: continue selected_users.append(user) needed_users -= 1 if needed_users: await client.message_create(channel, 'The guild does not have enough users for this size of pyramid.') return for user, count in zip(selected_users, chain(range(1, size), range(size, 0, -1))): await client.webhook_message_create(executor_webhook, ' '.join(emoji.as_emoji for _ in range(count)), name=user.name_at(message.guild), avatar_url=user.avatar_url_as(size=4096), wait=True) checks = [checks.has_guild_permissions(Permission().update_by_keys(manage_messages=True))] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('execute',( 'Creates a pyramid!\n' f'Usage: `{prefix}auto-pyramid-u <emoji> <size>`' ), color=SATORI_HELP_COLOR).add_footer( 'Guild only! You must have manage messages permission to use it.') async def parser_failure_handler(client, message, command, content, args): embed = await command.description(client, message) await Closer(client, message.channel, embed)