--- /dev/null
+# 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)