]> jfr.im git - erebus.git/blame - modules/admin_config.py
update comments
[erebus.git] / modules / admin_config.py
CommitLineData
017b57a0
JR
1# Erebus IRC bot - Author: Erebus Team
2# vim: fileencoding=utf-8
bac69af4 3# Commands to change config file settings
017b57a0
JR
4# This file is released into the public domain; see http://unlicense.org/
5
6# module info
7modinfo = {
8 'author': 'Erebus Team',
9 'license': 'public domain',
10 'compatible': [0], # compatible module API versions
11 'depends': [], # other modules required to work properly?
12 'softdeps': ['help'], # modules which are preferred but not required
13}
14# note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists)
15# 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.
16#
17# basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded)
18# for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded
19
20# preamble
21import modlib
22lib = modlib.modlib(__name__)
23modstart = lib.modstart
24modstop = lib.modstop
25
26# module code
27
28def _resolve_user(s):
29 if s.startswith("#"):
30 return lib.parent.User(s, s[1:])
31 else:
32 return lib.parent.user(s, create=False)
33
34def _resolve_level(s):
35 try:
36 i = int(s)
37 return i
38 except ValueError:
39 su = s.upper()
40 if su == "ANYONE":
41 su = "AUTHED" # resolve to 0 instead of -1
42 if su in lib.glevs:
43 return lib.glevs[su]
44 return None
45
46@lib.hook(needchan=False, glevel=lib.OWNER)
47@lib.help('<section> <key> <value>', 'sets a config file setting to a new value')
48@lib.argsGE(3)
49def setconfig(bot, user, chan, realtarget, *args):
50 section, key, value = args[0], args[1], ' '.join(args[2:])
51 bot.parent.cfg.set(section, key, value)
52 return "Set `[%s] %s` to: %s" % (section, key, value)
53
54@lib.hook(needchan=False, glevel=lib.OWNER)
55@lib.help('<section> <key>', 'deletes a config file setting')
56@lib.argsEQ(2)
57def delconfig(bot, user, chan, realtarget, *args):
58 section, key = args[0], args[1]
59 bot.parent.cfg.delete(section, key)
60 return "Deleted `[%s] %s`" % (section, key)