commit 5443917d4db22a7585b2b5da56c81f4ef4ffeb32 Author: zv Date: Sat Apr 18 21:14:18 2026 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..23c994d --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Python cache +__pycache__/ +*.py[cod] +*$py.class + +# Build / packaging +build/ +dist/ +*.egg-info/ +.eggs/ + +# Virtual environments +.venv/ +venv/ +env/ + +# Tool caches +.mypy_cache/ +.pytest_cache/ +.ruff_cache/ + +# IDE / OS noise +.idea/ +.vscode/ +.DS_Store +Thumbs.db + +# Runtime artifacts +*.log diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..50bd559 --- /dev/null +++ b/__init__.py @@ -0,0 +1,5 @@ +from .mentionhelp import MentionHelp + + +async def setup(bot): + await bot.add_cog(MentionHelp(bot)) diff --git a/info.json b/info.json new file mode 100644 index 0000000..a4fba98 --- /dev/null +++ b/info.json @@ -0,0 +1,6 @@ +{ + "name": "mentionhelp", + "short": "Replies with prefix and help hint when the bot is mentioned.", + "description": "When someone mentions the bot without using a command, the bot replies with its prefix and tells them to use help.", + "end_user_data_statement": "This cog does not store end user data." +} diff --git a/mentionhelp.py b/mentionhelp.py new file mode 100644 index 0000000..cf7f01a --- /dev/null +++ b/mentionhelp.py @@ -0,0 +1,64 @@ +import discord +from redbot.core import commands + + +class MentionHelp(commands.Cog): + def __init__(self, bot): + self.bot = bot + + def build_help_embed(self, message, prefix_text, main_prefix): + embed = discord.Embed( + title="Pomoc", + description=( + f"Użyj `{main_prefix}help`, aby zobaczyć wszystkie komendy bota." + ), + color=0xEB459E + ) + + author_name = str(message.author) + author_icon_url = message.author.display_avatar.url if message.author.display_avatar else None + + if author_icon_url: + embed.set_author(name=author_name, icon_url=author_icon_url) + else: + embed.set_author(name=author_name) + + if message.guild: + if message.guild.icon: + embed.set_thumbnail(url=message.guild.icon.url) + embed.set_footer( + text=message.guild.name, + icon_url=message.guild.icon.url + ) + else: + embed.set_footer(text=message.guild.name) + + return embed + + @commands.Cog.listener() + async def on_message_without_command(self, message): + if message.author.bot: + return + + if message.guild is None: + return + + if self.bot.user is None: + return + + mention_forms = { + f"<@{self.bot.user.id}>", + f"<@!{self.bot.user.id}>" + } + + content = message.content.strip() + + if content in mention_forms: + prefixes = await self.bot.get_valid_prefixes(message.guild) + + visible_prefixes = [p for p in prefixes if not p.startswith("<@")] + main_prefix = visible_prefixes[0] if visible_prefixes else prefixes[0] + prefix_text = ", ".join(visible_prefixes) if visible_prefixes else ", ".join(prefixes) + + embed = self.build_help_embed(message, prefix_text, main_prefix) + await message.channel.send(embed=embed)