percy 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +176 -0
  2. data/VERSION +1 -0
  3. data/lib/percy.rb +10 -10
  4. metadata +3 -2
  5. data/README.rdoc +0 -80
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Percy 0.0.5
2
+
3
+ ## Configuring and starting the bot
4
+
5
+ ### mybot.rb
6
+ $:.unshift "#{File.expand_path(File.dirname(__FILE__))}/lib"
7
+ PERCY_ROOT = File.expand_path(File.dirname(__FILE__))
8
+
9
+ require 'rubygems'
10
+ require 'percy'
11
+
12
+ bot = Percy.new
13
+
14
+ bot.configure do |c|
15
+ c.server = 'chat.eu.freenode.net'
16
+ c.port = 6667
17
+ c.nick = 'Percyguy'
18
+ c.verbose = true
19
+ c.logging = true
20
+ end
21
+
22
+ bot.connect
23
+
24
+ Start it with `ruby mybot.rb`.
25
+
26
+ ## Handling Events
27
+ ### Connect
28
+ bot.on :connect do
29
+ # ...
30
+ end
31
+ No variables.
32
+
33
+ ### Channel message
34
+ bot.on :channel, /^foo!/ do |env|
35
+ # ...
36
+ end
37
+ Variables:
38
+
39
+ <tt>env[:nick]
40
+ env[:user]
41
+ env[:host]
42
+ env[:channel]
43
+ env[:message]</tt>
44
+
45
+ ### Query message
46
+ bot.on :query, /^bar!/ do |env|
47
+ # ...
48
+ end
49
+ Variables:
50
+
51
+ <tt>env[:nick]
52
+ env[:user]
53
+ env[:host]
54
+ env[:message]</tt>
55
+
56
+ ### Join
57
+ bot.on :join do |env|
58
+ # ...
59
+ end
60
+ Variables:
61
+
62
+ <tt>env[:nick]
63
+ env[:user]
64
+ env[:host]
65
+ env[:channel]</tt>
66
+
67
+ ### Part
68
+ bot.on :part do |env|
69
+ # ...
70
+ end
71
+ Variables:
72
+
73
+ <tt>env[:nick]
74
+ env[:user]
75
+ env[:host]
76
+ env[:channel]
77
+ env[:message]</tt>
78
+
79
+ ### Quit
80
+ bot.on :quit do |env|
81
+ # ...
82
+ end
83
+ Variables:
84
+
85
+ <tt>env[:nick]
86
+ env[:user]
87
+ env[:host]
88
+ env[:message]</tt>
89
+
90
+ ### Nickchange
91
+ bot.on :nickchange do |env|
92
+ # ...
93
+ end
94
+ Variables:
95
+
96
+ <tt>env[:nick]
97
+ env[:user]
98
+ env[:host]
99
+ env[:new_nick]</tt>
100
+
101
+ ### Kick
102
+ bot.on :kick do |env|
103
+ # ...
104
+ end
105
+ Variables:
106
+
107
+ <tt>env[:nick]
108
+ env[:user]
109
+ env[:host]
110
+ env[:channel]
111
+ env[:victim]
112
+ env[:reason]</tt>
113
+
114
+ ## Availabe Methods
115
+
116
+ `raw(msg)`
117
+
118
+ Sends a raw message to the server.
119
+
120
+ `message(recipient, msg)`
121
+
122
+ Sends a message to a channel or an user.
123
+
124
+ `notice(recipient, msg)`
125
+
126
+ Sends a notice to an user.
127
+
128
+ `action(recipient, msg)`
129
+
130
+ Performs an action (/me ...).
131
+
132
+ `mode(recipient, option)`
133
+
134
+ Sets a mode for a channel or an user.
135
+
136
+ `channellimit(channel)`
137
+
138
+ Returns the channel limit of a channel (as integer if set, else (not set/timeout) false).
139
+
140
+ `kick(channel, user, reason)`
141
+
142
+ Kicks an user from a channel with a specific reason.
143
+
144
+ `topic(channel, topic)`
145
+
146
+ Sets the topic for a channel.
147
+
148
+ `join(channel, password = nil)`
149
+
150
+ Joins a channel.
151
+
152
+ `part(channel, msg)`
153
+
154
+ Parts a channel with a message.
155
+
156
+ `quit(msg = nil)`
157
+
158
+ Quits from the server with a message.
159
+
160
+ `users_on(channel)`
161
+
162
+ Returns an array of users from a channel (mode in front like: ['@percy', 'Peter_Parker', '+The_Librarian']) or false if timeout.
163
+
164
+
165
+ `is_online(nick)`
166
+
167
+ Returns a nickname as string if online, else false (not online/timeout)
168
+
169
+ ## License
170
+ Copyright (c) 2009 Tobias Bühlmann
171
+
172
+ 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:
173
+
174
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
175
+
176
+ 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/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
data/lib/percy.rb CHANGED
@@ -8,7 +8,7 @@ require 'thread'
8
8
  Thread.abort_on_exception = true
9
9
 
10
10
  class Percy
11
- VERSION = 'Percy 0.0.4 (http://github.com/tbuehlmann/percy)'
11
+ VERSION = 'Percy 0.0.5 (http://github.com/tbuehlmann/percy)'
12
12
 
13
13
  Config = Struct.new(:server, :port, :password, :nick, :username, :verbose, :logging)
14
14
 
@@ -67,8 +67,8 @@ class Percy
67
67
  raw "MODE #{recipient} #{option}"
68
68
  end
69
69
 
70
- # get the channellimit of a channel
71
- def channellimit(channel)
70
+ # get the channel limit of a channel
71
+ def channel_limit(channel)
72
72
  add_observer
73
73
  raw "MODE #{channel}"
74
74
 
@@ -76,8 +76,8 @@ class Percy
76
76
  Timeout::timeout(10) do # try 10 seconds to retrieve l mode of <channel>
77
77
  loop do
78
78
  @temp_socket.each do |line|
79
- if line =~ /^:(\S+) 324 (\S+) #{channel} .*l.* (\d+)/
80
- return $3.to_i
79
+ if line =~ /^:\S+ 324 \S+ #{channel} .*l.* (\d+)/
80
+ return $1.to_i
81
81
  end
82
82
  end
83
83
  sleep 0.5
@@ -99,8 +99,8 @@ class Percy
99
99
  Timeout::timeout(10) do
100
100
  loop do
101
101
  @temp_socket.each do |line|
102
- if line =~ /^:(\S+) 311 (\S+) (#{nick}) /i
103
- return $3
102
+ if line =~ /^:\S+ 311 \S+ (#{nick}) /i
103
+ return $1
104
104
  elsif line =~ /^:\S+ 401 \S+ #{nick} /i
105
105
  return false
106
106
  end
@@ -209,7 +209,7 @@ class Percy
209
209
  Timeout::timeout(10) do # try 10 seconds to retrieve the users of <channel>
210
210
  loop do
211
211
  @temp_socket.each do |line|
212
- if line =~ /^:(\S+) 353 (\S+) = #{channel} :/
212
+ if line =~ /^:\S+ 353 \S+ = #{channel} :/
213
213
  return $'.split(' ')
214
214
  end
215
215
  end
@@ -403,13 +403,13 @@ class Percy
403
403
  when /^PING \S+$/
404
404
  raw line.chomp.gsub('PING', 'PONG')
405
405
 
406
- when /^:(\S+) (376|422)/
406
+ when /^:\S+ 376|422/
407
407
  parse(:connect)
408
408
 
409
409
  when /^:(\S+)!(\S+)@(\S+) PRIVMSG #(\S+) :/
410
410
  parse(:channel, :nick => $1, :user => $2, :host => $3, :channel => "##{$4}", :message => $')
411
411
 
412
- when /^:(\S+)!(\S+)@(\S+) PRIVMSG (\S+) :/
412
+ when /^:(\S+)!(\S+)@(\S+) PRIVMSG \S+ :/
413
413
  parse(:query, :nick => $1, :user => $2, :host => $3, :message => $')
414
414
 
415
415
  when /^:(\S+)!(\S+)@(\S+) JOIN :*(\S+)$/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Tobias B\xC3\xBChlmann"
@@ -24,8 +24,9 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - lib/percy.rb
26
26
  - lib/percylogger.rb
27
- - README.rdoc
27
+ - README.md
28
28
  - LICENSE
29
+ - VERSION
29
30
  has_rdoc: true
30
31
  homepage: http://github.com/tbuehlmann/percy
31
32
  licenses: []
data/README.rdoc DELETED
@@ -1,80 +0,0 @@
1
- = Percy 0.0.4
2
-
3
- == Configuring the bot
4
-
5
- === mybot.rb
6
- $:.unshift "#{File.expand_path(File.dirname(__FILE__))}/lib"
7
- PERCY_ROOT = File.expand_path(File.dirname(__FILE__))
8
-
9
- require 'rubygems'
10
- require 'percy'
11
-
12
- bot = Percy.new
13
-
14
- bot.configure do |c|
15
- c.server = 'chat.eu.freenode.net'
16
- c.port = 6667
17
- c.nick = 'Percyguy'
18
- c.verbose = true
19
- c.logging = true
20
- end
21
-
22
- Start it with <tt>ruby mybot.rb</tt>.
23
-
24
- == Events
25
- Handle events with:
26
- bot.on :connect do
27
- # join channels
28
- # do things
29
- end
30
-
31
- bot.on :channel, /^foo!/ do |env|
32
- # available variables: env[:nick], env[:user], env[:host], env[:channel], env[:message]
33
- end
34
-
35
- bot.on :query, /^bar!/ do |env|
36
- # available variables: env[:nick], env[:user], env[:host], env[:message]
37
- end
38
-
39
- bot.on :join do |env|
40
- # available variables: env[:nick], env[:user], env[:host], env[:channel]
41
- end
42
-
43
- bot.on :part do |env|
44
- # available variables: env[:nick], env[:user], env[:host], env[:channel], env[:message]
45
- end
46
-
47
- bot.on :quit do |env|
48
- # available variables: env[:nick], env[:user], env[:host], env[:message]
49
- end
50
-
51
- bot.on :nickchange do |env|
52
- # available variables: env[:nick], env[:user], env[:host], env[:new_nick]
53
- end
54
-
55
- bot.on :kick do |env|
56
- # available variables: env[:nick], env[:user], env[:host], env[:new_nick], env[:channel], env[:victim]
57
- end
58
-
59
- == Methods availabe
60
- * message(recipient, msg)
61
- * notice(recipient, msg)
62
- * action(recipient, msg)
63
- * mode(recipient, option)
64
- * channellimit(channel)
65
- * kick(channel, user, reason)
66
- * topic(channel, topic)
67
- * join(channel, password = nil)
68
- * part(channel, msg)
69
- * quit(msg = nil)
70
- * users_on(channel)
71
- * is_online(nick)
72
-
73
- == License
74
- Copyright (c) 2009 Tobias Bühlmann
75
-
76
- 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:
77
-
78
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
79
-
80
- 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.