]> jfr.im git - erebus.git/blob - modules/server.py
691436a4a22e1ee6b09973ad9204d831b7c6cbc2
[erebus.git] / modules / server.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # This file is released into the public domain; see http://unlicense.org/
4
5 import time
6
7 # module info
8 modinfo = {
9 'author': 'Erebus Team',
10 'license': 'public domain',
11 'compatible': [0], # compatible module API versions
12 'depends': [], # other modules required to work properly?
13 'softdeps': ['help'], # modules which are preferred but not required
14 }
15
16 # preamble
17 import modlib
18 lib = modlib.modlib(__name__)
19 modstart = lib.modstart
20 modstop = lib.modstop
21
22 # module code
23 def _since(when):
24 duration = time.time() - when
25 days, duration = divmod(duration, 60*60*24)
26 hours, duration = divmod(duration, 60*60)
27 minutes, duration = divmod(duration, 60)
28 seconds = duration
29 output = []
30 if days > 0:
31 output += [str(int(days)), "days" if days > 1 else "day"]
32 if hours > 0:
33 output += [str(int(hours)), "hours" if hours > 1 else "hour"]
34 if minutes > 0:
35 output += [str(int(minutes)), "minutes" if minutes > 1 else "minute"]
36 if seconds > 0:
37 output += [str(int(seconds)), "seconds" if seconds > 1 else "second"]
38 return ' '.join(output)
39
40 @lib.hook(needchan=False, wantchan=True)
41 @lib.help(None, 'identifies which server the bot is connected to')
42 def server(bot, user, chan, realtarget, *args):
43 if chan is not None: replyto = chan
44 else: replyto = user
45
46 bot.msg(replyto, "Connected to %s (from %s:%s) since %s UTC" % (bot.servername, bot.server, bot.port, time.asctime(time.gmtime(bot.connecttime))))
47
48 @lib.hook(needchan=False, wantchan=True)
49 @lib.help(None, 'shows the uptime of the bot')
50 def uptime(bot, user, chan, realtarget, *args):
51 if chan is not None: replyto = chan
52 else: replyto = user
53
54 bot.msg(replyto, "This bot has been connected %s (process uptime %s)" % (_since(bot.connecttime), _since(bot.parent.starttime)))