async def delete(self, ctx, channel_type: str, channel: discord.TextChannel): """ Command to delete a registered TextChannel from a designated channel Args: channel_type (str): Designated channel to remove the textchannel from channel (discord.TextChannel): Channel to unregister """ channel_repo = DesignatedChannelRepository() if not await channel_repo.check_designated_channel(channel_type): await ctx.send(f'The requested designated channel `{channel_type}` does not exist') return if channel.id not in await channel_repo.get_guild_designated_channels(channel_type, ctx.guild.id): await ctx.send(f'{channel.mention} is not registered to `{channel_type}`') return await channel_repo.remove_from_designated_channel(channel_type, channel.id) embed = discord.Embed( title= 'Designated Channel deleted', color= Colors.ClemsonOrange) embed.add_field( name= channel_type, value=f'Successfully deleted {channel.mention} from `{channel_type}`') await ctx.send(embed= embed)
async def channel(self, ctx): """ Sends a formatted embed of the possible designated channels and their listeners to the context of the command """ channel_repo = DesignatedChannelRepository() channels = await channel_repo.get_all_designated_channels() embed = discord.Embed(title= f'Designated Channels', color= Colors.ClemsonOrange) if channels is None: embed.add_field(name= 'No possible designated channels', value= '') await ctx.send(embed= embed) return for designated_id, name in channels: assigned_channels = [] for channel_id in await channel_repo.get_guild_designated_channels(name, ctx.guild.id): assigned_channels.append(ctx.bot.get_channel(channel_id)) if len(assigned_channels) != 0: embed_value = '\n'.join(c.mention for c in assigned_channels) else: embed_value = 'No channel added' embed.add_field( name= f'#{designated_id} {name}', value= embed_value, inline= False) await ctx.send(embed= embed)
async def add(self, ctx, channel_type: str, channel: discord.TextChannel): """ Command to add a registered TextChannel too a designated channel Args: channel_type (str): Designated channel to add the textchannel too channel (discord.TextChannel): Channel to add """ channel_repo = DesignatedChannelRepository() if not await channel_repo.check_designated_channel(channel_type): await ctx.send(f'The requested designated channel `{channel_type}` does not exist') return if channel.id in await channel_repo.get_guild_designated_channels(channel_type, ctx.guild.id): await ctx.send(f'{channel.mention} already registered to `{channel_type}`') return await channel_repo.register_designated_channel(channel_type, channel) embed = discord.Embed( title= 'Designated Channel added', color= Colors.ClemsonOrange) embed.add_field( name= channel_type, value=f'Successfully added {channel.mention} to `{channel_type}`') await ctx.send(embed= embed)
async def send_designated_message(self, designated_name: DesignatedChannels, guild_id: int, content: Union[str, discord.Embed], dc_id: int = None): """ Event call back to sent a given string or embed message to all registered designated channels in a given guild Args: designated_name (DesignatedChannels): The enum name of the designated channel guild_id (int): the guild to send the message in content (Union[str, discord.Embed]): The message to send dc_id [optional] (int) an optional callback id to associate sent dc messages at the publish site """ dc_repo = DesignatedChannelRepository() assigned_channel_ids = await dc_repo.get_guild_designated_channels( designated_name.name, guild_id) if assigned_channel_ids is None: return sent_ids = await self._send_dc_messages(assigned_channel_ids, content) if dc_id: await self.messenger.publish(Events.on_designated_message_sent, dc_id, sent_ids)
async def add(self, ctx, channel_type: str, channel: discord.TextChannel): channel_repo = DesignatedChannelRepository() if OwnerDesignatedChannels.has(channel_type): await ctx.send(f""" The requested designated channel `{channel_type}` can only be managed by the owner of the bot instance If you are the owner of the instance please reference owner_cog.py for more information """) return if not DesignatedChannels.has(channel_type): await ctx.send( f'The requested designated channel `{channel_type}` does not exist' ) return if channel.id in await channel_repo.get_guild_designated_channels( channel_type, ctx.guild.id): await ctx.send( f'{channel.mention} already registered to `{channel_type}`') return await channel_repo.register_designated_channel(channel_type, channel) embed = discord.Embed(title='Designated Channel added', color=Colors.ClemsonOrange) embed.add_field( name=channel_type, value=f'Successfully added {channel.mention} to `{channel_type}`') await ctx.send(embed=embed)
async def broadcast_designated_message(self, designated_name: DesignatedChannels, content: Union[str, discord.Embed]): """ Event call back to broadcast a given string or embed message to all registered designated channels in all guilds Args: designated_name (DesignatedChannels): The enum name of the designated channel content (Union[str, discord.Embed]): The message to send """ dc_repo = DesignatedChannelRepository() assigned_channel_ids = await dc_repo.get_all_assigned_channels(designated_name.name) if assigned_channel_ids is None: return await self._send_dc_messages(assigned_channel_ids, content)
async def delete(self, ctx, channel_type: str, channel: discord.TextChannel): """ Command to delete a registered TextChannel from a designated channel Args: channel_type (str): Designated channel to remove the textchannel from channel (discord.TextChannel): Channel to unregister """ channel_repo = DesignatedChannelRepository() if OwnerDesignatedChannels.has(channel_type): await ctx.send(f""" The requested designated channel `{channel_type}` can only be managed by the owner of the bot instance If you are the owner of the instance please reference owner_cog.py for more information """) return if not DesignatedChannels.has(channel_type): await ctx.send( f'The requested designated channel `{channel_type}` does not exist' ) return if channel.id not in await channel_repo.get_guild_designated_channels( channel_type, ctx.guild.id): await ctx.send( f'{channel.mention} is not registered to `{channel_type}`') return await channel_repo.remove_from_designated_channel( channel_type, channel.id) embed = discord.Embed(title='Designated Channel deleted', color=Colors.ClemsonOrange) embed.add_field( name=channel_type, value= f'Successfully deleted {channel.mention} from `{channel_type}`') await ctx.send(embed=embed)
async def channel(self, ctx): channel_repo = DesignatedChannelRepository() embed = discord.Embed(title=f'Designated Channels', color=Colors.ClemsonOrange) for i, channel in enumerate(OwnerDesignatedChannels): assigned_channels = [] for channel_id in await channel_repo.get_guild_designated_channels( channel.name, ctx.guild.id): assigned_channels.append(ctx.bot.get_channel(channel_id)) if len(assigned_channels) != 0: embed_value = '\n'.join(c.mention for c in assigned_channels) else: embed_value = 'No channel added' embed.add_field(name=f'#{i+1} {channel.name}', value=embed_value, inline=False) await ctx.send(embed=embed)
async def load_service(self): repo = DesignatedChannelRepository() for channel in DesignatedChannels: log.info(f'Loading designated channel: {channel.name}') await repo.add_designated_channel_type(channel.name)
async def designated_channel_removed(self, channel): repo = DesignatedChannelRepository() if await repo.check_channel(channel): await repo.remove_from_all_designated_channels(channel)