moonbot 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/MoonBot/bot.rb +10 -2
- data/lib/MoonBot/parser.rb +4 -2
- data/lib/MoonBot/plugins/helpers.rb +19 -0
- data/lib/MoonBot/version.rb +1 -1
- metadata +6 -5
data/lib/MoonBot/bot.rb
CHANGED
@@ -11,11 +11,15 @@ module MoonBot
|
|
11
11
|
|
12
12
|
def start
|
13
13
|
EventMachine.run do
|
14
|
-
@client = EventMachine.connect @host, @port, Client, Proc.new
|
14
|
+
@client = EventMachine.connect @host, @port, Client, Proc.new do |message|
|
15
|
+
message = message.split("\r\n")
|
16
|
+
message.each do {|m| self.handle m}
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def handle message
|
22
|
+
return if message.nil?
|
19
23
|
@plugins.each do |name, instance|
|
20
24
|
instance.send('on_' + message[:command].downcase, message) rescue nil
|
21
25
|
instance.send('any', message) if instance.respond_to? 'any'
|
@@ -26,6 +30,10 @@ module MoonBot
|
|
26
30
|
@plugins[plugin.to_s] = plugin.new(self)
|
27
31
|
puts "Loading #{plugin.to_s}"
|
28
32
|
end
|
33
|
+
|
34
|
+
def command message
|
35
|
+
self.client.send_data(message + '\r\n')
|
36
|
+
end
|
29
37
|
|
30
38
|
end
|
31
|
-
end
|
39
|
+
end
|
data/lib/MoonBot/parser.rb
CHANGED
@@ -3,7 +3,7 @@ module MoonBot
|
|
3
3
|
def self.parse data
|
4
4
|
message = {}
|
5
5
|
# if not empty
|
6
|
-
if
|
6
|
+
if data.scan(/^:/)
|
7
7
|
separated = data.split ':'
|
8
8
|
body = separated[1].split ' '
|
9
9
|
message[:prefix] = body.shift
|
@@ -17,7 +17,9 @@ module MoonBot
|
|
17
17
|
message[:args] = body
|
18
18
|
end
|
19
19
|
message
|
20
|
+
rescue
|
21
|
+
nil
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
23
|
-
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MoonBot::Helpers
|
2
|
+
def parse_user user_string
|
3
|
+
user = {}
|
4
|
+
nick, host = user_string.split('@')
|
5
|
+
nick, name = nick.split('!')
|
6
|
+
user[:nick] = nick
|
7
|
+
user[:name] = name
|
8
|
+
user[:host] = host
|
9
|
+
user
|
10
|
+
end
|
11
|
+
|
12
|
+
def match msg, regex
|
13
|
+
if msg[:trailing].scan(regex)
|
14
|
+
args = msg[:trailing].gsub(regex, '')
|
15
|
+
yield args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/MoonBot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moonbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70287282711580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70287282711580
|
25
25
|
description: Amazingly simple IRC bot that handles everything via plugins with the
|
26
26
|
exception of connecting.
|
27
27
|
email:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/MoonBot/parser.rb
|
41
41
|
- lib/MoonBot/plugin.rb
|
42
42
|
- lib/MoonBot/plugins/auth.rb
|
43
|
+
- lib/MoonBot/plugins/helpers.rb
|
43
44
|
- lib/MoonBot/plugins/ping.rb
|
44
45
|
- lib/MoonBot/plugins/verbose.rb
|
45
46
|
- lib/MoonBot/version.rb
|
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
65
|
version: '0'
|
65
66
|
requirements: []
|
66
67
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.11
|
68
69
|
signing_key:
|
69
70
|
specification_version: 3
|
70
71
|
summary: Amazingly simple IRC bot.
|