-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuptime.py
57 lines (46 loc) · 1.98 KB
/
uptime.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
import os
import datetime as dt
import humanize
import helperfunctions
from helperfunctions import pick_string
import boto3
global db
db = boto3.client('dynamodb', region_name='us-east-2')
global record_uptime
record_uptime = dt.timedelta(seconds= 0)
start_time = dt.datetime.now()
class uptime:
def init():
d = db.get_item(TableName="trashbot", Key={'name':{'S':'uptime'}})
global record_uptime
if ('data' in d['Item']):
record_uptime = dt.timedelta(seconds=float(d['Item']['data']['S']))
async def run(self, message):
global record_uptime
if message.content == "!uptime":
t = dt.datetime.now() - start_time
s = humanize.precisedelta(t)
await message.channel.send(pick_string([
"Trashbot has been up for " + s + ". wow!",
"ya boi's been going for " + s + " aye!",
"choo choo! this train's been goin for like " + s + " or smth!",
"uh probably like " + s + " or something idk",
"thanks for asking! i've been up for " + s + "."
]))
if t > record_uptime:
record_uptime = t
uptime.save(record_uptime)
await message.channel.send(pick_string([
"hey, that's a new record!",
"whoa, i've never been up that long before!",
"ding ding! thas a record!"
]))
if message.content == "!recorduptime":
s = humanize.precisedelta(dt.datetime(record_uptime))
message.channel.send(pick_string([
"the longest i've been up is " + s + "!",
"my current record for staying awake is " + s + "!",
"my longest uptime is " + s + ", but i bet i could do better!"
]))
def save(t):
db.put_item(TableName="trashbot", Item={'name':{'S':'uptime'}, 'data':{'S':str(t.total_seconds())}})