rjp-jabber_cat 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/jabber_cat.rb +15 -68
- data/lib/jabber_cat/options.rb +61 -0
- metadata +4 -3
data/bin/jabber_cat.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems' # should only do this if we require it
|
2
4
|
require 'optparse'
|
3
5
|
require 'socket'
|
4
6
|
require 'xmpp4r'
|
@@ -6,82 +8,22 @@ require 'xmpp4r/framework/bot'
|
|
6
8
|
require 'xmpp4r/muc/helper/simplemucclient'
|
7
9
|
include Jabber
|
8
10
|
|
11
|
+
require 'jabber_cat/options'
|
12
|
+
|
9
13
|
def log(x)
|
10
14
|
if $options[:verbose] then
|
11
15
|
puts(*x)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
|
-
$options = {
|
16
|
-
:host => 'localhost',
|
17
|
-
:port => 9999,
|
18
|
-
:whoto => nil,
|
19
|
-
:config => ENV['HOME'] + '/.jabber_cat',
|
20
|
-
:verbose => nil,
|
21
|
-
:debug => 0,
|
22
|
-
:keyfile => nil,
|
23
|
-
:muc => nil
|
24
|
-
}
|
25
|
-
|
26
|
-
OptionParser.new do |opts|
|
27
|
-
opts.banner = "Usage: twittermoo.rb [-p port] [-h host] [-w jid] [-v] [-d N] [-m] [-k file]"
|
28
|
-
|
29
|
-
opts.on("-p", "--port N", Integer, "irccat port") do |p|
|
30
|
-
$options[:port] = p
|
31
|
-
end
|
32
|
-
|
33
|
-
opts.on("-h", "--host HOST", String, "host") do |p|
|
34
|
-
$options[:host] = p
|
35
|
-
end
|
36
|
-
|
37
|
-
opts.on("-w", "--whoto jid", String, "JID") do |p|
|
38
|
-
$options[:whoto] = p
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on("-c", "--config CONFIG", String, "config file") do |p|
|
42
|
-
$options[:config] = p
|
43
|
-
end
|
44
|
-
|
45
|
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
46
|
-
$options[:verbose] = v
|
47
|
-
end
|
48
|
-
|
49
|
-
opts.on("-d", "--debug N", Integer, "debug level") do |p|
|
50
|
-
$options[:debug] = p
|
51
|
-
end
|
52
|
-
|
53
|
-
opts.on("-k", "--key filename", String, "Shared key file") do |p|
|
54
|
-
$options[:keyfile] = p
|
55
|
-
end
|
56
|
-
|
57
|
-
opts.on("-m", "--muc", "Treat the destination as a MUC") do |v|
|
58
|
-
$options[:muc] = v
|
59
|
-
end
|
60
|
-
|
61
|
-
end.parse!
|
62
|
-
|
63
|
-
if $options[:whoto].nil? then # debug = 1 if not already set
|
64
|
-
$options[:debug] = $options[:debug] || 1
|
65
|
-
end
|
66
|
-
|
67
|
-
# TODO handle failing here with exceptions
|
68
|
-
config = YAML::load(open($options[:config]))
|
69
|
-
|
70
|
-
# TODO this won't work at all because $options has symbols, config has strings
|
71
|
-
unless config['options'].nil? then
|
72
|
-
config['options'].each { |k,v|
|
73
|
-
$options[k.to_sym] = v
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
19
|
if $options[:keyfile] then
|
78
20
|
puts "loading secret key from #{$options[:keyfile]}"
|
79
21
|
$options[:secret_key] = File.open($options[:keyfile]).read.chomp
|
80
22
|
end
|
81
23
|
|
82
24
|
# make sure we always have a filters list
|
83
|
-
if
|
84
|
-
|
25
|
+
if $options['filters'].nil? then
|
26
|
+
$options['filters'] = []
|
85
27
|
end
|
86
28
|
|
87
29
|
if $options[:debug] > 0 then
|
@@ -116,7 +58,7 @@ x = Thread.new do
|
|
116
58
|
line.gsub!(%r{^%/.*?/% }, '')
|
117
59
|
end
|
118
60
|
|
119
|
-
|
61
|
+
$options['filters'].each { |f|
|
120
62
|
if line =~ /#{f}/ then
|
121
63
|
if $options[:verbose] then
|
122
64
|
log "F #{f} =~ #{line}"
|
@@ -148,8 +90,8 @@ end
|
|
148
90
|
#### JABBER
|
149
91
|
|
150
92
|
# settings
|
151
|
-
myJID = JID.new(
|
152
|
-
myPassword =
|
93
|
+
myJID = JID.new($options['myjid'])
|
94
|
+
myPassword = $options['mypass']
|
153
95
|
|
154
96
|
log "creating jabber connection now"
|
155
97
|
|
@@ -157,6 +99,11 @@ if $options[:debug] > 1 then
|
|
157
99
|
Jabber::debug = true
|
158
100
|
end
|
159
101
|
|
102
|
+
if $options[:debug] > 2 then
|
103
|
+
x.join
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
160
107
|
if $options[:muc] then # can't distinguish MUC JID from normal JID
|
161
108
|
cl = Jabber::Client.new(Jabber::JID.new(myJID))
|
162
109
|
cl.connect
|
@@ -0,0 +1,61 @@
|
|
1
|
+
puts "included file"
|
2
|
+
|
3
|
+
$options = {
|
4
|
+
:host => 'localhost',
|
5
|
+
:port => 9999,
|
6
|
+
:whoto => nil,
|
7
|
+
:config => ENV['HOME'] + '/.jabber_cat',
|
8
|
+
:verbose => nil,
|
9
|
+
:debug => 0,
|
10
|
+
:keyfile => nil,
|
11
|
+
:muc => nil
|
12
|
+
}
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: twittermoo.rb [-p port] [-h host] [-w jid] [-v] [-d N] [-m] [-k file]"
|
16
|
+
|
17
|
+
opts.on("-p", "--port N", Integer, "irccat port") do |p|
|
18
|
+
$options[:port] = p
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-h", "--host HOST", String, "host") do |p|
|
22
|
+
$options[:host] = p
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-w", "--whoto jid", String, "JID") do |p|
|
26
|
+
$options[:whoto] = p
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-c", "--config CONFIG", String, "config file") do |p|
|
30
|
+
$options[:config] = p
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
34
|
+
$options[:verbose] = v
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-d", "--debug N", Integer, "debug level") do |p|
|
38
|
+
$options[:debug] = p
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-k", "--key filename", String, "Shared key file") do |p|
|
42
|
+
$options[:keyfile] = p
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("-m", "--muc", "Treat the destination as a MUC") do |v|
|
46
|
+
$options[:muc] = v
|
47
|
+
end
|
48
|
+
|
49
|
+
end.parse!
|
50
|
+
|
51
|
+
if $options[:whoto].nil? then # debug = 1 if not already set
|
52
|
+
$options[:debug] = $options[:debug] || 1
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO handle failing here with exceptions
|
56
|
+
config = YAML::load(open($options[:config]))
|
57
|
+
|
58
|
+
# merge the whole of the config file into the $options hash
|
59
|
+
config.each { |k,v|
|
60
|
+
$options[k.to_sym] = v
|
61
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjp-jabber_cat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Partington
|
@@ -24,14 +24,15 @@ dependencies:
|
|
24
24
|
version:
|
25
25
|
description:
|
26
26
|
email: zimpenfish@gmail.com
|
27
|
-
executables:
|
28
|
-
|
27
|
+
executables:
|
28
|
+
- jabber_cat.rb
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
34
|
- bin/jabber_cat.rb
|
35
|
+
- lib/jabber_cat/options.rb
|
35
36
|
has_rdoc: false
|
36
37
|
homepage: http://rjp.github.com/jabber_cat
|
37
38
|
post_install_message:
|