Spaces:
No application file
No application file
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,1024 +1,225 @@
|
|
| 1 |
-
"""
|
| 2 |
-
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 3 |
-
โ Discord Ticket Bot - Production Ready โ
|
| 4 |
-
โ Built with discord.py for Hugging Face โ
|
| 5 |
-
โ Author: Professional Discord Bot Developer โ
|
| 6 |
-
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 7 |
-
|
| 8 |
-
ุงููุตู: ูุธุงู
ุชุฐุงูุฑ ู
ุชูุงู
ู ุซูุงุฆู ุงููุบุฉ (ุนุฑุจู/ุฅูุฌููุฒู)
|
| 9 |
-
Description: Full bilingual ticket system (Arabic/English)
|
| 10 |
-
"""
|
| 11 |
-
|
| 12 |
import discord
|
| 13 |
-
from discord.ext import commands
|
| 14 |
from discord import app_commands
|
| 15 |
-
import
|
| 16 |
-
import
|
| 17 |
-
import sys
|
| 18 |
-
import traceback
|
| 19 |
-
import logging
|
| 20 |
-
import json
|
| 21 |
import random
|
| 22 |
import string
|
| 23 |
-
import
|
|
|
|
| 24 |
import re
|
| 25 |
-
from collections import defaultdict
|
| 26 |
-
|
| 27 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 28 |
-
# LOGGING SETUP | ุฅุนุฏุงุฏ ุงูุณุฌู
|
| 29 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 30 |
-
logging.basicConfig(
|
| 31 |
-
level=logging.INFO,
|
| 32 |
-
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
| 33 |
-
handlers=[
|
| 34 |
-
logging.StreamHandler(sys.stdout),
|
| 35 |
-
logging.FileHandler("bot.log", encoding="utf-8"),
|
| 36 |
-
],
|
| 37 |
-
)
|
| 38 |
-
log = logging.getLogger("TicketBot")
|
| 39 |
-
|
| 40 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 41 |
-
# CONFIGURATION | ุงูุฅุนุฏุงุฏุงุช
|
| 42 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 43 |
-
TOKEN = os.getenv("TOKEN") # โ ูููุถุน ูู Environment Variables ุนูู Hugging Face
|
| 44 |
|
|
|
|
| 45 |
OWNER_ID = 1429183440485486679
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
LOG_CHANNEL_ID = 1488536921813680218
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
1488187816201687181,
|
| 53 |
-
1488188612313874733,
|
| 54 |
-
1488537308700344490,
|
| 55 |
-
1488537566910218260,
|
| 56 |
]
|
|
|
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
1488187641424773140,
|
| 62 |
-
1488187816201687181,
|
| 63 |
-
1488188612313874733,
|
| 64 |
-
1488537308700344490,
|
| 65 |
-
1488537566910218260,
|
| 66 |
-
]
|
| 67 |
-
|
| 68 |
-
TICKET_SLOWMODE = 10 # ุซูุงูู
|
| 69 |
-
COOLDOWN_SECONDS = 60 # ุซูุงูู ุจุนุฏ ุฅุบูุงู ุงูุชุฐูุฑุฉ
|
| 70 |
-
|
| 71 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 72 |
-
# IN-MEMORY STORAGE | ุงูุชุฎุฒูู ูู ุงูุฐุงูุฑุฉ
|
| 73 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 74 |
-
# { user_id: thread_id }
|
| 75 |
-
active_tickets: dict[int, int] = {}
|
| 76 |
-
|
| 77 |
-
# { thread_id: {"user_id", "category", "opened_at", "claimed_by", "ticket_name"} }
|
| 78 |
-
ticket_data: dict[int, dict] = {}
|
| 79 |
-
|
| 80 |
-
# { user_id: datetime } - ููุช ุงูุชูุงุก ุงูู Cooldown
|
| 81 |
-
cooldowns: dict[int, datetime.datetime] = {}
|
| 82 |
-
|
| 83 |
-
# { user_id: [timestamps] } - ููุดู ุงูุณุจุงู
|
| 84 |
-
spam_tracker: dict[int, list] = defaultdict(list)
|
| 85 |
-
|
| 86 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 87 |
-
# HELPER FUNCTIONS | ุฏูุงู ู
ุณุงุนุฏุฉ
|
| 88 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 89 |
-
|
| 90 |
-
def generate_ticket_name() -> str:
|
| 91 |
-
"""ุชูููุฏ ุงุณู
ุนุดูุงุฆู ููุชุฐูุฑุฉ ู
ุซู ticket-4932-xa"""
|
| 92 |
-
number = random.randint(1000, 9999)
|
| 93 |
-
suffix = "".join(random.choices(string.ascii_lowercase, k=2))
|
| 94 |
-
return f"ticket-{number}-{suffix}"
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
def has_staff_role(member: discord.Member) -> bool:
|
| 98 |
-
"""ุงูุชุญูู ุฅุฐุง ูุงู ุงูุนุถู ูุฏูู ุฑุชุจุฉ ู
ูุธู"""
|
| 99 |
-
role_ids = {r.id for r in member.roles}
|
| 100 |
-
return bool(role_ids.intersection(ALLOWED_ROLE_IDS))
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
def is_owner(user: discord.User | discord.Member) -> bool:
|
| 104 |
-
"""ุงูุชุญูู ุฅุฐุง ูุงู ุงูู
ุณุชุฎุฏู
ูู ุงูู
ุงูู"""
|
| 105 |
-
return user.id == OWNER_ID
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
total = int(delta.total_seconds())
|
| 115 |
-
hours, remainder = divmod(total, 3600)
|
| 116 |
-
minutes, seconds = divmod(remainder, 60)
|
| 117 |
-
if hours:
|
| 118 |
-
return f"{hours}h {minutes}m {seconds}s"
|
| 119 |
-
elif minutes:
|
| 120 |
-
return f"{minutes}m {seconds}s"
|
| 121 |
-
else:
|
| 122 |
-
return f"{seconds}s"
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
def is_spam(user_id: int) -> bool:
|
| 126 |
-
"""
|
| 127 |
-
ูุดู ุงูุณุจุงู
: ุฃูุซุฑ ู
ู 5 ุฑุณุงุฆู ูู 5 ุซูุงูู
|
| 128 |
-
Spam detection: more than 5 messages in 5 seconds
|
| 129 |
-
"""
|
| 130 |
-
now = now_utc()
|
| 131 |
-
tracker = spam_tracker[user_id]
|
| 132 |
-
# ุฅุฒุงูุฉ ุงูุฑุณุงุฆู ุงููุฏูู
ุฉ ุฃูุซุฑ ู
ู 5 ุซูุงูู
|
| 133 |
-
spam_tracker[user_id] = [t for t in tracker if (now - t).total_seconds() < 5]
|
| 134 |
-
spam_tracker[user_id].append(now)
|
| 135 |
-
return len(spam_tracker[user_id]) > 5
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
def contains_link(content: str) -> bool:
|
| 139 |
-
"""ูุดู ุงูุฑูุงุจุท ูู ุงูุฑุณุงูุฉ"""
|
| 140 |
-
url_pattern = re.compile(
|
| 141 |
-
r"(https?://|www\.|discord\.gg/|\.com|\.net|\.org|\.io)", re.IGNORECASE
|
| 142 |
-
)
|
| 143 |
-
return bool(url_pattern.search(content))
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
def is_random_chars(content: str) -> bool:
|
| 147 |
-
"""
|
| 148 |
-
ูุดู ุงูุญุฑูู ุงูุนุดูุงุฆูุฉ: ูุณุจุฉ ุงูุญุฑูู ุบูุฑ ุงูู
ุนุฑููุฉ ุนุงููุฉ
|
| 149 |
-
Detect random character spam
|
| 150 |
-
"""
|
| 151 |
-
if len(content) < 10:
|
| 152 |
-
return False
|
| 153 |
-
# ุฅุฐุง ูุงูุช ูุณุจุฉ ุงูุฃุญุฑู ุบูุฑ ุงูุฃุจุฌุฏูุฉ ุฃู ุบูุฑ ุงูุนุฑุจูุฉ ุนุงููุฉ ุฌุฏุงู
|
| 154 |
-
alnum_count = sum(1 for c in content if c.isalnum() or "\u0600" <= c <= "\u06ff")
|
| 155 |
-
return alnum_count / len(content) < 0.3
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
def count_emojis(content: str) -> int:
|
| 159 |
-
"""ุนุฏู ุงูุฅูู
ูุฌู ูู ุงูุฑุณุงูุฉ"""
|
| 160 |
-
emoji_pattern = re.compile(
|
| 161 |
-
"[\U00010000-\U0010ffff]|[\u2600-\u26FF]|[\u2700-\u27BF]",
|
| 162 |
-
flags=re.UNICODE,
|
| 163 |
-
)
|
| 164 |
-
return len(emoji_pattern.findall(content))
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 168 |
-
# BOT SETUP | ุฅุนุฏุงุฏ ุงูุจูุช
|
| 169 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 170 |
-
intents = discord.Intents.default()
|
| 171 |
-
intents.message_content = True
|
| 172 |
-
intents.members = True
|
| 173 |
-
intents.guilds = True
|
| 174 |
-
|
| 175 |
-
bot = commands.Bot(command_prefix="!", intents=intents, help_command=None)
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
def __init__(self):
|
| 183 |
-
options = [
|
| 184 |
-
discord.SelectOption(
|
| 185 |
-
label="Complaint against staff | ุดููู ุถุฏ ู
ูุธู",
|
| 186 |
-
description="Report a staff member / ุงูุฅุจูุงุบ ุนู ู
ูุธู",
|
| 187 |
-
value="complaint_staff",
|
| 188 |
-
emoji="๐ฎ",
|
| 189 |
-
),
|
| 190 |
-
discord.SelectOption(
|
| 191 |
-
label="Complaint against user | ุดููู ุถุฏ ู
ุณุชุฎุฏู
",
|
| 192 |
-
description="Report another user / ุงูุฅุจูุงุบ ุนู ู
ุณุชุฎุฏู
",
|
| 193 |
-
value="complaint_user",
|
| 194 |
-
emoji="๐จ",
|
| 195 |
-
),
|
| 196 |
-
discord.SelectOption(
|
| 197 |
-
label="Bug report | ุงูุฅุจูุงุบ ุนู ุฎุทุฃ",
|
| 198 |
-
description="Report a bug / ุงูุฅุจูุงุบ ุนู ู
ุดููุฉ ุชูููุฉ",
|
| 199 |
-
value="bug_report",
|
| 200 |
-
emoji="๐",
|
| 201 |
-
),
|
| 202 |
-
discord.SelectOption(
|
| 203 |
-
label="Technical support | ุงูุฏุนู
ุงูุชููู",
|
| 204 |
-
description="Get technical help / ุทูุจ ู
ุณุงุนุฏุฉ ุชูููุฉ",
|
| 205 |
-
value="technical_support",
|
| 206 |
-
emoji="๐ง",
|
| 207 |
-
),
|
| 208 |
-
]
|
| 209 |
-
super().__init__(
|
| 210 |
-
placeholder="๐ ุงุฎุชุฑ ููุน ุงูุชุฐูุฑุฉ | Choose ticket type",
|
| 211 |
-
min_values=1,
|
| 212 |
-
max_values=1,
|
| 213 |
-
options=options,
|
| 214 |
-
custom_id="ticket_category_select",
|
| 215 |
-
)
|
| 216 |
|
| 217 |
-
|
| 218 |
-
await handle_ticket_creation(interaction, self.values[0])
|
| 219 |
|
|
|
|
|
|
|
|
|
|
| 220 |
|
|
|
|
| 221 |
class TicketPanelView(discord.ui.View):
|
| 222 |
-
"""View ุงูุซุงุจุช ูู Panel ุงูุชุฐุงูุฑ"""
|
| 223 |
-
|
| 224 |
def __init__(self):
|
| 225 |
super().__init__(timeout=None)
|
| 226 |
-
self.add_item(TicketCategorySelect())
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
#
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
|
|
|
| 235 |
def __init__(self):
|
| 236 |
super().__init__(timeout=None)
|
| 237 |
|
| 238 |
-
@discord.ui.button(
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
"โ **You don't have permission to claim tickets.**",
|
| 248 |
-
ephemeral=True,
|
| 249 |
-
)
|
| 250 |
-
return
|
| 251 |
-
|
| 252 |
-
thread_id = interaction.channel.id
|
| 253 |
-
data = ticket_data.get(thread_id)
|
| 254 |
-
if not data:
|
| 255 |
-
await interaction.response.send_message(
|
| 256 |
-
"โ ุจูุงูุงุช ุงูุชุฐูุฑุฉ ุบูุฑ ู
ูุฌูุฏุฉ. | Ticket data not found.", ephemeral=True
|
| 257 |
-
)
|
| 258 |
-
return
|
| 259 |
-
|
| 260 |
-
if data.get("claimed_by"):
|
| 261 |
-
await interaction.response.send_message(
|
| 262 |
-
f"โ ๏ธ **ูุฐู ุงูุชุฐูุฑุฉ ู
ุณุชูู
ุฉ ุจุงููุนู ู
ู ููุจู:** <@{data['claimed_by']}>\n"
|
| 263 |
-
f"โ ๏ธ **This ticket is already claimed by:** <@{data['claimed_by']}>",
|
| 264 |
-
ephemeral=True,
|
| 265 |
-
)
|
| 266 |
-
return
|
| 267 |
-
|
| 268 |
-
# ุชุณุฌูู ุงูู Claim
|
| 269 |
-
ticket_data[thread_id]["claimed_by"] = interaction.user.id
|
| 270 |
-
|
| 271 |
# ุฅุฑุณุงู DM ููู
ุณุชุฎุฏู
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
)
|
| 288 |
-
dm_embed.set_footer(text="Ticket System | ูุธุงู
ุงูุชุฐุงูุฑ")
|
| 289 |
-
await member.send(embed=dm_embed)
|
| 290 |
-
except discord.Forbidden:
|
| 291 |
-
pass # DM ู
ุบูู
|
| 292 |
-
|
| 293 |
-
# ุชุญุฏูุซ ุฑุณุงูุฉ ุงูุชุญูู
|
| 294 |
-
claim_embed = discord.Embed(
|
| 295 |
-
title="โ
ุชู
ุงุณุชูุงู
ุงูุชุฐูุฑุฉ | Ticket Claimed",
|
| 296 |
-
description=(
|
| 297 |
-
f"๐ธ๐ฆ **ุชู
ุงุณุชูุงู
ูุฐู ุงูุชุฐูุฑุฉ ู
ู ููุจู:** {interaction.user.mention}\n"
|
| 298 |
-
f"๐ฌ๐ง **This ticket has been claimed by:** {interaction.user.mention}"
|
| 299 |
-
),
|
| 300 |
-
color=discord.Color.green(),
|
| 301 |
-
timestamp=now_utc(),
|
| 302 |
-
)
|
| 303 |
-
await interaction.response.send_message(embed=claim_embed)
|
| 304 |
-
|
| 305 |
-
log.info(f"Ticket {data['ticket_name']} claimed by {interaction.user} ({interaction.user.id})")
|
| 306 |
-
|
| 307 |
-
@discord.ui.button(
|
| 308 |
-
label="๐ Close Ticket | ุฅุบูุงู ุงูุชุฐูุฑุฉ",
|
| 309 |
-
style=discord.ButtonStyle.danger,
|
| 310 |
-
custom_id="ticket_close",
|
| 311 |
-
)
|
| 312 |
-
async def close_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
| 313 |
-
if not has_staff_role(interaction.user):
|
| 314 |
-
await interaction.response.send_message(
|
| 315 |
-
"โ **ููุณ ูุฏูู ุตูุงุญูุฉ ูุฅุบูุงู ุงูุชุฐุงูุฑ.**\n"
|
| 316 |
-
"โ **You don't have permission to close tickets.**",
|
| 317 |
-
ephemeral=True,
|
| 318 |
-
)
|
| 319 |
-
return
|
| 320 |
-
|
| 321 |
-
# ุฅุฑุณุงู Modal ูุณุจุจ ุงูุฅุบูุงู
|
| 322 |
-
modal = CloseReasonModal(interaction.channel)
|
| 323 |
-
await interaction.response.send_modal(modal)
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 327 |
-
# CLOSE REASON MODAL | ูุงูุฐุฉ ุณุจุจ ุงูุฅุบูุงู
|
| 328 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 329 |
-
class CloseReasonModal(discord.ui.Modal, title="๐ Close Ticket | ุฅุบูุงู ุงูุชุฐูุฑุฉ"):
|
| 330 |
-
reason = discord.ui.TextInput(
|
| 331 |
-
label="ุณุจุจ ุงูุฅุบูุงู | Close Reason",
|
| 332 |
-
placeholder="ุงูุชุจ ุณุจุจ ุฅุบูุงู ุงูุชุฐูุฑุฉ... | Enter the reason for closing...",
|
| 333 |
-
style=discord.TextStyle.paragraph,
|
| 334 |
-
min_length=5,
|
| 335 |
-
max_length=500,
|
| 336 |
-
required=True,
|
| 337 |
-
)
|
| 338 |
-
|
| 339 |
-
def __init__(self, thread: discord.Thread):
|
| 340 |
-
super().__init__()
|
| 341 |
-
self.thread = thread
|
| 342 |
|
| 343 |
async def on_submit(self, interaction: discord.Interaction):
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
"
|
| 382 |
-
"technical_support": "๐ง ุงูุฏุนู
ุงูุชููู | Technical support",
|
| 383 |
-
}
|
| 384 |
-
|
| 385 |
-
await interaction.response.send_message(
|
| 386 |
-
embed=discord.Embed(
|
| 387 |
-
title="โณ ุฌุงุฑู ุฅูุดุงุก ุชุฐูุฑุชู... | Creating your ticket...",
|
| 388 |
-
description=(
|
| 389 |
-
f"๐ธ๐ฆ **ุงููุฆุฉ:** {category_labels.get(category, category)}\n"
|
| 390 |
-
f"๐ฌ๐ง **Category:** {category_labels.get(category, category)}\n\n"
|
| 391 |
-
"ููุฑุฌู ุงูุงูุชุธุงุฑ... | Please wait..."
|
| 392 |
-
),
|
| 393 |
-
color=discord.Color.yellow(),
|
| 394 |
-
),
|
| 395 |
-
ephemeral=True,
|
| 396 |
-
)
|
| 397 |
-
|
| 398 |
-
# โโ 4. ุงูุญุตูู ุนูู ููุงุฉ ุงูุชุฐุงูุฑ โโ
|
| 399 |
-
ticket_channel = guild.get_channel(TICKET_CHANNEL_ID)
|
| 400 |
-
if not ticket_channel:
|
| 401 |
-
try:
|
| 402 |
-
ticket_channel = await guild.fetch_channel(TICKET_CHANNEL_ID)
|
| 403 |
-
except Exception:
|
| 404 |
-
await interaction.followup.send(
|
| 405 |
-
"โ ูู
ูุชู
ุงูุนุซูุฑ ุนูู ููุงุฉ ุงูุชุฐุงูุฑ. ุชูุงุตู ู
ุน ุงูุฅุฏุงุฑุฉ.\n"
|
| 406 |
-
"โ Ticket channel not found. Contact an admin.",
|
| 407 |
-
ephemeral=True,
|
| 408 |
-
)
|
| 409 |
-
return
|
| 410 |
-
|
| 411 |
-
# โโ 5. ุฅูุดุงุก Thread ุฎุงุต โโ
|
| 412 |
-
ticket_name = generate_ticket_name()
|
| 413 |
-
opened_at = now_utc()
|
| 414 |
-
|
| 415 |
-
try:
|
| 416 |
-
thread = await ticket_channel.create_thread(
|
| 417 |
-
name=ticket_name,
|
| 418 |
-
type=discord.ChannelType.private_thread,
|
| 419 |
-
auto_archive_duration=10080, # 7 ุฃูุงู
|
| 420 |
-
invitable=False, # ูุง ูู
ูู ููุฃุนุถุงุก ุฏุนูุฉ ุขุฎุฑูู
|
| 421 |
-
reason=f"Ticket by {user} ({user.id}) - {category}",
|
| 422 |
-
)
|
| 423 |
-
except discord.Forbidden:
|
| 424 |
-
await interaction.followup.send(
|
| 425 |
-
"โ **ูุง ุฃู
ูู ุตูุงุญูุฉ ุฅูุดุงุก Thread. ุชูุงุตู ู
ุน ุงูุฅุฏุงุฑุฉ.**\n"
|
| 426 |
-
"โ **Missing permission to create threads. Contact an admin.**",
|
| 427 |
-
ephemeral=True,
|
| 428 |
-
)
|
| 429 |
-
return
|
| 430 |
-
except Exception as e:
|
| 431 |
-
log.error(f"Error creating thread: {e}")
|
| 432 |
-
await interaction.followup.send(
|
| 433 |
-
"โ ุญุฏุซ ุฎุทุฃ ุนูุฏ ุฅูุดุงุก ุงูุชุฐูุฑุฉ. | An error occurred creating the ticket.",
|
| 434 |
-
ephemeral=True,
|
| 435 |
-
)
|
| 436 |
-
return
|
| 437 |
-
|
| 438 |
-
# โโ 6. ุฅุถุงูุฉ ุงูู
ุณุชุฎุฏู
ููู Thread โโ
|
| 439 |
-
try:
|
| 440 |
-
await thread.add_user(user)
|
| 441 |
-
except Exception as e:
|
| 442 |
-
log.warning(f"Could not add user to thread: {e}")
|
| 443 |
-
|
| 444 |
-
# โโ 7. ุถุจุท Slow Mode โโ
|
| 445 |
-
try:
|
| 446 |
-
await thread.edit(slowmode_delay=TICKET_SLOWMODE)
|
| 447 |
-
except Exception:
|
| 448 |
-
pass
|
| 449 |
-
|
| 450 |
-
# โโ 8. ุชุณุฌูู ุจูุงูุงุช ุงูุชุฐูุฑุฉ โโ
|
| 451 |
-
ticket_data[thread.id] = {
|
| 452 |
-
"user_id": user.id,
|
| 453 |
-
"category": category,
|
| 454 |
-
"opened_at": opened_at,
|
| 455 |
-
"claimed_by": None,
|
| 456 |
-
"ticket_name": ticket_name,
|
| 457 |
-
"messages": [], # ูุชุชุจุน ุงูู
ุญุงุฏุซุฉ
|
| 458 |
-
}
|
| 459 |
-
active_tickets[user.id] = thread.id
|
| 460 |
-
|
| 461 |
-
# โโ 9. ุจูุงุก ุฑุณุงูุฉ ุงูุชุฑุญูุจ ุฏุงุฎู ุงูุชุฐูุฑุฉ โโ
|
| 462 |
-
welcome_embed = discord.Embed(
|
| 463 |
-
title=f"๐ซ {ticket_name}",
|
| 464 |
-
description=(
|
| 465 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n"
|
| 466 |
-
f"๐ธ๐ฆ **ู
ุฑุญุจุงู {user.mention}!**\n"
|
| 467 |
-
f"ุชู
ุฅูุดุงุก ุชุฐูุฑุชู ุจูุฌุงุญ. ููุฑุฌู ุดุฑุญ ู
ุดููุชู ูุณูููู
ุจู
ุณุงุนุฏุชู ูู ุฃูุฑุจ ููุช.\n\n"
|
| 468 |
-
f"๐ฌ๐ง **Welcome {user.mention}!**\n"
|
| 469 |
-
f"Your ticket has been created. Please describe your issue and we'll assist you shortly.\n"
|
| 470 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n"
|
| 471 |
-
f"๐ **ุงููุฆุฉ | Category:** {category_labels.get(category, category)}\n"
|
| 472 |
-
f"โฐ **ูููุชุญ ูู | Opened at:** <t:{int(opened_at.timestamp())}:F>"
|
| 473 |
-
),
|
| 474 |
-
color=discord.Color.blue(),
|
| 475 |
-
timestamp=opened_at,
|
| 476 |
-
)
|
| 477 |
-
welcome_embed.set_footer(text="Your ticket has been created, please wait... | ุชุฐูุฑุชู ุฌุงูุฒุฉุ ููุฑุฌู ุงูุงูุชุธุงุฑ...")
|
| 478 |
-
welcome_embed.set_thumbnail(url=guild.icon.url if guild.icon else None)
|
| 479 |
-
|
| 480 |
-
# ุจูุงุก Ping ููู
ูุธููู
|
| 481 |
-
staff_pings = " ".join(f"<@&{rid}>" for rid in STAFF_ROLE_PING_IDS)
|
| 482 |
-
|
| 483 |
-
# ุฅุฑุณุงู ุฑุณุงูุฉ ุงูุชุฑุญูุจ + Ping ุงูู
ูุธููู + ุฃุฒุฑุงุฑ ุงูุชุญูู
|
| 484 |
-
control_view = TicketControlView()
|
| 485 |
-
await thread.send(
|
| 486 |
-
content=f"**{staff_pings}**",
|
| 487 |
-
embed=welcome_embed,
|
| 488 |
-
view=control_view,
|
| 489 |
-
)
|
| 490 |
-
|
| 491 |
-
# โโ 10. DM ุชุฃููุฏ ููู
ุณุชุฎุฏู
โโ
|
| 492 |
-
dm_embed = discord.Embed(
|
| 493 |
-
title="โ
ุชู
ุฅูุดุงุก ุชุฐูุฑุชู | Your Ticket Has Been Created",
|
| 494 |
description=(
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
color=discord.Color.green(),
|
| 504 |
-
timestamp=opened_at,
|
| 505 |
-
)
|
| 506 |
-
dm_embed.set_footer(text=f"{guild.name} | Ticket System")
|
| 507 |
-
try:
|
| 508 |
-
await user.send(embed=dm_embed)
|
| 509 |
-
except discord.Forbidden:
|
| 510 |
-
pass # DM ู
ุบูู
|
| 511 |
-
|
| 512 |
-
# โโ 11. ุชุญุฏูุซ ุฑุณุงูุฉ ุงูุชุฃููุฏ โโ
|
| 513 |
-
await interaction.followup.send(
|
| 514 |
-
embed=discord.Embed(
|
| 515 |
-
title="โ
ุชู
ุฅูุดุงุก ุงูุชุฐูุฑุฉ | Ticket Created",
|
| 516 |
-
description=(
|
| 517 |
-
f"๐ธ๐ฆ **ุชุฐูุฑุชู ุฌุงูุฒุฉ:** <#{thread.id}>\n"
|
| 518 |
-
f"๐ฌ๐ง **Your ticket is ready:** <#{thread.id}>"
|
| 519 |
-
),
|
| 520 |
-
color=discord.Color.green(),
|
| 521 |
),
|
| 522 |
-
|
| 523 |
)
|
|
|
|
|
|
|
| 524 |
|
| 525 |
-
|
|
|
|
|
|
|
| 526 |
|
| 527 |
-
|
| 528 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 529 |
-
# CORE: CLOSE TICKET | ุฅุบูุงู ุงูุชุฐูุฑุฉ
|
| 530 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 531 |
-
async def close_ticket(
|
| 532 |
-
interaction: discord.Interaction,
|
| 533 |
-
thread: discord.Thread,
|
| 534 |
-
reason: str,
|
| 535 |
-
):
|
| 536 |
-
"""ุงูู
ูุทู ุงูุฑุฆูุณู ูุฅุบูุงู ุงูุชุฐูุฑุฉ ูุฅุฑุณุงู ุงูููู"""
|
| 537 |
-
thread_id = thread.id
|
| 538 |
-
data = ticket_data.get(thread_id)
|
| 539 |
-
|
| 540 |
-
if not data:
|
| 541 |
-
await interaction.followup.send(
|
| 542 |
-
"โ ุจูุงูุงุช ุงูุชุฐูุฑุฉ ุบูุฑ ู
ูุฌูุฏุฉ. | Ticket data not found.", ephemeral=True
|
| 543 |
-
)
|
| 544 |
-
return
|
| 545 |
-
|
| 546 |
-
closed_at = now_utc()
|
| 547 |
-
opened_at = data["opened_at"]
|
| 548 |
-
duration = closed_at - opened_at
|
| 549 |
-
user_id = data["user_id"]
|
| 550 |
-
guild = interaction.guild
|
| 551 |
-
|
| 552 |
-
# โโ 1. ุฅูุดุงุก ู
ูู ูุต ุงูู
ุญุงุฏุซุฉ โโ
|
| 553 |
-
transcript_lines = [
|
| 554 |
-
f"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ",
|
| 555 |
-
f"โ TICKET TRANSCRIPT | ุณุฌู ุงูุชุฐูุฑุฉ โ",
|
| 556 |
-
f"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ",
|
| 557 |
-
f"",
|
| 558 |
-
f"Ticket Name | ุงุณู
ุงูุชุฐูุฑุฉ : {data['ticket_name']}",
|
| 559 |
-
f"User | ุงูู
ุณุชุฎุฏู
: {guild.get_member(user_id) or user_id} ({user_id})",
|
| 560 |
-
f"Staff | ุงูู
ูุธู : {interaction.user} ({interaction.user.id})",
|
| 561 |
-
f"Category | ุงููุฆุฉ : {data['category']}",
|
| 562 |
-
f"Opened At | ููุช ุงููุชุญ : {opened_at.strftime('%Y-%m-%d %H:%M:%S UTC')}",
|
| 563 |
-
f"Closed At | ููุช ุงูุฅุบูุงู : {closed_at.strftime('%Y-%m-%d %H:%M:%S UTC')}",
|
| 564 |
-
f"Duration | ุงูู
ุฏุฉ : {format_duration(duration)}",
|
| 565 |
-
f"Close Reason | ุณุจุจ ุงูุฅุบูุงู : {reason}",
|
| 566 |
-
f"",
|
| 567 |
-
f"โโโโโโโโโโโโโโโโโโ MESSAGES | ุงูุฑุณุงุฆู โโโโโโโโโโโโโโโโโโ",
|
| 568 |
-
f"",
|
| 569 |
-
]
|
| 570 |
-
|
| 571 |
-
# ุฌู
ุน ุฑุณุงุฆู ุงูู Thread
|
| 572 |
-
messages_log = []
|
| 573 |
-
try:
|
| 574 |
-
async for msg in thread.history(limit=500, oldest_first=True):
|
| 575 |
-
if msg.author.bot:
|
| 576 |
-
continue
|
| 577 |
-
ts = msg.created_at.strftime("%Y-%m-%d %H:%M:%S UTC")
|
| 578 |
-
content = msg.content or "[Attachment/Embed]"
|
| 579 |
-
messages_log.append(f"[{ts}] {msg.author} ({msg.author.id}): {content}")
|
| 580 |
-
except Exception as e:
|
| 581 |
-
log.warning(f"Error fetching thread history: {e}")
|
| 582 |
-
|
| 583 |
-
transcript_lines.extend(messages_log)
|
| 584 |
-
transcript_lines.append("")
|
| 585 |
-
transcript_lines.append("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
|
| 586 |
-
transcript_text = "\n".join(transcript_lines)
|
| 587 |
-
transcript_bytes = transcript_text.encode("utf-8")
|
| 588 |
-
|
| 589 |
-
transcript_file = discord.File(
|
| 590 |
-
fp=__import__("io").BytesIO(transcript_bytes),
|
| 591 |
-
filename=f"{data['ticket_name']}-transcript.txt",
|
| 592 |
-
)
|
| 593 |
-
|
| 594 |
-
# โโ 2. ุฅุฑุณุงู ุงูููู ุฅูู ููุงุฉ ุงูุณุฌู โโ
|
| 595 |
-
log_channel = guild.get_channel(LOG_CHANNEL_ID)
|
| 596 |
-
if log_channel:
|
| 597 |
-
log_embed = discord.Embed(
|
| 598 |
-
title="๐ ุชุฐูุฑุฉ ู
ูุบููุฉ | Ticket Closed",
|
| 599 |
-
color=discord.Color.red(),
|
| 600 |
-
timestamp=closed_at,
|
| 601 |
-
)
|
| 602 |
-
log_embed.add_field(
|
| 603 |
-
name="๐ซ ุงูุชุฐูุฑุฉ | Ticket",
|
| 604 |
-
value=f"`{data['ticket_name']}`",
|
| 605 |
-
inline=True,
|
| 606 |
-
)
|
| 607 |
-
log_embed.add_field(
|
| 608 |
-
name="๐ค ุงูู
ุณุชุฎุฏู
| User",
|
| 609 |
-
value=f"<@{user_id}> (`{user_id}`)",
|
| 610 |
-
inline=True,
|
| 611 |
-
)
|
| 612 |
-
log_embed.add_field(
|
| 613 |
-
name="๐ฎ ุงูู
ูุธู | Staff",
|
| 614 |
-
value=f"{interaction.user.mention} (`{interaction.user.id}`)",
|
| 615 |
-
inline=True,
|
| 616 |
-
)
|
| 617 |
-
log_embed.add_field(
|
| 618 |
-
name="โฐ ููุช ุงููุชุญ | Opened At",
|
| 619 |
-
value=f"<t:{int(opened_at.timestamp())}:F>",
|
| 620 |
-
inline=True,
|
| 621 |
-
)
|
| 622 |
-
log_embed.add_field(
|
| 623 |
-
name="๐ ููุช ุงูุฅุบูุงู | Closed At",
|
| 624 |
-
value=f"<t:{int(closed_at.timestamp())}:F>",
|
| 625 |
-
inline=True,
|
| 626 |
-
)
|
| 627 |
-
log_embed.add_field(
|
| 628 |
-
name="โฑ๏ธ ุงูู
ุฏุฉ | Duration",
|
| 629 |
-
value=format_duration(duration),
|
| 630 |
-
inline=True,
|
| 631 |
-
)
|
| 632 |
-
log_embed.add_field(
|
| 633 |
-
name="๐ ุงููุฆุฉ | Category",
|
| 634 |
-
value=data["category"],
|
| 635 |
-
inline=True,
|
| 636 |
-
)
|
| 637 |
-
log_embed.add_field(
|
| 638 |
-
name="๐ ุณุจุจ ุงูุฅุบูุงู | Close Reason",
|
| 639 |
-
value=reason,
|
| 640 |
-
inline=False,
|
| 641 |
-
)
|
| 642 |
-
log_embed.set_footer(text="Ticket System | ูุธุงู
ุงูุชุฐุงูุฑ")
|
| 643 |
-
|
| 644 |
-
try:
|
| 645 |
-
await log_channel.send(embed=log_embed, file=transcript_file)
|
| 646 |
-
except Exception as e:
|
| 647 |
-
log.error(f"Error sending log: {e}")
|
| 648 |
-
|
| 649 |
-
# โโ 3. ุฅุดุนุงุฑ ุงูู
ุณุชุฎุฏู
ุจุงูุฅุบูุงู โโ
|
| 650 |
-
member = guild.get_member(user_id)
|
| 651 |
-
if member:
|
| 652 |
-
close_dm = discord.Embed(
|
| 653 |
-
title="๐ ุชู
ุฅุบูุงู ุชุฐูุฑุชู | Your Ticket Has Been Closed",
|
| 654 |
-
description=(
|
| 655 |
-
f"๐ธ๐ฆ **ุชู
ุฅุบูุงู ุชุฐูุฑุชู `{data['ticket_name']}` ู
ู ููุจู:** {interaction.user.display_name}\n"
|
| 656 |
-
f"**ุงูุณุจุจ:** {reason}\n\n"
|
| 657 |
-
f"๐ฌ๐ง **Your ticket `{data['ticket_name']}` has been closed by:** {interaction.user.display_name}\n"
|
| 658 |
-
f"**Reason:** {reason}"
|
| 659 |
-
),
|
| 660 |
-
color=discord.Color.red(),
|
| 661 |
-
timestamp=closed_at,
|
| 662 |
-
)
|
| 663 |
-
close_dm.add_field(name="โฑ๏ธ ู
ุฏุฉ ุงูุชุฐูุฑุฉ | Duration", value=format_duration(duration))
|
| 664 |
-
close_dm.set_footer(text="Thank you for contacting us | ุดูุฑุงู ูุชูุงุตูู ู
ุนูุง")
|
| 665 |
-
try:
|
| 666 |
-
await member.send(embed=close_dm)
|
| 667 |
-
except discord.Forbidden:
|
| 668 |
-
pass
|
| 669 |
-
|
| 670 |
-
# โโ 4. ุฅุฑุณุงู ุฑุณุงูุฉ ุฅุบูุงู ุฏุงุฎู ุงูู Thread โโ
|
| 671 |
-
close_embed = discord.Embed(
|
| 672 |
-
title="๐ ุชู
ุฅุบูุงู ุงูุชุฐูุฑุฉ | Ticket Closed",
|
| 673 |
-
description=(
|
| 674 |
-
f"๐ธ๐ฆ **ุชู
ุฅุบูุงู ูุฐู ุงูุชุฐูุฑุฉ ู
ู ููุจู:** {interaction.user.mention}\n"
|
| 675 |
-
f"**ุงูุณุจุจ:** {reason}\n\n"
|
| 676 |
-
f"๐ฌ๐ง **This ticket has been closed by:** {interaction.user.mention}\n"
|
| 677 |
-
f"**Reason:** {reason}"
|
| 678 |
-
),
|
| 679 |
-
color=discord.Color.red(),
|
| 680 |
-
timestamp=closed_at,
|
| 681 |
-
)
|
| 682 |
-
close_embed.add_field(name="โฑ๏ธ ู
ุฏุฉ ุงูุชุฐูุฑุฉ | Duration", value=format_duration(duration))
|
| 683 |
-
try:
|
| 684 |
-
await thread.send(embed=close_embed)
|
| 685 |
-
except Exception:
|
| 686 |
-
pass
|
| 687 |
-
|
| 688 |
-
# โโ 5. ุชูุธูู ุงูุจูุงูุงุช ูุถุจุท Cooldown โโ
|
| 689 |
-
if user_id in active_tickets:
|
| 690 |
-
del active_tickets[user_id]
|
| 691 |
-
if thread_id in ticket_data:
|
| 692 |
-
del ticket_data[thread_id]
|
| 693 |
-
|
| 694 |
-
# ุถุจุท ุงูู Cooldown
|
| 695 |
-
cooldowns[user_id] = now_utc() + datetime.timedelta(seconds=COOLDOWN_SECONDS)
|
| 696 |
-
|
| 697 |
-
# โโ 6. ุฃุฑุดูุฉ ุงูู Thread โโ
|
| 698 |
-
try:
|
| 699 |
-
await thread.edit(archived=True, locked=True)
|
| 700 |
-
except Exception as e:
|
| 701 |
-
log.warning(f"Error archiving thread: {e}")
|
| 702 |
-
|
| 703 |
-
await interaction.followup.send(
|
| 704 |
-
"โ
**ุชู
ุฅุบูุงู ุงูุชุฐูุฑุฉ ุจูุฌุงุญ. | Ticket closed successfully.**",
|
| 705 |
-
ephemeral=True,
|
| 706 |
-
)
|
| 707 |
-
|
| 708 |
-
log.info(f"Ticket '{data['ticket_name']}' closed by {interaction.user} - Reason: {reason}")
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 712 |
-
# ANTI-SPAM: MESSAGE FILTER | ููุชุฑ ุงูุฑุณุงุฆู
|
| 713 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 714 |
@bot.event
|
| 715 |
-
async def on_message(message
|
| 716 |
-
|
| 717 |
-
if message.
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
# ุงู
|
| 721 |
-
if
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
data = ticket_data[thread_id]
|
| 731 |
-
user_id = message.author.id
|
| 732 |
-
content = message.content or ""
|
| 733 |
-
|
| 734 |
-
# โโ ููุชุฑ ุงูู
ุญุชูู ุงูู
ู
ููุน โโ
|
| 735 |
-
|
| 736 |
-
# 1. ุงูุฑูุงุจุท
|
| 737 |
-
if contains_link(content):
|
| 738 |
-
try:
|
| 739 |
-
await message.delete()
|
| 740 |
-
await message.channel.send(
|
| 741 |
-
f"โ {message.author.mention} **ุงูุฑูุงุจุท ู
ู
ููุนุฉ ุฏุงุฎู ุงูุชุฐุงูุฑ. | Links are not allowed in tickets.**",
|
| 742 |
-
delete_after=5,
|
| 743 |
-
)
|
| 744 |
-
except Exception:
|
| 745 |
-
pass
|
| 746 |
-
return
|
| 747 |
-
|
| 748 |
-
# 2. ุงูู
ููุงุช ูุงูู
ุฑููุงุช ุบูุฑ ุงูู
ุณู
ูุญุฉ
|
| 749 |
-
for attachment in message.attachments:
|
| 750 |
-
fname = attachment.filename.lower()
|
| 751 |
-
# ุงูุณู
ุงุญ ุจุงูุตูุฑ ูุงูููุฏูู ููุท
|
| 752 |
-
allowed_extensions = (".png", ".jpg", ".jpeg", ".gif", ".webp", ".mp4", ".mov", ".mkv", ".avi")
|
| 753 |
-
if not fname.endswith(allowed_extensions):
|
| 754 |
-
try:
|
| 755 |
-
await message.delete()
|
| 756 |
-
await message.channel.send(
|
| 757 |
-
f"โ {message.author.mention} **ูุฐุง ุงูููุน ู
ู ุงูู
ููุงุช ู
ู
ููุน. | This file type is not allowed.**\n"
|
| 758 |
-
f"โ
ุงูู
ุณู
ูุญ: ุตูุฑ ูููุฏูู ููุท | Allowed: Images and videos only",
|
| 759 |
-
delete_after=6,
|
| 760 |
-
)
|
| 761 |
-
except Exception:
|
| 762 |
-
pass
|
| 763 |
-
return
|
| 764 |
-
|
| 765 |
-
# 3. Voice Messages
|
| 766 |
-
if message.flags.voice:
|
| 767 |
-
try:
|
| 768 |
-
await message.delete()
|
| 769 |
-
await message.channel.send(
|
| 770 |
-
f"โ {message.author.mention} **ุงูุฑุณุงุฆู ุงูุตูุชูุฉ ู
ู
ููุนุฉ. | Voice messages are not allowed.**",
|
| 771 |
-
delete_after=5,
|
| 772 |
-
)
|
| 773 |
-
except Exception:
|
| 774 |
-
pass
|
| 775 |
-
return
|
| 776 |
-
|
| 777 |
-
# 4. ุณุจุงู
ุงูุฅูู
ูุฌู (ุฃูุซุฑ ู
ู 10 ุฅูู
ูุฌู)
|
| 778 |
-
if count_emojis(content) > 10:
|
| 779 |
-
try:
|
| 780 |
-
await message.delete()
|
| 781 |
-
await message.channel.send(
|
| 782 |
-
f"โ {message.author.mention} **ุณุจุงู
ุงูุฅูู
ูุฌู ู
ู
ููุน. | Emoji spam is not allowed.**",
|
| 783 |
-
delete_after=5,
|
| 784 |
-
)
|
| 785 |
-
except Exception:
|
| 786 |
-
pass
|
| 787 |
-
return
|
| 788 |
-
|
| 789 |
-
# 5. ุณุจุงู
ุงูุญุฑูู ุงูุนุดูุงุฆูุฉ
|
| 790 |
-
if is_random_chars(content) and len(content) > 15:
|
| 791 |
-
try:
|
| 792 |
-
await message.delete()
|
| 793 |
-
await message.channel.send(
|
| 794 |
-
f"โ {message.author.mention} **ุงูุญุฑูู ุงูุนุดูุงุฆูุฉ ู
ู
ููุนุฉ. | Random character spam is not allowed.**",
|
| 795 |
-
delete_after=5,
|
| 796 |
-
)
|
| 797 |
-
except Exception:
|
| 798 |
-
pass
|
| 799 |
-
return
|
| 800 |
-
|
| 801 |
-
# 6. ุณุจุงู
ุงูุฑุณุงุฆู (ุณุฑุนุฉ ุงูุฅุฑุณุงู)
|
| 802 |
-
if is_spam(user_id):
|
| 803 |
-
try:
|
| 804 |
await message.delete()
|
| 805 |
-
await message.channel.send(
|
| 806 |
-
f"โ {message.author.mention} **ุฃูุช ุชุฑุณู ุฑุณุงุฆู ุจุณุฑุนุฉ ูุจูุฑุฉ! | You are sending messages too fast!**",
|
| 807 |
-
delete_after=5,
|
| 808 |
-
)
|
| 809 |
-
except Exception:
|
| 810 |
-
pass
|
| 811 |
-
return
|
| 812 |
-
|
| 813 |
-
# ุญูุธ ุงูุฑุณุงูุฉ ูู ุงูุณุฌู
|
| 814 |
-
ticket_data[thread_id]["messages"].append({
|
| 815 |
-
"author": str(message.author),
|
| 816 |
-
"author_id": message.author.id,
|
| 817 |
-
"content": content,
|
| 818 |
-
"timestamp": now_utc().isoformat(),
|
| 819 |
-
})
|
| 820 |
-
|
| 821 |
-
await bot.process_commands(message)
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 825 |
-
# SLASH COMMANDS | ุฃูุงู
ุฑ Slash
|
| 826 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 827 |
-
@bot.tree.command(name="setup-ticket-panel", description="ุฅุนุฏุงุฏ ููุญุฉ ุงูุชุฐุงูุฑ | Setup ticket panel (Owner only)")
|
| 828 |
-
async def setup_ticket_panel(interaction: discord.Interaction):
|
| 829 |
-
"""ุฃู
ุฑ ุฅุนุฏุงุฏ Panel ุงูุชุฐุงูุฑ - ููู
ุงูู ููุท"""
|
| 830 |
-
if not is_owner(interaction.user):
|
| 831 |
-
await interaction.response.send_message(
|
| 832 |
-
"โ **ูุฐุง ุงูุฃู
ุฑ ููู
ุงูู ููุท. | This command is for the owner only.**",
|
| 833 |
-
ephemeral=True,
|
| 834 |
-
)
|
| 835 |
-
return
|
| 836 |
-
|
| 837 |
-
panel_embed = discord.Embed(
|
| 838 |
-
title="๐ซ ูุธุงู
ุงูุชุฐุงูุฑ | Ticket System",
|
| 839 |
-
description=(
|
| 840 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n"
|
| 841 |
-
"๐ **ููุงููู ูุชุญ ุงูุชุฐูุฑุฉ | Ticket Rules**\n"
|
| 842 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n\n"
|
| 843 |
-
"โ **ู
ู
ููุน | Prohibited:**\n"
|
| 844 |
-
"โข ูุชุญ ุชุฐูุฑุฉ ูุฃุณุจุงุจ ุบูุฑ ู
ูู
ุฉ ุฃู ุชุงููุฉ\n"
|
| 845 |
-
"โข Opening tickets for unimportant or trivial reasons\n"
|
| 846 |
-
"โข ุฅุฑุณุงู ุฑูุงุจุท ุฃู ู
ููุงุช ุฏุงุฎู ุงูุชุฐูุฑุฉ\n"
|
| 847 |
-
"โข Sending links or files inside tickets\n"
|
| 848 |
-
"โข ุงูุณุจุงู
ุฃู ุงูุฑุณุงุฆู ุงูุนุดูุงุฆูุฉ\n"
|
| 849 |
-
"โข Spam or random messages\n\n"
|
| 850 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n"
|
| 851 |
-
"โ
**ุงูุฃุณุจุงุจ ุงูู
ุณู
ูุญ ุจูุง | Allowed Reasons:**\n"
|
| 852 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n\n"
|
| 853 |
-
"๐ฎ **ุดููู ุถุฏ ู
ูุธู | Staff Complaint**\n"
|
| 854 |
-
" โ ุฅุฐุง ูุงู ู
ูุธู ุชุตุฑู ุจุดูู ุฎุงุทุฆ\n"
|
| 855 |
-
" โ If a staff member acted inappropriately\n\n"
|
| 856 |
-
"๐จ **ุดููู ุถุฏ ู
ุณุชุฎุฏู
| User Complaint**\n"
|
| 857 |
-
" โ ุฅุฐุง ูุงู ู
ุณุชุฎุฏู
ููุชูู ุงูููุงููู\n"
|
| 858 |
-
" โ If a user is violating rules\n\n"
|
| 859 |
-
"๐ **ุงูุฅุจูุงุบ ุนู ุฎุทุฃ | Bug Report**\n"
|
| 860 |
-
" โ ู
ุดููุฉ ุชูููุฉ ูู ุงูุณูุฑูุฑ ุฃู ุงูุจูุช\n"
|
| 861 |
-
" โ Technical issue with the server or bot\n\n"
|
| 862 |
-
"๐ง **ุงูุฏุนู
ุงูุชููู | Technical Support**\n"
|
| 863 |
-
" โ ุทูุจ ุงูู
ุณุงุนุฏุฉ ูู ู
ุดููุฉ ุชูููุฉ\n"
|
| 864 |
-
" โ Requesting help with a technical issue\n\n"
|
| 865 |
-
"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n"
|
| 866 |
-
"โฌ๏ธ **ุงุฎุชุฑ ููุน ุชุฐูุฑุชู ู
ู ุงููุงุฆู
ุฉ ุฃุฏูุงู:**\n"
|
| 867 |
-
"โฌ๏ธ **Choose your ticket type from the menu below:**"
|
| 868 |
-
),
|
| 869 |
-
color=discord.Color.from_rgb(88, 101, 242),
|
| 870 |
-
timestamp=now_utc(),
|
| 871 |
-
)
|
| 872 |
-
panel_embed.set_footer(
|
| 873 |
-
text="Ticket System | ูุธุงู
ุงูุชุฐุงูุฑ โข ูุง ุชูุชุญ ุชุฐูุฑุฉ ุฅูุง ุนูุฏ ุงูุญุงุฌุฉ ุงููุนููุฉ"
|
| 874 |
-
)
|
| 875 |
-
if interaction.guild.icon:
|
| 876 |
-
panel_embed.set_thumbnail(url=interaction.guild.icon.url)
|
| 877 |
-
|
| 878 |
-
view = TicketPanelView()
|
| 879 |
-
await interaction.response.send_message(embed=panel_embed, view=view)
|
| 880 |
-
log.info(f"Ticket panel set up by {interaction.user} ({interaction.user.id}) in #{interaction.channel.name}")
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
@bot.tree.command(name="help", description="ููููุฉ ูุชุญ ุชุฐูุฑุฉ | How to open a ticket")
|
| 884 |
-
async def help_command(interaction: discord.Interaction):
|
| 885 |
-
"""ุฃู
ุฑ ุงูู
ุณุงุนุฏุฉ"""
|
| 886 |
-
await interaction.response.send_message(
|
| 887 |
-
embed=discord.Embed(
|
| 888 |
-
title="๐ ุงูู
ุณุงุนุฏุฉ | Help",
|
| 889 |
-
description=(
|
| 890 |
-
f"๐ธ๐ฆ **ููุชุญ ุชุฐูุฑุฉุ ุงุฐูุจ ุฅูู:** <#{TICKET_CHANNEL_ID}>\n\n"
|
| 891 |
-
f"๐ฌ๐ง **To open a ticket, go to:** <#{TICKET_CHANNEL_ID}>"
|
| 892 |
-
),
|
| 893 |
-
color=discord.Color.blue(),
|
| 894 |
-
timestamp=now_utc(),
|
| 895 |
-
),
|
| 896 |
-
ephemeral=True,
|
| 897 |
-
)
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 901 |
-
# BOT EVENTS | ุฃุญุฏุงุซ ุงูุจูุช
|
| 902 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 903 |
-
@bot.event
|
| 904 |
-
async def on_ready():
|
| 905 |
-
"""ุนูุฏ ุชุดุบูู ุงูุจูุช"""
|
| 906 |
-
log.info(f"โ
Bot logged in as {bot.user} ({bot.user.id})")
|
| 907 |
-
log.info(f"โ
Connected to {len(bot.guilds)} guild(s)")
|
| 908 |
-
|
| 909 |
-
# ุฅุนุงุฏุฉ ุชุณุฌูู ุงูู Views ุงูุซุงุจุชุฉ ูุชุนู
ู ุจุนุฏ ุฅุนุงุฏุฉ ุงูุชุดุบูู
|
| 910 |
-
bot.add_view(TicketPanelView())
|
| 911 |
-
bot.add_view(TicketControlView())
|
| 912 |
-
|
| 913 |
-
# ู
ุฒุงู
ูุฉ Slash Commands
|
| 914 |
-
try:
|
| 915 |
-
synced = await bot.tree.sync()
|
| 916 |
-
log.info(f"โ
Synced {len(synced)} slash command(s)")
|
| 917 |
-
except Exception as e:
|
| 918 |
-
log.error(f"โ Failed to sync commands: {e}")
|
| 919 |
-
|
| 920 |
-
# ุชุบููุฑ ุงูู Status
|
| 921 |
-
await bot.change_presence(
|
| 922 |
-
activity=discord.Activity(
|
| 923 |
-
type=discord.ActivityType.watching,
|
| 924 |
-
name="๐ซ Ticket System | ูุธุงู
ุงูุชุฐุงูุฑ",
|
| 925 |
-
),
|
| 926 |
-
status=discord.Status.online,
|
| 927 |
-
)
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
@bot.event
|
| 931 |
-
async def on_error(event: str, *args, **kwargs):
|
| 932 |
-
"""ู
ุนุงูุฌุฉ ุงูุฃุฎุทุงุก ุงูุนุงู
ุฉ"""
|
| 933 |
-
error_text = traceback.format_exc()
|
| 934 |
-
log.error(f"Error in event '{event}': {error_text}")
|
| 935 |
-
await send_error_to_channel(f"**Event Error: `{event}`**\n```\n{error_text[:1800]}\n```")
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
@bot.tree.error
|
| 939 |
-
async def on_app_command_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
|
| 940 |
-
"""ู
ุนุงูุฌุฉ ุฃุฎุทุงุก Slash Commands"""
|
| 941 |
-
error_msg = str(error)
|
| 942 |
-
log.error(f"Slash command error: {error_msg}")
|
| 943 |
-
|
| 944 |
-
if not interaction.response.is_done():
|
| 945 |
-
await interaction.response.send_message(
|
| 946 |
-
f"โ **ุญุฏุซ ุฎุทุฃ. | An error occurred.**\n```{error_msg[:500]}```",
|
| 947 |
-
ephemeral=True,
|
| 948 |
-
)
|
| 949 |
-
else:
|
| 950 |
-
await interaction.followup.send(
|
| 951 |
-
f"โ **ุญุฏุซ ุฎุทุฃ. | An error occurred.**\n```{error_msg[:500]}```",
|
| 952 |
-
ephemeral=True,
|
| 953 |
-
)
|
| 954 |
-
|
| 955 |
-
await send_error_to_channel(
|
| 956 |
-
f"**Slash Command Error**\n"
|
| 957 |
-
f"User: {interaction.user} (`{interaction.user.id}`)\n"
|
| 958 |
-
f"Command: `/{interaction.command.name if interaction.command else 'unknown'}`\n"
|
| 959 |
-
f"```\n{error_msg[:1500]}\n```"
|
| 960 |
-
)
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
async def send_error_to_channel(message: str):
|
| 964 |
-
"""ุฅุฑุณุงู ุงูุฃุฎุทุงุก ุฅูู ููุงุฉ ุงูุฃุฎุทุงุก ู
ุน Ping ุงูู
ุงูู"""
|
| 965 |
-
try:
|
| 966 |
-
for guild in bot.guilds:
|
| 967 |
-
error_channel = guild.get_channel(ERROR_CHANNEL_ID)
|
| 968 |
-
if error_channel:
|
| 969 |
-
await error_channel.send(
|
| 970 |
-
f"<@{OWNER_ID}> ๐จ **ุญุฏุซ ุฎุทุฃ ูู ุงูุจูุช! | Bot Error!**\n{message[:1900]}"
|
| 971 |
-
)
|
| 972 |
-
break
|
| 973 |
-
except Exception as e:
|
| 974 |
-
log.error(f"Could not send error to channel: {e}")
|
| 975 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 976 |
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
"""ุงูุฏุงูุฉ ุงูุฑุฆูุณูุฉ ู
ุน ูุธุงู
ุฅุนุงุฏุฉ ุงูุชุดุบูู ุงูุชููุงุฆู"""
|
| 982 |
-
if not TOKEN:
|
| 983 |
-
log.critical("โ TOKEN not found! Set TOKEN environment variable.")
|
| 984 |
-
sys.exit(1)
|
| 985 |
-
|
| 986 |
-
retry_delay = 5 # ุซูุงูู ูุจู ุฅุนุงุฏุฉ ุงูุงุชุตุงู
|
| 987 |
-
|
| 988 |
-
while True:
|
| 989 |
-
try:
|
| 990 |
-
log.info("๐ Starting bot...")
|
| 991 |
-
async with bot:
|
| 992 |
-
await bot.start(TOKEN)
|
| 993 |
-
except discord.LoginFailure:
|
| 994 |
-
log.critical("โ Invalid TOKEN. Please check your token.")
|
| 995 |
-
sys.exit(1)
|
| 996 |
-
except discord.HTTPException as e:
|
| 997 |
-
log.error(f"HTTP error: {e}. Retrying in {retry_delay}s...")
|
| 998 |
-
await asyncio.sleep(retry_delay)
|
| 999 |
-
except Exception as e:
|
| 1000 |
-
error_text = traceback.format_exc()
|
| 1001 |
-
log.error(f"Unexpected crash: {error_text}")
|
| 1002 |
-
# ู
ุญุงููุฉ ุฅุฑุณุงู ุงูุฎุทุฃ
|
| 1003 |
-
try:
|
| 1004 |
-
async with bot:
|
| 1005 |
-
await send_error_to_channel(
|
| 1006 |
-
f"**CRASH DETECTED! | ุชู
ุงูุชุดุงู ุงูููุงุฑ!**\n```\n{error_text[:1500]}\n```"
|
| 1007 |
-
)
|
| 1008 |
-
except Exception:
|
| 1009 |
-
pass
|
| 1010 |
-
log.info(f"๐ Restarting in {retry_delay} seconds...")
|
| 1011 |
-
await asyncio.sleep(retry_delay)
|
| 1012 |
-
retry_delay = min(retry_delay * 2, 60) # ุฒูุงุฏุฉ ุงูุชุฃุฎูุฑ ุชุฏุฑูุฌูุงู ุญุชู 60 ุซุงููุฉ
|
| 1013 |
-
else:
|
| 1014 |
-
break
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1018 |
-
# ENTRY POINT | ููุทุฉ ุงูุฏุฎูู
|
| 1019 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1020 |
-
if __name__ == "__main__":
|
| 1021 |
-
try:
|
| 1022 |
-
asyncio.run(main())
|
| 1023 |
-
except KeyboardInterrupt:
|
| 1024 |
-
log.info("๐ Bot stopped by user.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import discord
|
|
|
|
| 2 |
from discord import app_commands
|
| 3 |
+
from discord.ext import commands
|
| 4 |
+
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import random
|
| 6 |
import string
|
| 7 |
+
import io
|
| 8 |
+
import asyncio
|
| 9 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# --- ุงูุฅุนุฏุงุฏุงุช ุงูุซุงุจุชุฉ ---
|
| 12 |
OWNER_ID = 1429183440485486679
|
| 13 |
+
ERROR_LOG_CHANNEL_ID = 1488536752691085552
|
| 14 |
+
TICKETS_CHANNEL_ID = 1488536530019549344
|
| 15 |
+
LOG_CHANNEL_ID = 1488536921813680218
|
| 16 |
+
STAFF_ROLES_IDS = [
|
| 17 |
+
1488187501142216826, 1488187641424773140, 1488187816201687181,
|
| 18 |
+
1488188612313874733, 1488537308700344490, 1488537566910218260
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
]
|
| 20 |
+
PING_ROLES = "<@&1488187816201687181> <@&1488188612313874733> <@&1488537308700344490> <@&1488537566910218260>"
|
| 21 |
|
| 22 |
+
# --- ูุธุงู
ุงูุญู
ุงูุฉ ูุงููููุฏ ---
|
| 23 |
+
active_tickets = {} # user_id: thread_id
|
| 24 |
+
cooldowns = {} # user_id: datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
class MyBot(commands.Bot):
|
| 27 |
+
def __init__(self):
|
| 28 |
+
intents = discord.Intents.default()
|
| 29 |
+
intents.message_content = True
|
| 30 |
+
intents.members = True
|
| 31 |
+
super().__init__(command_prefix="!", intents=intents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
async def setup_hook(self):
|
| 34 |
+
self.add_view(TicketPanelView())
|
| 35 |
+
self.add_view(TicketControls())
|
| 36 |
+
await self.tree.sync()
|
| 37 |
|
| 38 |
+
async def on_error(self, event, *args, **kwargs):
|
| 39 |
+
channel = self.get_channel(ERROR_LOG_CHANNEL_ID)
|
| 40 |
+
if channel:
|
| 41 |
+
await channel.send(f"โ ๏ธ **Crash Detected / ุฎุทุฃ ูู ุงููุธุงู
**\n`{event}`\n<@{OWNER_ID}>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
bot = MyBot()
|
|
|
|
| 44 |
|
| 45 |
+
# --- ุฃุฏูุงุช ู
ุณุงุนุฏุฉ ---
|
| 46 |
+
def is_staff(interaction: discord.Interaction):
|
| 47 |
+
return any(role.id in STAFF_ROLES_IDS for role in interaction.user.roles) or interaction.user.id == OWNER_ID
|
| 48 |
|
| 49 |
+
# --- ูุธุงู
ูุงุฌูุฉ ุงูุชุฐุงูุฑ ---
|
| 50 |
class TicketPanelView(discord.ui.View):
|
|
|
|
|
|
|
| 51 |
def __init__(self):
|
| 52 |
super().__init__(timeout=None)
|
|
|
|
| 53 |
|
| 54 |
+
@discord.ui.select(
|
| 55 |
+
custom_id="ticket_select",
|
| 56 |
+
placeholder="Choose ticket type / ุงุฎุชุฑ ููุน ุงูุชุฐูุฑุฉ",
|
| 57 |
+
options=[
|
| 58 |
+
discord.SelectOption(label="Complaint against staff / ุดููู ุถุฏ ุฅุฏุงุฑู", value="staff_complaint", emoji="โ๏ธ"),
|
| 59 |
+
discord.SelectOption(label="Complaint against user / ุดููู ุถุฏ ูุงุนุจ", value="user_complaint", emoji="๐ฅ"),
|
| 60 |
+
discord.SelectOption(label="Bug report / ุจูุงุบ ุนู ุซุบุฑุฉ", value="bug_report", emoji="๐"),
|
| 61 |
+
discord.SelectOption(label="Technical support / ุฏุนู
ููู", value="tech_support", emoji="๐ ๏ธ"),
|
| 62 |
+
]
|
| 63 |
+
)
|
| 64 |
+
async def select_callback(self, interaction: discord.Interaction, select: discord.ui.Select):
|
| 65 |
+
user_id = interaction.user.id
|
| 66 |
+
|
| 67 |
+
# ุชุญูู ู
ู ุงูุชุฐูุฑุฉ ุงูู
ูุชูุญุฉ
|
| 68 |
+
if user_id in active_tickets:
|
| 69 |
+
return await interaction.response.send_message("โ You already have an open ticket! / ูุฏูู ุชุฐูุฑุฉ ู
ูุชูุญุฉ ุจุงููุนู!", ephemeral=True)
|
| 70 |
+
|
| 71 |
+
# ุชุญูู ู
ู ุงูู Cooldown
|
| 72 |
+
if user_id in cooldowns:
|
| 73 |
+
diff = (datetime.datetime.now() - cooldowns[user_id]).total_seconds()
|
| 74 |
+
if diff < 60:
|
| 75 |
+
return await interaction.response.send_message(f"โณ Wait {int(60-diff)}s / ุงูุชุธุฑ {int(60-diff)} ุซุงููุฉ", ephemeral=True)
|
| 76 |
|
| 77 |
+
await interaction.response.defer(ephemeral=True)
|
| 78 |
+
|
| 79 |
+
# ุฅูุดุงุก Thread
|
| 80 |
+
channel = bot.get_channel(TICKETS_CHANNEL_ID)
|
| 81 |
+
ticket_id = ''.join(random.choices(string.ascii_lowercase + string.digits, k=4))
|
| 82 |
+
thread_name = f"ticket-{random.randint(1000,9999)}-{ticket_id}"
|
| 83 |
+
|
| 84 |
+
thread = await channel.create_thread(
|
| 85 |
+
name=thread_name,
|
| 86 |
+
type=discord.ChannelType.private_thread,
|
| 87 |
+
invitable=False
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
active_tickets[user_id] = thread.id
|
| 91 |
+
await thread.add_user(interaction.user)
|
| 92 |
+
await thread.edit(slowmode_delay=10)
|
| 93 |
+
|
| 94 |
+
# ุฑุณุงูุฉ ุงูุชุฑุญูุจ
|
| 95 |
+
embed = discord.Embed(
|
| 96 |
+
title="Ticket Created / ุชู
ุฅูุดุงุก ุงูุชุฐูุฑุฉ",
|
| 97 |
+
description=f"Welcome {interaction.user.mention}\n{PING_ROLES}\nYour ticket has been created, please wait...\n\nู
ุฑุญุจุงู ุจูุ ุชู
ุฅูุดุงุก ุชุฐูุฑุชูุ ูุฑุฌู ุงูุงูุชุธุงุฑ...",
|
| 98 |
+
color=discord.Color.blue()
|
| 99 |
+
)
|
| 100 |
+
await thread.send(embed=embed, view=TicketControls())
|
| 101 |
+
|
| 102 |
+
# ุฅุฑุณุงู DM
|
| 103 |
+
try:
|
| 104 |
+
await interaction.user.send(f"โ
Your ticket has been created: {thread.jump_url}\nุชู
ุฅูุดุงุก ุชุฐูุฑุชู ุจูุฌุงุญ.")
|
| 105 |
+
except: pass
|
| 106 |
+
|
| 107 |
+
await interaction.followup.send(f"โ
Ticket Created: {thread.mention}", ephemeral=True)
|
| 108 |
|
| 109 |
+
class TicketControls(discord.ui.View):
|
| 110 |
def __init__(self):
|
| 111 |
super().__init__(timeout=None)
|
| 112 |
|
| 113 |
+
@discord.ui.button(label="Claim / ุงุณุชูุงู
", style=discord.ButtonStyle.green, custom_id="claim_btn")
|
| 114 |
+
async def claim(self, interaction: discord.Interaction, button: discord.ui.Button):
|
| 115 |
+
if not is_staff(interaction):
|
| 116 |
+
return await interaction.response.send_message("โ Staff only / ููู
ูุธููู ููุท", ephemeral=True)
|
| 117 |
+
|
| 118 |
+
button.disabled = True
|
| 119 |
+
await interaction.response.edit_message(view=self)
|
| 120 |
+
await interaction.followup.send(f"๐ Ticket claimed by / ุชู
ุงุณุชูุงู
ุงูุชุฐูุฑุฉ ู
ู ูุจู: {interaction.user.mention}")
|
| 121 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
# ุฅุฑุณุงู DM ููู
ุณุชุฎุฏู
|
| 123 |
+
thread_owner_id = next((k for k, v in active_tickets.items() if v == interaction.channel_id), None)
|
| 124 |
+
if thread_owner_id:
|
| 125 |
+
user = await bot.fetch_user(thread_owner_id)
|
| 126 |
+
try: await user.send(f"๐ Your ticket has been claimed by **{interaction.user.name}**\nุชู
ุงุณุชูุงู
ุชุฐูุฑุชู ุจูุงุณุทุฉ ุงูู
ูุธู.")
|
| 127 |
+
except: pass
|
| 128 |
+
|
| 129 |
+
@discord.ui.button(label="Close / ุฅุบูุงู", style=discord.ButtonStyle.red, custom_id="close_btn")
|
| 130 |
+
async def close(self, interaction: discord.Interaction, button: discord.ui.Button):
|
| 131 |
+
if not is_staff(interaction):
|
| 132 |
+
return await interaction.response.send_message("โ Staff only / ููู
ูุธููู ููุท", ephemeral=True)
|
| 133 |
+
|
| 134 |
+
await interaction.response.send_modal(CloseModal())
|
| 135 |
+
|
| 136 |
+
class CloseModal(discord.ui.Modal, title="Close Ticket / ุฅุบูุงู ุงูุชุฐูุฑุฉ"):
|
| 137 |
+
reason = discord.ui.TextInput(label="Reason / ุงูุณุจุจ", placeholder="Enter closing reason...", min_length=5, required=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
async def on_submit(self, interaction: discord.Interaction):
|
| 140 |
+
thread = interaction.channel
|
| 141 |
+
messages = [msg async for msg in thread.history(limit=None, oldest_first=True)]
|
| 142 |
+
|
| 143 |
+
# ุฅูุดุงุก ู
ูู ุณุฌู
|
| 144 |
+
transcript = ""
|
| 145 |
+
for m in messages:
|
| 146 |
+
transcript += f"[{m.created_at.strftime('%Y-%m-%d %H:%M')}] {m.author}: {m.content}\n"
|
| 147 |
+
|
| 148 |
+
file = discord.File(io.BytesIO(transcript.encode()), filename=f"{thread.name}.txt")
|
| 149 |
+
|
| 150 |
+
# ุฅุฑุณุงู ุงูููู
|
| 151 |
+
log_channel = bot.get_channel(LOG_CHANNEL_ID)
|
| 152 |
+
user_id = next((k for k, v in active_tickets.items() if v == thread.id), "Unknown")
|
| 153 |
+
|
| 154 |
+
embed = discord.Embed(title="Ticket Closed / ุฅุบูุงู ุชุฐูุฑุฉ", color=discord.Color.red())
|
| 155 |
+
embed.add_field(name="User / ุงูู
ุณุชุฎุฏู
", value=f"<@{user_id}>")
|
| 156 |
+
embed.add_field(name="Staff / ุงูู
ูุธู", value=interaction.user.mention)
|
| 157 |
+
embed.add_field(name="Reason / ุงูุณุจุจ", value=self.reason.value)
|
| 158 |
+
embed.add_field(name="Open Time / ููุช ุงููุชุญ", value=thread.created_at.strftime('%Y-%m-%d %H:%M'))
|
| 159 |
+
|
| 160 |
+
await log_channel.send(embed=embed, file=file)
|
| 161 |
+
|
| 162 |
+
# ุชูุธูู ุงูุจูุงูุงุช
|
| 163 |
+
if user_id != "Unknown":
|
| 164 |
+
active_tickets.pop(int(user_id), None)
|
| 165 |
+
cooldowns[int(user_id)] = datetime.datetime.now()
|
| 166 |
+
|
| 167 |
+
await interaction.response.send_message("Closing... / ุฌุงุฑู ุงูุฅุบูุงู...")
|
| 168 |
+
await thread.delete()
|
| 169 |
+
|
| 170 |
+
# --- ุงูุฃูุงู
ุฑ ---
|
| 171 |
+
@bot.tree.command(name="setup-ticket-panel", description="Setup the ticket panel (Owner Only)")
|
| 172 |
+
async def setup_ticket(interaction: discord.Interaction):
|
| 173 |
+
if interaction.user.id != OWNER_ID:
|
| 174 |
+
return await interaction.response.send_message("โ Access Denied", ephemeral=True)
|
| 175 |
+
|
| 176 |
+
embed = discord.Embed(
|
| 177 |
+
title="Support System / ูุธุงู
ุงูุฏุนู
ุงูููู",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
description=(
|
| 179 |
+
"**Rules / ุงูููุงููู:**\n"
|
| 180 |
+
"โ No spamming tickets / ูู
ูุน ูุชุญ ุชุฐุงูุฑ ุนุดูุงุฆูุฉ\n"
|
| 181 |
+
"โ
Use for complaints or support / ุงุณุชุฎุฏู
ุงูุชุฐุงูุฑ ููุดูุงูู ูุงูุฏุนู
ููุท\n\n"
|
| 182 |
+
"**Options / ุงูุฎูุงุฑุงุช:**\n"
|
| 183 |
+
"โข Staff Complaint / ุดููู ุฅุฏุงุฑู\n"
|
| 184 |
+
"โข User Complaint / ุดููู ูุงุนุจ\n"
|
| 185 |
+
"โข Bug Report / ุจูุงุบ ุซุบุฑุฉ\n"
|
| 186 |
+
"โข Technical Support / ุฏุนู
ููู"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
),
|
| 188 |
+
color=discord.Color.green()
|
| 189 |
)
|
| 190 |
+
await interaction.response.send_message("Panel Sent!", ephemeral=True)
|
| 191 |
+
await interaction.channel.send(embed=embed, view=TicketPanelView())
|
| 192 |
|
| 193 |
+
@bot.tree.command(name="help", description="Show help information")
|
| 194 |
+
async def help_cmd(interaction: discord.Interaction):
|
| 195 |
+
await interaction.response.send_message(f"To open a ticket, go to <#{TICKETS_CHANNEL_ID}>\nููุชุญ ุชุฐูุฑุฉุ ุชูุฌู ุฅูู ุงูููุงุฉ ุงูู
ุฎุตุตุฉ.", ephemeral=True)
|
| 196 |
|
| 197 |
+
# --- ูุธุงู
ุงูุญู
ุงูุฉ (Anti-Spam & Content Filter) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
@bot.event
|
| 199 |
+
async def on_message(message):
|
| 200 |
+
if message.author.bot: return
|
| 201 |
+
if not isinstance(message.channel, discord.Thread): return
|
| 202 |
+
if message.channel.parent_id != TICKETS_CHANNEL_ID: return
|
| 203 |
+
|
| 204 |
+
# ู
ูุน ุงูุฑูุงุจุทุ ุงูู
ููุงุชุ ูุงูุจุตู
ุงุช ุงูุตูุชูุฉ
|
| 205 |
+
if re.search(r'http[s]?://', message.content) or message.attachments or message.flags.voice:
|
| 206 |
+
# ุงูุณู
ุงุญ ููุท ุจุงูุตูุฑ ูุงูููุฏูู
|
| 207 |
+
allowed = True
|
| 208 |
+
if message.attachments:
|
| 209 |
+
for att in message.attachments:
|
| 210 |
+
if not att.content_type or (not att.content_type.startswith('image/') and not att.content_type.startswith('video/')):
|
| 211 |
+
allowed = False
|
| 212 |
+
|
| 213 |
+
if not allowed or re.search(r'http[s]?://', message.content) or message.flags.voice:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
await message.delete()
|
| 215 |
+
return await message.channel.send(f"{message.author.mention} โ Only text, images, and videos are allowed.\nู
ุณู
ูุญ ููุท ุจุงููุตูุตุ ุงูุตูุฑุ ูุงูููุฏูู.", delete_after=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
# ู
ูุน ุงูุณุจุงู
(ุฃุญุฑู ุนุดูุงุฆูุฉ ุทูููุฉ)
|
| 218 |
+
if len(message.content) > 50 and len(set(message.content)) < 10:
|
| 219 |
+
await message.delete()
|
| 220 |
+
return await message.channel.send("โ Random characters/spam detected.", delete_after=5)
|
| 221 |
|
| 222 |
+
import os
|
| 223 |
+
from dotenv import load_dotenv
|
| 224 |
+
load_dotenv()
|
| 225 |
+
bot.run(os.getenv('TOKEN'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|