]> jfr.im git - erebus.git/commitdiff
new `server` module - !SERVER and !UPTIME commands
authorJohn Runyon <redacted>
Sun, 13 Feb 2022 20:58:59 +0000 (14:58 -0600)
committerJohn Runyon <redacted>
Sun, 13 Feb 2022 20:58:59 +0000 (14:58 -0600)
!SERVER shows the server the bot is currently connected to, as well as when and to where the connection was established.
!UPTIME shows the time since the connection was established, as well as the time the bot process was started

modules/server.py [new file with mode: 0644]

diff --git a/modules/server.py b/modules/server.py
new file mode 100644 (file)
index 0000000..691436a
--- /dev/null
@@ -0,0 +1,54 @@
+# Erebus IRC bot - Author: Erebus Team
+# vim: fileencoding=utf-8
+# This file is released into the public domain; see http://unlicense.org/
+
+import time
+
+# module info
+modinfo = {
+       'author': 'Erebus Team',
+       'license': 'public domain',
+       'compatible': [0], # compatible module API versions
+       'depends': [], # other modules required to work properly?
+       'softdeps': ['help'], # modules which are preferred but not required
+}
+
+# preamble
+import modlib
+lib = modlib.modlib(__name__)
+modstart = lib.modstart
+modstop = lib.modstop
+
+# module code
+def _since(when):
+       duration = time.time() - when
+       days, duration = divmod(duration, 60*60*24)
+       hours, duration = divmod(duration, 60*60)
+       minutes, duration = divmod(duration, 60)
+       seconds = duration
+       output = []
+       if days > 0:
+               output += [str(int(days)), "days" if days > 1 else "day"]
+       if hours > 0:
+               output += [str(int(hours)), "hours" if hours > 1 else "hour"]
+       if minutes > 0:
+               output += [str(int(minutes)), "minutes" if minutes > 1 else "minute"]
+       if seconds > 0:
+               output += [str(int(seconds)), "seconds" if seconds > 1 else "second"]
+       return ' '.join(output)
+
+@lib.hook(needchan=False, wantchan=True)
+@lib.help(None, 'identifies which server the bot is connected to')
+def server(bot, user, chan, realtarget, *args):
+       if chan is not None: replyto = chan
+       else: replyto = user
+
+       bot.msg(replyto, "Connected to %s (from %s:%s) since %s UTC" % (bot.servername, bot.server, bot.port, time.asctime(time.gmtime(bot.connecttime))))
+
+@lib.hook(needchan=False, wantchan=True)
+@lib.help(None, 'shows the uptime of the bot')
+def uptime(bot, user, chan, realtarget, *args):
+       if chan is not None: replyto = chan
+       else: replyto = user
+
+       bot.msg(replyto, "This bot has been connected %s (process uptime %s)" % (_since(bot.connecttime), _since(bot.parent.starttime)))