Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial implementation idea

  • Loading branch information...
commit 664b27c89932a2f4bade40c8196ad9d4471565c6 0 parents
@raggi authored
23 .autotest
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
6 History.txt
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2009-11-12
+
+* 1 major enhancement
+
+ * Birthday!
+
8 Manifest.txt
@@ -0,0 +1,8 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/talker_bot
+lib/talker_bot.rb
+test/test_talker_bot.rb
48 README.txt
@@ -0,0 +1,48 @@
+= talker_bot
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2009 FIX
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 Rakefile
@@ -0,0 +1,12 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.spec 'talker_bot' do
+ # developer('FIX', 'FIX@example.com')
+
+ # self.rubyforge_name = 'talker_botx' # if different than 'talker_bot'
+end
+
+# vim: syntax=ruby
20 bin/talker_bot
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+unless ARGV.first && File.exists?(ARGV[1])
+ abort <<-TEXT
+ Usage: talker_bot room [config.bot]
+ config.bot is a ruby file of the form:
+
+ config :token, Talker::CLI.load_token # default
+ use Plugin.new
+ TEXT
+end
+
+config = ARGV[1] || 'config.bot'
+
+require 'talker_bot'
+
+bot = TalkerBot.new
+bot.instance_eval(File.read(config), config, 0)
+bot.connect
+bot.run
24 bin/talker_inspector
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+require 'talker_bot'
+
+class Inspector
+ NAME = "Inspector Jones"
+
+ attr_accessor :client
+
+ def respond_to?(name)
+ true if name.to_s =~ /^on_/
+ end
+
+ def method_missing(name, *args)
+ p [name, args]
+ end
+
+ def to_s
+ NAME
+ end
+end
+
+TalkerBot.start(:room => ARGV.first || abort('supply a room number')) do
+ use Inspector.new
+end
59 lib/talker_bot.rb
@@ -0,0 +1,59 @@
+require 'talker'
+require 'talker/cli'
+
+class TalkerBot
+ VERSION = '1.0.0'
+ TALKER_OPTS = [:host, :port, :room, :token]
+ TALKER_CALLBACKS = Talker.instance_methods.grep(/^on_/).map { |m| m.to_sym }
+ UNDERSCORE = '_'
+
+ def self.start(config = {}, &block)
+ bot = new(config)
+ bot.instance_eval(&block) if block
+ bot.connect
+ bot.run
+ end
+
+ def initialize(config = {})
+ @config = config
+ config[:token] ||= Talker::CLI.load_token
+ @plugins = []
+ @plugin_callbacks = Hash.new { |h,k| h[k] = [] }
+ end
+
+ def config(name, value = nil)
+ if value
+ @config[name] = value
+ else
+ @config[name]
+ end
+ end
+
+ def plugin(plugin)
+ @plugins << plugin
+ TALKER_CALLBACKS.each do |callback|
+ @plugin_callbacks[callback] << plugin if plugin.respond_to?(callback)
+ end
+ end
+ alias use plugin
+
+ def connect
+ Talker.connect(@config) do |client|
+ TALKER_CALLBACKS.each do |cb|
+ client.__send__(cb) { |*args| event(cb, *args) }
+ end
+ @plugins.each { |p| p.client = client if p.respond_to?(:client=)}
+ end
+ end
+ alias run connect
+
+ def event(type, *args)
+ @plugin_callbacks[type].each { |plugin| plugin.__send__(type, *args) }
+ end
+
+ def run_filter_actions(list, *args)
+ list.each do |filter, action|
+ action.call(*args) if filter === event
+ end
+ end
+end
8 test/test_talker_bot.rb
@@ -0,0 +1,8 @@
+require "test/unit"
+require "talker_bot"
+
+class TestTalkerBot < Test::Unit::TestCase
+ def test_sanity
+ flunk "write tests or I will kneecap you"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.