Maybe I'm stupid and doing something wrong, but if this is the case, I can't figure out what. I have an authorization/control plugin:
class Control
include Cinch::Plugin
@@passwords = {"owner" => ["over9000"]}
@@commands = { \
"auth" => {:syntax => /^([a-z]+) (.+)$/, :accessible_for => [:all], :method => lambda do |plugin, match|
if !match[1] or !match[2]
raise "Nieprawidłowa składnia. Użycie: !auth <poziom_uprawnień> <hasło>."
end
if not @@passwords.has_key? (match[1])
raise "Poziom uprawnień #{match[1]} nie istnieje."
end
if not @@passwords[match[1]].include? (match[2])
raise "Błędne hasło."
end
return "Uzyskano dostęp na poziomie #{match[1]}."
end}, \
"chan" => {:syntax => /^#[a-z]+$/, :accessible_for => ["owner"], :method => lambda do |plugin, match|
if !match[0]
raise "Nieprawidłowa składnia. Użycie: !chan <kanał>."
end
plugin.channel = match[0]
return "Bieżący kanał: #{match[0]}."
end}, \
"join" => {:syntax => /^$/, :accessible_for => ["owner"], :method => lambda do |plugin, match|
if not match
raise "Nieprawidłowa składnia. Użycie: !join."
end
if not plugin.channel
raise "Najpierw musisz ustawić bieżący kanał."
end
plugin.Channel(plugin.channel).join
return "Dołączyłem do kanału #{plugin.channel}."
end}, \
"part" => {:syntax => /^$/, :accessible_for => ["owner"], :method => lambda do |plugin, match|
if not match
raise "Nieprawidłowa składnia. Użycie: !part."
end
if not plugin.channel
raise "Najpierw musisz ustawić bieżący kanał."
end
plugin.Channel(plugin.channel).part
return "Opuściłem kanał #{plugin.channel}."
end}, \
"csay" => {:syntax => /^.+$/, :accessible_for => ["owner"], :method => lambda do |plugin, match|
if not match[0]
raise "Nieprawidłowa składnia. Użycie: !csay <wiadomość>."
end
if not plugin.channel
raise "Najpierw musisz ustawić bieżący kanał."
end
if not plugin.bot.channels.include? (plugin.Channel(plugin.channel))
raise "Najpierw musisz dołączyć do bieżącego kanału."
end
plugin.Channel(plugin.channel).send(match[0])
return "Wysłałem wiadomość na kanał #{plugin.channel}."
end}, \
"plug" => {:syntax => /^([A-Z][a-z]+)+$/, :accessible_for => ["owner"], :method => lambda do |plugin, match|
if not match[0]
raise "Nieprawidłowa składnia. Użycie: !plug <plugin>."
end
begin
plug = Object.const_get(match[0])
if plugin.bot.plugins.include? (plug)
raise "Ten plugin jest już aktywny."
end
plugin.bot.plugins.register_plugin(plug)
return "Aktywowałem plugin #{match[0]}."
rescue NameError
raise "Plugin #{match[0]} nie istnieje."
end
end}, \
"uplg" => {:syntax => /^([A-Z][a-z]+)+$/, :accessible_for => ["owner"], :method => lambda do |plugin, match|
if not match[0]
raise "Nieprawidłowa składnia. Użycie: !uplg <plugin>."
end
if match[0] == "Control"
raise "Deaktywacja pluginu kontroli jest niedozwolona."
end
success = false
plugin.bot.plugins.each do |plug|
if plug.class.name == match[0]
plugin.debug (msg = plug.unregister).to_s
success = true
break
end
end
if not success
raise "Ten plugin nie jest aktywny."
end
return "Deaktywowałem plugin #{match[0]}."
end}, \
"lplg" => {:syntax => /^$/, :accessible_for => [:all], :method => lambda do |plugin, match|
if not match[0]
raise "Nieprawidłowa składnia. Użycie: !lplg."
end
list = ["Aktywne pluginy:"]
plugin.bot.plugins.each do |plug|
list.push(plug.class.name)
end
return list.join("\n")
end} \
}
def initialize(*args)
super
@authenticated = {}
@channel = false
end
def channel
@channel
end
def channel=(value)
@channel = value
end
match /!.{4}( (.+))?/, react_on: :private, method: :execute
def execute(m)
command = m.message.slice(1, 4)
begin
if not @@commands.has_key? (command)
raise "Nie rozpoznałem komedy: #{command}."
end
if not @authenticated.has_key? (m.user.nick)
@authenticated.store(m.user.nick, [:all])
end
access = false
@authenticated[m.user.nick].each do |access_lvl|
if @@commands[command][:accessible_for].include? (access_lvl)
access = true
break
end
end
if not access
raise "Brak dostępu."
end
(parameters = m.message).slice!(0, 6)
params_match = @@commands[command][:syntax].match(parameters)
reply = @@commands[command][:method].call(self, params_match)
if command == "auth"
@authenticated[m.user.nick].push(params_match[1])
end
m.reply reply
rescue RuntimeError => e
m.reply e.message
end
end
end
I also tried unregistering by plug = Object.get_const() and plugin.bot.plugins.unregister_plugin(plug). Doesn't work either.
This is way too much code. Please reduce it to the minimal amount required to reproduce the problem. Also closing this because it probably timed out by now. Reopen if you want to.
Hey guys,
Maybe I'm stupid and doing something wrong, but if this is the case, I can't figure out what. I have an authorization/control plugin:
I also tried unregistering by
plug = Object.get_const()
andplugin.bot.plugins.unregister_plugin(plug)
. Doesn't work either.