]> jfr.im git - erebus.git/blame - modules/foo.py
Merge branch 'master' of github.com:zonidjan/erebus
[erebus.git] / modules / foo.py
CommitLineData
9bd05cf6 1# Erebus IRC bot - Author: Erebus Team
931c88a4 2# simple module example
3# This file is released into the public domain; see http://unlicense.org/
4
e4255e70 5# module info
6modinfo = {
9bd05cf6 7 'author': 'Erebus Team',
e4255e70 8 'license': 'public domain',
fa93b933 9 'compatible': [0], # compatible module API versions
e4255e70 10 'depends': [], # other modules required to work properly?
a62d0d18 11 'softdeps': ['help'], # modules which are preferred but not required
e4255e70 12}
a62d0d18 13# note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists)
14# 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.
15#
16# basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded)
17# for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded
e4255e70 18
6c70d82c 19# preamble
20import modlib
21lib = modlib.modlib(__name__)
22modstart = lib.modstart
db50981b 23modstop = lib.modstop
6c70d82c 24
e4255e70 25# module code
f5aec865 26@lib.hook(needchan=False, wantchan=True) #since no cmd= is provided, defaults to function name
fb20be7c 27@lib.help('<args>', 'tells you what you said')
28def test(bot, user, chan, realtarget, *args):
f5aec865 29 if chan is not None: replyto = chan
586997a7 30 else: replyto = user
31
8583bc12 32 bot.msg(replyto, "You said: %s" % (' '.join([str(arg) for arg in args])))
fb20be7c 33
34@lib.hook(('foo', 'bar'), needchan=False) #hooks !foo and !bar as aliases
0f8352dd 35@lib.help(None, 'replies with nonsense.', "it's a very non-sensical command", "more lines")
fb20be7c 36def foobar(bot, user, chan, realtarget, *args):
37 bot.msg(user, "Foo bar baz.")
4773e2cf 38
39@lib.hook()
40@lib.help(None, 'a command that does nothing but requires you specify a channel')
41def needchan(bot, user, chan, realtarget, *args):
42 bot.msg(user, "You did it!")
f5aec865 43
44@lib.hook(needchan=False, wantchan=True)
45@lib.help(None, 'a command which will consume a channel if given')
46 if chan is not None:
47 bot.msg(user, "Channel provided: %s" % (chan))
48 else:
49 bot.msg(user, "No channel provided")