diff --git a/examples/dslify.rb b/examples/dslify.rb new file mode 100644 index 0000000..fa5e01c --- /dev/null +++ b/examples/dslify.rb @@ -0,0 +1,19 @@ +require 'lib/isaac.rb' + +class K + def initialize + Isaac.app.dslify do + msg "harryjr", "foobarnar" + end + end +end + +config do |c| + c.server = "irc.freenode.net" + c.nick = "DSLBOT" + c.port = 6667 +end + +on :connect do + k = K.new +end diff --git a/lib/isaac.rb b/lib/isaac.rb index 7a2e5f7..78273eb 100644 --- a/lib/isaac.rb +++ b/lib/isaac.rb @@ -28,12 +28,21 @@ def on(type, match=nil, &block) @events[type] << Event.new(match, block) end + # TODO Fix this crappy name. + def dslify(&block) + context = EventContext.new + context.instance_eval(&block) + context.commands.each {|cmd| @irc.puts cmd} + end + private def connect @irc = TCPSocket.open(@config.server, @config.port) register @events[:connect].first.invoke.commands.each {|cmd| @irc.puts cmd} - handle(line) while line = @irc.gets + while line = @irc.gets + handle line + end end def register @@ -42,6 +51,8 @@ def register end def handle(line) + # TODO this is ugly as well. do something about the args. + p line if ARGV[0] == "-v" case line when /^:(\S+)!\S+ PRIVMSG (\S+) :?(.*)/ nick = $1