119 lines
4.8 KiB
Python
119 lines
4.8 KiB
Python
# ╔══════════════════════════════════════════════════════════════════╗
|
|
# ║ ║
|
|
# ║ +-+-+-+-+-+-+-+-+ ║
|
|
# ║ |H|e|x|a|H|o|s|t| ║
|
|
# ║ +-+-+-+-+-+-+-+-+ ║
|
|
# ║ ║
|
|
# ║ © 2026 HexaHost — All Rights Reserved ║
|
|
# ║ ║
|
|
# ║ discord ── https://discord.gg/hexahost ║
|
|
# ║ github ── https://github.com/theoneandonlymace ║
|
|
# ║ ║
|
|
# ╚══════════════════════════════════════════════════════════════════╝
|
|
|
|
import discord
|
|
from core import Axiom, Cog
|
|
from utils.config import BotName, BRAND_NAME, DISCORD_CLIENT_ID, serverLink
|
|
from discord.ext import commands
|
|
from discord.ui import Button, View
|
|
|
|
# HexaHost brand accent (matches dashboard primary/accent)
|
|
EMBED_COLOR = 0xA348FF
|
|
DASHBOARD_URL = "https://bot.hexahost.de"
|
|
|
|
|
|
class Autorole(Cog):
|
|
def __init__(self, bot: Axiom):
|
|
self.bot = bot
|
|
|
|
def _invite_url(self) -> str | None:
|
|
client_id = DISCORD_CLIENT_ID or (str(self.bot.user.id) if self.bot.user else "")
|
|
if not client_id:
|
|
return None
|
|
return (
|
|
f"https://discord.com/oauth2/authorize?client_id={client_id}"
|
|
f"&permissions=8&scope=bot%20applications.commands"
|
|
)
|
|
|
|
def _welcome_embed(self, guild: discord.Guild, adder: discord.abc.User) -> discord.Embed:
|
|
bot_avatar = guild.me.display_avatar.url if guild.me else (
|
|
self.bot.user.display_avatar.url if self.bot.user else None
|
|
)
|
|
|
|
embed = discord.Embed(
|
|
title=f"Thanks for adding {BotName}",
|
|
description=(
|
|
f"Hey {adder.mention}, **{BotName}** is now in **{guild.name}**.\n\n"
|
|
"Here's everything you need to get started:"
|
|
),
|
|
color=EMBED_COLOR,
|
|
)
|
|
|
|
if bot_avatar:
|
|
embed.set_author(name=BotName, icon_url=bot_avatar)
|
|
embed.set_thumbnail(url=bot_avatar)
|
|
|
|
embed.add_field(
|
|
name="Prefix",
|
|
value="Default prefix is `>`\nExample: `>help`",
|
|
inline=True,
|
|
)
|
|
embed.add_field(
|
|
name="Slash commands",
|
|
value="Type `/` in your server to browse available commands.",
|
|
inline=True,
|
|
)
|
|
embed.add_field(
|
|
name="Dashboard",
|
|
value=f"Configure modules online at **[bot.hexahost.de]({DASHBOARD_URL})**",
|
|
inline=False,
|
|
)
|
|
embed.add_field(
|
|
name="Need help?",
|
|
value=f"Join our **[Support Server]({serverLink})** for guides, FAQ and assistance.",
|
|
inline=False,
|
|
)
|
|
|
|
embed.set_footer(text=f"Powered by HexaHost · {BRAND_NAME}")
|
|
return embed
|
|
|
|
def _welcome_view(self) -> View:
|
|
view = View()
|
|
view.add_item(
|
|
Button(label="Open Dashboard", style=discord.ButtonStyle.link, url=DASHBOARD_URL)
|
|
)
|
|
view.add_item(
|
|
Button(label="Support Server", style=discord.ButtonStyle.link, url=serverLink)
|
|
)
|
|
invite = self._invite_url()
|
|
if invite:
|
|
view.add_item(
|
|
Button(label="Add to another server", style=discord.ButtonStyle.link, url=invite)
|
|
)
|
|
return view
|
|
|
|
@commands.Cog.listener(name="on_guild_join")
|
|
async def send_msg_to_adder(self, guild: discord.Guild):
|
|
try:
|
|
async for entry in guild.audit_logs(limit=5, action=discord.AuditLogAction.bot_add):
|
|
if entry.target is None or entry.user is None:
|
|
continue
|
|
if entry.target.id != self.bot.user.id:
|
|
continue
|
|
|
|
embed = self._welcome_embed(guild, entry.user)
|
|
view = self._welcome_view()
|
|
try:
|
|
await entry.user.send(embed=embed, view=view)
|
|
except discord.Forbidden:
|
|
# User has DMs closed — ignore silently
|
|
pass
|
|
except Exception as e:
|
|
print(f"Welcome DM failed: {e}")
|
|
break
|
|
except discord.Forbidden:
|
|
# Missing View Audit Log permission
|
|
pass
|
|
except Exception as e:
|
|
print(f"Welcome DM (audit log) failed: {e}")
|