]> jfr.im git - erebus.git/commitdiff
add bashorg module
authorJohn Runyon <redacted>
Sat, 12 Aug 2023 07:55:18 +0000 (01:55 -0600)
committerJohn Runyon <redacted>
Sat, 12 Aug 2023 07:55:18 +0000 (01:55 -0600)
bot.config.example
modules/bashorg.py [new file with mode: 0644]

index b69aa76bfc0d3982b2a1c6c273f2725209f7c03a..5a475516c9d99f434c5a5ea0a0aa36dac2eb0f4f 100644 (file)
@@ -31,3 +31,13 @@ mynumber = +11234567890 (sms "callerid")
 
 [help]
 url = https://where.ever/dir/%d.txt
+
+[reddark]
+update_interval = 600
+topicsuffix = | Something something mumble mumble
+
+[weatherstack_weather]
+key = your API Key
+
+[bashorg]
+path = /home/erebus/bash.org/
diff --git a/modules/bashorg.py b/modules/bashorg.py
new file mode 100644 (file)
index 0000000..457ecb3
--- /dev/null
@@ -0,0 +1,56 @@
+# Erebus IRC bot - Author: Erebus Team
+# vim: fileencoding=utf-8
+# bash.org quoter
+# This file is released into the public domain; see http://unlicense.org/
+
+# Note: this basically requires nofakelag since quotes can be many lines
+
+# The config value [bashorg] path must point to a folder with
+# files named like 0030507.txt for quote #30507 ("%07d.txt")
+
+# 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
+}
+# note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists)
+# however, if it is disabled it will be silently ignored, and if it is unloaded at runtime it won't cause this one to unload.
+#
+# basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded)
+# for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded
+
+# preamble
+import modlib
+lib = modlib.modlib(__name__)
+modstart = lib.modstart
+modstop = lib.modstop
+
+# module code
+import os, random
+
+@lib.hook(needchan=False, wantchan=True)
+@lib.help('[<number>]', 'gives you a bash.org quote')
+def bash(bot, user, chan, realtarget, *args):
+       path = bot.parent.cfg.get('bashorg', 'path')
+       target = chan if chan else user
+       try:
+               if len(args) == 0:
+                       filename = random.choice(os.listdir(path))
+                       number = int(filename[:-4])
+                       which = os.path.join(path, filename)
+               else:
+                       number = int(args[0])
+                       filename = "%07d.txt" % (number)
+                       which = os.path.join(path, filename)
+                       if not os.path.isfile(which):
+                               return "That quote doesn't exist!"
+       except ValueError:
+               return "Invalid quote number."
+
+       fh = open(which, 'r')
+       target.msg("--- bash.org #%d" % (number))
+       for line in fh:
+               target.msg(line)