mpex 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mpex/irc.rb +49 -19
- data/lib/mpex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2e9cf3a474bbeed9681a7ce0907ff7e05b27c28
|
4
|
+
data.tar.gz: 437eee712d95706cc8b6c033ca71f447120f1f16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa574c8245e15b4458b15c07c6296bf29559a42ef803f9a16f8d087585ca03bcbc2c96c45a0f1872cf1baddbdc4b3dcb4fc9a128a15d42402b6d8668b9495d7f
|
7
|
+
data.tar.gz: 44eb7fc2214ed39de00e59f5864d9f800c568f2183b96ac76328af486f62967baba049327f3846aeac8d8d7e08d2307ce24d33def160e320083579c806aca6fb
|
data/lib/mpex/irc.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/yail'
|
2
2
|
require 'net/http'
|
3
|
+
require 'timeout'
|
3
4
|
|
4
5
|
module Mpex
|
5
6
|
# TODO to be improved and to be made configurable!
|
@@ -7,6 +8,7 @@ module Mpex
|
|
7
8
|
|
8
9
|
ASSBOT = "assbot"
|
9
10
|
MPEXBOT = "mpexbot"
|
11
|
+
TIMEOUT = 30 # seconds
|
10
12
|
|
11
13
|
def initialize
|
12
14
|
@irc = Net::YAIL.new(
|
@@ -26,6 +28,10 @@ module Mpex
|
|
26
28
|
@connected = true
|
27
29
|
end
|
28
30
|
|
31
|
+
@irc.hearing_msg do |event|
|
32
|
+
@last_message = {:nick => event.nick, :message => event.message}
|
33
|
+
end
|
34
|
+
|
29
35
|
puts "Connecting. Please wait."
|
30
36
|
|
31
37
|
@irc.start_listening
|
@@ -44,39 +50,63 @@ module Mpex
|
|
44
50
|
dpaste_url = res['Location']
|
45
51
|
@irc.msg(ASSBOT, "!mp " + dpaste_url)
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
53
|
+
status = Timeout::timeout(TIMEOUT) {
|
54
|
+
yield wait_for_assbot_message
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def wait_for_assbot_message
|
59
|
+
while true
|
60
|
+
if @last_message
|
61
|
+
answer = handle_assbot_incoming(@last_message[:message])
|
62
|
+
if answer
|
63
|
+
@last_message = nil
|
64
|
+
return answer
|
65
|
+
end
|
66
|
+
end
|
51
67
|
end
|
52
68
|
end
|
53
69
|
|
54
|
-
def
|
70
|
+
def handle_assbot_incoming(msg)
|
55
71
|
if msg.start_with? "Response: http:"
|
56
|
-
|
72
|
+
resp_url = msg.split[1]
|
73
|
+
return Net::HTTP.get(URI.parse(resp_url))
|
57
74
|
end
|
58
75
|
end
|
59
76
|
|
60
77
|
def vwap(&block)
|
61
78
|
@irc.msg MPEXBOT, '$vwap'
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
79
|
+
|
80
|
+
status = Timeout::timeout(TIMEOUT) {
|
81
|
+
yield wait_for_mpexbot_message
|
82
|
+
}
|
67
83
|
end
|
68
84
|
|
69
85
|
def depth(&block)
|
70
86
|
@irc.msg MPEXBOT, '$depth'
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
87
|
+
|
88
|
+
status = Timeout::timeout(TIMEOUT) {
|
89
|
+
yield wait_for_mpexbot_message
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def wait_for_mpexbot_message
|
94
|
+
while true
|
95
|
+
if @last_message
|
96
|
+
answer = handle_mpexbot_incoming(@last_message[:message])
|
97
|
+
if answer
|
98
|
+
@last_message = nil
|
99
|
+
return answer
|
100
|
+
end
|
78
101
|
end
|
79
|
-
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def handle_mpexbot_incoming(msg)
|
106
|
+
if msg.start_with?("http://pastebin.com")
|
107
|
+
id = URI.parse(msg).path[1..-1]
|
108
|
+
uri = URI.parse("http://pastebin.com/raw.php?i=" + id)
|
109
|
+
return Net::HTTP.get(uri)
|
80
110
|
end
|
81
111
|
end
|
82
112
|
|
data/lib/mpex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fa Wuxi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cri
|