purzelrakete-mini 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CREDITS.markdown +2 -0
- data/LICENSE.markdown +7 -0
- data/README.markdown +64 -0
- data/TODO.markdown +1 -0
- data/bin/minigen +11 -0
- data/lib/mini.rb +2 -0
- data/lib/mini/bot.rb +20 -0
- data/lib/mini/irc.rb +72 -0
- data/lib/mini/listener.rb +9 -0
- data/lib/mini/web.rb +6 -0
- data/scripts/minicmd.erb +14 -0
- data/scripts/minictl.erb +20 -0
- metadata +69 -0
data/CREDITS.markdown
ADDED
data/LICENSE.markdown
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2009 Rany Keddo
|
2
|
+
|
3
|
+
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:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
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.
|
data/README.markdown
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# a ruby eventmachine bot inspired by richard jones' irccat. interact via netcat, irc or web.
|
2
|
+
|
3
|
+
## installing
|
4
|
+
|
5
|
+
sudo gem install purzelrakete-mini --source=http://gems.github.com
|
6
|
+
|
7
|
+
create a directory for mini and run the following
|
8
|
+
|
9
|
+
minigen create <your-mini-dir>
|
10
|
+
|
11
|
+
this creates two files in your mini dir. edit both as you see fit, then add your mini dir to your $PATH inside of your shell's rc file.
|
12
|
+
|
13
|
+
## usage
|
14
|
+
|
15
|
+
launch: (leave the # off the channel names. you can add many channel names, main one is first)
|
16
|
+
|
17
|
+
minictl irc.freenode.net 6667 my_bot_name my_bot_nickserv_passwd my_bot_control_channel next_channel
|
18
|
+
|
19
|
+
íf you want to background this, just do something like
|
20
|
+
|
21
|
+
nohup minictl irc.freenode.net 6667 mimi secret mini-lounge &
|
22
|
+
|
23
|
+
### via netcat
|
24
|
+
|
25
|
+
now send some data down the pipes!
|
26
|
+
|
27
|
+
echo "Ilovethistuffs yes .. i .. do. " | nc localhost 12345
|
28
|
+
vmstat | nc localhost 12345
|
29
|
+
echo "#musicteam,#legal,@alice New album uploaded: ..." | nc somemachine 12345
|
30
|
+
tail -f /var/log/important.log | nc somemachine 12345
|
31
|
+
|
32
|
+
to send IRC commands from the bot, prepend '/':
|
33
|
+
|
34
|
+
echo "/JOIN #some_channel"
|
35
|
+
|
36
|
+
### via irc
|
37
|
+
|
38
|
+
run stuff by typing ?command in the main mini channel or by dmsging mini bot. this will invoke minicmd (in your mini dir) with the command as an arg. if you want the script to run a different language (ie php), just change the bang and replace with your own stuff.
|
39
|
+
|
40
|
+
you have to be on the control channel for the script to execute. this is the first channel in your list.
|
41
|
+
|
42
|
+
### via web
|
43
|
+
|
44
|
+
post to `hostname:MINI_WEB_PORT/command/MINI_SECRET`. ie:
|
45
|
+
|
46
|
+
curl -d "netcat, lolcats, pigs, sweaty snout, nixon" http://localhost:2345/echo/dscds789svjskdlvsdz789mkvcjvklsd6
|
47
|
+
|
48
|
+
of course normally, you'd proxy to startup.com:2345 from something sitting behind :80. Set up ports in minictl in your mini dir.
|
49
|
+
|
50
|
+
you can find `MINI_SECRET` and `MINI_WEB_PORT` inside of the minictl file in your mini directory.
|
51
|
+
|
52
|
+
## configuration
|
53
|
+
|
54
|
+
### commands
|
55
|
+
|
56
|
+
you can create commands simply by providing your own minicmd script. ARGV.first is the command, the rest is arguments. mini comes bundled with a ruby based minicmd script which you can extend by adding procs to it:
|
57
|
+
|
58
|
+
Mini::Bot.commands["echo"] = lambda { |*args| puts args }
|
59
|
+
|
60
|
+
you can also require any mini plugins in there.
|
61
|
+
|
62
|
+
### web callbacks
|
63
|
+
|
64
|
+
there is a secret key (see above) wich you can configure inside of minicmd (inside of your mini dir).
|
data/TODO.markdown
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
- add logbot functions
|
data/bin/minigen
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
abort("mini create <mini-directory>") unless ARGV.first == "create" && dir = Dir[ARGV.last].first
|
4
|
+
|
5
|
+
%w{ minictl minicmd }.each do |script|
|
6
|
+
target = dir.chomp('/') + '/' + script
|
7
|
+
File.open(target, 'w') { |f| f.write(ERB.new(IO.read(File.dirname(__FILE__) + "/../scripts/#{ script }.erb")).result) }
|
8
|
+
%x{ chmod +x #{ target } }
|
9
|
+
end
|
10
|
+
|
11
|
+
puts "generated files into #{ dir }. edit files, then add #{ dir } to your $PATH in your shell rc file. start with minictl."
|
data/lib/mini.rb
ADDED
data/lib/mini/bot.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mini
|
2
|
+
class Bot
|
3
|
+
cattr_accessor :commands, :secret
|
4
|
+
@@commands = {}
|
5
|
+
|
6
|
+
def self.start(options)
|
7
|
+
EventMachine::run do
|
8
|
+
Mini::IRC.connect(options)
|
9
|
+
EventMachine::start_server("0.0.0.0", options[:mini_port].to_i, Mini::Listener)
|
10
|
+
Bot.secret = options[:secret]
|
11
|
+
@@web.run! :port => options[:web_port].to_i
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.run(command, args)
|
16
|
+
proc = Bot.commands[command]
|
17
|
+
proc ? proc.call(args) : (puts "command #{ command } not found. ")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/mini/irc.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Mini
|
2
|
+
class IRC < EventMachine::Connection
|
3
|
+
include EventMachine::Protocols::LineText2
|
4
|
+
|
5
|
+
attr_accessor :config, :moderators
|
6
|
+
cattr_accessor :connection
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
self.config = OpenStruct.new(options)
|
10
|
+
@queue = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def say(msg, targets = [])
|
14
|
+
targets = ['#' + config.channels.first] if targets.blank?
|
15
|
+
msg.split("\n").each do |msg|
|
16
|
+
targets.each do |target|
|
17
|
+
command( (msg.starts_with?("/") ? msg[1..-1] : "PRIVMSG #{ target.delete("@") } :#{ msg }") )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def command(*cmd)
|
23
|
+
send_data "#{ cmd.flatten.join(' ') }\r\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def queue(sender, receiver, msg)
|
27
|
+
@queue << [sender.split("!").first, msg]
|
28
|
+
command "NAMES", "#" + config.channels.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def dequeue(nicks)
|
32
|
+
self.moderators = nicks.split.map { |nick| nick.delete("@").delete("+") }
|
33
|
+
|
34
|
+
while job = @queue.pop
|
35
|
+
sender, cmd = job
|
36
|
+
execute(cmd) if self.moderators.include?(sender)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(cmd)
|
41
|
+
command = "minicmd #{ [*cmd].join(' ') }"
|
42
|
+
say(%x{#{ command }})
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.connect(options)
|
46
|
+
self.connection = EM.connect(options[:server], options[:port].to_i, self, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
# callbacks
|
50
|
+
def post_init
|
51
|
+
command "USER", [config.user]*4
|
52
|
+
command "NICK", config.user
|
53
|
+
command("NickServ IDENTIFY", config.user, config.password) if config.password
|
54
|
+
config.channels.each { |channel| command("JOIN", "##{ channel }") } if config.channels
|
55
|
+
end
|
56
|
+
|
57
|
+
def receive_line(line)
|
58
|
+
case line
|
59
|
+
when /^PING (.*)/ : command('PONG', $1)
|
60
|
+
when /^:(\S+) PRIVMSG (.*) :\?(.*)$/ : queue($1, $2, $3)
|
61
|
+
when /^:\S* \d* #{ config.user } @ #{ '#' + config.channels.first } :(.*)/ : dequeue($1)
|
62
|
+
else puts line; end
|
63
|
+
end
|
64
|
+
|
65
|
+
def unbind
|
66
|
+
EM.add_timer(3) do
|
67
|
+
reconnect(config.server, config.port)
|
68
|
+
post_init
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Mini
|
2
|
+
module Listener
|
3
|
+
def receive_data(data) # echo "#musicteam,#legal,@alice New album uploaded: ..." | nc somemachine 12345.
|
4
|
+
all, targets, *payload = *data.match(/^(([\#@]\S+,? ?)*)(.*)$/)
|
5
|
+
targets = targets.split(",").map { |target| target.strip }.uniq
|
6
|
+
IRC.connection.say(payload.pop.strip, targets)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/mini/web.rb
ADDED
data/scripts/minicmd.erb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!<%= %x{ which ruby } %>
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mini'
|
4
|
+
|
5
|
+
#
|
6
|
+
# require any plugins you want to load into the default minicmd:
|
7
|
+
# require 'mini_my_plugin'
|
8
|
+
#
|
9
|
+
# or write some commands straight into here, like...
|
10
|
+
#
|
11
|
+
Mini::Bot.commands["echo"] = lambda { |*args| puts args.join(" ") }
|
12
|
+
|
13
|
+
command, *args = ARGV
|
14
|
+
Mini::Bot.run(command, args)
|
data/scripts/minictl.erb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!<%= %x{ which ruby } %>
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mini'
|
4
|
+
|
5
|
+
abort("minictl <server> <port> <user> <password> <main channel> <channel2>. no hashes 4 chans pls. ") unless ARGV.length >= 4
|
6
|
+
server, port, user, password, *channels = ARGV
|
7
|
+
|
8
|
+
#
|
9
|
+
# Change defaults as needed here.
|
10
|
+
#
|
11
|
+
|
12
|
+
Mini::Bot.start \
|
13
|
+
:secret => '<%= (0...40).map{ 65.+(rand(25)).chr }.join %>', # randomly generated for you.
|
14
|
+
:mini_port => 12345,
|
15
|
+
:web_port => 2345,
|
16
|
+
:server => server,
|
17
|
+
:port => port,
|
18
|
+
:user => user,
|
19
|
+
:password => password,
|
20
|
+
:channels => [*channels]
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: purzelrakete-mini
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rany
|
8
|
+
- Keddo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-03-01 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: purzelrakete@gmail.com
|
19
|
+
executables:
|
20
|
+
- minigen
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- CREDITS.markdown
|
27
|
+
- LICENSE.markdown
|
28
|
+
- README.markdown
|
29
|
+
- TODO.markdown
|
30
|
+
- bin/minigen
|
31
|
+
- lib/mini
|
32
|
+
- lib/mini/bot.rb
|
33
|
+
- lib/mini/irc.rb
|
34
|
+
- lib/mini/listener.rb
|
35
|
+
- lib/mini/web.rb
|
36
|
+
- lib/mini.rb
|
37
|
+
- scripts/minicmd.erb
|
38
|
+
- scripts/minictl.erb
|
39
|
+
has_rdoc: false
|
40
|
+
homepage: http://github.com/purzelrakete/mini
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --line-numbers
|
44
|
+
- --inline-source
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements:
|
60
|
+
- eventmachine
|
61
|
+
- activesupport
|
62
|
+
- sinatra
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: a ruby eventmachine bot inspired by richard jones' irccat. interact via netcat, irc or web.
|
68
|
+
test_files: []
|
69
|
+
|