From 570d8535619cf3a9d20ca3d72e5176db2c4c8223 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 17 Aug 2006 13:36:53 +0000 Subject: Fix help. For real --- lib/rbot/core/auth.rb | 60 ++++++++++++++++++++++++++++----------------------- lib/rbot/plugins.rb | 18 ++++++++++------ 2 files changed, 44 insertions(+), 34 deletions(-) (limited to 'lib/rbot') diff --git a/lib/rbot/core/auth.rb b/lib/rbot/core/auth.rb index b38dd49a..1fec6e4b 100644 --- a/lib/rbot/core/auth.rb +++ b/lib/rbot/core/auth.rb @@ -221,36 +221,42 @@ class AuthModule < CoreBotModule m.reply rep end - def help(plugin, topic="") - case topic - when /^login/ + def help(cmd, topic="") + case cmd + when "login" return "login [] []: logs in to the bot as botuser with password . When using the full form, you must contact the bot in private. can be omitted if allows login-by-mask and your netmask is among the known ones. if is omitted too autologin will be attempted" - when /^whoami/ + when "whoami" return "whoami: names the botuser you're linked to" - when /^permission syntax/ - return "a permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix" when /^permission/ - return "permissions (re)set [in ] for : sets or resets the permissions for botuser in channel (use ? to change the permissions for private addressing)" - when /^user show/ - return "user show : shows info about the user; can be any of autologin, login-by-mask, netmasks" - when /^user (en|dis)able/ - return "user enable|disable : turns on or off (autologin, login-by-mask)" - when /^user set/ - return "user set password : sets the user password to ; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long" - when /^user (add|rm)/ - return "user add|rm netmask : adds/removes netmask from the list of netmasks known to the botuser you're linked to" - when /^user reset/ - return "user reset : resets to the default values. can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)" - when /^user tell/ - return "user tell the password for : contacts in private to tell him/her the password for " - when /^user create/ - return "user create : create botuser named with password . The password can be omitted, in which case a random one will be generated. The should only contain alphanumeric characters and the underscore (_)" - when /^user list/ - return "user list : lists all the botusers" - when /^user destroy/ - return "user destroy : destroys ; this function #{Bold}must#{Bold} be called in two steps. On the first call, no password must be specified: is then queued for destruction. On the second call, you must specify the correct password for , and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy +" - when /^user/ - return "user show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy" + case topic + when "syntax" + return "a permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix" + else + return "permissions (re)set [in ] for : sets or resets the permissions for botuser in channel (use ? to change the permissions for private addressing)" + end + when "user" + case topic + when "show" + return "user show : shows info about the user; can be any of autologin, login-by-mask, netmasks" + when /^(en|dis)able/ + return "user enable|disable : turns on or off (autologin, login-by-mask)" + when "set" + return "user set password : sets the user password to ; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long" + when "add", "rm" + return "user add|rm netmask : adds/removes netmask from the list of netmasks known to the botuser you're linked to" + when "reset" + return "user reset : resets to the default values. can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)" + when "tell" + return "user tell the password for : contacts in private to tell him/her the password for " + when "create" + return "user create : create botuser named with password . The password can be omitted, in which case a random one will be generated. The should only contain alphanumeric characters and the underscore (_)" + when "list" + return "user list : lists all the botusers" + when "destroy" + return "user destroy : destroys ; this function #{Bold}must#{Bold} be called in two steps. On the first call, no password must be specified: is then queued for destruction. On the second call, you must specify the correct password for , and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy +" + else + return "user show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy" + end else return "#{name}: login, whoami, permission syntax, permissions, user" end diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 933ea14f..b0626b96 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -504,8 +504,12 @@ module Plugins when /^(\S+)\s*(.*)$/ key = $1 params = $2 - (core_modules + plugins).each { |p| - next unless p.name == key + + # We test for the mapped commands first + k = key.to_sym + [core_commands, plugin_commands].each { |pl| + next unless pl.has_key?(k) + p = pl[k][:botmodule] begin return p.help(key, params) rescue Exception => err @@ -513,12 +517,12 @@ module Plugins error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) end } - k = key.to_sym - [core_commands, plugin_commands].each { |pl| - next unless pl.has_key?(k) - p = pl[k][:botmodule] + + # If no such commmand was found, we look for a botmodule with that name + (core_modules + plugins).each { |p| + next unless p.name == key begin - return p.help(p.name, params) + return p.help(key, params) rescue Exception => err #rescue TimeoutError, StandardError, NameError, SyntaxError => err error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) -- cgit v1.2.3