class get_role_id: async def command(client, message, role: Converter( 'role', ConverterFlag().update_by_keys(mention=True, name=True), default_code='message.guild.default_role')): if role is None: role_id = 'N/A' else: role_id = str(role.id) await client.message_create(message.channel, role_id) name = 'roleid' aliases = ['role-id', 'rid'] category = 'UTILITY' checks = [checks.guild_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed( 'roleid', ('Sends the guild\'s default role\'s or the given role\'s id.\n' f'Usage: `{prefix}roleid <role name / mention>`'), color=UTILITY_COLOR).add_footer('Guild only.')
class guild_icon: async def command(client, message): guild = message.guild if guild is None: return icon_url = guild.icon_url_as(size=4096) if icon_url is None: embed = Embed(description=f'`{guild.name}` has no icon.') else: color = guild.icon_hash & 0xffffff embed = Embed(f'{guild.name}\' icon', color=color, url=icon_url) embed.add_image(icon_url) await client.message_create(message.channel, embed=embed) category = 'UTILITY' checks = [checks.guild_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('guild-icon', ('Do you wanna see the guild\'s icon in 4K?!\n' f'Usage: `{prefix}guild-icon`\n'), color=UTILITY_COLOR).add_footer('Guild only!')
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 get_guild_id: async def command(client, message): channel = message.channel guild = channel.guild if guild is None: return await client.message_create(channel, str(guild.id)) name = 'guildid' aliases = ['guild-id', 'serverid', 'server-id', 'gid', 'sid'] category = 'UTILITY' checks = [checks.guild_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('guildid', ('Sends the guild\'s id.\n' f'Usage: `{prefix}guildid`'), color=UTILITY_COLOR).add_footer('Guild only.')
class welcome_screen: async def command(client, message): guild = message.guild if guild is None: return welscome_screen = await client.welcome_screen_get(guild) if welscome_screen is None: embed = Embed( description=f'**{guild.name}** *has no welcome screen enabled*.' ) else: embed = Embed( f'Welcome to **{guild.name}**', f'{welscome_screen.description}\n\n*TOP THINGS TO DO HERE*') icon_url = guild.icon_url if (icon_url is not None): embed.add_thumbnail(icon_url) for welcome_channel in welscome_screen.welcome_channels: embed.add_field( f'{welcome_channel.emoji:e} {welcome_channel.description}', f'#{welcome_channel.channel:d}') await client.message_create(message.channel, embed=embed) aliases = ['guild_welcome_screen'] category = 'UTILITY' checks = [checks.guild_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('welcome-screen', ('Displays the guild\'s welcome screen\n' f'Usage: `{prefix}welcome-screen`'), color=UTILITY_COLOR).add_footer('Guild only!')
def setup(lib): Koishi.commands(battle_manager, name='bs', checks=[checks.guild_only()], category='GAMES')
def teardown(lib): main_client.commands.unextend(TEST_COMMANDS) @TEST_COMMANDS async def test_choose_menu_repr(client, message): ''' Creates a ChooseMenu and returns it's repr. ''' choices = ['nice', 'cat'] choose_menu = await ChooseMenu(client, message.channel, choices, lambda *args: Future(KOKORO)) await client.message_create(message.channel, repr(choose_menu)) @TEST_COMMANDS(checks=[checks.guild_only()]) async def test_role_create(client, message): ''' Creates and deletes a role. ''' guild = message.guild role = await client.role_create(guild, 'Mokou') await client.role_delete(role) await client.message_create('done') @TEST_COMMANDS async def test_allowed_edit(client, message): ''' Creates a message and edits it. Shoult not ping you. '''
break channeller.cancel(channel) text = 'Success' break await client.message_create(channel, text) async def channeling_stop_description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed('channeling_stop', ( 'Cancels the channelling of this channel.\n' f'Usage: `{prefix}channeling_stop`\n' 'If more channels are connected, you need to call this command, ' 'from every of them, to cancel all.\n' 'If only one channel is left alone, it will be cancelled automatically.' ), color=CHANNELLER_COLOR).add_footer('Owner only!') CHANNELLER_COMMANDS(channeling_start, description=channeling_start_description, checks=[checks.guild_only(), checks.owner_only()], category='UTILITY') CHANNELLER_COMMANDS(channeling_stop, description=channeling_stop_description, checks=[checks.owner_only()], category='UTILITY')
'If the message has active auto react role on it, will display that, and if it has active GUI too, will cancel ' 'that.\n' f'Usage: `{prefix}auto-react-roles *channel* <message_id>`'), color=AUTO_REACT_ROLE_COLOR ).add_footer( 'Guild only! You must have administrator permission to use this command.' ) AUTO_REACT_ROLE_COMMANDS( create_auto_react_role, name='auto-react-role', category='ADMINISTRATION', description=auto_react_roles_description, checks=[ checks.guild_only(), checks.has_permissions(Permission().update_by_keys(administrator=True), handler=permission_check_handler), ]) async def show_auto_react_roles(client, message): guild = message.guild if guild is None: return managers = client.events.guild_delete.get_waiters(guild, AutoReactRoleManager, by_type=True, is_method=True)
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!')
class roles: class command(object): __slots__ = ( 'cache', 'guild', 'roles', ) async def __new__(cls, client, message): channel = message.channel self = object.__new__(cls) roles = channel.guild.role_list roles.reverse() self.roles = roles self.cache = [None for _ in range(len(self.roles) + 1)] self.createpage0(channel.guild) #we return awaitable, so it is OK return await PAGINATION_5PN(client, channel, self) def __len__(self): return self.cache.__len__() def createpage0(self, guild): embed = Embed(f'Roles of **{guild.name}**:', '\n'.join([role.mention for role in self.roles]), color=(guild.icon_hash & 0xFFFFFF if (guild.icon_type is ICON_TYPE_NONE) else (guild.id >> 22) & 0xFFFFFF)) embed.add_footer(f'Page 1 / {len(self.cache)}') self.cache[0] = embed def __getitem__(self, index): page = self.cache[index] if page is None: return self.create_page(index) return page def create_page(self, index): role = self.roles[index - 1] embed = Embed(role.name, '\n'.join([ f'id : {role.id!r}', f'color : {role.color.as_html}', f'permission number : {role.permissions}', f'managed : {role.managed}', f'separated : {role.separated}', f'mentionable : {role.mentionable}', '\nPermissions:\n```diff', *(f'{"+" if value else "-"}{key}' for key, value in role.permissions.items()), '```', ]), color=role.color) embed.add_footer(f'Page {index+1} / {len(self.cache)}') self.cache[index] = embed return embed category = 'UTILITY' checks = [checks.guild_only()] async def description(client, message): prefix = client.command_processer.get_prefix_for(message) return Embed( 'roles', ('Cutie, do you want me, to list the roles of the guild and their ' 'permissions?\n' f'Usage: `{prefix}roles`'), color=UTILITY_COLOR).add_footer('Guild only!')
from hata.discord.reader import EMPTY_VOICE_FRAME_ENCODED, EMPTY_VOICE_FRAME_DECODED from hata.discord.player import AudioSource from hata.discord.opus import OpusDecoder from hata.ext.commands import Command, checks, Pagination, FlaggedAnnotation, ConverterFlag from config import AUDIO_PATH, AUDIO_PLAY_POSSIBLE, MARISA_MODE from bot_utils.shared import DUNGEON, WrapMultyple if not MARISA_MODE: from bots.flan import FLAN_HELP_COLOR, CHESUTO_FOLDER, get_bgm, FLAN_HELP_COLOR VOICE_COLORS = {} if MARISA_MODE: VOICE_COMMANDS_MARISA = eventlist(category='VOICE', checks=[checks.guild_only()]) WRAPPER = WrapMultyple(VOICE_COMMANDS_MARISA) VOICE_COMMANDS_MAIN = VOICE_COMMANDS_MARISA VOICE_COMMANDS_CHESUTO = WrapMultyple() MAIN_VOICE_COLOR = Color.from_rgb(121, 231, 78) VOICE_COLORS[Marisa] = MAIN_VOICE_COLOR else: VOICE_COMMANDS_KOISHI = eventlist(category='VOICE', checks=[checks.guild_only()]) VOICE_COMMANDS_FLAN = eventlist(checks=[checks.guild_only()]) WRAPPER = WrapMultyple(VOICE_COMMANDS_KOISHI, VOICE_COMMANDS_FLAN) VOICE_COMMANDS_MAIN = VOICE_COMMANDS_KOISHI VOICE_COMMANDS_CHESUTO = VOICE_COMMANDS_FLAN MAIN_VOICE_COLOR = Color.from_rgb(235, 52, 207) VOICE_COLORS[Flan] = FLAN_HELP_COLOR
'You can pass any amount of tags, mentions are ignored.'), color=IMAGE_COLOR).add_footer('Owner only!') RESERVED_TAGS = { 'animated', 'static', 'count', 'index', 'hex', } @IMAGE_COMMANDS(category='UTILITY', description=image_description, checks=[checks.guild_only()]) async def image(client, message, content): result = process_on_command_image(content) if type(result) is str: await client.message_create(message.channel, result) else: with client.keep_typing(message.channel): with (await ReuAsyncIO(join(IMAGE_PATH, result.path))) as image: await client.message_create(message.channel, file=image) def process_on_command_image(content): content = [ x.lower() for x in FIND_TAGS_RP.findall(content) if not is_mention(x) ] limit = len(content)