aboutsummaryrefslogtreecommitdiff
path: root/modules/info.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-08-12 17:29:01 +0100
committerGravatar jesopo2019-08-12 17:29:01 +0100
commitfc5e3d39369fbb514a1e13e2e71b9ca864c24a4f (patch)
tree8a3c1a14f79ea9b3b9fdc3e11f41fe073df7d3c7 /modules/info.py
parentsuggest similar feeds when trying to remove an unknown feed (diff)
signature
add !version and !source
closes #84
Diffstat (limited to 'modules/info.py')
-rw-r--r--modules/info.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/info.py b/modules/info.py
new file mode 100644
index 00000000..ee67c3e4
--- /dev/null
+++ b/modules/info.py
@@ -0,0 +1,29 @@
+import os
+from src import IRCBot, ModuleManager, utils
+
+class Module(ModuleManager.BaseModule):
+ @utils.hook("received.command.version")
+ def version(self, event):
+ commit_hash = None
+ git_dir = os.path.join(self.bot.directory, ".git")
+ head_filepath = os.path.join(git_dir, "HEAD")
+ print(head_filepath)
+ if os.path.isfile(head_filepath):
+ ref = None
+ with open(head_filepath, "r") as head_file:
+ ref = head_file.readline().split(" ", 1)[1].strip()
+
+ ref_filepath = os.path.join(git_dir, ref)
+ print(ref_filepath)
+ if os.path.isfile(ref_filepath):
+ with open(ref_filepath, "r") as ref_file:
+ commit_hash = ref_file.readline().strip()
+
+ out = "Version: BitBot %s" % IRCBot.VERSION
+ if not commit_hash == None:
+ out = "%s (%s)" % (out, commit_hash[:8])
+ event["stdout"].write(out)
+
+ @utils.hook("received.command.source")
+ def source(self, event):
+ event["stdout"].write("Source: %s" % IRCBot.SOURCE)