meimei 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/README +4 -2
- data/lib/meimei/client.rb +19 -5
- data/lib/meimei/gemspec.rb +3 -3
- data/lib/meimei/server.rb +3 -1
- data/lib/meimei/specification.rb +1 -1
- data/lib/meimei/version.rb +1 -1
- metadata +2 -2
data/CHANGES
CHANGED
data/README
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
== DESCRIPTION
|
4
4
|
Meimei is a simple IRC bot framework. It is designed to be easily extensible. In the interest of simplicity it only implements a subset RFC 1459, mainly those dealing with PRIVMSGs.
|
5
5
|
|
6
|
+
See the documentation for Meimei::Client for help on creating new client instances.
|
7
|
+
|
6
8
|
=== Usage
|
7
9
|
|
8
10
|
require 'meimei'
|
@@ -23,6 +25,6 @@ Meimei is a simple IRC bot framework. It is designed to be easily extensible. In
|
|
23
25
|
say("localhost", "#meimei", "One hour has passed.")
|
24
26
|
end
|
25
27
|
|
26
|
-
===
|
28
|
+
=== Architecture
|
27
29
|
|
28
|
-
Meimei
|
30
|
+
Meimei uses a single select loop to handle multiple TCP sockets. This eliminates the need to use threads and all the synchronicity issues that result. However, Meimei does not use any global or class variables, so it should be thread-safe.
|
data/lib/meimei/client.rb
CHANGED
@@ -7,12 +7,12 @@ module Meimei
|
|
7
7
|
class Client
|
8
8
|
# === Parameters
|
9
9
|
# - nick: The nickname your bot will use.
|
10
|
-
# - options[:username]: The username of your bot (
|
11
|
-
# - options[:realname]: The real name of your bot (
|
10
|
+
# - options[:username]: The username of your bot (defaults to nick).
|
11
|
+
# - options[:realname]: The real name of your bot (defaults to nick).
|
12
12
|
# - options[:password]: The password for your bot's account.
|
13
|
-
# - options[:plugin_dir]:
|
14
|
-
# - options[:log_dir]:
|
15
|
-
# - options[:log_level]: The log level. Can be: :error, :info, :debug.
|
13
|
+
# - options[:plugin_dir]: A path to the directory where Meimei plugins will be stored (defaults to plugins).
|
14
|
+
# - options[:log_dir]: A path to where log files will be stored (defaults to .).
|
15
|
+
# - options[:log_level]: The log level. Can be: :error, :info, :debug. Defaults to :info.
|
16
16
|
def initialize(nick, options = {})
|
17
17
|
@servers = []
|
18
18
|
@running = false
|
@@ -27,6 +27,7 @@ module Meimei
|
|
27
27
|
@log_level = options[:log_level] || :info
|
28
28
|
@logger = Logger.new(open("#{@log_dir}/#{@nick}-#{Time.now.strftime('%Y%m%d-%H%M')}.log", "w"))
|
29
29
|
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
30
|
+
@last_saw_traffic_at = Time.now
|
30
31
|
end
|
31
32
|
|
32
33
|
# Registers a server with the client. This method will not open a connection.
|
@@ -45,6 +46,18 @@ module Meimei
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
# Autopings any server that hasn't seen traffic in over 5 minutes
|
50
|
+
def autoping
|
51
|
+
@servers.each do |server|
|
52
|
+
if server.last_saw_traffic_at + 300 < Time.now
|
53
|
+
server.write("PING #{server.hostname}")
|
54
|
+
|
55
|
+
# Artificially set the last_saw_traffic_at value to now so that we don't flood the server
|
56
|
+
server.last_saw_traffic_at = Time.now
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
48
61
|
# Creates a new plugin.
|
49
62
|
#
|
50
63
|
# === Parameters
|
@@ -151,6 +164,7 @@ module Meimei
|
|
151
164
|
end
|
152
165
|
end
|
153
166
|
|
167
|
+
self.autoping()
|
154
168
|
self.check_timer_plugins()
|
155
169
|
|
156
170
|
@current_server = self.select()
|
data/lib/meimei/gemspec.rb
CHANGED
@@ -34,11 +34,11 @@ module Meimei
|
|
34
34
|
spec.platform = Gem::Platform::RUBY
|
35
35
|
|
36
36
|
spec.local_rdoc_dir = "doc/rdoc"
|
37
|
-
spec.remote_rdoc_dir = "
|
37
|
+
spec.remote_rdoc_dir = "rdoc"
|
38
38
|
spec.local_coverage_dir = "doc/coverage"
|
39
|
-
spec.remote_coverage_dir= "
|
39
|
+
spec.remote_coverage_dir= "coverage"
|
40
40
|
|
41
|
-
spec.remote_site_dir = "
|
41
|
+
spec.remote_site_dir = "/"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
data/lib/meimei/server.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Meimei
|
2
2
|
class Server
|
3
|
-
attr_accessor :socket, :hostname, :port, :is_connected, :logger, :autojoin
|
3
|
+
attr_accessor :socket, :hostname, :port, :is_connected, :logger, :autojoin, :last_saw_traffic_at
|
4
4
|
|
5
5
|
def initialize(hostname, port, autojoin, options = {})
|
6
6
|
@hostname, @port, @is_connected = hostname, port, false
|
7
7
|
@log_dir = options[:log_dir] || "."
|
8
8
|
@logger = Logger.new(open("#{@log_dir}/#{@hostname}-#{Time.now.strftime('%Y%m%d-%H%M')}.log", "w"))
|
9
9
|
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
10
|
+
@last_saw_traffic_at = Time.now
|
10
11
|
|
11
12
|
case options[:log_level]
|
12
13
|
when :fatal
|
@@ -73,6 +74,7 @@ module Meimei
|
|
73
74
|
def read
|
74
75
|
begin
|
75
76
|
msg = @socket.gets
|
77
|
+
@last_saw_traffic_at = Time.now
|
76
78
|
@logger.debug "> #{msg}"
|
77
79
|
return msg
|
78
80
|
rescue Errno::ECONNRESET => x
|
data/lib/meimei/specification.rb
CHANGED
data/lib/meimei/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: meimei
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2008-
|
6
|
+
version: 0.1.2
|
7
|
+
date: 2008-03-04 00:00:00 -05:00
|
8
8
|
summary: A simple IRC bot framework.
|
9
9
|
require_paths:
|
10
10
|
- lib
|