This repository was archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
58 lines (45 loc) · 1.53 KB
/
core.py
File metadata and controls
58 lines (45 loc) · 1.53 KB
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
from discordbot.module import Module
import discord
import datetime
class Core(Module):
name = 'core'
uptime = None
msg = []
init = datetime.datetime.now()
def bot(self):
if 'core' in self.container.config['global']:
self.config = self.container.config['global']['core']
if 'website' in self.config:
self.msg.append(self.config['website'])
self.msg.append('Uptime: {}')
if 'description' in self.config and type(self.config['description']) is list:
self.msg.append('\n'.join(self.config['description']))
async def on_message(self, message: discord.Message):
if self.is_my(message):
return False
if self.has_command('info', message):
self.uptime = self.__uptime()
await self.container.client.send_message(
message.channel,
'\n'.join(self.msg).format(self.uptime)
)
def __uptime(self):
def plural(val):
if val == 1:
return ''
else:
return 's'
diff = datetime.datetime.now() - self.init
hours = (diff.seconds // 3600) % 24
minutes = (diff.seconds // 60) % 60
seconds = diff.seconds % 60
return '{} day{} {} hour{} {} minute{} {} second{}'.format(
diff.days,
plural(diff.days),
hours,
plural(hours),
minutes,
plural(minutes),
seconds,
plural(seconds),
)