class sync_avatar: async def command(client, message): avatar_url = client.application.icon_url_as(ext='png', size=4096) if avatar_url is None: await client.message_create(message.channel, 'The application has no avatar set.') return avatar = await client.download_url(avatar_url) await client.client_edit(avatar=avatar) await client.message_create(message.channel, 'Avatar synced.') checks = [checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('sync_avatar', ( 'Hello there Esuto!\n' 'This is a specific command for You, to sync the bot\'s avatar with ' 'the application\'s. I know, You might struggle with updating the ' 'bot\'s avatar the other way, so I made a command for it.\n' 'Have a nice day!\n' f'Usage: `{prefix}sync_avatar`'), color=FLAN_HELP_COLOR)
class update_application_info: async def update_application_info(client, message, user: Converter( 'user', flags=ConverterFlag.user_default.update_by_keys(everywhere=True), default_code='client')): if isinstance(user, Client): await user.update_application_info() content = f'Application info of `{user:f}` is updated succesfully!' else: content = 'I can update application info only of a client.' await client.message_create(message.channel, content) category = 'UTILITY' checks = [checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed( 'update_application_info', ('I can update applicaction info of any of the active clients ' 'at my mansion.\n' f'Usage: `{prefix}update_application_info <user>`\n' '`user` is otional and can be only an another client.'), color=UTILITY_COLOR).add_footer('Owner only!')
class rules: async def command(client, message): embed = Embed( f'Rules of {DUNGEON}:', color=KOISHI_HELP_COLOR, ).add_field( 'Guidelines', 'Follow [Discord\'s guidelines](https://discord.com/guidelines)', ).add_field( 'Behaviour', 'Listen to staff and follow their instructions.', ).add_field( 'Language', f'{DUNGEON} is an english speaking server, please try to stick yourself to it.', ).add_field( 'Channels', 'Read the channel\'s topics. Make sure to keep the conversations in their respective channels.' ).add_field( 'Usernames', 'Invisible, offensive or noise unicode names are not allowed.' ).add_field( 'Spamming', 'Forbidden in any form. Spamming server members in DM-s counts as well.', ).add_field( 'NSFW', 'Keep explicit content in nsfw channels', ).add_field( 'Roles', f'Do not beg for roles. You can claim {EVERYNYAN_ROLE.mention} role, what gives you access to ' f'additional channels by typing `nya` at {WELCOME_CHANNEL.mention}.\n' f'*You must be the member of the guild for at least 10 minutes and {client.mention} must be online ' f'as well.*' '\n\n' f'Addtionally you can also claim (or unclaim) {ANNOUNCEMNETS_ROLE.mention} by typing `i meow` ' '(or `i not meow`), or if you are the member of the server for at least half year, you can claim the ' f'superior {WORSHIPPER_ROLE.mention} role by typing `nekogirl`!' ).add_field( 'Advertisements', 'Advertising other social medias, servers, communities or services in chat or in DM-s are disallowed.' ).add_field( 'No political or religious topics.', 'I do not say either that aliens exists, even tho they do.', ) await client.message_create(message.channel, embed=embed, allowed_mentions=None) if message.channel.cached_permissions_for(client).can_manage_messages: await client.message_delete(message) category = 'HELP' checks = [checks.owner_only(), checks.is_guild(DUNGEON)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('rules', (f'Shows the rules of the {DUNGEON} guild.' f'Usage : `{prefix}rules`'), color=KOISHI_HELP_COLOR).add_footer( f'Owner only and can be used only at {DUNGEON}.')
class reload: async def command(client, message, name: str): while True: try: extension = EXTENSION_LOADER.extensions[name] except KeyError: result = 'There is no extension with the specified name' break if extension.locked: result = 'The extension is locked, propably for reason.' break try: await EXTENSION_LOADER.reload(name) except BaseException as err: result = repr(err) if len(result) > 2000: result = result[-2000:] break result = 'success' break await client.message_create(message.channel, result) return category = 'UTILITY' checks = [checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) lines = [ 'Reloads the specified extension by it\'s name.', f'Usage : `{prefix}reload <name>`', '\nAvailable extensions:', ] for extension in EXTENSION_LOADER.extensions.values(): lines.append( f'- `{extension.name}`{" (locked)" if extension.locked else ""}' ) pages = [ Embed('reload', chunk, color=KOISHI_HELP_COLOR) for chunk in chunkify(lines) ] limit = len(pages) index = 0 while index < limit: embed = pages[index] index += 1 embed.add_footer(f'page {index}/{limit}') return pages
class resend_webhook: async def command(client, message, message_id: int, channel: Converter('channel', default_code='message.channel')): permissions = message.channel.cached_permissions_for(client) can_delete = permissions.can_manage_messages if not permissions.can_manage_webhooks: message = await client.message_create( message.channel, 'I have no permissions to get webhooks from this channel.') if can_delete: await sleep(30.0, client.loop) await client.message_delete(message) return try: target_message = await client.message_get(channel, message_id) except DiscordException as err: message = await client.message_create(message.channel, repr(err)) if can_delete: await sleep(30.0, client.loop) await client.message_delete(message) return webhooks = await client.webhook_get_channel(channel) if webhooks: webhook = webhooks[0] else: webhook = await client.webhook_create(channel, 'Love You') await client.webhook_message_create( webhook, embed=target_message.embeds, name=target_message.author.name, avatar_url=target_message.author.avatar_url) category = 'UTILITY' checks = [checks.guild_only(), checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed( 'resend_webhook', ('I can resend a webhook, if chu really want.\n' f'Usage: `{prefix}resend_webhook *message_id* <channel>`\n' 'The `message_id` must be the `id` of the message sent by the ' 'webhook.\n' 'The `channel` by default is zhis channel, but if the message ' 'is at a different channel, you should tell me > <.'), color=UTILITY_COLOR).add_footer('Guild only. Owner only!')
class show_help_for: async def command(client, message,user:Converter('user', ConverterFlag.user_default.update_by_keys(everywhere=True), default=None), rest): if user is None: await client.message_create(message.channel, 'Please define a user as well.') return message = message.custom(author=user) await client.command_processer.commands['help'](client, message,rest) category = 'ADMINISTRATION' checks = [checks.owner_only(handler=not_bot_owner_handler)] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('show_help_for', ( 'Calls `help` command, as the given user would do it.\n' f'Usage: `{prefix}show_help_for *user*`\n' ), color=ADMINISTRATION_COLOR).add_footer( 'Owner only!')
class clear: async def command(client, message, limit : Converter('int', default=1,), reason): if not reason: reason = f'{message.author.full_name} asked for it' if limit>0: await client.message_delete_sequence(channel=message.channel,limit=limit,reason=reason) category = 'ADMINISTRATION' #checks = [checks.has_permissions(Permission().update_by_keys(manage_messages=True), handler=permission_check_handler)] checks = [checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('clear', ( 'I ll clear up the leftover after your lewd messages O-NEE-CHA-N.' f'Usage : `{prefix}clear <amount> <reason>`\n' '`amount` is optional, by default it is just 1.\n' 'The `reason` will show up at the audit logs of the guild.' ), color=ADMINISTRATION_COLOR).add_footer( 'This command can be executed only at a guild, and you must have ' '`manage messages` permission as well.')
class shutdown: async def command(client, message): for client_ in CLIENTS: await client_.disconnect() await client.message_create(message.channel, 'Clients stopped, stopping process.') KOKORO.stop() thread_id = main_thread().ident signal.pthread_kill(thread_id, signal.SIGKILL) category = 'UTILITY' checks = [checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('shutdown', ('Shuts the clients down, then stops the process.' f'Usage `{prefix}shutdown`'), color=KOISHI_HELP_COLOR).add_footer('Owner only!')
class telekinesisban: async def command(client, message, guild:Converter('guild', default_code='message.guild'), user:Converter('user', ConverterFlag.user_default.update_by_keys(everywhere=True), default=None), reason): # Should not happen normally if guild is None: return if user is None: await client.message_create(message.channel, 'Please define a user to ban.') return if not reason: author = message.author reason = f'For the request of {author.full_name} ({author.id})' for maybe_banner in guild.clients: if guild.cached_permissions_for(client).can_ban_users: banner = maybe_banner break else: await client.message_create(message.channel, 'No one of has can ban the user in the guild.') return await banner.guild_ban_add(guild, user, reason=reason) await client.message_create(message.channel, f'{user.full_name} banned at guild {guild.name} by {banner.full_name}.') category = 'ADMINISTRATION' checks=[checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('telekinesisban', ( 'Bans the given user at the specified guild.\n' f'Usage: `{prefix}telekinesisban <guild> *user* <reason>`\n' ), color=ADMINISTRATION_COLOR).add_footer( 'Owner only!')
ConverterFlag().update_by_keys(name=True)), FlaggedAnnotation('role', ConverterFlag().update_by_keys(name=True)), ), ): if isinstance(entity, UserBase): result = 'user' elif isinstance(entity, ChannelBase): result = 'channel' else: result = 'role' await client.message_create(message.channel, result) async def owner_only_handler(client, message, command, check): await client.message_create( message.channel, f'You must be the owner of the bot to use the `{command}` command.', ) @NekoBot.commands(checks=[checks.owner_only(handler=owner_only_handler)]) async def owner(client, message): await client.message_create(message.channel, f'My masuta is {client.owner:f} !') start_clients()
def setup(lib): Koishi.command_processer.create_category('OAUTH2', checks=[checks.owner_only()]) Koishi.commands.extend(OAUTH2_COMMANDS)
def setup(lib): category = Koishi.command_processer.get_category('STATS') if (category is None): Koishi.command_processer.create_category('STATS', checks=[checks.owner_only()]) Koishi.commands.extend(STAT_COMMANDS)
f'{prefix}execute\n' '```\n' '# code goes here\n' '# code goes here\n' '```\n' '*not code*\n' '\n' '... and many more ways.'), color=KOISHI_HELP_COLOR).add_footer('Owner only!') Koishi.commands(Interpreter(locals().copy()), name='execute', description=execute_description, category='UTILITY', checks=[checks.owner_only()]) PATTERN_ROLE_RELATION = [ (re.compile('nya+', re.I), EVERYNYAN_ROLE, timedelta(minutes=10), True), (re.compile('[il] *meow+', re.I), ANNOUNCEMNETS_ROLE, timedelta(), True), (re.compile('[il] *not? *meow+', re.I), ANNOUNCEMNETS_ROLE, timedelta(), False), (re.compile('nekogirl', re.I), WORSHIPPER_ROLE, timedelta(days=183), True), ] async def role_giver(client, message): for pattern, role, delta, add in PATTERN_ROLE_RELATION: if (pattern.fullmatch(message.content) is None): continue
ConverterFlag().update_by_keys(name=True)), FlaggedAnnotation('role', ConverterFlag().update_by_keys(name=True)), )): if isinstance(entity, UserBase): result = 'user' elif isinstance(entity, ChannelBase): result = 'channel' else: result = 'role' await client.message_create(message.channel, result) @TEST_COMMANDS(checks=[checks.owner_only()]) async def owner_1(client, message): await client.message_create(message.channel, f'My masuta is {client.owner:f} !') # Note, this will be never called, because the category has a check already. async def owner_only_handler(client, message, command, check): await client.message_create( message.channel, f'You must be the owner of the bot to use the `{command}` command.') @TEST_COMMANDS(checks=[checks.owner_only(handler=owner_only_handler)]) async def owner_2(client, message): await client.message_create(message.channel,
class invite_gen: async def command(client, message, target_channel: ChannelText, time: int): guild = message.guild if guild is None: return if time < 1: await client.message_create( message.channel, f'Time cannot be less than 1, got {time!r}') return canceller = Future(KOKORO) KOKORO.call_later(time * 3600.0, Future.set_result_if_pending, canceller, None) await client.message_create( message.channel, f'Starting loop over {target_channel.mention} for {time} hours.') invites = [] total = 0 while True: try: invite = await client.invite_create(target_channel) parsed = INVITE_GEN_RP.search(invite.code) if parsed is None: await client.invite_delete(invite) else: invites.append(invite) total += 1 except BaseException as err: if isinstance(err, ConnectionError): canceller.cancel() sys.stderr.write( 'invite_gen failed, connection error occured meanwhile!\n' ) return if isinstance(err, DiscordException): err_code = err.code if err_code in ( ERROR_CODES. invalid_permissions, # permissions changed meanwhile ERROR_CODES.invalid_access, # client removed ): canceller.set_result_if_pending(None) break if err_code == ERROR_CODES.unknown_channel: # message's channel deleted canceller.cancel() return if err_code == ERROR_CODES.max_invites: canceller.set_result_if_pending(None) break canceller.cancel() await client.events.error(client, 'invite_gen', err) return if canceller.done(): break title = f'{total} invites generated, from this {len(invites)} passed.' pages = [ Embed(title, chunk) for chunk in cchunkify([invite.url for invite in invites]) ] await Pagination(client, message.channel, pages, timeout=7200.0) category = 'UTILITY' checks = [checks.guild_only(), checks.owner_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('invite-gen', ( 'Creates invite at the guild with any of the predefined words.\n' f'Usage: `{prefix}invite-gen *text-channel* *time*`\n' 'Note that time is in hours, for how much time it should circle the invites!' ), color=UTILITY_COLOR).add_footer('Guild and owner only!')
text = 'Added to queue' text = f'{text} {bgm.display_name!r}!' break await client.message_create(message.channel, text) async def voice_state(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('voice-state', ( 'Gets the voice state of the respective voice client.\n' f'Usage: `{prefix}voice-state`\n' ), color=VOICE_COLORS.get(client)).add_footer('Owner only!') @WRAPPER(description=loop_all_description, checks=[checks.owner_only()]) async def voice_state(client, message): voice_client = client.voice_client_for(message) lines = [] guild = message.guild if voice_client is None: title = f'No client in {guild.name}.' else: title = f'Client info for {guild.name}.' source = voice_client.source queue = voice_client.queue if (source is not None) or queue: if (source is not None): lines.append(f'Actual: {source.title}')