net-irc 0.0.7 → 0.0.8
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/ChangeLog +6 -0
- data/README +14 -15
- data/Rakefile +1 -1
- data/examples/client.rb +1 -1
- data/examples/echo_bot.rb +1 -1
- data/examples/gmail.rb +2 -1
- data/examples/hatena-star-stream.rb +56 -11
- data/examples/hig.rb +54 -22
- data/examples/iig.rb +63 -86
- data/examples/ircd.rb +358 -0
- data/examples/mixi.rb +2 -1
- data/examples/sig.rb +2 -1
- data/examples/tig.rb +1671 -524
- data/examples/wig.rb +27 -27
- data/lib/net/irc.rb +36 -21
- data/lib/net/irc/client.rb +8 -2
- data/lib/net/irc/client/channel_manager.rb +13 -13
- data/lib/net/irc/constants.rb +2 -2
- data/lib/net/irc/message.rb +17 -10
- data/lib/net/irc/message/modeparser.rb +5 -5
- data/lib/net/irc/message/serverconfig.rb +3 -3
- data/lib/net/irc/pattern.rb +2 -2
- data/lib/net/irc/server.rb +8 -5
- data/spec/net-irc_spec.rb +33 -8
- metadata +16 -18
- data/examples/lig.rb +0 -551
- data/examples/lingr.rb +0 -327
- data/examples/nig.rb +0 -154
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
== Description
|
6
6
|
|
7
|
-
IRC library. This is mostly conform to
|
7
|
+
IRC library. This is mostly conform to RFC 1459 but partly not for convenience.
|
8
8
|
|
9
9
|
|
10
10
|
== Installation
|
@@ -44,49 +44,48 @@ So, be careful to use @channels instance variable and call super surely.
|
|
44
44
|
|
45
45
|
=== Server
|
46
46
|
|
47
|
-
see example/
|
47
|
+
see example/tig.rb
|
48
48
|
|
49
49
|
|
50
50
|
== IRC Gateways
|
51
51
|
|
52
52
|
There are some gateways connecting to webservices.
|
53
53
|
|
54
|
-
* Lingr
|
55
54
|
* Twitter
|
56
55
|
* Wassr
|
56
|
+
* Hatena Haiku
|
57
|
+
* Hatena Star
|
57
58
|
|
58
59
|
If you want to run it, type following:
|
59
60
|
|
60
61
|
$ cd `ruby -rubygems -e 'print Gem.searcher.find("net/irc").full_gem_path+"/examples"'`
|
61
62
|
|
62
|
-
Lingr:
|
63
|
-
$ sudo gem install pit # for configuration
|
64
|
-
$ ./lig.rb
|
65
|
-
|
66
63
|
Twitter:
|
67
|
-
$ ./tig.rb
|
64
|
+
$ ./tig.rb -f >> /dev/null 2>&1
|
68
65
|
|
69
66
|
Wassr:
|
70
67
|
$ ./wig.rb
|
71
68
|
|
72
69
|
Run as daemon in default. If you want to help:
|
73
70
|
|
74
|
-
$ ./
|
75
|
-
Usage:
|
71
|
+
$ ./tig.rb --help
|
72
|
+
Usage: tig.rb [opts]
|
76
73
|
|
77
74
|
|
78
75
|
Options:
|
79
|
-
-p, --port [PORT=
|
80
|
-
-h, --host [HOST=localhost] listen
|
76
|
+
-p, --port [PORT=16668] port number to listen
|
77
|
+
-h, --host [HOST=localhost] host name or IP address to listen
|
81
78
|
-l, --log LOG log file
|
82
|
-
-a, --api_key API_KEY Your api key on Lingr
|
83
79
|
--debug Enable debug mode
|
80
|
+
-f, --foreground run foreground
|
81
|
+
-n [user name or email address]
|
82
|
+
--name
|
84
83
|
|
85
84
|
|
86
85
|
== Copyright
|
87
86
|
|
88
|
-
This library is based on RICE
|
87
|
+
This library is based on RICE <http://arika.org/ruby/rice> written by akira yamada.
|
89
88
|
|
90
89
|
Author:: cho45 <cho45@lowreal.net>
|
91
|
-
Copyright:: Copyright (c) 2008 cho45
|
90
|
+
Copyright:: Copyright (c) 2008-2009 cho45
|
92
91
|
License:: Ruby's
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ DESCRIPTION = "library for implementing IRC server and client"
|
|
22
22
|
RUBYFORGE_PROJECT = "lowreal"
|
23
23
|
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
24
24
|
BIN_FILES = %w( )
|
25
|
-
VERS = Net::IRC::VERSION
|
25
|
+
VERS = Net::IRC::VERSION.dup
|
26
26
|
|
27
27
|
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
28
28
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
data/examples/client.rb
CHANGED
data/examples/echo_bot.rb
CHANGED
data/examples/gmail.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# vim:fileencoding=UTF-8:
|
2
3
|
=begin
|
3
4
|
|
4
|
-
|
5
5
|
## Licence
|
6
6
|
|
7
7
|
Ruby's by cho45
|
@@ -11,7 +11,7 @@ Ruby's by cho45
|
|
11
11
|
$LOAD_PATH << "lib"
|
12
12
|
$LOAD_PATH << "../lib"
|
13
13
|
|
14
|
-
$KCODE = "u" # json use this
|
14
|
+
$KCODE = "u" if RUBY_VERSION < "1.9" # json use this
|
15
15
|
|
16
16
|
require "rubygems"
|
17
17
|
require "json"
|
@@ -20,6 +20,8 @@ require "mechanize"
|
|
20
20
|
require "sdbm"
|
21
21
|
require "tmpdir"
|
22
22
|
require "nkf"
|
23
|
+
require "hpricot"
|
24
|
+
WWW::Mechanize.html_parser = Hpricot
|
23
25
|
|
24
26
|
class HatenaStarStream < Net::IRC::Server::Session
|
25
27
|
def server_name
|
@@ -101,25 +103,34 @@ class HatenaStarStream < Net::IRC::Server::Session
|
|
101
103
|
db = SDBM.open("#{Dir.tmpdir}/#{@real}.db", 0666)
|
102
104
|
entries.reverse_each do |entry|
|
103
105
|
next if stars[entry].empty?
|
104
|
-
|
105
|
-
|
106
|
+
i = 0
|
107
|
+
s = stars[entry].select {|star|
|
108
|
+
id = "#{entry}::#{i}"
|
109
|
+
i += 1
|
106
110
|
if db.include?(id)
|
107
111
|
false
|
108
112
|
else
|
109
113
|
db[id] = "1"
|
110
114
|
true
|
111
115
|
end
|
112
|
-
}
|
113
|
-
|
114
|
-
post server_name, NOTICE, main_channel,
|
115
|
-
|
116
|
-
|
117
|
-
post server_name, NOTICE, main_channel, "id
|
116
|
+
}
|
117
|
+
|
118
|
+
post server_name, NOTICE, main_channel, "↓ #{entry} #{title(entry)}" if s.length > 0
|
119
|
+
|
120
|
+
s.each do |star|
|
121
|
+
post server_name, NOTICE, main_channel, "id:%s \x03%d%s%s\x030 %s" % [
|
122
|
+
star.name,
|
123
|
+
Star::Colors[star.color],
|
124
|
+
((star.color == "normal") ? "☆" : "★") * ([star.count, 10].min),
|
125
|
+
(star.count > 10) ? "(...#{star.count})" : "",
|
126
|
+
star.quote
|
127
|
+
]
|
118
128
|
end
|
119
129
|
end
|
120
130
|
|
121
131
|
rescue Exception => e
|
122
132
|
@log.error e.inspect
|
133
|
+
@log.error e.backtrace
|
123
134
|
ensure
|
124
135
|
db.close rescue nil
|
125
136
|
end
|
@@ -138,7 +149,25 @@ class HatenaStarStream < Net::IRC::Server::Session
|
|
138
149
|
if i["stars"].any? {|star| star.kind_of? Numeric }
|
139
150
|
i = JSON.load(@ua.get("http://s.hatena.ne.jp/entry.json?uri=#{URI.escape(i["uri"])}").body)["entries"].first
|
140
151
|
end
|
141
|
-
|
152
|
+
stars = []
|
153
|
+
|
154
|
+
if i["colored_stars"]
|
155
|
+
i["colored_stars"].each do |s|
|
156
|
+
s["stars"].each do |j|
|
157
|
+
stars << Star.new(j, s["color"])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
i["stars"].each do |j|
|
163
|
+
star = Star.new(j)
|
164
|
+
if star.quote.empty? && stars.last && stars.last.name == star.name && stars.last.color == "normal"
|
165
|
+
stars.last.count += 1
|
166
|
+
else
|
167
|
+
stars << star
|
168
|
+
end
|
169
|
+
end
|
170
|
+
r.update(i["uri"] => stars)
|
142
171
|
}
|
143
172
|
if n < entries.length
|
144
173
|
ret.update retrive_stars(entries, n)
|
@@ -185,6 +214,22 @@ class HatenaStarStream < Net::IRC::Server::Session
|
|
185
214
|
finish
|
186
215
|
end
|
187
216
|
end
|
217
|
+
|
218
|
+
class Star < OpenStruct
|
219
|
+
Colors = {
|
220
|
+
"purple" => 6,
|
221
|
+
"blue" => 2,
|
222
|
+
"green" => 3,
|
223
|
+
"red" => 4,
|
224
|
+
"normal" => 8,
|
225
|
+
}
|
226
|
+
|
227
|
+
def initialize(obj, col="normal")
|
228
|
+
super(obj)
|
229
|
+
self.count = obj["count"].to_i + 1
|
230
|
+
self.color = col
|
231
|
+
end
|
232
|
+
end
|
188
233
|
end
|
189
234
|
|
190
235
|
if __FILE__ == $0
|
data/examples/hig.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# vim:
|
2
|
+
# vim:fileencoding=UTF-8:
|
3
3
|
=begin
|
4
4
|
# hig.rb
|
5
5
|
|
@@ -90,7 +90,7 @@ Ruby's by cho45
|
|
90
90
|
$LOAD_PATH << "lib"
|
91
91
|
$LOAD_PATH << "../lib"
|
92
92
|
|
93
|
-
$KCODE = "u" # json use this
|
93
|
+
$KCODE = "u" if RUBY_VERSION < "1.9" # json use this
|
94
94
|
|
95
95
|
require "rubygems"
|
96
96
|
require "net/irc"
|
@@ -142,7 +142,6 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
142
142
|
super
|
143
143
|
@channels = {}
|
144
144
|
@user_agent = "#{self.class}/#{server_version} (hig.rb)"
|
145
|
-
@map = nil
|
146
145
|
@counters = {} # for jabber fav
|
147
146
|
end
|
148
147
|
|
@@ -228,7 +227,7 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
228
227
|
end
|
229
228
|
|
230
229
|
def on_privmsg(m)
|
231
|
-
return on_ctcp(m[0],
|
230
|
+
return m[1].ctcps.each {|ctcp| on_ctcp(m[0], ctcp) } if m.ctcp?
|
232
231
|
retry_count = 3
|
233
232
|
ret = nil
|
234
233
|
target, message = *m.params
|
@@ -242,17 +241,24 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
242
241
|
else
|
243
242
|
channel = "" if "##{channel}" == main_channel
|
244
243
|
rid = rid_for(reply) if reply
|
245
|
-
|
244
|
+
if @typo
|
245
|
+
log "typo mode. requesting..."
|
246
|
+
message.gsub!(/\\n/, "\n")
|
247
|
+
file = Net::HTTP.get(URI("http://lab.lowreal.net/test/haiku.rb/?text=" + URI.escape(message)))
|
248
|
+
ret = api("statuses/update", {"file" => file, "in_reply_to_status_id" => rid, "keyword" => channel})
|
249
|
+
else
|
250
|
+
ret = api("statuses/update", {"status" => message, "in_reply_to_status_id" => rid, "keyword" => channel})
|
251
|
+
end
|
246
252
|
log "Status Updated via API"
|
247
253
|
end
|
248
254
|
raise ApiFailed, "API failed" unless ret
|
249
255
|
check_timeline
|
250
256
|
rescue => e
|
251
|
-
@log.error [retry_count, e.inspect].inspect
|
257
|
+
@log.error [retry_count, e.message, e.inspect, e.backtrace].inspect
|
252
258
|
if retry_count > 0
|
253
259
|
retry_count -= 1
|
254
260
|
@log.debug "Retry to setting status..."
|
255
|
-
retry
|
261
|
+
# retry
|
256
262
|
else
|
257
263
|
log "Some Error Happened on Sending #{message}. #{e}"
|
258
264
|
end
|
@@ -315,10 +321,13 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
315
321
|
else
|
316
322
|
post nil, NOTICE, main_channel, "No such id #{tid}"
|
317
323
|
end
|
324
|
+
when "typo"
|
325
|
+
@typo = !@typo
|
326
|
+
post nil, NOTICE, main_channel, "typo mode: #{@typo}"
|
318
327
|
end
|
319
328
|
rescue ApiFailed => e
|
320
329
|
log e.inspect
|
321
|
-
end
|
330
|
+
end; private :on_ctcp
|
322
331
|
|
323
332
|
def on_whois(m)
|
324
333
|
nick = m.params[0]
|
@@ -553,7 +562,32 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
553
562
|
req = nil
|
554
563
|
if require_post?(path)
|
555
564
|
req = Net::HTTP::Post.new(uri.path)
|
556
|
-
|
565
|
+
if q["file"]
|
566
|
+
boundary = (rand(0x1_00_00_00_00_00) + 0x1_00_00_00_00_00).to_s(16)
|
567
|
+
@log.info boundary
|
568
|
+
req["content-type"] = "multipart/form-data; boundary=#{boundary}"
|
569
|
+
|
570
|
+
body = ""
|
571
|
+
q.each do |k, v|
|
572
|
+
body << "--#{boundary}\r\n"
|
573
|
+
if k == "file"
|
574
|
+
body << "Content-Disposition: form-data; name=\"#{k}\"; filename=\"temp.png\";\r\n"
|
575
|
+
body << "Content-Transfer-Encoding: binary\r\n"
|
576
|
+
body << "Content-Type: image/png\r\n"
|
577
|
+
else
|
578
|
+
body << "Content-Disposition: form-data; name=\"#{k}\";\r\n"
|
579
|
+
end
|
580
|
+
body << "\r\n"
|
581
|
+
body << v.to_s
|
582
|
+
body << "\r\n"
|
583
|
+
end
|
584
|
+
body << "--#{boundary}--\r\n"
|
585
|
+
|
586
|
+
req.body = body
|
587
|
+
uri.query = ""
|
588
|
+
else
|
589
|
+
req.body = uri.query
|
590
|
+
end
|
557
591
|
else
|
558
592
|
req = Net::HTTP::Get.new(uri.request_uri)
|
559
593
|
end
|
@@ -604,20 +638,18 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
604
638
|
end
|
605
639
|
|
606
640
|
class TypableMap < Hash
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
when
|
612
|
-
|
613
|
-
else
|
614
|
-
%w|a i u e o|
|
641
|
+
Roman = %w[
|
642
|
+
k g ky gy s z sh j t d ch n ny h b p hy by py m my y r ry w v q
|
643
|
+
].unshift("").map do |consonant|
|
644
|
+
case consonant
|
645
|
+
when "y", /\A.{2}/ then %w|a u o|
|
646
|
+
when "q" then %w|a i e o|
|
647
|
+
else %w|a i u e o|
|
615
648
|
end.map {|vowel| "#{consonant}#{vowel}" }
|
616
|
-
|
649
|
+
end.flatten
|
617
650
|
|
618
|
-
def initialize(size=1)
|
619
|
-
@seq =
|
620
|
-
@map = {}
|
651
|
+
def initialize(size = 1)
|
652
|
+
@seq = Roman
|
621
653
|
@n = 0
|
622
654
|
@size = size
|
623
655
|
end
|
@@ -635,7 +667,7 @@ class HaikuIrcGateway < Net::IRC::Server::Session
|
|
635
667
|
id = generate(@n)
|
636
668
|
self[id] = obj
|
637
669
|
@n += 1
|
638
|
-
@n
|
670
|
+
@n %= @seq.size ** @size
|
639
671
|
id
|
640
672
|
end
|
641
673
|
alias << push
|
data/examples/iig.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# vim:fileencoding=UTF-8:
|
2
3
|
=begin
|
3
4
|
|
4
5
|
# iig.rb
|
@@ -22,7 +23,7 @@ Configuration example for Tiarra <http://coderepos.org/share/wiki/Tiarra>.
|
|
22
23
|
identica {
|
23
24
|
host: localhost
|
24
25
|
port: 16672
|
25
|
-
name: username@example.com athack tid ratio=
|
26
|
+
name: username@example.com athack tid ratio=77:1:12 replies
|
26
27
|
password: password on Identi.ca
|
27
28
|
in-encoding: utf8
|
28
29
|
out-encoding: utf8
|
@@ -64,7 +65,6 @@ Apply ID to each message for make favorites by CTCP ACTION.
|
|
64
65
|
14 => grey
|
65
66
|
15 => lightgrey silver
|
66
67
|
|
67
|
-
|
68
68
|
### jabber=<jid>:<pass>
|
69
69
|
|
70
70
|
If `jabber=<jid>:<pass>` option specified,
|
@@ -89,61 +89,41 @@ Use IM instead of any APIs (e.g. post)
|
|
89
89
|
|
90
90
|
### checkrls=<interval seconds>
|
91
91
|
|
92
|
+
## Feed
|
93
|
+
|
94
|
+
<http://coderepos.org/share/log/lang/ruby/net-irc/trunk/examples/iig.rb?limit=100&mode=stop_on_copy&format=rss>
|
95
|
+
|
92
96
|
## License
|
93
97
|
|
94
98
|
Ruby's by cho45
|
95
99
|
|
96
100
|
=end
|
97
101
|
|
98
|
-
$LOAD_PATH << "lib"
|
99
|
-
$
|
100
|
-
|
101
|
-
$KCODE = "u" # json use this
|
102
|
+
$LOAD_PATH << "lib" << "../lib"
|
103
|
+
$KCODE = "u" if RUBY_VERSION < "1.9" # json use this
|
102
104
|
|
103
105
|
require "rubygems"
|
104
106
|
require "net/irc"
|
105
107
|
require "net/http"
|
106
108
|
require "uri"
|
107
|
-
require "json"
|
108
109
|
require "socket"
|
109
110
|
require "time"
|
110
111
|
require "logger"
|
111
112
|
require "yaml"
|
112
113
|
require "pathname"
|
113
114
|
require "cgi"
|
114
|
-
|
115
|
-
Net::HTTP.version_1_2
|
115
|
+
require "json"
|
116
116
|
|
117
117
|
class IdenticaIrcGateway < Net::IRC::Server::Session
|
118
|
-
def server_name
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
def
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
def main_channel
|
127
|
-
"#Identi.ca"
|
128
|
-
end
|
118
|
+
def server_name; "identicagw" end
|
119
|
+
def server_version; "0.0.0" end
|
120
|
+
def main_channel; "#Identi.ca" end
|
121
|
+
def api_base; URI("http://identi.ca/api/") end
|
122
|
+
def api_source; "iig.rb" end
|
123
|
+
def jabber_bot_id; "update@identi.ca" end
|
124
|
+
def hourly_limit; 100 end
|
129
125
|
|
130
|
-
|
131
|
-
URI("http://identi.ca/api/")
|
132
|
-
end
|
133
|
-
|
134
|
-
def api_source
|
135
|
-
"iig.rb"
|
136
|
-
end
|
137
|
-
|
138
|
-
def jabber_bot_id
|
139
|
-
"update@identi.ca"
|
140
|
-
end
|
141
|
-
|
142
|
-
def hourly_limit
|
143
|
-
60
|
144
|
-
end
|
145
|
-
|
146
|
-
class ApiFailed < StandardError; end
|
126
|
+
class APIFailed < StandardError; end
|
147
127
|
|
148
128
|
def initialize(*args)
|
149
129
|
super
|
@@ -151,7 +131,6 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
151
131
|
@channels = [] # joined channels (groups)
|
152
132
|
@user_agent = "#{self.class}/#{server_version} (#{File.basename(__FILE__)})"
|
153
133
|
@config = Pathname.new(ENV["HOME"]) + ".iig"
|
154
|
-
@map = nil
|
155
134
|
load_config
|
156
135
|
end
|
157
136
|
|
@@ -201,7 +180,7 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
201
180
|
loop do
|
202
181
|
begin
|
203
182
|
check_friends
|
204
|
-
rescue
|
183
|
+
rescue APIFailed => e
|
205
184
|
@log.error e.inspect
|
206
185
|
rescue Exception => e
|
207
186
|
@log.error e.inspect
|
@@ -221,7 +200,7 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
221
200
|
begin
|
222
201
|
check_timeline
|
223
202
|
# check_direct_messages
|
224
|
-
rescue
|
203
|
+
rescue APIFailed => e
|
225
204
|
@log.error e.inspect
|
226
205
|
rescue Exception => e
|
227
206
|
@log.error e.inspect
|
@@ -240,7 +219,7 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
240
219
|
loop do
|
241
220
|
begin
|
242
221
|
check_replies
|
243
|
-
rescue
|
222
|
+
rescue APIFailed => e
|
244
223
|
@log.error e.inspect
|
245
224
|
rescue Exception => e
|
246
225
|
@log.error e.inspect
|
@@ -254,15 +233,15 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
254
233
|
end
|
255
234
|
|
256
235
|
def on_disconnected
|
257
|
-
@check_friends_thread.kill
|
258
|
-
@check_replies_thread.kill
|
259
|
-
@check_timeline_thread.kill
|
260
|
-
@im_thread.kill
|
261
|
-
@im.disconnect
|
236
|
+
@check_friends_thread.kill rescue nil
|
237
|
+
@check_replies_thread.kill rescue nil
|
238
|
+
@check_timeline_thread.kill rescue nil
|
239
|
+
@im_thread.kill rescue nil
|
240
|
+
@im.disconnect rescue nil
|
262
241
|
end
|
263
242
|
|
264
243
|
def on_privmsg(m)
|
265
|
-
return on_ctcp(m[0],
|
244
|
+
return m[1].ctcps.each {|ctcp| on_ctcp(m[0], ctcp) } if m.ctcp?
|
266
245
|
retry_count = 3
|
267
246
|
ret = nil
|
268
247
|
target, message = *m.params
|
@@ -278,7 +257,7 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
278
257
|
# direct message
|
279
258
|
ret = api("direct_messages/new", {"user" => target, "text" => message})
|
280
259
|
end
|
281
|
-
raise
|
260
|
+
raise APIFailed, "API failed" unless ret
|
282
261
|
log "Status Updated"
|
283
262
|
rescue => e
|
284
263
|
@log.error [retry_count, e.inspect].inspect
|
@@ -363,9 +342,9 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
363
342
|
location = location.empty? ? "nowhere" : "in #{location}"
|
364
343
|
post server_name, NOTICE, main_channel, "You are #{location} now."
|
365
344
|
end
|
366
|
-
rescue
|
345
|
+
rescue APIFailed => e
|
367
346
|
log e.inspect
|
368
|
-
end
|
347
|
+
end; private :on_ctcp
|
369
348
|
|
370
349
|
def on_whois(m)
|
371
350
|
nick = m.params[0]
|
@@ -667,19 +646,19 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
667
646
|
when Net::HTTPOK # 200
|
668
647
|
ret = JSON.parse(ret.body.gsub(/'(y(?:es)?|no?|true|false|null)'/, '"\1"'))
|
669
648
|
if ret.kind_of?(Hash) && !opt[:avoid_error] && ret["error"]
|
670
|
-
raise
|
649
|
+
raise APIFailed, "Server Returned Error: #{ret["error"]}"
|
671
650
|
end
|
672
651
|
ret
|
673
652
|
when Net::HTTPNotModified # 304
|
674
653
|
[]
|
675
654
|
when Net::HTTPBadRequest # 400
|
676
655
|
# exceeded the rate limitation
|
677
|
-
raise
|
656
|
+
raise APIFailed, "#{ret.code}: #{ret.message}"
|
678
657
|
else
|
679
|
-
raise
|
658
|
+
raise APIFailed, "Server Returned #{ret.code} #{ret.message}"
|
680
659
|
end
|
681
660
|
rescue Errno::ETIMEDOUT, JSON::ParserError, IOError, Timeout::Error, Errno::ECONNRESET => e
|
682
|
-
raise
|
661
|
+
raise APIFailed, e.inspect
|
683
662
|
end
|
684
663
|
|
685
664
|
def message(sender, target, str)
|
@@ -692,7 +671,7 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
692
671
|
end
|
693
672
|
|
694
673
|
def log(str)
|
695
|
-
str.gsub!(/\r
|
674
|
+
str.gsub!(/\r\n|[\r\n]/, " ")
|
696
675
|
post server_name, NOTICE, main_channel, str
|
697
676
|
end
|
698
677
|
|
@@ -712,20 +691,18 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
712
691
|
end
|
713
692
|
|
714
693
|
class TypableMap < Hash
|
715
|
-
Roman = %w
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
when
|
720
|
-
|
721
|
-
else
|
722
|
-
%w|a i u e o|
|
694
|
+
Roman = %w[
|
695
|
+
k g ky gy s z sh j t d ch n ny h b p hy by py m my y r ry w v q
|
696
|
+
].unshift("").map do |consonant|
|
697
|
+
case consonant
|
698
|
+
when "y", /\A.{2}/ then %w|a u o|
|
699
|
+
when "q" then %w|a i e o|
|
700
|
+
else %w|a i u e o|
|
723
701
|
end.map {|vowel| "#{consonant}#{vowel}" }
|
724
|
-
|
702
|
+
end.flatten
|
725
703
|
|
726
704
|
def initialize(size = 1)
|
727
705
|
@seq = Roman
|
728
|
-
@map = {}
|
729
706
|
@n = 0
|
730
707
|
@size = size
|
731
708
|
end
|
@@ -743,7 +720,7 @@ class IdenticaIrcGateway < Net::IRC::Server::Session
|
|
743
720
|
id = generate(@n)
|
744
721
|
self[id] = obj
|
745
722
|
@n += 1
|
746
|
-
@n
|
723
|
+
@n %= @seq.size ** @size
|
747
724
|
id
|
748
725
|
end
|
749
726
|
alias << push
|
@@ -814,27 +791,27 @@ if __FILE__ == $0
|
|
814
791
|
opts[:logger] = Logger.new(opts[:log], "daily")
|
815
792
|
opts[:logger].level = opts[:debug] ? Logger::DEBUG : Logger::INFO
|
816
793
|
|
817
|
-
#
|
818
|
-
#
|
819
|
-
#
|
820
|
-
#
|
821
|
-
#
|
822
|
-
#
|
823
|
-
#
|
824
|
-
#
|
825
|
-
#
|
826
|
-
#
|
827
|
-
#
|
828
|
-
#
|
829
|
-
#
|
830
|
-
#
|
831
|
-
#
|
832
|
-
#
|
833
|
-
#
|
834
|
-
|
835
|
-
#
|
794
|
+
#def daemonize(foreground = false)
|
795
|
+
# trap("SIGINT") { exit! 0 }
|
796
|
+
# trap("SIGTERM") { exit! 0 }
|
797
|
+
# trap("SIGHUP") { exit! 0 }
|
798
|
+
# return yield if $DEBUG || foreground
|
799
|
+
# Process.fork do
|
800
|
+
# Process.setsid
|
801
|
+
# Dir.chdir "/"
|
802
|
+
# File.open("/dev/null") {|f|
|
803
|
+
# STDIN.reopen f
|
804
|
+
# STDOUT.reopen f
|
805
|
+
# STDERR.reopen f
|
806
|
+
# }
|
807
|
+
# yield
|
808
|
+
# end
|
809
|
+
# exit! 0
|
810
|
+
#end
|
811
|
+
|
812
|
+
#daemonize(opts[:debug] || opts[:foreground]) do
|
836
813
|
Net::IRC::Server.new(opts[:host], opts[:port], IdenticaIrcGateway, opts).start
|
837
|
-
#
|
814
|
+
#end
|
838
815
|
end
|
839
816
|
|
840
817
|
# Local Variables:
|