async def convert(self, ctx, argument): try: return await EmojiConverter.convert(EmojiConverter(), ctx, argument) except commands.BadArgument: try: return await PartialEmojiConverter.convert(PartialEmojiConverter(), ctx, argument) except commands.BadArgument: return argument
async def get_emoji(ctx: commands.Context, emoji: str): try: converter = EmojiConverter() return await converter.convert(ctx, emoji) except BadArgument: if is_emoji(emoji): return emoji else: raise
async def activate_role_reaction_subscription( self, ctx, role: discord.Role, channel: discord.TextChannel, subscription_message_id, subscribe_emoji, unsubscribe_emoji): """ Activate reaction-based role subscription. :param ctx: :param role: :param channel: :param subscription_message_id: :param subscribe_emoji: :param unsubscribe_emoji: :return: """ if subscribe_emoji == unsubscribe_emoji: await ctx.message.channel.send( f"{ctx.author.mention} Emoji used for subscribing and unsubscribing must be distinct." ) return emoji_converter = EmojiConverter() try: actual_subscribe_emoji = await emoji_converter.convert( ctx, subscribe_emoji) except BadArgument: actual_subscribe_emoji = subscribe_emoji try: actual_unsubscribe_emoji = await emoji_converter.convert( ctx, unsubscribe_emoji) except BadArgument: actual_unsubscribe_emoji = unsubscribe_emoji self.db.configure_role_reaction_subscription(ctx.guild, channel, subscription_message_id, actual_subscribe_emoji, actual_unsubscribe_emoji, role) message = await channel.fetch_message(subscription_message_id) try: await message.add_reaction(actual_subscribe_emoji) await message.add_reaction(actual_unsubscribe_emoji) except discord.Forbidden: await ctx.message.channel.send( f"{ctx.author.mention} Bot {ctx.guild.get_member(self.bot.user.id)} does not" f"have the appropriate permissions to add a reaction.") await ctx.message.channel.send( f"{ctx.author.mention} Reaction role subscription for this guild's {role} role has been " f"configured with {self.get_bot_member(ctx.guild).name}.")
async def activate_ex_gating(self, ctx, disclaimer_channel: discord.TextChannel, disclaimer_message_id, approve_emoji, ex_role: discord.Role, wait_time: float, approval_message_template): """ Activate EX gating by adding this guild to the database. :param ctx: :param disclaimer_channel: :param disclaimer_message_id: :param approve_emoji: :param ex_role: :param wait_time: :param approval_message_template :return: """ # First, check that the client can write to this channel and manage messages. channel_perms = disclaimer_channel.permissions_for(ctx.guild.get_member(self.bot.user.id)) if not channel_perms.send_messages: await ctx.message.channel.send( f'{ctx.author.mention} {self.get_bot_member(ctx.guild).name} ' f'cannot write to channel {disclaimer_channel}.' ) return elif not channel_perms.manage_messages: await ctx.message.channel.send( f'{ctx.author.mention} {self.get_bot_member(ctx.guild).name} needs Manage Messages ' f'permissions on channel {disclaimer_channel}.' ) return emoji_converter = EmojiConverter() try: actual_emoji = await emoji_converter.convert(ctx, approve_emoji) except BadArgument: actual_emoji = approve_emoji self.db.configure_ex_gating(ctx.guild, disclaimer_channel, disclaimer_message_id, actual_emoji, ex_role, wait_time, approval_message_template) await ctx.message.channel.send( f'{ctx.author.mention} EX gating for this guild has been ' f'configured with {self.get_bot_member(ctx.guild).name}.' )
async def configure_fyi(self, ctx, fyi_emoji, timezone_str): """ Configure the raid FYI functionality for this guild. :param ctx: :param fyi_emoji: :param timezone_str: string describing the guild's timezone, as understood by pytz :return: """ self.can_configure_bot_validator(ctx) emoji_converter = EmojiConverter() try: actual_emoji = await emoji_converter.convert(ctx, fyi_emoji) except BadArgument: actual_emoji = fyi_emoji self.db.configure_fyi(ctx.guild, actual_emoji, timezone_str) await ctx.channel.send( f"{ctx.author.mention} Raid FYI functionality is now enabled.")
async def configure_enhanced_fyi(self, ctx, rsvp_emoji, remote_emoji, cancelled_emoji, relay_to_chat: bool): """ Configure the enhanced raid FYI functionality for this guild. :param ctx: :param rsvp_emoji: :param remote_emoji: :param cancelled_emoji: :param relay_to_chat: :return: """ self.can_configure_bot_validator(ctx) emoji_converter = EmojiConverter() try: actual_rsvp_emoji = await emoji_converter.convert(ctx, rsvp_emoji) except BadArgument: actual_rsvp_emoji = rsvp_emoji try: actual_remote_emoji = await emoji_converter.convert( ctx, remote_emoji) except BadArgument: actual_remote_emoji = remote_emoji try: actual_cancelled_emoji = await emoji_converter.convert( ctx, cancelled_emoji) except BadArgument: actual_cancelled_emoji = cancelled_emoji self.db.activate_enhanced_fyi( ctx.guild, actual_rsvp_emoji, actual_remote_emoji, actual_cancelled_emoji, relay_to_chat, ) await ctx.channel.send( f"{ctx.author.mention} Enhanced FYI functionality is now enabled.")
async def configure_team_emoji(self, ctx, team, emoji): """ Update the guild information in the database with the given team's emoji. :param ctx: :param team: :param emoji: :return: """ self.can_configure_bot_validator(ctx) self.guild_registered_validator(ctx.guild) emoji_converter = EmojiConverter() try: actual_emoji = await emoji_converter.convert(ctx, emoji) except BadArgument: actual_emoji = emoji self.db.set_team_emoji(ctx.guild, team, actual_emoji) await ctx.message.channel.send( f'{ctx.author.mention} Guild information has been updated: {team.lower()} emoji is {emoji}.' )
async def change_show_subscription_emoji(self, ctx, new_show_subscription_emoji): """ Change the emoji used by the bot for showing subscriptions. :param ctx: :param new_show_subscription_emoji: :return: """ emoji_converter = EmojiConverter() try: actual_emoji = await emoji_converter.convert( ctx, new_show_subscription_emoji) except BadArgument: actual_emoji = new_show_subscription_emoji config = self.db.get_no_command_subscription_settings(ctx.guild) if config is None: await ctx.message.channel.send( f'{ctx.author.mention} No-command subscription is not configured.' ) return instruction_message = await config[ "subscription_channel"].fetch_message( config["instruction_message_id"]) members_who_already_added_this = [ x for x in instruction_message.reactions if x.emoji == actual_emoji ] if not ctx.guild.get_member( self.bot.user.id) in members_who_already_added_this: await instruction_message.add_reaction(actual_emoji) self.db.change_show_subscriptions_emoji(ctx.guild, actual_emoji) await ctx.message.channel.send( f'{ctx.author.mention} No-command subscription now uses {actual_emoji} to send ' f'members\' list of roles.')
def __init__(self, bot): self.bot = bot self.emojiConverter = EmojiConverter()