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