def __init__(self, bot): super().__init__(bot) @bot.has_permissions(administrator=True) async def send(ctx: discord.commands.context.ApplicationContext, channel: discord.commands.Option( discord.TextChannel, description=bot.i18n.get('MESSAGING_SEND_CHANNEL_OPTION'), ), message: discord.commands.Option( str, description=bot.i18n.get('MESSAGING_SEND_MESSAGE_OPTION'), )): await channel.send(message) return await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get('MESSAGING_SEND_SUCCESSFUL'), color=discord.Color.green())) self.commands = [ discord.SlashCommand( func=send, name=self.bot.i18n.get('MESSAGING_SEND_COMMAND'), description=self.bot.i18n.get('MESSAGING_SEND_COMMAND_DESCRIPTION'), ) ]
def __init__(self, bot): super().__init__(bot) async def tic_tac_toe( ctx: discord.commands.context.ApplicationContext): await TicTacToeViewHolder(bot, ctx).start() async def chess(ctx: discord.commands.context.ApplicationContext): await ChessViewHolder(self.bot, ctx).start() self.commands = [ discord.SlashCommand( func=tic_tac_toe, name=self.bot.i18n.get('GAMES_TIC_TAC_TOE_COMMAND'), description=self.bot.i18n.get( 'GAMES_TIC_TAC_TOE_COMMAND_DESCRIPTION')), discord.SlashCommand(func=chess, name=self.bot.i18n.get('GAMES_CHESS_COMMAND'), description=self.bot.i18n.get( 'GAMES_CHESS_COMMAND_DESCRIPTION')), ]
def __init__(self, bot): super().__init__(bot) async def boost(ctx: discord.commands.context.ApplicationContext, member: discord.commands.Option( discord.Member, description=bot.i18n.get('BOOST_MEMBER_OPTION'), default=None)): if member is None: embed = await self.boost_get_embed(ctx.author) return await ctx.respond(embed=embed) if not await self.get_dependency('levelsystem').leveling_allowed( member): return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('BOT_NOT_ALLOWED_LEVELING'), color=discord.Color.red())) try: await self.boost_user(ctx.author, member) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('BOOSTING_NOW').format( member.display_name), color=discord.Color.green())) except BoostingYourselfForbiddenException: return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('BOOSTING_SELF_FORBIDDEN'), color=discord.Color.red())) except BoostNotExpiredException: return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('BOOST_NOT_EXPIRED'), color=discord.Color.red())) self.commands = [ discord.SlashCommand( func=boost, name=self.bot.i18n.get('BOOST_COMMAND'), description=self.bot.i18n.get('BOOST_DESCRIPTION')) ]
def __init__(self, bot): super().__init__(bot) self.guild_promo_codes = {} async def promo(ctx: discord.commands.context.ApplicationContext): promo_code = await self.create_promo_code(ctx.author) if promo_code is None: raise UnknownException(detail='Promo code not found') try: await ctx.author.send(embed=discord.Embed( title='', description=self.bot.i18n.get( 'PROMO_CODE_PRIVATE_MESSAGE').format( ctx.author.guild.name, self.bot.module_manager.settings.get( ctx.author.guild.id, 'PROMO_CODE_EXPIRES_HOURS'), promo_code), color=discord.Color.blue()), ) await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'PROMO_CODE_CREATE_SUCCESSFUL'), color=discord.Color.green()), ephemeral=True, ) except discord.Forbidden: await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'DIRECT_MESSAGE_FORBIDDEN'), color=discord.Color.red()), ephemeral=True, ) self.commands = [ discord.SlashCommand( func=promo, name=self.bot.i18n.get('PROMO_COMMAND'), description=self.bot.i18n.get('PROMO_COMMAND_DESCRIPTION'), ) ]
def __init__(self, bot): super().__init__(bot) @bot.has_permissions(administrator=True) async def get_reactions( ctx: discord.commands.context.ApplicationContext): reactions = self.bot.db.get_message_reactions(ctx.guild.id) embed = discord.Embed( title=self.bot.i18n.get('MESSAGE_REACTIONS_TITLE'), color=discord.Color.green()) for reaction in reactions: embed.add_field(name=reaction.trigger, value=reaction.reaction, inline=False) return await ctx.respond(embed=embed) @bot.has_permissions(administrator=True) async def set_reaction( ctx: discord.commands.context.ApplicationContext, trigger: discord.commands.Option( str, description=bot.i18n.get( 'MESSAGE_REACTIONS_TRIGGER_OPTION_DESCRIPTION'), ), reaction: discord.commands.Option( str, description=bot.i18n.get( 'MESSAGE_REACTIONS_REACTION_OPTION_DESCRIPTION'), )): self.bot.db.set_message_reaction(ctx.guild.id, trigger, reaction) return await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'MESSAGE_REACTIONS_ADD_SUCCESSFUL'). format(trigger, reaction), color=discord.Color.green())) @bot.has_permissions(administrator=True) async def reaction_trigger_autocomplete( ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, list( map( lambda x: x.trigger, self.bot.db.get_message_reactions( ctx.interaction.guild.id)))) @bot.has_permissions(administrator=True) async def remove_reaction( ctx: discord.commands.context.ApplicationContext, trigger: discord.commands.Option( str, description=bot.i18n.get( 'MESSAGE_REACTIONS_TRIGGER_OPTION_DESCRIPTION'), autocomplete=reaction_trigger_autocomplete)): self.bot.db.remove_message_reaction(ctx.guild.id, trigger) return await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'MESSAGE_REACTIONS_REMOVE_SUCCESSFUL'), color=discord.Color.green())) message_reactions = discord.SlashCommandGroup( name=self.bot.i18n.get('MESSAGE_REACTIONS_COMMAND'), description=self.bot.i18n.get( 'MESSAGE_REACTIONS_COMMAND_DESCRIPTION'), ) message_reactions.subcommands.append( discord.SlashCommand( func=get_reactions, name=self.bot.i18n.get('MESSAGE_REACTIONS_GET_COMMAND'), description=self.bot.i18n.get( 'MESSAGE_REACTIONS_GET_COMMAND_DESCRIPTION'), parent=message_reactions)) message_reactions.subcommands.append( discord.SlashCommand( func=set_reaction, name=self.bot.i18n.get('MESSAGE_REACTIONS_SET_COMMAND'), description=self.bot.i18n.get( 'MESSAGE_REACTIONS_SET_COMMAND_DESCRIPTION'), parent=message_reactions)) message_reactions.subcommands.append( discord.SlashCommand( func=remove_reaction, name=self.bot.i18n.get('MESSAGE_REACTIONS_REMOVE_COMMAND'), description=self.bot.i18n.get( 'MESSAGE_REACTIONS_REMOVE_COMMAND_DESCRIPTION'), parent=message_reactions)) self.commands = [message_reactions]
def __init__(self, bot): super().__init__(bot) def settings_embed(settings_items, max_length=80): embed = discord.Embed(title=self.bot.i18n.get('SETTINGS_TITLE'), description='', color=discord.Color.gold()) for key, value in settings_items.items(): res = '"{}"'.format(value) embed.add_field( name='{}'.format(key), value=(res[:max_length] + '...') if len(res) > max_length else res, inline=False) return embed @bot.has_permissions(administrator=True) async def setting_key_autocomplete_get( ctx: discord.AutocompleteContext): return autocomplete_match(ctx.value, ['_'] + self.bot.module_manager.settings.keys( ctx.interaction.guild.id)) @bot.has_permissions(administrator=True) async def setting_key_autocomplete(ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, self.bot.module_manager.settings.keys( ctx.interaction.guild.id)) @bot.has_permissions(administrator=True) async def set_setting( ctx: discord.commands.context.ApplicationContext, key: discord.commands.Option( str, description=bot.i18n.get('SET_SETTING_KEY_OPTION'), autocomplete=setting_key_autocomplete, ), value: discord.commands.Option( str, description=bot.i18n.get('SET_SETTING_VALUE_OPTION'), )): try: if not self.bot.module_manager.settings.set( ctx.guild.id, key, value): raise UnknownException(detail='Setting not found') return await ctx.respond(embed=settings_embed( { key: self.bot.module_manager.settings.get( ctx.guild.id, key) }, max_length=1020)) except KeyError: return await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'SETTING_NOT_FOUND').format(key), color=discord.Color.red())) @bot.has_permissions(administrator=True) async def get_setting( ctx: discord.commands.context.ApplicationContext, key: discord.commands.Option( str, description=bot.i18n.get('GET_SETTING_KEY_OPTION'), autocomplete=setting_key_autocomplete_get, )): if key == '_': return await ctx.respond(embed=settings_embed( self.bot.module_manager.settings.all(ctx.guild.id))) try: return await ctx.respond(embed=settings_embed( { key: self.bot.module_manager.settings.get( ctx.guild.id, key) }, max_length=1020)) except KeyError: return await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'SETTING_NOT_FOUND').format(key), color=discord.Color.red())) @bot.has_permissions(administrator=True) async def reset_setting( ctx: discord.commands.context.ApplicationContext, key: discord.commands.Option( str, description=bot.i18n.get('RESET_SETTING_KEY_OPTION'), autocomplete=setting_key_autocomplete, )): try: self.bot.module_manager.settings.remove(ctx.guild.id, key) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'SETTING_RESET_SUCCESSFUL').format(key), color=discord.Color.green())) except KeyError: return await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'SETTING_NOT_FOUND').format(key), color=discord.Color.red())) settings_command = discord.SlashCommandGroup( name=self.bot.i18n.get('SETTINGS_COMMAND'), description=self.bot.i18n.get('SETTINGS_DESCRIPTION'), ) settings_command.subcommands.append( discord.SlashCommand( func=set_setting, name=self.bot.i18n.get('SETTINGS_SET_COMMAND'), description=self.bot.i18n.get('SET_SETTING_DESCRIPTION'), parent=settings_command)) settings_command.subcommands.append( discord.SlashCommand( func=get_setting, name=self.bot.i18n.get('SETTINGS_GET_COMMAND'), description=self.bot.i18n.get('GET_SETTING_DESCRIPTION'), parent=settings_command)) settings_command.subcommands.append( discord.SlashCommand( func=reset_setting, name=self.bot.i18n.get('SETTINGS_RESET_COMMAND'), description=self.bot.i18n.get('RESET_SETTING_DESCRIPTION'), parent=settings_command)) @bot.has_permissions(administrator=True) async def activate_module_autocomplete( ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, self.bot.module_manager.get_activatable_modules( ctx.interaction.guild.id)) @bot.has_permissions(administrator=True) async def activate_module( ctx: discord.commands.context.ApplicationContext, module: discord.commands.Option( str, description=bot.i18n.get('MODULE_ACTIVATE_OPTION'), autocomplete=activate_module_autocomplete, )): await ctx.defer(ephemeral=True) try: await self.bot.module_manager.activate_module( ctx.guild.id, module) except WrongInputException as e: return await ctx.respond(embed=discord.Embed( title='', description=e.detail, color=discord.Color.red())) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'MODULE_ACTIVATED_SUCCESSFUL').format(module), color=discord.Color.green())) @bot.has_permissions(administrator=True) async def deactivate_module_autocomplete( ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, self.bot.module_manager.get_deactivatable_modules( ctx.interaction.guild.id)) @bot.has_permissions(administrator=True) async def deactivate_module( ctx: discord.commands.context.ApplicationContext, module: discord.commands.Option( str, description=bot.i18n.get('MODULE_DEACTIVATE_OPTION'), autocomplete=deactivate_module_autocomplete, )): await ctx.defer(ephemeral=True) try: await self.bot.module_manager.deactivate_module( ctx.guild.id, module) except WrongInputException as e: return await ctx.respond(embed=discord.Embed( title='', description=e.detail, color=discord.Color.red())) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'MODULE_DEACTIVATED_SUCCESSFUL').format(module), color=discord.Color.green())) @bot.has_permissions(administrator=True) async def get_active_modules( ctx: discord.commands.context.ApplicationContext): return await ctx.respond(embed=discord.Embed( title=self.bot.i18n.get('ACTIVE_MODULES_TITLE'), description='\n'.join( self.bot.module_manager.get_deactivatable_modules( ctx.guild.id)), color=discord.Color.green())) modules = discord.SlashCommandGroup( name=self.bot.i18n.get('MODULES_COMMAND'), description=self.bot.i18n.get('MODULES_DESCRIPTION'), ) modules.subcommands.append( discord.SlashCommand( func=deactivate_module, name=self.bot.i18n.get('MODULE_DEACTIVATE_COMMAND'), description=self.bot.i18n.get('MODULE_DEACTIVATE_DESCRIPTION'), parent=modules)) modules.subcommands.append( discord.SlashCommand( func=activate_module, name=self.bot.i18n.get('MODULE_ACTIVATE_COMMAND'), description=self.bot.i18n.get('MODULE_ACTIVATE_DESCRIPTION'), parent=modules)) modules.subcommands.append( discord.SlashCommand( func=get_active_modules, name=self.bot.i18n.get('MODULES_GET_ACTIVE_COMMAND'), description=self.bot.i18n.get( 'MODULES_GET_ACTIVE_DESCRIPTION'), parent=modules)) self.commands = [settings_command, modules]
def __init__(self, bot): super().__init__(bot) @bot.has_permissions(administrator=True) async def get_levelsystem( ctx: discord.commands.context.ApplicationContext): return await ctx.respond( embed=await self.lvlsys_get_embed(ctx.guild)) @bot.has_permissions(administrator=True) async def set_levelsystem( ctx: discord.commands.context.ApplicationContext, level: discord.commands.Option( int, description=bot.i18n.get( 'LEVELSYSTEM_SET_LEVEL_ROLE_LEVEL_OPTION'), ), role: discord.commands.Option( discord.Role, description=bot.i18n.get( 'LEVELSYSTEM_SET_LEVEL_ROLE_ROLE_OPTION'), )): self.bot.db.set_levelsystem(ctx.guild.id, level, role.id) await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('LEVELSYSTEM_SET_SUCCESSFUL'), color=discord.Color.green())) return await ctx.respond( embed=await self.lvlsys_get_embed(ctx.guild)) @bot.has_permissions(administrator=True) async def remove_levelsystem( ctx: discord.commands.context.ApplicationContext, level: discord.commands.Option( int, description=bot.i18n.get( 'LEVELSYSTEM_REMOVE_LEVEL_ROLE_LEVEL_OPTION'), )): self.bot.db.remove_levelsystem_by_level(ctx.guild.id, level) await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('LEVELSYSTEM_REMOVE_SUCCESSFUL'), color=discord.Color.green())) return await ctx.respond( embed=await self.lvlsys_get_embed(ctx.guild)) @bot.has_permissions(administrator=True) async def boost_add(ctx: discord.commands.context.ApplicationContext, member: discord.commands.Option( discord.Member, description=bot.i18n.get( 'LEVELSYSTEM_BOOST_ADD_MEMBER_OPTION'), ), amount: discord.commands.Option( float, description=bot.i18n.get( 'LEVELSYSTEM_BOOST_ADD_AMOUNT_OPTION'), )): if not await self.leveling_allowed(member): return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('BOT_NOT_ALLOWED_LEVELING'), color=discord.Color.red())) self.bot.db.add_xp_boost(member.guild.id, member.id, amount, 'command') await ctx.respond( embed=discord.Embed(title='', description=self.bot.i18n.get( 'LEVELSYSTEM_BOOST_ADD_SUCCESSFUL'), color=discord.Color.green())) @bot.has_permissions(administrator=True) async def set_level( ctx: discord.commands.context.ApplicationContext, member: discord.commands.Option( discord.Member, description=bot.i18n.get( 'LEVELSYSTEM_SET_LEVEL_MEMBER_OPTION'), ), level: discord.commands.Option( float, description=bot.i18n.get('LEVELSYSTEM_SET_LEVEL_LEVEL_OPTION'), )): if not await self.leveling_allowed(member): return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get('BOT_BOOSTING_NOT_ALLOWED'), color=discord.Color.red())) await self.check_level_user(member) await self.member_set_lvl(member, level) await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'LEVELSYSTEM_SET_LEVEL_SUCCESSFUL').format(level), color=discord.Color.green())) @bot.has_permissions(administrator=True) async def blacklist_user( ctx: discord.commands.context.ApplicationContext, member: discord.commands.Option( discord.Member, description=bot.i18n.get( 'LEVELSYSTEM_BLACKLIST_MEMBER_OPTION'), ), blacklist: discord.commands.Option( bool, description=bot.i18n.get( 'LEVELSYSTEM_BLACKLIST_BLACKLIST_OPTION'), )): await self.check_level_user(member) self.bot.db.update_level_user(member.guild.id, member.id, { 'blacklisted': blacklist, }) if blacklist: await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'LEVELSYSTEM_BLACKLIST_SUCCESSFUL'), color=discord.Color.green())) else: await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'LEVELSYSTEM_BLACKLIST_REMOVE_SUCCESSFUL'), color=discord.Color.green())) @bot.has_permissions(administrator=True) async def blacklisted_users( ctx: discord.commands.context.ApplicationContext): description = [] for user in self.bot.db.get_blacklisted_level_users( ctx.guild.id, True): member = get(ctx.guild.members, id=int(user.user_id)) if member is not None: description.append(str(member)) return await ctx.respond(embed=discord.Embed( title=self.bot.i18n.get('LEVELSYSTEM_BLACKLISTED_TITLE'), description='\n'.join(description), color=discord.Color.green())) async def leaderboard( ctx: discord.commands.context.ApplicationContext): await ctx.defer() await ctx.respond( file=await self.create_leaderboard_image(ctx.author)) levelsystem = discord.SlashCommandGroup( name=self.bot.i18n.get('LEVELSYSTEM_COMMAND'), description=self.bot.i18n.get('LEVELSYSTEM_COMMAND_DESCRIPTION'), ) levelsystem.subcommands.append( discord.SlashCommand( func=get_levelsystem, name=self.bot.i18n.get('LEVELSYSTEM_GET_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_GET_COMMAND_DESCRIPTION'), parent=levelsystem)) levelsystem.subcommands.append( discord.SlashCommand( func=set_levelsystem, name=self.bot.i18n.get('LEVELSYSTEM_SET_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_SET_COMMAND_DESCRIPTION'), parent=levelsystem)) levelsystem.subcommands.append( discord.SlashCommand( func=remove_levelsystem, name=self.bot.i18n.get('LEVELSYSTEM_REMOVE_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_REMOVE_COMMAND_DESCRIPTION'), parent=levelsystem)) levelsystem.subcommands.append( discord.SlashCommand( func=boost_add, name=self.bot.i18n.get('LEVELSYSTEM_BOOST_ADD_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_BOOST_ADD_COMMAND_DESCRIPTION'), parent=levelsystem)) levelsystem.subcommands.append( discord.SlashCommand( func=set_level, name=self.bot.i18n.get('LEVELSYSTEM_SET_LEVEL_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_SET_LEVEL_COMMAND_DESCRIPTION'), parent=levelsystem)) levelsystem.subcommands.append( discord.SlashCommand( func=blacklist_user, name=self.bot.i18n.get('LEVELSYSTEM_BLACKLIST_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_BLACKLIST_COMMAND_DESCRIPTION'), parent=levelsystem)) levelsystem.subcommands.append( discord.SlashCommand( func=blacklisted_users, name=self.bot.i18n.get('LEVELSYSTEM_BLACKLISTED_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_BLACKLISTED_COMMAND_DESCRIPTION'), parent=levelsystem)) self.commands = [ levelsystem, discord.SlashCommand( func=leaderboard, name=self.bot.i18n.get('LEVELSYSTEM_LEADERBOARD_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_LEADERBOARD_COMMAND_DESCRIPTION'), ) ] async def give_xp_boost(member: discord.Member, amount, equipped, options): current_time = time.time() self.bot.db.add_xp_boost( member.guild.id, member.id, amount * options['amount'], 'itemboosted', current_time + (options['duration'] * 60 * 60)) self.bot.module_manager.hooks.add( self, INVENTORY_ITEM_ACTION_HOOK, hook_id='xp-boost', name='XP Boost', options={ 'amount': { 'type': 'float', 'description': self.bot.i18n.get('XP_BOOST_AMOUNT_DESCRIPTION') }, 'duration': { 'type': 'float', 'description': self.bot.i18n.get('XP_BOOST_DURATION_DESCRIPTION') }, }, callback=give_xp_boost) async def add_level(member: discord.Member, amount, equipped, options): if not await self.leveling_allowed(member): return await self.check_level_user(member) level_user = self.bot.db.get_level_user(member.guild.id, member.id) if level_user.blacklisted: return old_level = level_user.level level_user.level += amount * options['amount'] await self.member_set_lvl(member, level_user.level, old_level) self.bot.module_manager.hooks.add( self, INVENTORY_ITEM_ACTION_HOOK, hook_id='level-add', name='Level Add', options={ 'amount': { 'type': 'float', 'description': self.bot.i18n.get('LEVEL_GIVE_AMOUNT_DESCRIPTION') }, }, callback=add_level)
def __init__(self, bot): super().__init__(bot) async def get_inventory( ctx: discord.commands.context.ApplicationContext): return await ctx.respond(file=await self.create_inventory_image( ctx.author.guild.id, (await self.get_inventory(ctx.author)).values()), ephemeral=True) async def list_inventory( ctx: discord.commands.context.ApplicationContext): embed = discord.Embed( title=bot.i18n.get('INVENTORY_USER_TITLE').format( ctx.author.display_name), description='', color=discord.Color.gold()) prev_rarity = None items_in_rarity = [] for item in self.bot.db.get_user_items(ctx.author.guild.id, ctx.author.id): if prev_rarity != item.InventoryRarity.name and len( items_in_rarity) > 0: embed.add_field(name=prev_rarity, value='\n'.join(items_in_rarity), inline=False) items_in_rarity = [] items_in_rarity.append( self.bot.i18n.get('INVENTORY_ITEM').format( item.InventoryItemType.name, item.UserInventoryItem.amount)) prev_rarity = item.InventoryRarity.name if len(items_in_rarity) > 0: embed.add_field(name=prev_rarity, value='\n'.join(items_in_rarity), inline=False) return await ctx.respond(embed=embed, ephemeral=True) async def use_item_autocomplete(ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, list( map( lambda item: 'ID: {} Rarity: {} Name: {} Amount: {:g}'. format(item.InventoryItemType.id, item.InventoryRarity. name, item.InventoryItemType.name, item. UserInventoryItem.amount), self.bot.db.get_user_useable_items( ctx.interaction.guild.id, ctx.interaction.user.id)))) async def use_item( ctx: discord.commands.context.ApplicationContext, item: discord.commands.Option( str, description=bot.i18n.get('INVENTORY_USE_ITEM_OPTION'), autocomplete=use_item_autocomplete)): try: item_type_id = int(item[4:].split(' ')[0]) except: raise ItemNotFoundException() res = await self.use_item(ctx.author, item_type_id, 1) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'INVENTORY_USE_ITEM_SUCCESSFUL').format(res), color=discord.Color.green()), ephemeral=True) async def equip_item_autocomplete(ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, list( map( lambda item: 'ID: {} Rarity: {} Name: {} Amount: {:g}'. format(item.InventoryItemType.id, item.InventoryRarity. name, item.InventoryItemType.name, item. UserInventoryItem.amount), self.bot.db.get_user_equippable_items( ctx.interaction.guild.id, ctx.interaction.user.id)))) async def equip_item( ctx: discord.commands.context.ApplicationContext, item: discord.commands.Option( str, description=bot.i18n.get('INVENTORY_EQUIP_ITEM_OPTION'), autocomplete=equip_item_autocomplete)): try: item_type_id = int(item[4:].split(' ')[0]) except: raise ItemNotFoundException() res = await self.use_item(ctx.author, item_type_id, 1) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'INVENTORY_EQUIP_ITEM_SUCCESSFUL').format(res), color=discord.Color.green()), ephemeral=True) async def unequip_item_autocomplete(ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, list( map( lambda item: 'ID: {} Rarity: {} Name: {} Amount: {:g}'. format(item.InventoryItemType.id, item.InventoryRarity. name, item.InventoryItemType.name, item. UserInventoryItem.amount), self.bot.db.get_user_equipped_items( ctx.interaction.guild.id, ctx.interaction.user.id)))) async def unequip_item( ctx: discord.commands.context.ApplicationContext, item: discord.commands.Option( str, description=bot.i18n.get('INVENTORY_UNEQUIP_ITEM_OPTION'), autocomplete=unequip_item_autocomplete)): try: item_type_id = int(item[4:].split(' ')[0]) except: raise ItemNotFoundException() res = await self.use_item(ctx.author, item_type_id, 1) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'INVENTORY_UNEQUIP_ITEM_SUCCESSFUL').format(res), color=discord.Color.green()), ephemeral=True) @bot.has_permissions(administrator=True) async def admin_item_type_autocomplete( ctx: discord.AutocompleteContext): return autocomplete_match( ctx.value, list( map(lambda x: 'ID: {} Name: {}'.format(x.id, x.name), self.bot.db.get_item_types(ctx.interaction.guild.id)))) @bot.has_permissions(administrator=True) async def admin_give_item( ctx: discord.commands.context.ApplicationContext, member: discord.Member, item_type: discord.commands.Option( str, description=bot.i18n.get( 'INVENTORY_ADMIN_GIVE_ITEM_OPTION_DESCRIPTION'), autocomplete=admin_item_type_autocomplete), amount: float): try: item_type_id = int(item_type[4:].split(' ')[0]) except: raise ItemNotFoundException() await self.give_item(member, item_type_id, amount) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'INVENTORY_ADMIN_GIVE_COMMAND_SUCCESS').format( amount, item_type), color=discord.Color.green()), ephemeral=True) inventory = discord.SlashCommandGroup( name=self.bot.i18n.get('INVENTORY_COMMAND'), description=self.bot.i18n.get('INVENTORY_COMMAND_DESCRIPTION'), ) inventory.subcommands.append( discord.SlashCommand( func=get_inventory, name=self.bot.i18n.get('INVENTORY_GET_COMMAND'), description=self.bot.i18n.get( 'INVENTORY_GET_COMMAND_DESCRIPTION'), parent=inventory)) inventory.subcommands.append( discord.SlashCommand( func=list_inventory, name=self.bot.i18n.get('INVENTORY_LIST_COMMAND'), description=self.bot.i18n.get( 'INVENTORY_LIST_COMMAND_DESCRIPTION'), parent=inventory)) inventory.subcommands.append( discord.SlashCommand( func=use_item, name=self.bot.i18n.get('INVENTORY_USE_COMMAND'), description=self.bot.i18n.get( 'INVENTORY_USE_COMMAND_DESCRIPTION'), parent=inventory)) inventory.subcommands.append( discord.SlashCommand( func=equip_item, name=self.bot.i18n.get('INVENTORY_EQUIP_COMMAND'), description=self.bot.i18n.get( 'INVENTORY_EQUIP_COMMAND_DESCRIPTION'), parent=inventory)) inventory.subcommands.append( discord.SlashCommand( func=unequip_item, name=self.bot.i18n.get('INVENTORY_UNEQUIP_COMMAND'), description=self.bot.i18n.get( 'INVENTORY_UNEQUIP_COMMAND_DESCRIPTION'), parent=inventory)) inventory.subcommands.append( discord.SlashCommand( func=admin_give_item, name=self.bot.i18n.get('INVENTORY_ADMIN_GIVE_COMMAND'), description=self.bot.i18n.get( 'INVENTORY_ADMIN_GIVE_COMMAND_DESCRIPTION'), parent=inventory)) self.commands = [inventory] self.bot.module_manager.hooks.add(self, INVENTORY_ADD_ITEM_HOOK, 'inventory', callback=self.give_item) self.bot.module_manager.hooks.add(self, INVENTORY_EQUIPPED_ITEMS_HOOK, 'inventory', callback=self.equipped_items)
def __init__(self, bot): super().__init__(bot) async def coinflip(ctx: discord.ApplicationContext): res = random.choice(['heads', 'tails']) message = await ctx.respond(file=discord.File( os.path.join(self.bot.current_dir, 'images', '{}.gif'.format( res)))) if random.random() < self.bot.module_manager.settings.get( ctx.author.guild.id, 'COIN_FLIP_AUDIO_CHANCE'): if ctx.author.voice is not None and ctx.author.voice.channel is not None: await self.bot.play_audio( discord.FFmpegPCMAudio( os.path.join(self.bot.current_dir, 'audio', 'tossacoin.mp3')), ctx.author.voice.channel) await asyncio.sleep(13) await ctx.edit(file=discord.File( os.path.join(self.bot.current_dir, 'images', '{}.png'.format( res)))) async def dice(ctx: discord.ApplicationContext): await ctx.respond(file=discord.File( os.path.join(self.bot.current_dir, 'images', '{}.gif'.format( random.randint(1, 6))))) async def random_command( ctx: discord.ApplicationContext, args: discord.Option( str, description=bot.i18n.get('RANDOM_ARGS_OPTION'))): random_string = self.bot.i18n.get('RANDOM_COMMAND_RESULT') if len(args) == 1: if args[0].isnumeric(): return await ctx.send( random_string.format(random.randint(1, int(args[0])))) if len(args) == 2: if args[0].isnumeric() and args[1].isnumeric(): opts = [int(args[0]), int(args[1])] return await ctx.send( random_string.format( random.randint(min(opts), max(opts)))) await ctx.send(random_string.format(random.choice(args))) self.commands = [ discord.SlashCommand( func=coinflip, name=self.bot.i18n.get('COINFLIP_COMMAND'), description=self.bot.i18n.get('COINFLIP_COMMAND_DESCRIPTION'), ), discord.SlashCommand( func=dice, name=self.bot.i18n.get('DICE_COMMAND'), description=self.bot.i18n.get('DICE_COMMAND_DESCRIPTION'), ), discord.SlashCommand( func=random_command, name=self.bot.i18n.get('RANDOM_COMMAND'), description=self.bot.i18n.get('RANDOM_COMMAND_DESCRIPTION'), ) ]
def __init__(self, bot): super().__init__(bot) self.reaction_types = { self.ADD_ROLE: 'EMOJI_REACTIONS_ADD_ROLE', self.TRIGGER_ROLE: 'EMOJI_REACTIONS_TRIGGER_ROLE', self.SEND_DM: 'EMOJI_REACTIONS_SEND_DM', } self.activating_reactions = {} @bot.has_permissions(administrator=True) async def add_emoji_action( ctx: discord.commands.context.ApplicationContext, message: discord.Message): async def custom_emoji_response(button: CustomButton, interaction1: discord.Interaction): m = await ctx.send( embed=discord.Embed(description=self.bot.i18n.get( 'EMOJI_REACTIONS_CUSTOM_EMOJI_MESSAGE'), color=discord.Color.blue())) await ctx.edit(embed=discord.Embed( title=self.bot.i18n.get('EMOJI_REACTIONS_REACT_TO'), description=m.jump_url), view=None) self.activating_reactions[(m.channel.id, m.id)] = (ctx.author.id, ctx, message) async def response(dropdown1: CustomDropdown, interaction1: discord.Interaction): emoji = get(ctx.guild.emojis, id=int(dropdown1.values[0])) if not emoji: raise UnknownException(detail='Emoji not found') await self.add_emoji_reaction_action(ctx.guild, ctx, message, emoji) options = [ discord.SelectOption(label=str(emoji.name), emoji=str(emoji), value=str(emoji.id)) for emoji in ctx.guild.emojis ] pages = [] for i in range(math.ceil(len(options) / 25)): view = discord.ui.View() view.add_item( CustomButton( custom_emoji_response, label=bot.i18n.get( 'EMOJI_REACTIONS_CUSTOM_EMOJI_LABEL'), emoji=bot.i18n.get('EMOJI_REACTIONS_CUSTOM_EMOJI'))) view.add_item( CustomDropdown( response, bot.i18n.get( 'EMOJI_REACTIONS_CHOOSE_EMOJI_PLACEHOLDER'), options[i * 25:(i + 1) * 25])) pages.append(view) paginator = ViewPaginator(pages, hide_empty=True) await ctx.respond(view=paginator.view(), ephemeral=True) @bot.has_permissions(administrator=True) async def get_emoji_reactions( ctx: discord.commands.context.ApplicationContext): reactions = self.bot.db.get_emoji_reactions(ctx.guild.id) embed = discord.Embed( title=self.bot.i18n.get('EMOJI_REACTIONS_TITLE'), color=discord.Color.green()) for reaction in reactions: val = 'Not Found' if reaction.action_type == self.ADD_ROLE or reaction.action_type == self.TRIGGER_ROLE: r = ctx.guild.get_role(int(reaction.action)) if r is not None: val = r.name elif reaction.action_type == self.SEND_DM: val = json.dumps(reaction.action if len(reaction.action) < 40 else reaction.action[:37] + '...') embed.add_field( name=self.bot.i18n.get( 'EMOJI_REACTIONS_IDENTIFIER').format( reaction.id, reaction.emoji, self.bot.i18n.get( self.reaction_types[reaction.action_type]), val), value='https://discord.com/channels/{}/{}/{}'.format( reaction.guild_id, reaction.channel_id, reaction.message_id), inline=False) return await ctx.respond(embed=embed) @bot.has_permissions(administrator=True) async def remove_emoji_reaction_autocomplete( ctx: discord.AutocompleteContext): reactions = [] for reaction in self.bot.db.get_emoji_reactions( ctx.interaction.guild.id): val = 'Not Found' if reaction.action_type == self.ADD_ROLE or reaction.action_type == self.TRIGGER_ROLE: r = ctx.interaction.guild.get_role(int(reaction.action)) if r is not None: val = r.name elif reaction.action_type == self.SEND_DM: val = json.dumps(reaction.action if len(reaction.action) < 20 else reaction.action[:20] + '...') reactions.append('ID: {} | {} | {} | {}'.format( reaction.id, discord.PartialEmoji.from_str(reaction.emoji).name, self.bot.i18n.get( self.reaction_types[reaction.action_type]), val)) return tools.autocomplete_match(ctx.value, reactions) @bot.has_permissions(administrator=True) async def remove_emoji_reaction( ctx: discord.commands.context.ApplicationContext, reaction: discord.commands.Option( str, description=bot.i18n.get('REMOVE_REACTION_OPTION'), autocomplete=remove_emoji_reaction_autocomplete, )): try: reaction_id = int(reaction[4:].split(' ')[0]) except: raise UnknownException(detail='Reaction ID not found') self.bot.db.remove_emoji_reaction(ctx.author.guild.id, reaction_id) return await ctx.respond(embed=discord.Embed( title='', description=self.bot.i18n.get( 'EMOJI_REACTIONS_REMOVE_SUCCESSFUL').format(reaction), color=discord.Color.green())) emoji_reactions = discord.SlashCommandGroup( name=self.bot.i18n.get('EMOJI_REACTIONS_COMMAND'), description=self.bot.i18n.get( 'EMOJI_REACTIONS_COMMAND_DESCRIPTION'), ) emoji_reactions.subcommands.append( discord.SlashCommand( func=get_emoji_reactions, name=self.bot.i18n.get('EMOJI_REACTIONS_GET_COMMAND'), description=self.bot.i18n.get( 'EMOJI_REACTIONS_GET_COMMAND_DESCRIPTION'), parent=emoji_reactions)) emoji_reactions.subcommands.append( discord.SlashCommand( func=remove_emoji_reaction, name=self.bot.i18n.get('EMOJI_REACTIONS_REMOVE_COMMAND'), description=self.bot.i18n.get( 'EMOJI_REACTIONS_REMOVE_COMMAND_DESCRIPTION'), parent=emoji_reactions)) self.commands = [ discord.MessageCommand( func=add_emoji_action, name=self.bot.i18n.get('EMOJI_REACTIONS_ADD_COMMAND'), ), emoji_reactions ]
def __init__(self, bot): super().__init__(bot) async def profile( ctx: discord.commands.context.ApplicationContext, member: discord.commands.Option( discord.Member, description=bot.i18n.get('LEVELSYSTEM_PROFILE_MEMBER_OPTION'), default=None)): if member is None: member = ctx.author await ctx.defer() await ctx.respond( file=await self.member_create_profile_image(member)) self.commands = [ discord.SlashCommand( func=profile, name=self.bot.i18n.get('LEVELSYSTEM_PROFILE_COMMAND'), description=self.bot.i18n.get( 'LEVELSYSTEM_PROFILE_COMMAND_DESCRIPTION'), ) ] async def set_custom_profile_card(member: discord.Member, amount, equipped, options): pass self.bot.module_manager.hooks.add( self, INVENTORY_ITEM_ACTION_HOOK, hook_id='custom-profile-card', name='Custom Profile Card', options={ 'template': { 'type': 'text', 'description': self.bot.i18n.get( 'CUSTOM_PROFILE_CARD_TEMPLATE_DESCRIPTION') }, }, callback=set_custom_profile_card) async def replace_custom_profile(member: discord.Member, amount, equipped, options): pass self.bot.module_manager.hooks.add(self, INVENTORY_ITEM_ACTION_HOOK, hook_id='custom-profile-replace', name='Custom Profile Replace', options={ 'replace_id': { 'type': 'str', 'description': 'Replace Id' }, 'replace_content': { 'type': 'str', 'description': 'New content' }, }, callback=replace_custom_profile)