percy 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +4 -5
- data/VERSION +1 -1
- data/examples/github_blog.rb +30 -0
- data/examples/is_online_checker.rb +33 -0
- data/lib/percy.rb +49 -19
- data/lib/percylogger.rb +11 -7
- data/percy.gemspec +24 -0
- metadata +27 -13
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2009 Tobias Bühlmann
|
1
|
+
Copyright (c) 2009, 2010 Tobias Bühlmann
|
2
2
|
|
3
3
|
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:
|
4
4
|
|
data/README.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# Percy 1.
|
1
|
+
# Percy 1.3.0
|
2
|
+
|
3
|
+
- You can now call all the class methods without `Percy.` in front.
|
2
4
|
|
3
5
|
## Configuring and starting the bot
|
4
6
|
|
5
7
|
### mybot.rb
|
6
|
-
$:.unshift "#{File.expand_path(File.dirname(__FILE__))}/lib"
|
7
|
-
PERCY_ROOT = File.expand_path(File.dirname(__FILE__))
|
8
|
-
|
9
8
|
require 'rubygems'
|
10
9
|
require 'percy'
|
11
10
|
|
@@ -177,7 +176,7 @@ Returns an array of users from a channel (mode in front like: ['@percy', 'Peter_
|
|
177
176
|
Returns a nickname as string if online, else false (not online/timeout)
|
178
177
|
|
179
178
|
## License
|
180
|
-
Copyright (c) 2009 Tobias Bühlmann
|
179
|
+
Copyright (c) 2009, 2010 Tobias Bühlmann
|
181
180
|
|
182
181
|
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:
|
183
182
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'percy'
|
5
|
+
|
6
|
+
configure do |c|
|
7
|
+
c.server = 'chat.eu.freenode.net'
|
8
|
+
c.port = 6667
|
9
|
+
c.nick = 'Percy_ghblog'
|
10
|
+
c.verbose = true
|
11
|
+
c.logging = false
|
12
|
+
c.reconnect = false
|
13
|
+
end
|
14
|
+
|
15
|
+
on :connect do
|
16
|
+
join '#that_cool_channel'
|
17
|
+
end
|
18
|
+
|
19
|
+
on :channel, /^!quit$/ do
|
20
|
+
quit
|
21
|
+
end
|
22
|
+
|
23
|
+
on :channel, /^blog?$/ do |env|
|
24
|
+
doc = Nokogiri::HTML(open('http://github.com/blog'))
|
25
|
+
title = doc.xpath('//html/body/div/div[2]/div/div/ul/li/h2/a')[0].text
|
26
|
+
|
27
|
+
message env[:channel], "Newest Github Blog Post: #{title}"
|
28
|
+
end
|
29
|
+
|
30
|
+
connect
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'percy'
|
3
|
+
|
4
|
+
Percy.configure do |c|
|
5
|
+
c.server = 'chat.eu.freenode.net'
|
6
|
+
c.port = 6667
|
7
|
+
c.nick = 'Percy_onlchk'
|
8
|
+
c.verbose = true
|
9
|
+
c.logging = false
|
10
|
+
c.reconnect = false
|
11
|
+
end
|
12
|
+
|
13
|
+
Percy.on :connect do
|
14
|
+
Percy.join '#that_cool_channel'
|
15
|
+
end
|
16
|
+
|
17
|
+
Percy.on :channel, /^!quit$/ do
|
18
|
+
Percy.quit
|
19
|
+
end
|
20
|
+
|
21
|
+
Percy.on :channel, /^online\?/ do |env|
|
22
|
+
match = env[:message].split(' ')
|
23
|
+
if match.length > 1
|
24
|
+
user = Percy.is_online(match[1])
|
25
|
+
if user
|
26
|
+
Percy.message env[:channel], "#{user} is online!"
|
27
|
+
else
|
28
|
+
Percy.message env[:channel], "#{user} is not online!"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Percy.connect
|
data/lib/percy.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
-
|
3
1
|
require 'rubygems'
|
2
|
+
require 'pathname'
|
3
|
+
$:.unshift Pathname.new(__FILE__).dirname.expand_path
|
4
4
|
require 'eventmachine'
|
5
|
-
require '
|
5
|
+
require 'ostruct'
|
6
6
|
require 'timeout'
|
7
7
|
require 'thread'
|
8
|
+
autoload :PercyLogger, 'percylogger'
|
8
9
|
|
9
10
|
Thread.abort_on_exception = true
|
10
11
|
|
@@ -21,6 +22,7 @@ class Connection < EventMachine::Connection
|
|
21
22
|
Percy.connected = false
|
22
23
|
Percy.traffic_logger.info('-- Percy disconnected') if Percy.traffic_logger
|
23
24
|
puts "#{Time.now.strftime('%d.%m.%Y %H:%M:%S')} -- Percy disconnected"
|
25
|
+
|
24
26
|
if Percy.config.reconnect
|
25
27
|
Percy.traffic_logger.info("-- Reconnecting in #{Percy.config.reconnect_interval} seconds") if Percy.traffic_logger
|
26
28
|
puts "#{Time.now.strftime('%d.%m.%Y %H:%M:%S')} -- Reconnecting in #{Percy.config.reconnect_interval} seconds"
|
@@ -28,6 +30,8 @@ class Connection < EventMachine::Connection
|
|
28
30
|
EventMachine::add_timer(Percy.config.reconnect_interval) do
|
29
31
|
reconnect Percy.config.server, Percy.config.port
|
30
32
|
end
|
33
|
+
else
|
34
|
+
EventMachine::stop_event_loop
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
@@ -42,11 +46,16 @@ class Percy
|
|
42
46
|
attr_accessor :traffic_logger, :connected
|
43
47
|
end
|
44
48
|
|
45
|
-
VERSION = 'Percy 1.
|
49
|
+
VERSION = 'Percy 1.3.0 (http://github.com/tbuehlmann/percy)'
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
@config = OpenStruct.new({:server => 'localhost',
|
52
|
+
:port => 6667,
|
53
|
+
:nick => 'Percy',
|
54
|
+
:username => 'Percy',
|
55
|
+
:verbose => true,
|
56
|
+
:logging => false,
|
57
|
+
:reconnect => true,
|
58
|
+
:reconnect_interval => 30})
|
50
59
|
|
51
60
|
# helper variables for getting server return values
|
52
61
|
@observers = 0
|
@@ -64,9 +73,14 @@ class Percy
|
|
64
73
|
def self.configure(&block)
|
65
74
|
block.call(@config)
|
66
75
|
|
76
|
+
# set the percy root directory
|
77
|
+
Object::const_set(:PERCY_ROOT, Pathname.new($0).dirname.expand_path)
|
78
|
+
|
67
79
|
# logger
|
68
|
-
|
69
|
-
|
80
|
+
if @config.logging
|
81
|
+
@traffic_logger = PercyLogger.new(Pathname.new(PERCY_ROOT).join('logs'), 'traffic.log')
|
82
|
+
@error_logger = PercyLogger.new(Pathname.new(PERCY_ROOT).join('logs'), 'error.log')
|
83
|
+
end
|
70
84
|
end
|
71
85
|
|
72
86
|
# raw IRC messages
|
@@ -288,6 +302,18 @@ class Percy
|
|
288
302
|
end
|
289
303
|
end
|
290
304
|
|
305
|
+
# connect!
|
306
|
+
def self.connect
|
307
|
+
@traffic_logger.info('-- Starting Percy') if @traffic_logger
|
308
|
+
puts "#{Time.now.strftime('%d.%m.%Y %H:%M:%S')} -- Starting Percy"
|
309
|
+
|
310
|
+
EventMachine::run do
|
311
|
+
@connection = EventMachine::connect(@config.server, @config.port, Connection)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
private
|
316
|
+
|
291
317
|
# add observer
|
292
318
|
def self.add_observer
|
293
319
|
@mutex_observer.synchronize do
|
@@ -325,6 +351,7 @@ class Percy
|
|
325
351
|
end
|
326
352
|
end
|
327
353
|
end
|
354
|
+
|
328
355
|
# :connect
|
329
356
|
if type =~ /^376|422$/
|
330
357
|
@events[:connect].each do |block|
|
@@ -479,16 +506,6 @@ class Percy
|
|
479
506
|
end
|
480
507
|
end
|
481
508
|
|
482
|
-
# connect!
|
483
|
-
def self.connect
|
484
|
-
@traffic_logger.info('-- Starting Percy') if @traffic_logger
|
485
|
-
puts "#{Time.now.strftime('%d.%m.%Y %H:%M:%S')} -- Starting Percy"
|
486
|
-
|
487
|
-
EventMachine::run do
|
488
|
-
@connection = EventMachine::connect(@config.server, @config.port, Connection)
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
509
|
# parsing incoming traffic
|
493
510
|
def self.parse(message)
|
494
511
|
@traffic_logger.info("<< #{message.chomp}") if @traffic_logger
|
@@ -528,3 +545,16 @@ class Percy
|
|
528
545
|
end
|
529
546
|
end
|
530
547
|
end
|
548
|
+
|
549
|
+
def delegate(*methods)
|
550
|
+
methods.each do |method|
|
551
|
+
eval <<-EOS
|
552
|
+
def #{method}(*args, &block)
|
553
|
+
Percy.send(#{method.inspect}, *args, &block)
|
554
|
+
end
|
555
|
+
EOS
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
delegate :action, :channel_limit, :configure, :connect, :is_online, :join, :kick, :message,
|
560
|
+
:mode, :nick, :notice, :on, :part, :quit, :raw, :topic, :users_on, :users_with_status_on
|
data/lib/percylogger.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class PercyLogger
|
2
|
+
require 'pathname'
|
2
3
|
require 'thread'
|
4
|
+
autoload :FileUtils, 'fileutils'
|
3
5
|
|
4
6
|
DEBUG = 0
|
5
7
|
INFO = 1
|
@@ -11,20 +13,22 @@ class PercyLogger
|
|
11
13
|
|
12
14
|
attr_accessor :level, :time_format, :file
|
13
15
|
|
14
|
-
def initialize(filename = 'log.log', level = DEBUG, time_format = '%d.%m.%Y %H:%M:%S')
|
15
|
-
@
|
16
|
+
def initialize(dirpath = Pathname.new($0).dirname.expand_path.join('logs'), filename = 'log.log', level = DEBUG, time_format = '%d.%m.%Y %H:%M:%S')
|
17
|
+
@dirpath = dirpath
|
18
|
+
@pathname = dirpath.join(filename)
|
16
19
|
@level = level
|
17
20
|
@time_format = time_format
|
18
21
|
@mutex = Mutex.new
|
19
22
|
|
20
|
-
unless
|
21
|
-
unless
|
22
|
-
|
23
|
+
unless @pathname.exist?
|
24
|
+
unless @dirpath.directory?
|
25
|
+
FileUtils.mkdir_p @dirpath
|
23
26
|
end
|
24
|
-
|
27
|
+
|
28
|
+
File.new(@pathname, 'w+')
|
25
29
|
end
|
26
30
|
|
27
|
-
@file = File.open(@
|
31
|
+
@file = File.open(@pathname, 'a+')
|
28
32
|
@file.sync = true
|
29
33
|
end
|
30
34
|
|
data/percy.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'percy'
|
3
|
+
s.version = '1.3.0'
|
4
|
+
s.summary = '(DSL, EventMachine) IRC Bot Framework inspired by isaac'
|
5
|
+
s.description = 'Percy is an IRC Bot framework inspired by isaac with various changes.'
|
6
|
+
s.homepage = 'http://github.com/tbuehlmann/percy'
|
7
|
+
s.date = '04.03.2010'
|
8
|
+
|
9
|
+
s.author = 'Tobias Bühlmann'
|
10
|
+
s.email = 'tobias.buehlmann@gmx.de'
|
11
|
+
|
12
|
+
s.require_paths = ['lib']
|
13
|
+
s.files = ['LICENSE',
|
14
|
+
'README.md',
|
15
|
+
'VERSION',
|
16
|
+
'examples/github_blog.rb',
|
17
|
+
'examples/is_online_checker.rb',
|
18
|
+
'lib/percy.rb',
|
19
|
+
'lib/percylogger.rb',
|
20
|
+
'percy.gemspec']
|
21
|
+
|
22
|
+
s.has_rdoc = false
|
23
|
+
s.add_dependency('eventmachine', '>= 0.12.10')
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 1.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- "Tobias B\xC3\xBChlmann"
|
@@ -9,20 +14,24 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-04 00:00:00 +01:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: eventmachine
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 12
|
30
|
+
- 10
|
23
31
|
version: 0.12.10
|
24
|
-
|
25
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Percy is an IRC Bot framework inspired by isaac with various changes.
|
26
35
|
email: tobias.buehlmann@gmx.de
|
27
36
|
executables: []
|
28
37
|
|
@@ -31,11 +40,14 @@ extensions: []
|
|
31
40
|
extra_rdoc_files: []
|
32
41
|
|
33
42
|
files:
|
34
|
-
- lib/percy.rb
|
35
|
-
- lib/percylogger.rb
|
36
|
-
- README.md
|
37
43
|
- LICENSE
|
44
|
+
- README.md
|
38
45
|
- VERSION
|
46
|
+
- examples/github_blog.rb
|
47
|
+
- examples/is_online_checker.rb
|
48
|
+
- lib/percy.rb
|
49
|
+
- lib/percylogger.rb
|
50
|
+
- percy.gemspec
|
39
51
|
has_rdoc: true
|
40
52
|
homepage: http://github.com/tbuehlmann/percy
|
41
53
|
licenses: []
|
@@ -49,18 +61,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
61
|
requirements:
|
50
62
|
- - ">="
|
51
63
|
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
52
66
|
version: "0"
|
53
|
-
version:
|
54
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
68
|
requirements:
|
56
69
|
- - ">="
|
57
70
|
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
58
73
|
version: "0"
|
59
|
-
version:
|
60
74
|
requirements: []
|
61
75
|
|
62
76
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.3.
|
77
|
+
rubygems_version: 1.3.6
|
64
78
|
signing_key:
|
65
79
|
specification_version: 3
|
66
80
|
summary: (DSL, EventMachine) IRC Bot Framework inspired by isaac
|