-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.py
128 lines (104 loc) · 3.98 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
import discord
import asyncio
import time
import sys
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from stats import Stats
from API import API
from update import Update
from util import Util
from post import Post
token = open('token.txt',"r").read().strip()
client = discord.Client()
@client.event
async def on_read():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.content.startswith('!test'):
counter = 0
tmp = await client.send_message(message.channel, 'Calculating messages...')
async for log in client.logs_from(message.channel, limit=100):
if log.author == message.author:
counter += 1
await client.edit_message(tmp, 'You have {} messages.'.format(counter))
elif message.content.startswith('!sleep'):
await asyncio.sleep(5)
await client.send(message.channel, 'Done sleeping')
#elif message.content.find("cv"):
#await client.send_message(message.channel,'ree')
#elif(int(message.content.find('cv'))>=0):
#print(str(message.channel)+": "+message.content+" "+str(message.timestamp))
#await client.send_message(message.channel,'ree')
elif(message.content.startswith('cv')):
await client.send_message(message.channel,'reee')
elif(message.content.startswith('!stop')):
exit()
sys.exit()
elif(message.content.startswith('!getID')):
temp = message.content
inputname = temp[7:]
api = API()
playerID = api.getPlayerID(inputname)
playername = api.getPlayerName(playerID)
ret = playername+"'s ID: "+str(playerID)
await client.send_message(message.channel,ret)
elif(message.content.startswith("!stats")):
temp = message.content
inputname = temp[7:]
api = API()
playerID = api.getPlayerID(inputname)
playername = api.getPlayerName(playerID)
playerstats = api.getPlayerStats(playerID)
print(playerstats)
ret = str(api.getPlayerStats(playerID))[:2000]
await client.send_message(message.channel,ret)
elif(message.content.startswith('!embed')):
temp = message.content
input = temp[7:]
await client.send_message(message.channel,str('Processing '+input+' Statistics'))
a = API()
if(len(a.getClanMembers(a.getClanID(input)))>25):
embed0 = await postValues(input,0,24)
await client.send_message(message.channel,embed=embed0)
embed1 = await postValues(input,25,50)
await client.send_message(message.channel,embed=embed1)
else:
embed = await postValues(input,0,25)
await client.send_message(message.channel,embed=embed)
print(str(message.channel)+": "+message.content)
async def postValues(clanname,start,end):
start_time=time.time()
embed = discord.Embed()
#TODO: Check member size to determine if multiple embeds are required
p = Post()
a = API()
u = Util()
embed = p.createEmbed(clanname,embed,start,end)
postname = "["+str(clanname)+"] "+a.getClanName(a.getClanID(clanname))+" Statistics"
embed.set_author(name=postname, icon_url=client.user.default_avatar_url)
runtime = "Runtime: "+str(u.round3(time.time()-start_time))+" Seconds"
embed.set_footer(text=str(runtime))
return embed
def scheduled_job():
print("Updated Started")
#TODO: send a discord message
u = Update()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(u.saveExpValues())
loop.run_until_complete(u.saveStats())
t = Util()
print("Update Finished: "+str(t.getGMTTime()))
if(__name__=="__main__"):
sched = AsyncIOScheduler()
sched.add_job(scheduled_job,'cron',hour=5,minute=37,timezone='UTC')
sched.start()
print("Scheduler Started")
print("Bot Started")
client.run(token)
a = API()
print(a.getClanMembers('MIA-E'))