From: John Runyon Date: Mon, 4 Sep 2023 02:57:19 +0000 (-0600) Subject: add admin_config module with SETCONFIG and DELCONFIG command X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/017b57a012e44705df2093cf33021eda12fd25af add admin_config module with SETCONFIG and DELCONFIG command --- diff --git a/modules/admin_config.py b/modules/admin_config.py new file mode 100644 index 0000000..7caf6d0 --- /dev/null +++ b/modules/admin_config.py @@ -0,0 +1,60 @@ +# Erebus IRC bot - Author: Erebus Team +# vim: fileencoding=utf-8 +# simple module example +# This file is released into the public domain; see http://unlicense.org/ + +# 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 + +def _resolve_user(s): + if s.startswith("#"): + return lib.parent.User(s, s[1:]) + else: + return lib.parent.user(s, create=False) + +def _resolve_level(s): + try: + i = int(s) + return i + except ValueError: + su = s.upper() + if su == "ANYONE": + su = "AUTHED" # resolve to 0 instead of -1 + if su in lib.glevs: + return lib.glevs[su] + return None + +@lib.hook(needchan=False, glevel=lib.OWNER) +@lib.help('
', 'sets a config file setting to a new value') +@lib.argsGE(3) +def setconfig(bot, user, chan, realtarget, *args): + section, key, value = args[0], args[1], ' '.join(args[2:]) + bot.parent.cfg.set(section, key, value) + return "Set `[%s] %s` to: %s" % (section, key, value) + +@lib.hook(needchan=False, glevel=lib.OWNER) +@lib.help('
', 'deletes a config file setting') +@lib.argsEQ(2) +def delconfig(bot, user, chan, realtarget, *args): + section, key = args[0], args[1] + bot.parent.cfg.delete(section, key) + return "Deleted `[%s] %s`" % (section, key)