percy 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +67 -28
- data/VERSION +1 -1
- data/examples/github_blog.rb +2 -1
- data/examples/is_online_checker.rb +10 -10
- data/lib/percy/connection.rb +35 -0
- data/lib/percy/formatting.rb +28 -0
- data/lib/percy/irc.rb +508 -0
- data/lib/percy/percylogger.rb +72 -0
- data/lib/percy.rb +7 -542
- data/percy.gemspec +6 -3
- metadata +7 -4
- data/lib/percylogger.rb +0 -71
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
# Percy 1.
|
2
|
-
|
3
|
-
- You can now call all the class methods without `Percy.` in front.
|
1
|
+
# Percy 1.4.0
|
4
2
|
|
5
3
|
## Configuring and starting the bot
|
6
4
|
|
@@ -8,7 +6,7 @@
|
|
8
6
|
require 'rubygems'
|
9
7
|
require 'percy'
|
10
8
|
|
11
|
-
|
9
|
+
configure do |c|
|
12
10
|
c.server = 'chat.eu.freenode.net'
|
13
11
|
c.port = 6667
|
14
12
|
# c.password = 'password'
|
@@ -20,19 +18,22 @@
|
|
20
18
|
c.reconnect_interval = 30
|
21
19
|
end
|
22
20
|
|
23
|
-
|
21
|
+
connect
|
24
22
|
|
25
23
|
Start it with `ruby mybot.rb`.
|
26
24
|
|
27
25
|
## Handling Events
|
26
|
+
|
27
|
+
- You can also call all methods with `Percy::IRC`, like `Percy::IRC.join('#that_cool_channel')`.
|
28
|
+
|
28
29
|
### Connect
|
29
|
-
|
30
|
+
on :connect do
|
30
31
|
# ...
|
31
32
|
end
|
32
33
|
No variables.
|
33
34
|
|
34
35
|
### Channel message
|
35
|
-
|
36
|
+
on :channel, /^foo!/ do |env|
|
36
37
|
# ...
|
37
38
|
end
|
38
39
|
Variables:
|
@@ -44,7 +45,7 @@ env[:channel]<br />
|
|
44
45
|
env[:message]</tt>
|
45
46
|
|
46
47
|
### Query message
|
47
|
-
|
48
|
+
on :query, /^bar!/ do |env|
|
48
49
|
# ...
|
49
50
|
end
|
50
51
|
Variables:
|
@@ -55,7 +56,7 @@ env[:host]<br />
|
|
55
56
|
env[:message]</tt>
|
56
57
|
|
57
58
|
### Join
|
58
|
-
|
59
|
+
on :join do |env|
|
59
60
|
# ...
|
60
61
|
end
|
61
62
|
Variables:
|
@@ -66,7 +67,7 @@ env[:host]<br />
|
|
66
67
|
env[:channel]</tt>
|
67
68
|
|
68
69
|
### Part
|
69
|
-
|
70
|
+
on :part do |env|
|
70
71
|
# ...
|
71
72
|
end
|
72
73
|
Variables:
|
@@ -78,7 +79,7 @@ env[:channel]<br />
|
|
78
79
|
env[:message]</tt>
|
79
80
|
|
80
81
|
### Quit
|
81
|
-
|
82
|
+
on :quit do |env|
|
82
83
|
# ...
|
83
84
|
end
|
84
85
|
Variables:
|
@@ -89,7 +90,7 @@ env[:host]<br />
|
|
89
90
|
env[:message]</tt>
|
90
91
|
|
91
92
|
### Nickchange
|
92
|
-
|
93
|
+
on :nickchange do |env|
|
93
94
|
# ...
|
94
95
|
end
|
95
96
|
Variables:
|
@@ -100,7 +101,7 @@ env[:host]<br />
|
|
100
101
|
env[:new_nick]</tt>
|
101
102
|
|
102
103
|
### Kick
|
103
|
-
|
104
|
+
on :kick do |env|
|
104
105
|
# ...
|
105
106
|
end
|
106
107
|
Variables:
|
@@ -113,7 +114,7 @@ env[:victim]<br />
|
|
113
114
|
env[:reason]</tt>
|
114
115
|
|
115
116
|
### Raw Numerics
|
116
|
-
|
117
|
+
on '301' do |env|
|
117
118
|
# ...
|
118
119
|
end
|
119
120
|
Variables:
|
@@ -122,59 +123,97 @@ Variables:
|
|
122
123
|
|
123
124
|
## Availabe Class Methods
|
124
125
|
|
125
|
-
`
|
126
|
+
`raw(msg)`
|
126
127
|
|
127
128
|
Sends a raw message to the server.
|
128
129
|
|
129
|
-
`
|
130
|
+
`message(recipient, msg)`
|
130
131
|
|
131
132
|
Sends a message to a channel or an user.
|
132
133
|
|
133
|
-
`
|
134
|
+
`notice(recipient, msg)`
|
134
135
|
|
135
136
|
Sends a notice to an user.
|
136
137
|
|
137
|
-
`
|
138
|
+
`action(recipient, msg)`
|
138
139
|
|
139
140
|
Performs an action (/me ...).
|
140
141
|
|
141
|
-
`
|
142
|
+
`mode(recipient, option)`
|
142
143
|
|
143
144
|
Sets a mode for a channel or an user.
|
144
145
|
|
145
|
-
`
|
146
|
+
`channellimit(channel)`
|
146
147
|
|
147
148
|
Returns the channel limit of a channel (as integer if set, else (not set/timeout) false).
|
148
149
|
|
149
|
-
`
|
150
|
+
`kick(channel, user, reason)`
|
150
151
|
|
151
152
|
Kicks an user from a channel with a specific reason.
|
152
153
|
|
153
|
-
`
|
154
|
+
`topic(channel, topic)`
|
154
155
|
|
155
156
|
Sets the topic for a channel.
|
156
157
|
|
157
|
-
`
|
158
|
+
`join(channel, password = nil)`
|
158
159
|
|
159
160
|
Joins a channel.
|
160
161
|
|
161
|
-
`
|
162
|
+
`part(channel, msg)`
|
162
163
|
|
163
164
|
Parts a channel with a message.
|
164
165
|
|
165
|
-
`
|
166
|
+
`quit(msg = nil)`
|
166
167
|
|
167
168
|
Quits from the server with a message.
|
168
169
|
|
169
|
-
`
|
170
|
+
`users_on(channel)`
|
170
171
|
|
171
172
|
Returns an array of users from a channel (mode in front like: ['@percy', 'Peter_Parker', '+The_Librarian']) or false if timeout.
|
172
173
|
|
173
|
-
|
174
|
-
`Percy.is_online(nick)`
|
174
|
+
`is_online(nick)`
|
175
175
|
|
176
176
|
Returns a nickname as string if online, else false (not online/timeout)
|
177
177
|
|
178
|
+
## Formatting
|
179
|
+
|
180
|
+
There are constants for formatting your messages. They are all availabe through `Percy::Formatting` or by including the module.
|
181
|
+
|
182
|
+
Availabe formatting constants:
|
183
|
+
|
184
|
+
`PLAIN`
|
185
|
+
`BOLD`
|
186
|
+
`ITALIC`
|
187
|
+
`UNDERLINE`
|
188
|
+
`COLOR_CODE`
|
189
|
+
`UNCOLOR`
|
190
|
+
`COLORS`
|
191
|
+
|
192
|
+
Availabe colors through the `COLORS` hash:
|
193
|
+
|
194
|
+
`:white`
|
195
|
+
`:black`
|
196
|
+
`:blue`
|
197
|
+
`:green`
|
198
|
+
`:red`
|
199
|
+
`:brown`
|
200
|
+
`:purple`
|
201
|
+
`:orange`
|
202
|
+
`:yellow`
|
203
|
+
`:lime`
|
204
|
+
`:teal`
|
205
|
+
`:cyan`
|
206
|
+
`:royal`
|
207
|
+
`:pink`
|
208
|
+
`:gray`
|
209
|
+
`:silver`
|
210
|
+
|
211
|
+
### Example:
|
212
|
+
message '#that_cool_channel', "#{Percy::Formatting::COLOR_CODE}#{Percy::Formatting::COLORS[:red]}This is red text.#{Percy::Formatting::UNCOLOR} This is not."
|
213
|
+
|
214
|
+
### Example with included Percy::Formatting module:
|
215
|
+
message '#that_cool_channel', "#{COLOR_CODE}#{COLORS[:red]}This is red text.#{UNCOLOR} This is not."
|
216
|
+
|
178
217
|
## License
|
179
218
|
Copyright (c) 2009, 2010 Tobias Bühlmann
|
180
219
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/examples/github_blog.rb
CHANGED
@@ -3,6 +3,7 @@ require 'nokogiri'
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'percy'
|
5
5
|
|
6
|
+
# abbreviated notation without Percy::IRC
|
6
7
|
configure do |c|
|
7
8
|
c.server = 'chat.eu.freenode.net'
|
8
9
|
c.port = 6667
|
@@ -20,7 +21,7 @@ on :channel, /^!quit$/ do
|
|
20
21
|
quit
|
21
22
|
end
|
22
23
|
|
23
|
-
on :channel, /^blog
|
24
|
+
on :channel, /^blog\?$/ do |env|
|
24
25
|
doc = Nokogiri::HTML(open('http://github.com/blog'))
|
25
26
|
title = doc.xpath('//html/body/div/div[2]/div/div/ul/li/h2/a')[0].text
|
26
27
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'percy'
|
3
3
|
|
4
|
-
Percy.configure do |c|
|
4
|
+
Percy::IRC.configure do |c|
|
5
5
|
c.server = 'chat.eu.freenode.net'
|
6
6
|
c.port = 6667
|
7
7
|
c.nick = 'Percy_onlchk'
|
@@ -10,24 +10,24 @@ Percy.configure do |c|
|
|
10
10
|
c.reconnect = false
|
11
11
|
end
|
12
12
|
|
13
|
-
Percy.on :connect do
|
14
|
-
Percy.join '#that_cool_channel'
|
13
|
+
Percy::IRC.on :connect do
|
14
|
+
Percy::IRC.join '#that_cool_channel'
|
15
15
|
end
|
16
16
|
|
17
|
-
Percy.on :channel, /^!quit$/ do
|
18
|
-
Percy.quit
|
17
|
+
Percy::IRC.on :channel, /^!quit$/ do
|
18
|
+
Percy::IRC.quit
|
19
19
|
end
|
20
20
|
|
21
|
-
Percy.on :channel, /^online\?/ do |env|
|
21
|
+
Percy::IRC.on :channel, /^online\?/ do |env|
|
22
22
|
match = env[:message].split(' ')
|
23
23
|
if match.length > 1
|
24
|
-
user = Percy.is_online(match[1])
|
24
|
+
user = Percy::IRC.is_online(match[1])
|
25
25
|
if user
|
26
|
-
Percy.message env[:channel], "#{user} is online!"
|
26
|
+
Percy::IRC.message env[:channel], "#{user} is online!"
|
27
27
|
else
|
28
|
-
Percy.message env[:channel], "#{user} is not online!"
|
28
|
+
Percy::IRC.message env[:channel], "#{user} is not online!"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
Percy.connect
|
33
|
+
Percy::IRC.connect
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'eventmachine'
|
3
|
+
|
4
|
+
module Percy
|
5
|
+
class Connection < EventMachine::Connection
|
6
|
+
include EventMachine::Protocols::LineText2
|
7
|
+
|
8
|
+
def connection_completed
|
9
|
+
IRC.raw "NICK #{IRC.config.nick}"
|
10
|
+
IRC.raw "USER #{IRC.config.nick} 0 * :#{IRC.config.username}"
|
11
|
+
IRC.raw "PASS #{IRC.config.password}" if IRC.config.password
|
12
|
+
end
|
13
|
+
|
14
|
+
def unbind
|
15
|
+
IRC.connected = false
|
16
|
+
IRC.traffic_logger.info('-- Percy disconnected') if IRC.traffic_logger
|
17
|
+
puts "#{Time.now.strftime('%d.%m.%Y %H:%M:%S')} -- Percy disconnected"
|
18
|
+
|
19
|
+
if IRC.config.reconnect
|
20
|
+
IRC.traffic_logger.info("-- Reconnecting in #{IRC.config.reconnect_interval} seconds") if IRC.traffic_logger
|
21
|
+
puts "#{Time.now.strftime('%d.%m.%Y %H:%M:%S')} -- Reconnecting in #{IRC.config.reconnect_interval} seconds"
|
22
|
+
|
23
|
+
EventMachine::add_timer(IRC.config.reconnect_interval) do
|
24
|
+
reconnect IRC.config.server, IRC.config.port
|
25
|
+
end
|
26
|
+
else
|
27
|
+
EventMachine::stop_event_loop
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def receive_line(line)
|
32
|
+
IRC.parse line
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Percy
|
2
|
+
module Formatting
|
3
|
+
PLAIN = 15.chr
|
4
|
+
BOLD = 2.chr
|
5
|
+
ITALIC = 22.chr
|
6
|
+
UNDERLINE = 31.chr
|
7
|
+
COLOR_CODE = 3.chr
|
8
|
+
UNCOLOR = COLOR_CODE
|
9
|
+
|
10
|
+
#mIRC color codes from http://www.mirc.com/help/color.txt
|
11
|
+
COLORS = {:white => '00',
|
12
|
+
:black => '01',
|
13
|
+
:blue => '02',
|
14
|
+
:green => '03',
|
15
|
+
:red => '04',
|
16
|
+
:brown => '05',
|
17
|
+
:purple => '06',
|
18
|
+
:orange => '07',
|
19
|
+
:yellow => '08',
|
20
|
+
:lime => '09',
|
21
|
+
:teal => '10',
|
22
|
+
:cyan => '11',
|
23
|
+
:royal => '12',
|
24
|
+
:pink => '13',
|
25
|
+
:gray => '14',
|
26
|
+
:silver => '15'}
|
27
|
+
end
|
28
|
+
end
|