-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
368 lines (328 loc) · 14.2 KB
/
bot.py
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
# imports
import random
import discord
from discord import app_commands
from discord.ext import commands
from scripts import *
load_dotenv('.env')
TOKEN = os.getenv('TOKEN')
default_custom_status = os.getenv('default_custom_status')
default_status = os.getenv('default_status')
default_version = os.getenv('default_version')
setting_version = os.getenv('setting_version')
# 固定不变
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=intents)
# 版本号
bot_version = "v0.1.4"
bot_build = "1"
bot_type = "Release Build"
# 启动之后
@client.event
async def on_ready():
# 终端输出
print("Bot is ready for use!")
# 从配置文件中获取设定的状态
if default_status == 'idle':
edit_status = discord.Status.idle
elif default_status == 'online':
edit_status = discord.Status.online
elif default_status == 'do_not_disturb':
edit_status = discord.Status.dnd
else:
print("Unknown Status")
edit_status = discord.Status.online
# 自定义状态的内容
game = discord.Game(default_custom_status)
await client.change_presence(status=edit_status, activity=game)
# 同步命令 并输出
try:
synced = await client.tree.sync()
print(f"synced {len(synced)} command(s)")
except Exception as e:
print(e)
# /say [things_to_say]
@client.tree.command(name="say", description="Let bot say something.")
@app_commands.describe(things_to_say="What should I say?")
async def say(interaction: discord.Interaction, things_to_say: str):
await interaction.response.send_message(f"{things_to_say}")
# /status [choice] [custom]
@client.tree.command(name="status", description="Change the status")
@app_commands.choices(
choices=[
app_commands.Choice(name="Online", value="online"),
app_commands.Choice(name="idle", value="idle"),
app_commands.Choice(name="Do Not Disturb", value="dnd"),
]
)
async def status(interaction: discord.Interaction, choices: app_commands.Choice[str], *, custom_status_message: str):
if choices.value == "online":
changed_status = discord.Status.online
elif choices.value == "idle":
changed_status = discord.Status.idle
elif choices.value == "dnd":
changed_status = discord.Status.dnd
else:
await interaction.response.send_message(f"Unknown Status. Please specify 'online', 'idle', 'Do Not Disturb'",
ephemeral=True)
return
game = discord.Game(custom_status_message)
await client.change_presence(status=changed_status, activity=game)
await interaction.response.send_message(f"Status Updated!", ephemeral=True)
# /roll
@client.tree.command(name='roll', description='Roll a dice.')
async def roll(interaction: discord.Interaction):
number = random.randint(1, 6)
await interaction.response.send_message(f"Number is {number}")
# /zipcode [country] [zipcode]
@client.tree.command(name='zipcode', description='search address from zipcode')
@app_commands.choices(
country=[
app_commands.Choice(name='Japan', value='JP'),
]
)
async def zipcode(interaction: discord.Interaction, country: app_commands.Choice[str], zipcodes: str):
await interaction.response.defer(ephemeral=True)
if country.value == 'JP':
result = search_zipcode_jp(zipcodes)
if result is None:
await interaction.followup.send(f"Invalid Zipcode.")
else:
await interaction.followup.send(
f"""
**Prefecture 都道府県:** {result['address1']} {result['kana1']}
**City 市区町村:** {result['address2']} {result['kana2']}
**Town 町域:** {result['address3']} {result['kana3']}
"""
)
if country.value == 'CN':
result = "Unavaliable"
if result is None:
await interaction.followup.send(f"Invalid Zipcode.")
else:
await interaction.followup.send(f"Address: {result}")
else:
await interaction.followup.send(f'Invalid Country.')
return
# /ipdetails
@client.tree.command(name='ipdetail', description="Show the details from IP address")
async def ipdetail(interaction: discord.Interaction, ipaddress: str):
await interaction.response.defer(ephemeral=True)
result = ipdetails(ipaddress)
if result is None:
await interaction.followup.send(f"Invalid IP address or Inter Error")
return
else:
embed = discord.Embed(
colour=discord.Colour.blue(),
title="IP Detail",
description=f"This is the Result of {ipaddress}"
)
embed.add_field(name='IP address', value=result['ip'])
embed.add_field(name='IP number', value=result['ip_number'])
embed.add_field(name='IP version', value=result['ip_version'])
embed.add_field(name='IP country name', value=result['country_name'])
embed.add_field(name='IP country code', value=result['country_code2'])
embed.add_field(name='IP ISP', value=result['isp'])
embed.add_field(name='IP response_code', value=result['response_code'])
embed.add_field(name='IP response_message', value=result['response_message'])
await interaction.followup.send(embed=embed)
return
# /iplocation
@client.tree.command(name='iplocation', description="Show the Geolocation from IP address")
async def iplocation(interaction: discord.Interaction, ipaddress: str):
await interaction.response.defer(ephemeral=True)
result = iplocations(ipaddress)
if result is None:
await interaction.followup.send(f"Invalid IP address or Inter Error")
return
else:
embed = discord.Embed(
colour=discord.Colour.blue(),
title="IP Location",
description=f"This is the Result of {ipaddress}"
)
embed.add_field(name='Query', value=result['query'])
embed.add_field(name='Timezone', value=result['timezone'])
embed.add_field(name='Country', value=result['country'])
embed.add_field(name='City', value=result['city'])
embed.add_field(name='ISP', value=result['isp'])
embed.add_field(name='org', value=result['org'])
embed.add_field(name='ASN', value=result['as'])
await interaction.followup.send(embed=embed)
return
# /domain
@client.tree.command(name='domain', description='Find the cheapest domain registrar')
@app_commands.choices(
order=[
app_commands.Choice(name='New', value='new'),
app_commands.Choice(name='Renew', value='renew'),
app_commands.Choice(name='Transfer', value='transfer'),
]
)
async def domain(interaction: discord.Interaction, tld: str, order: app_commands.Choice[str]):
await interaction.response.defer(ephemeral=True)
result = cheapest(tld, str(order))
if result is None:
await interaction.followup.send(f"Invalid input or Inter Error")
else:
await interaction.followup.send(
"## Domain Registrar"
f"\n**TLD**: {result['domain']} **| Order**: {result['order']}"
"\n### 1st:"
f"\n- **Registrar**: {result['reg_1']}"
f"\n- **Currency**: {result['currency_1']}"
f"\n- **New**: {result['new_1']}"
f"\n- **Renew**: {result['renew_1']}"
f"\n- **Transfer**: {result['transfer_1']}"
f"\n- **Registrar Website**: {result['reg_web_1']}"
"\n### 2nd:"
f"\n- **Registrar**: {result['reg_2']}"
f"\n- **Currency**: {result['currency_2']}"
f"\n- **New**: {result['new_2']}"
f"\n- **Renew**: {result['renew_2']}"
f"\n- **Transfer**: {result['transfer_2']}"
f"\n- **Registrar Website**: {result['reg_web_2']}"
"\n### 3rd:"
f"\n- **Registrar**: {result['reg_3']}"
f"\n- **Currency**: {result['currency_3']}"
f"\n- **New**: {result['new_3']}"
f"\n- **Renew**: {result['renew_3']}"
f"\n- **Transfer**: {result['transfer_3']}"
f"\n- **Registrar Website**: {result['reg_web_3']}"
"\n### 4th:"
f"\n- **Registrar**: {result['reg_4']}"
f"\n- **Currency**: {result['currency_4']}"
f"\n- **New**: {result['new_4']}"
f"\n- **Renew**: {result['renew_4']}"
f"\n- **Transfer**: {result['transfer_4']}"
f"\n- **Registrar Website**: {result['reg_web_4']}"
"\n### 5th:"
f"\n- **Registrar**: {result['reg_5']}"
f"\n- **Currency**: {result['currency_5']}"
f"\n- **New**: {result['new_5']}"
f"\n- **Renew**: {result['renew_5']}"
f"\n- **Transfer**: {result['transfer_5']}"
f"\n- **Registrar Website**: {result['reg_web_5']}"
)
return
# /registrars
@client.tree.command(name='registrars', description='Find the cheapest domain registrar')
@app_commands.choices(
order=[
app_commands.Choice(name='New', value='new'),
app_commands.Choice(name='Renew', value='renew'),
app_commands.Choice(name='Transfer', value='transfer'),
],
)
async def registrars(interaction: discord.Interaction, registrar: str, order: app_commands.Choice[str]):
await interaction.response.defer(ephemeral=True)
result = registrar_search(registrar, order)
if result is None:
await interaction.followup.send(f"Invalid input or Inter Error")
return
else:
await interaction.followup.send(
"## Domain Registrar"
f"\n**Registrar**: {result['reg']} **| Registrar Website**: {result['reg_web']} **| Order**: {result['order']}"
"\n### 1st:"
f"\n**Domain**: {result['domain_1']}"
f"\n**New**: {result['new_1']}"
f"\n**Renew**: {result['renew_1']}"
f"\n**Transfer**: {result['transfer_1']}"
f"\n**Currency**: {result['currency_1']}"
"\n### 2nd:"
f"\n**Domain**: {result['domain_2']}"
f"\n**New**: {result['new_2']}"
f"\n**Renew**: {result['renew_2']}"
f"\n**Transfer**: {result['transfer_2']}"
f"\n**Currency**: {result['currency_2']}"
"\n### 3rd:"
f"\n**Domain**: {result['domain_3']}"
f"\n**New**: {result['new_3']}"
f"\n**Renew**: {result['renew_3']}"
f"\n**Transfer**: {result['transfer_3']}"
f"\n**Currency**: {result['currency_3']}"
"\n### 4th:"
f"\n**Domain**: {result['domain_4']}"
f"\n**New**: {result['new_4']}"
f"\n**Renew**: {result['renew_4']}"
f"\n**Transfer**: {result['transfer_4']}"
f"\n**Currency**: {result['currency_4']}"
"\n### 5th:"
f"\n**Domain**: {result['domain_5']}"
f"\n**New**: {result['new_5']}"
f"\n**Renew**: {result['renew_5']}"
f"\n**Transfer**: {result['transfer_5']}"
f"\n**Currency**: {result['currency_5']}"
)
return
# Minecraft server detection
@client.tree.command(name='mcserver', description='Get debug and details of a minecraft server')
@app_commands.choices(
server_type=[
app_commands.Choice(name='Java', value='java'),
app_commands.Choice(name='Bedrock', value='bedrock'),
]
)
async def mcserver(interaction: discord.Interaction, server_type: app_commands.Choice[str], ipaddress: str):
await interaction.response.defer(ephemeral=True)
result = minecraftServer(server_type, ipaddress)
if result is None:
await interaction.followup.send("Invalid Input / Server Type")
else:
embed = discord.Embed(
colour=discord.Colour.dark_grey(),
title="Minecraft Server",
description=f"This is the Result of {ipaddress}"
)
embed.add_field(name='Actual IP address', value=result['ip'])
embed.add_field(name='Server Listening Port', value=result['port'])
embed.add_field(name='Hostname', value=result['hostname'])
embed.add_field(name='Game Version', value=result['version'])
embed.add_field(name='MOTD', value=result['motd'])
embed.add_field(name='Ping', value=result['ping'])
embed.add_field(name='SRV Record', value=result['srv'])
embed.add_field(name='Player', value=f"{result['player']} / {result['maxPlayer']}")
await interaction.followup.send(embed=embed)
return
# /bincheck
@client.tree.command(name='bincheck', description="Check a card issuer and country")
async def bincheck(interaction: discord.Interaction, bin_code: int):
await interaction.response.defer(ephemeral=True)
result = bin_check_request(bin_code)
if result is None:
await interaction.followup.send("Request Error or BIN code doesn't exist")
else:
embed = discord.Embed(
colour=discord.Colour.dark_grey(),
title="BinCheck",
description=f"The result of {bin_code}"
)
embed.add_field(name='Valid', value=result['valid'])
embed.add_field(name='Brand', value=result['brand'])
embed.add_field(name='Type', value=result['type'])
embed.add_field(name='Level', value=result['level'])
embed.add_field(name='Commercial', value=result['is_commercial'])
embed.add_field(name='Prepaid', value=result['is_prepaid'])
embed.add_field(name='Currency', value=result['currency'])
embed.add_field(name='Country', value=result['country'])
embed.add_field(name='Flag', value=result['flag'])
embed.add_field(name='Issuer', value=result['issuer'])
await interaction.followup.send(embed=embed, ephemeral=True)
return
# /info
@client.tree.command(name='info', description="Some information about this bot")
async def version(interaction: discord.Interaction):
await interaction.response.send_message(
"## JianyueBot"
"\nThis bot was developed by [JianyueLab](https://awa.ms)."
"\nIf you have any questions or require assistance, please contact @jianyuehugo."
"\n- **GitHub Repo**: https://github.com/jianyuelab/jianyuebot"
f"\n- **Bot Version:** {bot_version}"
f"\n- **Bot Build:** {bot_build}"
f"\n- **Settings Version:** {setting_version}"
f"\n- **Build Type:** {[bot_type]}",
ephemeral=True
)
client.run(TOKEN)