forked from opencodeiiita/OC-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
428 lines (331 loc) · 13.9 KB
/
main.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
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
from discord.ext import commands
import discord
from server import start
import json
from dotenv import load_dotenv
import os
import requests
import random
import openai
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='-', intents=intents)
separators = [":", "-", "="]
@bot.command()
async def chat(ctx, *args):
prompt = " ".join(args)
response = openai.Completion.create(
engine='text-davinci-003', prompt=prompt, max_tokens=1000)
await ctx.send(response.choices[0].text)
@bot.event
async def on_ready():
print('ready')
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send('Enter a Valid command, Ciao')
@bot.command()
async def hi(ctx):
await ctx.send("Hello!!")
@bot.command()
async def avatar(ctx, *, member: discord.Member = None):
if member == None:
embed = discord.Embed(description='Can you please specify a User dum dum!',
color=discord.Color.red())
await ctx.reply(embed=embed)
else:
Avatar = member.avatar
embed = discord.Embed(
title=(f'Avatar of {member.name}:'), colour=0x109319)
embed.set_image(url=f'{Avatar}')
await ctx.reply(embed=embed)
@bot.command()
async def lb(ctx):
tempData = requests.get(
f'https://leaderboard-response-cache.anurag10jain.repl.co/get-all-data')
tempData = tempData.json()
userArray = list()
pointsArray = list()
imageArray = list()
for i in range(10):
tempJson = tempData["data"][i]
userArray.append(tempJson["username"])
pointsArray.append(tempJson["total_points"])
imageArray.append(tempJson["image"])
embed = discord.Embed(title="LeaderBoard", url="https://manas2403.github.io/Opencode-Leaderboard/",
description="Contributers in OpenCode 22", color=0x00FFFF)
embed.add_field(
name=chr(173), value="```--------Top 10 Contibuters--------```", inline=False)
for i in range(10):
embed.add_field(
name=f'***Rank #{i+1}***', value=f'*{userArray[i]}* ➤ `{pointsArray[i]}`', inline=False)
embed.set_thumbnail(
url="https://cdn.discordapp.com/icons/885149696249708635/6f1402c1fbaae5dbca952b011cb7a504.png")
await ctx.send(embed=embed)
@bot.command()
async def weather(ctx, args):
res = requests.get(
f'https://api.openweathermap.org/data/2.5/weather?q={args}&appid={os.getenv("API_KEY")}')
tempData = res.json()
weather = tempData['weather'][0]
file = discord.File(
f'icons/weather/{weather["icon"]}.png', filename="image.png")
embed = discord.Embed(title="Weather Report", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley",
description=f'{tempData["name"]}', color=0x109319)
embed.set_thumbnail(url="attachment://image.png")
embed.add_field(name=f'{weather["main"]}',
value=f'{weather["description"]}', inline=False)
embed.add_field(name='Temperature:',
value=f'{round(tempData["main"]["temp"]-273.14,2)}°C', inline=True)
embed.add_field(name="Feels Like:",
value=f'{round(tempData["main"]["feels_like"]-273.14,2)}°C', inline=True)
embed.add_field(name="Temperature Range:",
value=f'{round(tempData["main"]["temp_min"]-273.14,2)}°C-{round(tempData["main"]["temp_max"]-273.14,2)}°C', inline=False)
embed.add_field(name="Pressure",
value=f'{tempData["main"]["pressure"]} N/m2', inline=True)
embed.add_field(name="Humidity:",
value=f'{tempData["main"]["humidity"]} g/kg', inline=True)
embed.add_field(name="Visibility:",
value=f'{tempData["visibility"]}m', inline=True)
embed.set_footer(text="https://openweathermap.org/current")
await ctx.send(file=file, embed=embed)
@bot.command()
async def remove(ctx, args):
serverId = ctx.message.guild.id
if (os.path.exists(f'./tags/{serverId}.json')):
with open(f'./tags/{serverId}.json', 'r') as file:
tempData = json.load(file)
del tempData[args]
with open(f'./tags/{serverId}.json', 'w') as file:
json.dump(tempData, file)
await ctx.send("The command has been successfully removed. Maybe don't be such a crybaby next time and just let the command live!")
else:
await ctx.send("Bruh, first make a command then try to delete it.....")
@bot.command()
async def edit(ctx, *args):
serverId = ctx.message.guild.id
command = args[0]
tempList = list(args)
tempList.pop(0)
message = " ".join(tempList)
dict = {command: message}
if (os.path.exists(f'./tags/{serverId}.json')):
with open(f'./tags/{serverId}.json', 'r') as file:
tempData = json.load(file)
tempData.update(dict)
with open(f'./tags/{serverId}.json', 'w') as file:
json.dump(tempData, file)
await ctx.send("Your command has been successfully edited! Maybe from next time think before making a command, r word...")
else:
await ctx.send("Instead of editing command if you tried to make one first it would be fruitful for both of us, don't you think?")
@bot.command()
async def create(ctx, *args):
serverId = ctx.message.guild.id
command = args[0]
tempList = list(args)
tempList.pop(0)
message = " ".join(tempList)
dict = {command: message}
if os.path.exists(f'./tags/{serverId}.json'):
with open(f'./tags/{serverId}.json', 'r') as file:
tempData = json.load(file)
tempData.update(dict)
with open(f'./tags/{serverId}.json', 'w') as file:
json.dump(tempData, file)
else:
with open(f'./tags/{serverId}.json', 'w') as file:
json.dump(dict, file)
await ctx.send("The command has been successfully created! You can write +tag [command] to check if it is working.")
@bot.command()
async def tag(ctx, args):
serverId = ctx.message.guild.id
with open(f'./tags/{serverId}.json', 'r') as file:
data = json.load(file)
await ctx.send(data[args])
@bot.command()
async def tags(ctx):
serverId = ctx.message.guild.id
embed = discord.Embed(color=0x109319)
tagsString = ""
with open(f'./tags/{serverId}.json', 'r') as file:
data = json.load(file)
index = 1
for key, value in data.items():
tagsString += f'{index}. {key+chr(10)}'
index += 1
embed.add_field(name="The tags made in this server are given below:",
value=tagsString, inline=False)
await ctx.send(embed=embed)
# Discord: Gamma Microwave#4389 GitHub:GammaMicrowave
@ bot.command()
async def GammaMicrowave(ctx):
embed = discord.Embed()
embed.set_image(
url="https://media.giphy.com/media/EtB1yylKGGAUg/giphy.gif")
await ctx.send(embed=embed)
# Github: aasthaaaa7 Discord: Asta.#4094
@bot.command()
async def aasthaaaa7(ctx):
embed = discord.Embed()
embed.set_image(
url="https://media.discordapp.net/attachments/763053037332725790/903827271473844285/image0-15-3.gif")
await ctx.send(embed=embed)
# Discord & Github Name: frikinomad
@ bot.command()
async def frikinomad(ctx):
await ctx.send("Hello, I am frikinomad, I like to code and travel")
# Github: VBajaj113 Discord: im_nothing#4509
@ bot.command()
async def VBajaj113(ctx):
await ctx.send("You should have tagged instead of issuing a bot command if you wanted to talk to me xD!")
# Github: SanyamAgrawal07 Discord: Buzzinga#2392
@ bot.command()
async def SanyamAgrawal07(ctx):
await ctx.send("https://tinyurl.com/jn4x5awv")
# Github: sushantk1274 Discord: sushant#3233
@ bot.command()
async def sushantk1274(ctx):
await ctx.send("Hey,i am sushant contributing in ocbot folder and i am your bot ")
# Github : akshatsgh Discord: strange#0227
@ bot.command()
async def akshatsgh(ctx):
pic_link = "https://source.unsplash.com/random/300%C3%97300/?coder"
await ctx.send(pic_link)
# Github : RibhavBansal Discord: ThunderBeast#1696
@ bot.command()
async def RibhavBansal(ctx):
await ctx.send("Hey, I am Ribhav, I like to develop my skills")
# Github : Koshal7 Discord : Sick Duck#8496
@bot.command()
async def Koshal7(ctx):
await ctx.send("London Me Taxi Chalaega?")
movie_api_key = "ec63f0a6b27d6c92073d8a63ffbc8ec5"
@bot.command()
async def movie(ctx,* ,mystr):
movie_name = mystr.replace(" ","+")
movie_response = requests.get(f'https://api.themoviedb.org/3/search/movie?api_key={movie_api_key}&query={movie_name}')
title = movie_response.json()['results'][0]['original_title']
overview = movie_response.json()['results'][0]['overview']
rating = movie_response.json()['results'][0]['vote_average']
emb=discord.Embed(title=title, description=overview)
emb.set_footer(text=f'Rating : {rating}')
await ctx.send(embed = emb)
@bot.command()
async def quote(ctx):
random_quote = requests.get("https://zenquotes.io/api/random")
quo = random_quote.json()[0]['q']
aut = random_quote.json()[0]['a']
em = discord.Embed(title="Random Quote", description=quo)
em.set_footer(text=f'Author : {aut}')
await ctx.send(embed = em)
# Discord ID: MistyRavager#2412 Github ID: MistyRavager
@ bot.command()
async def MistyRavager(ctx):
separators = [":", "-", "="]
discordIDs = []
with open("main.py", "r") as f:
lines = f.readlines()
comments = [i.strip() for i in lines if i.strip()
!= '' and i.strip()[0] == "#"]
for comment in comments:
sentence = comment.split()
for word in sentence:
if word.find("#") != -1:
index = 0
while (index < len(separators) and word.find(separators[index]) == -1):
index += 1
if index == len(separators):
if word[0] == "#":
continue
discordIDs.append(word)
else:
discordIDs.append(word.split(separators[index])[-1])
res = ""
for i in discordIDs:
res += i+" "
await ctx.send("the following people have made a personal command:")
await ctx.send(res)
@ bot.command()
async def birthdays(ctx):
res = requests.get(
f'https://gpl-at-iiita.anurag10jain.repl.co/')
all_b = res.json()
embed = discord.Embed(title="Birthdays",
description="All Birthdays", color=0x109319)
for each in all_b:
for key in each:
embed.add_field(name=key, value=each[key], inline=True)
@ bot.command()
async def points(ctx, *args):
username = args[0]
found = 0
points = 0
res = requests.get(
"https://leaderboard-response-cache.anurag10jain.repl.co/get-all-data")
data = res.json()
githubID = ""
list_of_participants = data["data"]
for i in list_of_participants:
if i["username"] == username:
found = 1
points = i['total_points']
githubID = i['image'].rstrip(".png")
break
embed = discord.Embed(description=f"Contribution Details of {username}:")
embed.set_thumbnail(
url="https://cdn.discordapp.com/icons/885149696249708635/6f1402c1fbaae5dbca952b011cb7a504.webp?size=128")
if found:
embed.add_field(name="Total Points", value=points, inline=True)
embed.add_field(name="Github ID", value=githubID, inline=True)
else:
embed.add_field(name="Enter correct username dummy",
value=" cuz user not found")
await ctx.send(embed=embed)
@ bot.command()
async def meme(ctx, subreddit=random.choice(["memes", "AdviceAnimals", "ComedyCemetery", "dankmemes"])):
limit_of_memes = 100
res = requests.get(
f"https://www.reddit.com/r/{subreddit}/top.json?limit={limit_of_memes}&t=year", headers={'User-agent': 'yourbot'})
meme_num = random.randint(0, 99)
embed = discord.Embed(title="")
embed.set_author(name=f"Here is a meme for you from {subreddit} subreddit!",
icon_url="https://cdn.discordapp.com/icons/885149696249708635/6f1402c1fbaae5dbca952b011cb7a504.webp?size=128")
if res.status_code != 404 and res.json()['data']['children'] != []:
image = res.json()['data']['children'][meme_num]['data']['url']
embed.set_image(url=image)
string = 'https://reddit.com' + \
res.json()['data']['children'][meme_num]['data']['permalink']
embed.add_field(name="Link:", value=string, inline=True)
else:
embed.set_image(
url="https://media.tenor.com/QSFMj0VddAQAAAAM/hold-on-wait-a-minute.gif")
await ctx.send(embed=embed)
@ bot.command()
async def pokemon(ctx):
index = random.randint(1, 500)
res = requests.get(f"https://pokeapi.co/api/v2/pokemon-species/{index}/")
data = res.json()
name = data['name']
generation = data['generation']['name']
desc = ''
for entry in data['flavor_text_entries']:
if entry['language']['name'] == "en":
desc = entry['flavor_text'].replace('\n', ' ')
embed = discord.Embed(title="Pokemon details")
embed.add_field(name="Name", value=name, inline=False)
embed.add_field(name="Pokedex ID", value=index, inline=False)
embed.add_field(name="Generation name", value=generation, inline=False)
embed.set_image(
url=f"https://img.pokemondb.net/sprites/x-y/normal/{name}.png")
embed.set_footer(text=f"Pokedex Entry: \n{desc}")
await ctx.send(embed=embed)
# Github : JahnaviGadde Discord: JahnaviGadde#0818
@ bot.command()
async def JahnaviGadde(ctx):
await ctx.send("Hello ! I am Jahnavi, This is my first bot command !!!")
start()
# token will be provided with the every claimed issue
# Now add the token in a .env file named TOKEN and it will run automatically
bot.run(os.getenv("TOKEN"))