X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fscript.rb;h=11aed3968d006ad81bee53c235285fc61c92a430;hb=6cf365c49ce5fbe24c0a4ff0663550390b501fea;hp=e2669088c1c6062928d0ca8f4c2c85247504e8a5;hpb=83bfc1d808e63691b2f3081f903aa05684c379b6;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/script.rb b/data/rbot/plugins/script.rb index e2669088..11aed396 100644 --- a/data/rbot/plugins/script.rb +++ b/data/rbot/plugins/script.rb @@ -1,16 +1,19 @@ -# Plugin for the Ruby IRC bot (http://linuxbrit.co.uk/rbot/) +#-- vim:sw=2:et +#++ # -# Create mini plugins on IRC. +# :title: Script plugin for rbot # -# Scripts are little Ruby programs that run in the context of the script plugin. You -# can create them directly in an IRC channel, and invoke them just like normal rbot plugins. +# Author:: Mark Kretschmann +# Copyright:: (C) 2006 Mark Kretschmann +# License:: GPL v2 # -# (c) 2006 Mark Kretschmann -# Licensed under GPL V2. - - -Command = Struct.new( "Command", :code, :nick, :created, :channel ) +# Create mini plugins on IRC. +# +# Scripts are little Ruby programs that run in the context of the script +# plugin. You can create them directly in an IRC channel, and invoke them just +# like normal rbot plugins. +define_structure :Command, :code, :nick, :created, :channel class ScriptPlugin < Plugin @@ -18,18 +21,10 @@ class ScriptPlugin < Plugin super if @registry.has_key?(:commands) @commands = @registry[:commands] - end - - if @commands.nil? + raise LoadError, "corrupted script database" unless @commands + else @commands = Hash.new end - - # Migrate old Hash to new: - @commands.each_pair do |name, cmd| - unless cmd.instance_of?( Command ) - @commands[name] = Command.new( cmd, 'unknown hacker', 'somedate', '#somechan' ) - end - end end @@ -39,51 +34,94 @@ class ScriptPlugin < Plugin def help( plugin, topic="" ) - if topic == "add" - "Scripts are little Ruby programs that run in the context of the script plugin. You can access @bot (class IrcBot), m (class PrivMessage), user (class String, either the first argument, or if missing the sourcenick), and args (class Array, an array of arguments). Example: 'script add greet m.reply( 'Hello ' + user )'. Invoke the script just like a plugin: ': greet'." - else - "Create mini plugins on IRC. 'script add ' => Create script named with the code . 'script list' => Show a list of all known scripts. 'script show ' => Show the source code for . 'script del ' => Delete the script ." + case topic + when "add" + "Scripts are little Ruby programs that run in the context of the script plugin. You can access @bot (class Irc::Bot), m (class Irc::PrivMessage), user (class String, either the first argument, or if missing the sourcenick), and args (class Array, an array of arguments). Example: 'script add greet m.reply( 'Hello ' + user )'. Invoke the script just like a plugin: ': greet'." + when "allow" + "script allow