-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
195 lines (168 loc) · 7.01 KB
/
script.py
File metadata and controls
195 lines (168 loc) · 7.01 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
import discord
from discord.ext import commands
import asyncio
import random
from datetime import datetime
import aiohttp
import time
bot = commands.Bot(command_prefix='!', self_bot=True)
last_whois = {}
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('Ready. Commands (anyone can use):')
print(' whois [@mention | ID]')
print(' del (deletes last whois)')
print(' ping / latency')
print(' bl [@mention | ID] (blacklist reply + auto-delete)')
async def fetch_profile(user_id: int) -> dict:
try:
async with aiohttp.ClientSession() as session:
async with session.get(
f"https://discord.com/api/v10/users/{user_id}/profile",
headers={"Authorization": bot.http.token}
) as resp:
if resp.status == 200:
return await resp.json()
except Exception as e:
print(f"Profile fetch failed: {e}")
return {}
@bot.event
async def on_message(message: discord.Message):
if message.author.bot:
return
# prevents self loop
if message.author.id == bot.user.id:
if any(phrase in message.content.lower() for phrase in [
"user information:",
"latency information",
"blacklisted",
"could not send"
]):
return
content = message.content.lower().strip()
channel_id = message.channel.id
# ──────────────────────────────────────────────
# bl command
# ──────────────────────────────────────────────
if content.startswith('bl '):
target = None
if message.mentions:
target = message.mentions[0]
else:
parts = message.content.split()
if len(parts) > 1:
raw = parts[1].strip('<@!>')
try:
uid = int(raw)
target = await bot.fetch_user(uid)
except:
await message.channel.send("Invalid user ID or mention.")
return
if target:
reply_text = f"blacklisted {target.mention} ({target.id})"
try:
sent = await message.channel.send(reply_text)
await asyncio.sleep(0.8)
await sent.delete()
except Exception as e:
print(f"bl failed: {e}")
await message.channel.send("blacklisted — could not delete reply")
return
# del command
if 'del' in content:
if channel_id in last_whois:
try:
msg = await message.channel.fetch_message(last_whois[channel_id])
await msg.delete()
del last_whois[channel_id]
except:
pass
return
# whois command
if content.startswith('whois'):
target = message.author
if message.mentions:
target = message.mentions[0]
else:
parts = message.content.split()
if len(parts) > 1:
raw = parts[1].strip('<@!>')
try:
uid = int(raw)
target = await bot.fetch_user(uid)
except:
await message.channel.send("Invalid user ID or user not found.")
return
profile = await fetch_profile(target.id)
lines = []
lines.append(f"User Information: {target}")
lines.append("─" * 50)
lines.append(f"User ID : {target.id}")
lines.append(f"Username : @{target.name}")
lines.append(f"Display Name : {target.display_name}")
lines.append(f"Global Name : {target.global_name or '—'}")
lines.append(f"Created : {target.created_at.strftime('%Y-%m-%d %H:%M UTC')}")
if hasattr(target, 'joined_at') and target.joined_at:
lines.append(f"Joined Server : {target.joined_at.strftime('%Y-%m-%d %H:%M UTC')}")
badges = []
if target.public_flags:
pf = target.public_flags
if pf.active_developer: badges.append("Active Developer")
if pf.bug_hunter: badges.append("Bug Hunter")
if pf.bug_hunter_level_2: badges.append("Bug Hunter Level 2")
if pf.early_supporter: badges.append("Early Supporter")
if pf.partner: badges.append("Partner")
if pf.staff: badges.append("Discord Staff")
lines.append(f"Badges : {', '.join(badges) if badges else 'None'}")
if profile:
lines.append(f"Bio : {profile.get('bio', '—')[:600] or '—'}")
lines.append(f"Pronouns : {profile.get('pronouns', '—')}")
if message.guild:
member = message.guild.get_member(target.id)
if member:
lines.append(f"Nickname : {member.nick or '—'}")
lines.append(f"Bot Account : {'Yes' if member.bot else 'No'}")
roles = [r.name for r in member.roles if r.name != "@everyone"]
lines.append(f"Roles : {', '.join(roles) or 'None'}")
lines.append("─" * 50)
lines.append(f"Requested by {message.author} • {datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')}")
output = "\n".join(lines)
await asyncio.sleep(random.uniform(0.8, 2.5))
try:
sent = await message.channel.send(output)
last_whois[channel_id] = sent.id
except Exception as e:
print(f"whois send error: {e}")
await message.channel.send("Could not send whois result.")
return
# ping / latency — no temp message
if 'latency' in content or 'ping' in content:
gateway = round(bot.latency * 1000, 2)
start = time.time()
api = "failed"
try:
async with aiohttp.ClientSession() as s:
async with s.get("https://discord.com/api/v10/users/@me", headers={"Authorization": bot.http.token}) as r:
end = time.time()
api = round((end - start) * 1000, 2)
except:
pass
lines = [
"Latency Information",
"─" * 40,
f"Gateway latency : {gateway} ms",
f"API estimate : {api} ms" if isinstance(api, float) else f"API estimate : {api}",
f"Account : {bot.user}",
f"User ID : {bot.user.id}",
f"Time : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
]
await asyncio.sleep(random.uniform(0.5, 1.8))
try:
await message.channel.send("\n".join(lines))
except Exception as e:
print(f"ping send error: {e}")
await message.channel.send("Could not send latency info.")
return
bot.run('USER_TOKEN')
# ^ enter user token! ^