Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot_that_tinh.py
More file actions
547 lines (495 loc) · 19.5 KB
/
Copy pathbot_that_tinh.py
File metadata and controls
547 lines (495 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
import discord
import random
import asyncio
from datetime import datetime
import os
from dotenv import load_dotenv
from keep_alive import keep_alive
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
OWNER_ID = os.getenv('OWNER_ID')
print("Vui lòng tạo file .env chứa những thông tin sau: TOKEN={YOUR DISCORD APP TOKEN} ; OWNER_ID={YOUR DISCORD ID USER} 2 DÒNG")
# ==================== BỘ STATUS THẤT TÌNH ====================
HEARTBREAK_STATUSES = {
"buồn_sâu": [
{
"text": "💔 Tim vỡ thành ngàn mảnh",
"emoji": "💔",
"type": "listening"
},
{
"text": "😔 Thở dài một ngày dài",
"emoji": "😔",
"type": "playing"
},
{
"text": "🌧️ Ngồi nhìn mưa rơi lặng lẽ",
"emoji": "🌧️",
"type": "watching"
},
{
"text": "🖤 Đen tối như tâm trạng hiện tại",
"emoji": "🖤",
"type": "listening"
},
{
"text": "🚬 Khói thuốc vấn vương nỗi buồn",
"emoji": "🚬",
"type": "playing"
},
{
"text": "🍷 Ly rượu cạn, lòng vẫn đau",
"emoji": "🍷",
"type": "playing"
},
{
"text": "🛏️ Nằm một chỗ nhớ người xưa",
"emoji": "🛏️",
"type": "watching"
},
{
"text": "📱 Block nhưng vẫn lén xem story",
"emoji": "📱",
"type": "watching"
},
],
"nhớ_nhung": [
{
"text": "💭 Lại nhớ về em lần thứ n...",
"emoji": "💭",
"type": "listening"
},
{
"text": "📸 Lật từng tấm ảnh kỷ niệm",
"emoji": "📸",
"type": "watching"
},
{
"text": "🎶 Nghe bài hát chúng ta từng yêu",
"emoji": "🎶",
"type": "listening"
},
{
"text": "🍂 Mùa thu về nhớ người cũ",
"emoji": "🍂",
"type": "playing"
},
{
"text": "🏙️ Đi trên phố quen một mình",
"emoji": "🏙️",
"type": "playing"
},
{
"text": "☕ Uống ly cà phê vị đắng",
"emoji": "☕",
"type": "playing"
},
{
"text": "📖 Đọc tin nhắn cũ lần cuối",
"emoji": "📖",
"type": "listening"
},
{
"text": "🌸 Hoa rơi nhẹ nhàng như tình ta",
"emoji": "🌸",
"type": "watching"
},
],
"chua_xót": [
{
"text": "🔪 Lưỡi dao nào sắc bằng lời chia tay",
"emoji": "🔪",
"type": "listening"
},
{
"text": "💢 Giận bản thân vì đã quá yêu",
"emoji": "💢",
"type": "playing"
},
{
"text": "🌪️ Cơn lốc cảm xúc cuốn phăng tất cả",
"emoji": "🌪️",
"type": "watching"
},
{
"text": "🔥 Lòng như lửa đốt mỗi khi nhớ đến",
"emoji": "🔥",
"type": "playing"
},
{
"text": "⚡ Sét đánh ngang tai khi em nói lời chia tay",
"emoji": "⚡",
"type": "listening"
},
{
"text": "💣 Trái tim nổ tung từng mảnh",
"emoji": "💣",
"type": "playing"
},
{
"text": "🌀 Xoáy sâu vào nỗi đau không lối thoát",
"emoji": "🌀",
"type": "watching"
},
{
"text": "❄️ Lạnh giá như trái tim không còn yêu",
"emoji": "❄️",
"type": "playing"
},
],
"chấp_nhận": [
{
"text": "🕊️ Thả cho nhẹ lòng, buông cho thanh thản",
"emoji": "🕊️",
"type": "listening"
},
{
"text": "🌅 Bình minh mới sau đêm dài đau khổ",
"emoji": "🌅",
"type": "watching"
},
{
"text": "💪 Mạnh mẽ lên, cuộc sống vẫn tiếp diễn",
"emoji": "💪",
"type": "playing"
},
{
"text": "🧘♂️ Hít thở sâu, quá khứ để lại sau",
"emoji": "🧘♂️",
"type": "listening"
},
{
"text": "📚 Tập trung vào bản thân, yêu chính mình",
"emoji": "📚",
"type": "playing"
},
{
"text": "🌟 Tự hứa sẽ tốt hơn từ hôm nay",
"emoji": "🌟",
"type": "watching"
},
{
"text": "🚶♂️ Bước đi, không ngoảnh lại phía sau",
"emoji": "🚶♂️",
"type": "playing"
},
{
"text": "🌈 Cầu vồng sau mưa, hạnh phúc sau nỗi buồn",
"emoji": "🌈",
"type": "watching"
},
],
"ẩn_ý": [
{
"text": "🎭 Vở kịch tình yêu không có hồi kết đẹp",
"emoji": "🎭",
"type": "watching"
},
{
"text": "♟️ Ván cờ tình đã thua từ nước đầu",
"emoji": "♟️",
"type": "playing"
},
{
"text": "🎪 Gánh xiếc tình yêu, anh là chú hề",
"emoji": "🎪",
"type": "watching"
},
{
"text": "🕰️ Đồng hồ tình yêu đã ngừng lại",
"emoji": "🕰️",
"type": "watching"
},
{
"text": "🎨 Bức tranh tình yêu thiếu màu hạnh phúc",
"emoji": "🎨",
"type": "playing"
},
{
"text": "📖 Truyện tình buồn không ai muốn đọc",
"emoji": "📖",
"type": "listening"
},
{
"text": "🎵 Bản nhạc tình dang dở giữa chừng",
"emoji": "🎵",
"type": "listening"
},
{
"text": "🌌 Chòm sao tình yêu đã tắt lịm",
"emoji": "🌌",
"type": "watching"
},
]
}
class FinalBot(discord.Client):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(intents=intents)
# Tất cả status trong một list
self.all_statuses = []
for mood_statuses in HEARTBREAK_STATUSES.values():
self.all_statuses.extend(mood_statuses)
self.current_mood = "buồn_sâu"
self.auto_interval = 120 # 2 phút
self.auto_task = None
self.is_auto_running = True
async def on_ready(self):
print(f'💔 Bot "{self.user}" - Chuyên gia thất tình')
print(f'📊 Đang ở {len(self.guilds)} server')
print('=' * 50)
print('🎮 TẤT CẢ LỆNH ĐÃ SẴN SÀNG:')
print(' !sad - Random status ngay')
print(' !mood - Đổi tâm trạng')
print(' !time - Đổi thời gian (60-300s)')
print(' !info - Xem thông tin')
print(' !stop - Dừng auto-change')
print(' !start - Bật auto-change')
print(' !help - Xem hướng dẫn')
print(' !shutdown - Tắt bot')
print('=' * 50)
# Bắt đầu auto-change
await self.start_auto_change()
async def start_auto_change(self):
"""Bắt đầu tự động đổi status"""
if self.auto_task and not self.auto_task.done():
self.auto_task.cancel()
self.is_auto_running = True
self.auto_task = self.loop.create_task(self.auto_change_loop())
print(f"✅ Auto-change started: {self.auto_interval}s")
async def stop_auto_change(self):
"""Dừng auto-change"""
self.is_auto_running = False
if self.auto_task:
self.auto_task.cancel()
print("⏸️ Auto-change stopped")
async def auto_change_loop(self):
"""Vòng lặp tự động đổi status"""
await self.wait_until_ready()
while self.is_auto_running and not self.is_closed():
try:
# Random đổi mood 30% cơ hội
if random.random() < 0.3:
moods = list(HEARTBREAK_STATUSES.keys())
self.current_mood = random.choice(moods)
print(f"🎭 Chuyển mood: {self.current_mood}")
# Lấy status từ mood hiện tại
mood_statuses = HEARTBREAK_STATUSES.get(
self.current_mood, self.all_statuses)
status = random.choice(mood_statuses)
# Đổi status
await self.change_presence(activity=discord.Game(
name=f"{status['emoji']} {status['text']}"))
# Log
timestamp = datetime.now().strftime("%H:%M:%S")
print(f"[{timestamp}] 💔 {status['emoji']} {status['text']}")
# Chờ
await asyncio.sleep(self.auto_interval)
except asyncio.CancelledError:
break
except Exception as e:
print(f"❌ Lỗi auto-change: {e}")
await asyncio.sleep(10)
async def on_message(self, message):
"""Xử lý TẤT CẢ commands"""
# Bỏ qua tin nhắn từ bot
if message.author == self.user:
return
# Chỉ xử lý commands với prefix '!'
if not message.content.startswith('!'):
return
# Lấy command và arguments
content = message.content[1:].strip()
parts = content.split()
command = parts[0].lower() if parts else ""
args = parts[1:] if len(parts) > 1 else []
# ========== TẤT CẢ COMMANDS ==========
# !sad - Random status ngay
if command == "sad":
status = random.choice(self.all_statuses)
await self.change_presence(activity=discord.Game(
name=f"{status['emoji']} {status['text']}"))
await message.channel.send(
f"💔 **Đã random:** {status['emoji']} {status['text']}")
# !mood - Đổi hoặc xem mood
elif command == "mood":
if not args:
# Hiển thị danh sách mood
moods = "\n".join(
[f"• `{m}`" for m in HEARTBREAK_STATUSES.keys()])
await message.channel.send(
f"🎭 **Các mood có sẵn:**\n{moods}\n👉 Dùng: `!mood <tên_mood>`"
)
else:
mood_name = args[0]
if mood_name in HEARTBREAK_STATUSES:
self.current_mood = mood_name
await message.channel.send(
f"💔 **Đã chuyển mood:** `{mood_name}`")
else:
await message.channel.send(
f"❌ Mood `{mood_name}` không tồn tại. Dùng `!mood` để xem danh sách."
)
# !time hoặc !interval - Đổi thời gian
elif command in ["time", "interval"]:
if not args:
# Hiển thị interval hiện tại
minutes = self.auto_interval / 60
await message.channel.send(
f"⏱️ **Interval hiện tại:** {self.auto_interval}s ({minutes:.1f} phút)\n"
f"👉 Dùng: `!time 90` để đổi thành 90 giây")
else:
try:
seconds = int(args[0])
if 60 <= seconds <= 300:
old = self.auto_interval
self.auto_interval = seconds
# Restart auto-change với interval mới
await self.stop_auto_change()
await asyncio.sleep(1)
await self.start_auto_change()
minutes = seconds / 60
await message.channel.send(
f"✅ **Đã đổi interval:**\n"
f"• Cũ: {old}s\n• Mới: {seconds}s ({minutes:.1f} phút)"
)
else:
await message.channel.send(
"❌ Phải từ **60-300 giây** (1-5 phút)")
except ValueError:
await message.channel.send(
"❌ Vui lòng nhập **số** (ví dụ: `!time 90`)")
# !info hoặc !status - Xem thông tin
elif command in ["info", "status"]:
embed = discord.Embed(title="💔 Thông Tin Bot Thất Tình",
color=discord.Color.dark_grey(),
timestamp=datetime.now())
# Status count
total_statuses = len(self.all_statuses)
mood_statuses = HEARTBREAK_STATUSES.get(self.current_mood, [])
embed.add_field(name="🎭 Mood hiện tại",
value=self.current_mood,
inline=True)
embed.add_field(name="📊 Status trong mood",
value=str(len(mood_statuses)),
inline=True)
embed.add_field(name="⏱️ Interval",
value=f"{self.auto_interval}s",
inline=True)
embed.add_field(
name="🔄 Auto-change",
value="✅ Đang chạy" if self.is_auto_running else "⏸️ Đã dừng",
inline=True)
embed.add_field(name="📈 Tổng status",
value=str(total_statuses),
inline=True)
# Ví dụ status
sample = random.choice(mood_statuses)
embed.add_field(name="🎯 Ví dụ status",
value=f"{sample['emoji']} {sample['text']}",
inline=False)
embed.set_footer(text="Bot Thất Tình - Luôn đồng cảm với bạn")
await message.channel.send(embed=embed)
# !stop - Dừng auto-change
elif command == "stop":
await self.stop_auto_change()
await message.channel.send(
"⏸️ **Đã dừng auto-change**\nDùng `!start` để bật lại")
# !start - Bật auto-change
elif command == "start":
await self.start_auto_change()
await message.channel.send(
f"✅ **Đã bật auto-change**\nInterval: {self.auto_interval}s")
elif command == "stop":
await self.stop_auto_change()
await message.channel.send(
"⏸️ **Đã dừng auto-change**\nDùng `!start` để bật lại")
# !start - Bật auto-change
elif command == "start":
await self.start_auto_change()
await message.channel.send(
f"✅ **Đã bật auto-change**\nInterval: {self.auto_interval}s")
# !shutdown - Tắt bot (chỉ owner)
elif command == "shutdown":
# Kiểm tra owner
owner_id = int(OWNER_ID) if OWNER_ID else message.author.id
if message.author.id != owner_id:
await message.channel.send(
"❌ Chỉ **owner** mới được dùng lệnh này!")
return
confirm_embed = discord.Embed(
title="⚠️ XÁC NHẬN TẮT BOT",
description=
"Bạn có chắc muốn tắt bot?\n\n**⚠️ CẢNH BÁO:**\n• Bot sẽ ngừng hoạt động\n• Cần khởi động lại thủ công",
color=discord.Color.red())
confirm_embed.add_field(
name="Xác nhận",
value="Gõ `!confirm` trong 30 giây để xác nhận")
confirm_embed.set_footer(text="Lệnh sẽ tự hủy sau 30 giây")
await message.channel.send(embed=confirm_embed)
# Chờ xác nhận
def check(m):
return m.author == message.author and m.content == "!confirm"
try:
await self.wait_for('message', timeout=30.0, check=check)
# Xác nhận thành công
shutdown_embed = discord.Embed(
title="💔 Bot đang tắt...",
description="*Trái tim tan vỡ cũng cần nghỉ ngơi*",
color=discord.Color.dark_grey())
shutdown_embed.add_field(name="👋 Tạm biệt",
value="Hẹn gặp lại khi tim lành lại")
shutdown_embed.set_footer(text="Bot Thất Tình - Tạm dừng")
await message.channel.send(embed=shutdown_embed)
# Dừng auto-change
await self.stop_auto_change()
await asyncio.sleep(1)
# Đổi status offline
await self.change_presence(status=discord.Status.offline)
await asyncio.sleep(2)
# Tắt bot
print(
f"👋 Bot đang tắt bởi {message.author.name}#{message.author.discriminator}"
)
await self.close()
except asyncio.TimeoutError:
await message.channel.send(
"⏰ Đã hết thời gian xác nhận, lệnh tắt bot bị hủy.")
# !help - Trợ giúp
elif command == "help":
embed = discord.Embed(title="💔 Trợ giúp Bot Thất Tình",
description="*Tất cả lệnh bắt đầu bằng `!`*",
color=discord.Color.dark_purple())
commands_info = [
("`!sad`", "Random một status buồn ngay lập tức"),
("`!mood [tên]`",
"Đổi mood (buồn_sâu, nhớ_nhung, chua_xót, chấp_nhận, ẩn_ý)"),
("`!time [số]`", "Đổi thời gian auto-change (60-300 giây)"),
("`!info`", "Xem thông tin bot hiện tại"),
("`!stop`", "Tạm dừng auto-change"),
("`!start`", "Bật lại auto-change"),
("`!help`", "Hiển thị hướng dẫn này"),
("`!shutdown`", "Tắt bot (chỉ chủ sở hữu)")
]
for cmd, desc in commands_info:
embed.add_field(name=cmd, value=desc, inline=False)
embed.set_footer(
text=
f"Hiện tại: mood={self.current_mood}, interval={self.auto_interval}s"
)
await message.channel.send(embed=embed)
# Command không tìm thấy
else:
await message.channel.send(
f"❌ Command `!{command}` không tồn tại.\n"
f"👉 Dùng `!help` để xem tất cả lệnh.")
# ========== CHẠY BOT ==========
if __name__ == "__main__":
keep_alive()
if TOKEN:
print("🚀 Đang khởi động Final Bot (100% working)...")
bot = FinalBot()
bot.run(TOKEN)
else:
print("❌ Thiếu token! Kiểm tra file .env")
You can’t perform that action at this time.
