]> jfr.im git - erebus.git/blame - modules/control.py
userinfo - create json file if it doesnt exist
[erebus.git] / modules / control.py
CommitLineData
e2b30093 1# Erebus IRC bot - Author: Erebus Team
4df64299 2# Various highly recommended "control" commands.
e2b30093 3# This file is released into the public domain; see http://unlicense.org/
4
5# module info
6modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1],
10 'depends': [],
11}
12
13# preamble
14import modlib
15lib = modlib.modlib(__name__)
16modstart = lib.modstart
17modstop = lib.modstop
18
19# module code
20import sys
21import ctlmod
22
23
fb20be7c 24@lib.hook(needchan=False, glevel=lib.MANAGER)
25def die(bot, user, chan, realtarget, *args):
574ce192 26 for botitem in bot.parent.bots.itervalues():
27 for chan in botitem.chans:
28 chan.fastmsg("Bot is restarting! %s" % ' '.join(args))
29 bot.conn.send("QUIT :Restarting.")
e2b30093 30 sys.exit(0)
31 os._exit(0)
4df64299 32
fb20be7c 33@lib.hook(needchan=False, glevel=lib.MANAGER)
4df64299 34@lib.argsEQ(1)
fb20be7c 35def modload(bot, user, chan, realtarget, *args):
4df64299 36 okay = ctlmod.load(bot.parent, args[0])
37 if okay:
38 bot.msg(user, "Loaded %s" % (args[0]))
39 else:
40 bot.msg(user, "Error loading %s: %r" % (args[0], okay))
41
fb20be7c 42@lib.hook(needchan=False, glevel=lib.MANAGER)
4df64299 43@lib.argsEQ(1)
fb20be7c 44def modunload(bot, user, chan, realtarget, *args):
4df64299 45 okay = ctlmod.unload(bot.parent, args[0])
46 if okay:
47 bot.msg(user, "Unloaded %s" % (args[0]))
48 else:
49 bot.msg(user, "Error unloading %s: %r" % (args[0], okay))
50
fb20be7c 51@lib.hook(needchan=False, glevel=lib.MANAGER)
4df64299 52@lib.argsEQ(1)
fb20be7c 53def modreload(bot, user, chan, realtarget, *args):
4df64299 54 okay = ctlmod.reloadmod(bot.parent, args[0])
55 if okay:
56 bot.msg(user, "Reloaded %s" % (args[0]))
57 else:
58 bot.msg(user, "Error occurred: %r" % (okay))
59
fb20be7c 60@lib.hook(needchan=False, glevel=lib.STAFF)
4df64299 61@lib.argsEQ(0)
fb20be7c 62def modlist(bot, user, chan, realtarget, *args):
4df64299 63 mods = ctlmod.modules
64 for mod in mods.itervalues():
65 bot.msg(user, "- %s %r" % (mod.__name__, mod))
66 bot.msg(user, "Done.")
fb20be7c 67
68@lib.hook(cmd='whoami', needchan=False)
69def whoami(bot, user, chan, realtarget, *args):
70 if not user.isauthed():
71 bot.msg(user, "You are not authed.")
72 return
73
74 fillers = {'auth': user.auth}
75 fmt = "You are %(auth)s"
76
77 if user.glevel >= 1:
78 fillers['glevel'] = user.glevel
79 fmt += " (global access: %(glevel)s)"
80 else:
81 fmt += " (not staff)"
82
83 if chan is not None and chan.levelof(user.auth) >= 1:
84 fillers['clevel'] = chan.levelof(user.auth)
85 fmt += " (channel access: %(clevel)s)"
86 else:
87 fmt += " (not a channel user)"
88 bot.msg(user, fmt % fillers)