-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
427 lines (356 loc) · 12.4 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
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
import os
import random
from dotenv import load_dotenv
from discord.ext import commands
import asyncio
import emoji
from bs4 import BeautifulSoup
import requests
import discord
from fake_useragent import UserAgent
from datetime import datetime
import pandas as pd
import time
# NzU0Mjg1NzUzNDU0MDM0OTg0.X1yhWQ.a4qGLUjqUJksH7_xWYDsW2jkX0w
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='+')
ua={"UserAgent":'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0'}
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
while True:
await bot.change_presence(activity=discord.Game(name="Ipl 2021"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Ipl21 Live Score"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Ipl21 Schedule"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Ipl21 Next Match"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Ipl21 Point Table"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Ipl21 Comentatry"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Ipl21 Live Score Board"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Spamming"))
await asyncio.sleep(10)
await bot.change_presence(activity=discord.Game(name="Type +help for HELP"))
await asyncio.sleep(10)
@bot.command(name='hello')
async def stts(ctx):
await ctx.trigger_typing()
await ctx.send(f"Namaste {ctx.author.mention}")
def get_score(team):
flag=0
tm =""
ind= 0
for index , i in enumerate(team):
if i == ')':
tm = tm + i
ind = index
break
elif not i.isalpha() and flag==0:
# print(i)
tm+=" "+i
flag = 1
elif not i.isalpha() and flag==1:
# print(i)
tm+=i
else:
tm+=i
# print(tm)
tm+='\n'
y =team[ind+2:]
flag = 0
for index , i in enumerate(y):
if not i.isalpha() and flag==0:
# print(i)
tm+=" "+i
flag = 1
elif not i.isalpha() and flag==1:
# print(i)
tm+=i
else:
tm+=i
return tm
def get_right(team):
flag=0
tm1 =""
for i in team:
if i =='(':
tm1+=" -> "
flag=1
if i ==')':
tm1+=i
tm1+=' , '
continue
if not i.isalpha() and flag==0:
tm1+=" -> "
flag=1
tm1+=i
return tm1
@bot.command(help='Shows IPL Live Score')
async def ls(ctx):
await ctx.trigger_typing()
# url = "https://iplt20api.herokuapp.com/livescore"
url="https://www.cricbuzz.com/cricket-match/live-scores"
res = requests.get(url , headers = ua)
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None,requests.get,url)
res = await future
soup = BeautifulSoup(res.content , features='lxml')
head = soup.findAll(class_='cb-lv-scrs-well-live') #cb-lv-scrs-well-live cb-lv-scrs-well-complete
if len(head) > 0:
y = get_score(head[0].get_text().lstrip())
else:
y = "No Current Match Is Running"
print(y)
embed = discord.Embed(color=0x7e76dc, title='Live Score')
desc='```arm\n'
desc+=y+"\n"
# desc+=tm2+"\n"
# desc+=status+"\n"
desc += '```'
embed.description = desc
await ctx.send(embed=embed)
# await ctx.send(head + "\n" + tm1 + "\n"+tm2 + "\n" + status)
@bot.command()
async def nm(ctx):
await ctx.trigger_typing()
url = "https://iplt20api.herokuapp.com/nextmatch"
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None, requests.get, url)
res = await future
y = res.json()
embed = discord.Embed(color=0x7e76dc, title='IPL 2021 Next Match')
desc='```arm\n'
desc+= y['Team']+"\n"
desc+=y['Date']+"\n"
desc+=y['Time']+"\n"
desc += '```'
embed.description = desc
await ctx.send(embed=embed)
Team_name=['DC', 'CSK','RCB','KKR','KXIP','RR','MI','SRH']
@bot.command(help='Shows IPL Schedule (Add agrue [+sc 2 ,3 , 4..])')
async def sc(ctx , cnt:int):
await ctx.trigger_typing()
if cnt >=15:
return await ctx.send(f"Sorry {ctx.author.mention} I Can Only Respond Upto 17 Count "+emoji.emojize(":pensive:"))
url = "https://www.firstpost.com/firstcricket/cricket-schedule/series/ipl-2021.html"
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None, requests.get, url)
res = await future
soup = BeautifulSoup(res.content , features='lxml')
data =soup.findAll(class_='schedule-head')
team_name = soup.findAll(class_='sc-match-name')
time = soup.findAll(class_='sc-label-val')
tm=0
day = datetime.now().date().day
# print(day , "cfdscdfc")
embed = discord.Embed(color=0xff0000, title='Ipl 2021 Schedule ')
desc='```\n'
i = 0
k = 1
while k <= cnt:
if i < len(data) and i <len(team_name) and tm < len(time):
y = data[i].get_text().strip()
y = y.replace('\n' , ' ')
y = y.replace('\t' , '')
y = y[:6]
# print(y.split(' ')[0],'decfdcdffvfd')
p = time[tm].get_text().strip()
p = p.replace('\n' , ' ')
p = p.replace('\t' , '')
r = time[tm+1].get_text().strip()
r = r.replace('\n' , ' ')
r = r.replace('\t' , '')
tm=tm+2
if int(y.split(' ')[0]) >= int(day):
k = k+1
desc+=team_name[i].get_text().strip()+'\n'+p+" "+r+" "+y+"\n\n"
# print(k)
if k <= cnt:
desc+='```'+'```'+'\n\n'
i = i+1
desc += '```'
embed.description = desc
await ctx.send(embed=embed)
@bot.command(help='Shows IPL point table')
async def pt(ctx):
await ctx.trigger_typing()
url = 'https://www.espncricinfo.com/series/ipl-2021-1249214'
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None, requests.get, url)
res = await future
soup = BeautifulSoup(res.content , features='lxml')
points = soup.findAll(class_='pr-3')
team = soup.findAll(class_='text-left')
teams=[]
for i in range(1 , 9):
teams.append(team[i].get_text())
match =[]
win=[]
loss=[]
point=[]
nr=[]
flag = 0
for i in range(5 , 45):
y = points[i].get_text()
if flag == 0:
match.append(y)
flag=1
continue
if flag ==1:
win.append(y)
flag=2
continue
if flag == 2:
loss.append(y)
flag=3
continue
if flag ==3:
point.append(y)
flag=4
continue
if flag == 4 :
nr.append(y)
flag=0
embed = discord.Embed(color=0x7e76dc, title='IPL 2021 Point Table')
desc='```arm\n'
desc+='Team Match Win Loss Point NRR\n'
desc+='---- ----- --- ---- ----- -----\n'
for i in range(0, 8):
if (nr[i][0] == '-' and len(nr[i]) == 5) or len(nr[i]) == 4:
nr[i] += '0'
desc += teams[i] + ' ' * (9 - len(teams[i]) - len(match[i]))
desc += match[i] + ' ' * (6 - len(win[i]))
desc += win[i] + ' ' * (6 - len(loss[i]))
desc += loss[i] + ' ' * (6 - len(point[i]))
desc += point[i] + ' ' * (9 - len(nr[i])) + nr[i] + '\n'
desc += '```'
embed.description = desc
await ctx.send(embed=embed)
@bot.command(help='Spam Six')
async def six(ctx):
await ctx.trigger_typing()
for i in range(0,15):
await asyncio.sleep(1)
await ctx.send(emoji.emojize(":six:")+emoji.emojize(":fire:") , delete_after=25)
@bot.command(help='Spam Four')
async def four(ctx):
await ctx.trigger_typing()
for i in range(0,15):
await asyncio.sleep(1)
await ctx.send(emoji.emojize(":four:"), delete_after=25)
@bot.command(help='Spam out')
async def out(ctx):
await ctx.trigger_typing()
for i in range(0,15):
await asyncio.sleep(1)
await ctx.send("Out"+" "+emoji.emojize(u'\U0001F625') , delete_after=25)
@bot.command(help='Spam Freehit')
async def freehit(ctx):
await ctx.trigger_typing()
for i in range(0,15):
await asyncio.sleep(1)
await ctx.send("Hurray FreeHit"+emoji.emojize(u'\U0001F57A') , delete_after=25)
@bot.command(help='For Spamming (+ipl argu)')
async def ipl(ctx , *args):
await ctx.trigger_typing()
for i in range(0,15):
await asyncio.sleep(1)
await ctx.send('{}'.format(' '.join(args)) , delete_after=25)
@bot.command(help='Shows IPL Live Score Board')
async def lb(ctx):
await ctx.trigger_typing()
url = "https://www.cricbuzz.com/cricket-schedule/upcoming-series/league"
res = requests.get(url , headers=ua)
soup =BeautifulSoup(res.content , features='lxml')
data1 = soup.findAll('div' , {'class':'cb-adjst-lst'})
y = data1[0].find('a').get('href')
url1 = 'https://www.cricbuzz.com'+str(y)
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None, requests.get, url1)
res = await future
soup = BeautifulSoup(res.content , features='lxml')
data = soup.findAll(class_='cb-min-inf')
# print(data)
embed = discord.Embed(color=0x7e76dc, title="Live Score Board")
desc='```arm\n'
for ind , val in enumerate(data):
if ind ==1:
desc+='\n'+'------------------------------------'
for i , k in enumerate(val) :
if i == 1 or i == 3:
desc+="\n"
desc+="\n"
for j in k:
# print(j.get_text() , end=" ")
desc+=j.get_text()+" "
desc += '```'
embed.description = desc
# print(desc)
if desc =='```arm'+"\n"+'```':
return await ctx.send("No Current IPL Match Is Going")
await ctx.send(embed=embed)
@bot.command(help = 'Shows stats')
async def stats(ctx):
await ctx.trigger_typing()
url = "https://www.cricbuzz.com/cricket-schedule/upcoming-series/league"
res = requests.get(url , headers=ua)
soup =BeautifulSoup(res.content , features='lxml')
data1 = soup.findAll('div' , {'class':'cb-adjst-lst'})
y = data1[0].find('a').get('href')
url1 = 'https://www.cricbuzz.com'+str(y)
# print(url1)
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None, requests.get, url1)
res = await future
soup = BeautifulSoup(res.content , features='lxml')
data = soup.findAll(class_='cb-key-st-lst')
if len(data)==0 :
return await ctx.send("No Current IPL Match Is Going")
embed = discord.Embed(color=0x7e76dc, title="Key Stats")
desc='```arm\n'
desc+=data[0].get_text()[13:33]+'\n'
rest = data[0].get_text()[32:].split(':')
desc+=rest[0]+' : '+rest[1].split(',')[0].strip()+' ,'+rest[1].split(',')[1].strip()[0:7] +'\n'
desc+=rest[1].split(',')[1].strip()[9:]+' : '+rest[len(rest)-1]+'\n'
desc += '```'
embed.description = desc
await ctx.send(embed=embed)
# @bot.command(help='Shows IPL Live Comentatry')
# async def cm(ctx):
# await ctx.trigger_typing()
# url="https://www.espncricinfo.com/series/8048/game/1216533/chennai-super-kings-vs-rajasthan-royals-37th-match-indian-premier-league-2020-21"
# print(ctx.author.id)
# if str(ctx.author.id) != "640108121804636160":
# return await ctx.send("This Operation is only performed by Owner")
# store=""
# dict1={}
# while(True):
# store=""
# res = requests.get(url , headers=ua)
# soup = BeautifulSoup(res.content , features='lxml')
# data = soup.findAll(class_='match-comment-long-text')
# ball_up = soup.findAll(class_='match-comment-short-text')
# store+=ball_up[0].get_text()+"\n"
# store+=data[0].get_text()+"\n"
# if store in dict1:
# time.sleep(10)
# continue
# dict1[store]=1
# now = datetime.now().time() # time object
# now = str(now)
# embed = discord.Embed(color=0x7e76dc, title="Time ->"+now[:5])
# desc='```arm\n'
# desc+= ball_up[0].get_text()
# desc+="\n"
# desc+=data[0].get_text()
# desc += '```'
# embed.description = desc
# # print(store)
# await ctx.send(embed=embed)
bot.run(TOKEN)