Initial commit
This commit is contained in:
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@@ -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
|
||||
5
__init__.py
Normal file
5
__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .mentionhelp import MentionHelp
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(MentionHelp(bot))
|
||||
6
info.json
Normal file
6
info.json
Normal file
@@ -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."
|
||||
}
|
||||
64
mentionhelp.py
Normal file
64
mentionhelp.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user