Skip to content

Commit

Permalink
SEND SPIKE
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Mar 18, 2012
0 parents commit 9168f93
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gem 'celluloid', :git => 'https://github.com/tarcieri/celluloid.git'

# Specify your gem's dependencies in cellulon.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012 Tony Arcieri

MIT License

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.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Cellulon

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'cellulon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cellulon

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
76 changes: 76 additions & 0 deletions bin/cellulon
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'

require 'cinch'
require 'celluloid'

# The colors, Duke! The colors!1!
module Tty extend self
def escape(n); "\033[#{n}m" if STDOUT.tty? end
def bold(n); escape "1;#{n}" end
def blue; bold 34; end
def white; bold 39; end
def underline(n); escape "4;#{n}" end
def red; underline 31; end
def reset; escape 0; end
def ohai(something)
puts "#{Tty.blue}*** #{Tty.white}#{something}#{Tty.reset}" if STDOUT.tty?
end
end

class Worker
include Celluloid

ROOT = File.expand_path '../..', __FILE__
TIMEOUT = 900
HOOK = /^![a-z][a-z0-9\-]*[a-z0-9]*/

def handle_message(msg)
p msg
hook = msg.message[HOOK]
return unless hook


args = msg.message.split(/\w+/)
args.shift # remove the hook as an argument

run hook, msg.user.nick, args do |response|
msg.reply response
end
end

def run(hook, user, args)
script = File.join(ROOT, 'scripts', 'hooks', hook.sub(/^!/, ''))
return unless File.executable?(script)

Tty.ohai "Running #{hook} #{args.join(' ')}"

Timeout.timeout TIMEOUT do
Open3.popen2e({'CALLED_BY' => user}, script, *args) do |stdin, stdout|
while line = stdout.gets
line.force_encoding("UTF-8") if line.respond_to? :force_encoding
line.strip!
yield line
end
end
end
end

alias_method :<<, :handle_message
end

pool = Celluloid::Pool.new Worker, :max_size => 10

bot = Cinch::Bot.new do
configure do |c|
c.nick = "cellulon"
c.server = "irc.freenode.net"
c.channels = ["#celluloid"]
end

on(:message) { |msg| pool.get! { |worker| worker << msg } }
end

bot.start
20 changes: 20 additions & 0 deletions cellulon.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/cellulon/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["Tony Arcieri"]
gem.email = ["tony.arcieri@gmail.com"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.homepage = ""

gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "cellulon"
gem.require_paths = ["lib"]
gem.version = Cellulon::VERSION

gem.add_dependency 'cinch'
gem.add_dependency 'celluloid'
end
5 changes: 5 additions & 0 deletions lib/cellulon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "cellulon/version"

module Cellulon
# Your code goes here...
end
3 changes: 3 additions & 0 deletions lib/cellulon/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Cellulon
VERSION = "0.0.1"
end
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions scripts/hooks/ohai
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "Hello there, $CALLED_BY"

0 comments on commit 9168f93

Please sign in to comment.