]>
jfr.im git - erebus.git/blob - modules/bashorg.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
4 # This file is released into the public domain; see http://unlicense.org/
6 # Note: this basically requires nofakelag since quotes can be many lines
8 # The config value [bashorg] path must point to a folder with
9 # files named like 0030507.txt for quote #30507 ("%07d.txt")
13 'author': 'Erebus Team',
14 'license': 'public domain',
15 'compatible': [0], # compatible module API versions
16 'depends': [], # other modules required to work properly?
17 'softdeps': ['help'], # modules which are preferred but not required
19 # note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists)
20 # 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.
22 # basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded)
23 # for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded
27 lib
= modlib
.modlib(__name__
)
28 modstart
= lib
.modstart
34 @lib.hook(('bash','bashorg','bash.org'), needchan
=False, wantchan
=True)
35 @lib.help('[<number>]', 'gives you a bash.org quote')
36 def bash(bot
, user
, chan
, realtarget
, *args
):
37 path
= bot
.parent
.cfg
.get('bashorg', 'path')
38 target
= chan
if chan
else user
41 filename
= random
.choice(os
.listdir(path
))
42 number
= int(filename
[:-4])
43 which
= os
.path
.join(path
, filename
)
46 filename
= "%07d.txt" % (number
)
47 which
= os
.path
.join(path
, filename
)
48 if not os
.path
.isfile(which
):
49 return "That quote doesn't exist!"
51 return "Invalid quote number."
54 target
.msg("--- bash.org #%d" % (number
))