async def about(self, ctx): """ABOUT_TITLE""" e = DefraEmbed( title=Translator.translate("ABOUT_TITLE", ctx), footer_text=Translator.translate("ABOUT_FOOTER", ctx, user=ctx.author), footer_icon_url=ctx.author.avatar_url, description=Translator.translate('ABOUT_DESCRIPTION', ctx, owner=self.bot.owner, lib_version=f"discord.py {discord.__version__}") ) e.set_thumbnail(url=self.bot.user.avatar_url_as(format="png")) await ctx.send(embed=e)
async def fox(self, ctx): """FOX_HELP""" await ctx.trigger_typing() some_cat = await self.bot.apis.get_fox() embed = DefraEmbed( title=":fox: {0}".format(Translator.translate("THIS_FOX", ctx))) embed.set_image(url=some_cat) await ctx.send(embed=embed)
async def cat(self, ctx): """CAT_HELP""" await ctx.trigger_typing() some_cat = await self.bot.apis.get_cat(self.bot.cfg['API_KEYS']['CATS'] ) embed = DefraEmbed( title=":cat: {0}".format(Translator.translate("THIS_CAT", ctx))) embed.set_image(url=some_cat) await ctx.send(embed=embed)
async def avatar(self, ctx, user: Union[discord.Member, SmartUser] = None): """AVATAR_HELP""" user = user or ctx.author avatar_url = user.avatar_url_as(static_format="png") embed = DefraEmbed( title=Translator.translate("AVATAR_TITLE", ctx, user=user), description=Translator.translate("AVATAR_DESCRIPTION", ctx, url=avatar_url) ) embed.set_image(url=avatar_url) await ctx.send(embed=embed)
async def translate(self, ctx, translate_from, translate_to, *, text: str): """TRANSLATE_HELP""" await ctx.trigger_typing() data = await self.bot.apis.yandex_translate(text=text, tr_to=translate_to, tr_from=translate_from) if data['code'] != 200: await ctx.send(embed=error_embed(title=Translator.translate('YANDEX_TRANSLATE_FAILED', ctx), text=data['message'])) elif data['code'] == 200: e = DefraEmbed() e.description = data['text'][0] e.set_footer(text=Translator.translate('YANDEX_TRANSLATE_NOTICE', ctx), icon_url="https://translate.yandex.ru/icons/favicon.png") await ctx.send(embed=e)
async def mod_roles_remove(self, ctx, roles: commands.Greedy[int] = None): """MOD_ROLES_REMOVE_HELP""" if roles is None: return await ctx.send(embed=error_embed( text=None, title=Translator.translate('CONFIG_MOD_ROLES_EMPTY_ARGUMENT', ctx.guild.id))) # Iterate through provided list of roles for role_id in roles: # Check if role_id is already a mod role if role_id not in self.bot.cache.guilds.get( ctx.guild.id).mod_roles: return await ctx.send( embed=error_embed(text=None, title=Translator.translate( 'CONFIG_MOD_ROLES_REMOVE_BAD_ROLE', ctx, role_id=role_id))) # Delete the role await self.bot.db.roles.remove(TableRolesTypes.mod_roles, ctx.guild.id, role_id) await self.bot.cache.refresh(ctx.guild.id) await ctx.send(embed=DefraEmbed( title=Translator.translate('CONFIG_MOD_ROLES_REMOVED', ctx.guild.id), description='\n'.join([ str( ctx.guild.get_role(role_id).mention if ctx.guild. get_role(role_id) is not None else role_id) for role_id in roles ])))
async def on_guild_remove(self, guild: Guild): await self.bot.dev_channel.send( content=f"\U00002139 **`[{current_time_with_tz().strftime('%d.%m.%Y %H:%M:%S')}]`**", embed=DefraEmbed( title="Removed from Guild", color=Color.red(), description=f":inbox_tray: {guild.name} (`{guild.id}`)" ).add_field(name="Owner", value=f"{guild.owner} (`{guild.owner_id}`)").add_field( name="Members count", value=f"{guild.member_count}").add_field( name="Channels count", value=f"{len(guild.channels)}" ))
async def mod_roles(self, ctx): """MOD_ROLES_HELP""" if ctx.invoked_subcommand is None: e = DefraEmbed(title=Translator.translate( 'CONFIG_MOD_ROLES_CURRENT', ctx.guild.id), description='\n'.join([ f'{role.mention} (`{role.id}`)' if (role := ctx.guild.get_role(role_id)) is not None else f"`{role_id}`" for role_id in self.bot.cache.guilds.get( ctx.guild.id).mod_roles ]))
async def on_guild_join(self, guild: Guild): await self.bot.dev_channel.send( content=f"\U00002139 **`[{current_time_with_tz().strftime('%d.%m.%Y %H:%M:%S')}]`**", embed=DefraEmbed( title="New Guild", color=Color.green(), description=f":inbox_tray: {guild.name} (`{guild.id}`)" ).add_field(name="Owner", value=f"{guild.owner} (`{guild.owner_id}`)").add_field( name="Members count", value=f"{guild.member_count}").add_field( name="Channels count", value=f"{len(guild.channels)}" )) # Adding the guild to database of settings await self.bot.db.safe_add_guild(guild.id) # Refreshing bot's cache for the guild await self.bot.cache.refresh(guild.id)
async def logging(self, ctx): """CONFIG_LOGGING_HELP""" if ctx.invoked_subcommand is None: logging_settings = self.bot.cache.guilds.get(ctx.guild.id).logging embed = DefraEmbed(title=Translator.translate( 'LOGGING_CURRENT_TITLE', ctx, servername=ctx.guild.name)) for modlog_type in ModLoggingType: channel_ids = [ channel_id for channel_id in getattr( logging_settings, modlog_type.value) ] channels_fmt = "\n".join([ f"{channel.mention}" if (channel := self.bot.get_channel(channel_id)) else f"~~`{channel_id}`~~" for channel_id in channel_ids ])
async def mod_roles_add(self, ctx, roles: commands.Greedy[int] = None): """MOD_ROLES_ADD_HELP""" if roles is None: return await ctx.send(embed=error_embed( text=None, title=Translator.translate('CONFIG_MOD_ROLES_EMPTY_ARGUMENT', ctx.guild.id))) # Filtering out non-existing roles and deleting duplicates roles = [ ctx.guild.get_role(role) for role in set( filter( lambda _id: True if ctx.guild.get_role(_id) is not None else False, roles)) ] if len(roles) <= 0: return await ctx.send(embed=error_embed( text=None, title=Translator.translate('CONFIG_MOD_ROLES_NONE_ADDED', ctx.guild.id))) # Adding each role id into the database for role in roles: if role.id not in self.bot.cache.guilds.get( ctx.guild.id).mod_roles: await self.bot.db.roles.add(TableRolesTypes.mod_roles, ctx.guild.id, role.id) else: return await ctx.send( embed=error_embed(title=Translator.translate( 'NOTHING_CHANGED', ctx.guild.id), text=None)) await self.bot.cache.refresh(ctx.guild.id) await ctx.send(embed=DefraEmbed( title=Translator.translate('CONFIG_MOD_ROLES_ADDED', ctx.guild.id), description='\n'.join( [f"{role.mention} (`{role.id}`)" for role in roles])))
async def remove(self, ctx, todo_id): """TODO_REMOVE_HELP""" await ctx.trigger_typing() if not todo_id.isdigit(): return await ctx.send(Translator.translate("TODO_MUST_BE_INT", ctx)) todo_id = int(todo_id) target_todo = None async with (await self.bot.db.get_pool()).acquire() as conn: todos = await conn.fetch( "SELECT * FROM bot.todos WHERE user_id = $1 ORDER BY timestamp DESC LIMIT 200;", ctx.author.id) for index, todo in enumerate(todos): if index + 1 == todo_id: target_todo = todo if target_todo is None: await ctx.send(embed=warn_embed( title=Translator.translate('TODO_NOT_EXISTING', ctx))) else: async with (await self.bot.db.get_pool()).acquire() as conn: async with conn.transaction(): params = (target_todo.get('timestamp'), target_todo.get('user_id')) is_deleted = await conn.fetchval( "DELETE FROM bot.todos WHERE timestamp = $1 AND user_id = $2 RETURNING True", *params) if is_deleted: await ctx.send(embed=DefraEmbed( description=Translator.translate( 'TODO_REMOVED', ctx, todo=target_todo.get('content'))))
async def serverinfo(self, ctx, server_id: Union[discord.Guild, int] = None): """SERVERINFO_HELP""" if server_id is None: guild = ctx.guild else: guild = self.bot.get_guild(server_id) if guild is None: return await ctx.send(Translator.translate('SERVERINFO_NOT_FOUND', ctx, id=str(server_id))) guild_features = "\n".join(guild.features) if len(guild.features) > 0 else None guild_emojis = " ".join(walk_emojis(guild.emojis)) embed = DefraEmbed(title=f"{guild.name}") embed.set_thumbnail(url=guild.icon_url) embed.add_field(name="**ID**", value=str(guild.id), inline=False) embed.add_field(name=Translator.translate("SERVERINFO_OWNER", ctx), value=str(guild.owner), inline=False) embed.add_field(name=Translator.translate("SERVERINFO_MEMBERS", ctx), value=str(guild.member_count), inline=False) if guild_features is not None: embed.add_field(name=Translator.translate("SERVERINFO_FEATURES", ctx), value=guild_features, inline=False) embed.add_field(name=Translator.translate("SERVERINFO_EMOJILIST", ctx), value=guild_emojis[0:1000], inline=False) await ctx.send(embed=embed)
async def invite(self, ctx): """INVITE_HELP""" embed = DefraEmbed(title=Translator.translate("INVITE_BOT", ctx)) embed.description = Translator.translate("INVITE_BOT_URL", ctx, url=discord.utils.oauth_url(self.bot.user.id)) await ctx.send(embed=embed)