--[[ cmd_unban.lua v0.03 by blastbeat - this script adds a command "unban" to unban users by ip/nick/cid - usage: [+!#]unban ip|nick|cid || - IMPORTANT: cmd_unban.lua depends on following scripts: - cmd_ban.lua v0.03+ for banfile - bot_opchat.lua v0.03+ in case of enabled opchat feed - changelog 0.03: - updated script api - changelog 0.02: - added level checking ]]-- --// settings begin //-- local permission = { --// [ user_level = level means user_level can unban users banned by level //-- [ 60 ] = 60, -- operator can unban users banned by operators [ 80 ] = 80, -- admin [ 100 ] = 100, -- hubowner } local opchat_feed = true --// send status message to opchat? local msg_denied = "You are not allowed to use this command." local msg_import = "Error while importing bot_opchat.lua/cmd_ban.lua" local msg_usage = "Usage: [+!#]unban ip|nick|cid ||" local msg_off = "User not found." local msg_god = "You are not allowed to unban this user." local msg_ok = "%s removed ban of %s" local cmd = "unban" --// settings end //-- local utf_match = utf.match local opchat local bans local path hub:setListener( "onStart", { }, function( ) opchat = hub.import "bot_opchat" local ban = hub.import "cmd_ban" if ( not opchat and opchat_feed ) or not ban then error( msg_import ) end bans = ban.bans local help = hub.import "cmd_help" if help then help.reg( "unban", "[+!#]unban ip|nick|cid ||", "unbans user by ip or nick or cid", 60 ) end return nil end ) hub:setListener( "onBroadcast", { }, function( user, adccmd, txt ) local command, parameters = utf_match( txt, "^[+!#](%a+) ?(.*)" ) if command == cmd then local user_level = user:getLevel( ) if not permission[ user_level ] then user:reply( msg_denied, hub.getbot( ) ) return PROCESSED end local by, id = utf.match( parameters, "^(%S+) (%S+)" ) if not ( (by == "sid" or by == "nick" or by == "cid" ) and id ) then user:reply( msg_usage, hub.getbot( ) ) return PROCESSED end for i, ban_tbl in ipairs( bans ) do if ban_tbl[ by ] == id then if permission[ user_level ] < ( ban_tbl.by_level or 100 ) then user:reply( msg_god, hub.getbot( ) ) return PROCESSED end table.remove( bans, i ) util.saveArray( bans, path ) local user_nick = hub.escapefrom( user:getNick( ) ) local status_message = utf.format( msg_ok, user_nick, id ) local _ = opchat_feed and opchat.feed( status_message ) user:reply( status_message, hub.getbot( ) ) return PROCESSED end end user:reply( msg_off, hub.getbot( ) ) return PROCESSED end return nil end ) hub.debug( "** Loaded cmd_unban.lua **" )