+++ /dev/null
-# 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
-
-@lib.hook(clevel=lib.FRIEND)
-@lib.help(None, "rejoin a channel (if the bot has been kicked)")
-def rejoin(bot, user, chan, realtarget, *args):
- bot.join(str(chan))
- bot.msg(user, "Rejoined %s." % (chan))
-
-
-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):
- s = s.lower()
- levels = ['unknown'] + [x.lower() for x in lib.clevs if x is not None]
- if s in levels:
- return levels.index(s)
- try:
- return int(s)
- except:
- pass
-
-
-@lib.hook(('clevel','setlevel','chanlev'), clevel=lib.FRIEND)
-@lib.help('<nick|#auth> <level>', "adds or sets a user's channel access level", "Levels: Unknown, " + ', '.join([x for x in lib.clevs if x]))
-@lib.argsEQ(2)
-def clevel(bot, user, chan, realtarget, *args):
- target = _resolve_user(args[0])
- level = _resolve_level(args[1])
- user_clevel = chan.levelof(user.auth)
-
- if target is None:
- return "User not found (try #auth)"
- if target.auth is None:
- return "User is not authed"
- if level is None or level < 0 or level > lib.COWNER:
- return "Level is unknown"
-
- target_clevel = chan.levelof(target.auth)
-
- if not (target == user and level == 0) and user_clevel != lib.COWNER:
- if user_clevel < lib.MASTER:
- return "I'm afraid I can't let you do that. You can only reset your own level to 0."
- if user_clevel <= target_clevel:
- return "I'm afraid I can't let you do that. Your current access level is not higher than theirs."
- if user_clevel <= level:
- return "I'm afraid I can't let you do that. Your current access level is not higher than you are trying to set."
-
- chan.setlevel(target.auth, level)
- return "Set #%s channel level to %s" % (target.auth, args[1])
-
-
-@lib.hook(glevel=lib.MANAGER)
-@lib.help('<level>', "sets your own clevel on a channel")
-@lib.argsEQ(1)
-def forceclevel(bot, user, chan, realtarget, *args):
- target = user.auth
- level = _resolve_level(args[0])
- chan.setlevel(target, level)
- return 'Your level on %s has been set to %d' % (chan, level)