fantasy-irc 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -6
- data/fantasy-irc.gemspec +1 -2
- data/lib/fantasy-irc/irc.rb +7 -4
- data/lib/fantasy-irc/plugins.rb +24 -2
- data/lib/fantasy-irc/users.rb +1 -0
- data/lib/plugins/hackersays.rb +36 -0
- data/lib/plugins/magic8ball.rb +41 -0
- data/lib/plugins/nettools.rb +7 -7
- metadata +4 -18
data/README.md
CHANGED
@@ -22,17 +22,17 @@ TODO: Write usage instructions here
|
|
22
22
|
|
23
23
|
## Getting support
|
24
24
|
|
25
|
-
There is a support channel on
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
There is a support channel on freenode in #fantasy where you can get
|
26
|
+
live help on the gem. Getting answers in a IRC channel can take some
|
27
|
+
time but as you are reading the README of a IRC gem, you probably
|
28
|
+
already knew this.
|
29
29
|
|
30
30
|
TLDR:
|
31
31
|
|
32
32
|
Support?
|
33
33
|
|
34
|
-
irc.
|
35
|
-
irc://irc.
|
34
|
+
irc.freenode.net #fantasy
|
35
|
+
irc://irc.freenode.net/fantasy
|
36
36
|
|
37
37
|
## Contributing
|
38
38
|
|
data/fantasy-irc.gemspec
CHANGED
@@ -8,9 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.files = `git ls-files`.split("\n")
|
9
9
|
s.name = "fantasy-irc"
|
10
10
|
s.require_paths = ['lib']
|
11
|
-
s.version = "0.2.
|
11
|
+
s.version = "0.2.2"
|
12
12
|
|
13
13
|
s.rubyforge_project = s.name
|
14
14
|
s.add_runtime_dependency "array-unique", "~> 1.1.1"
|
15
|
-
s.add_runtime_dependency "ddate", "~> 1.0.0"
|
16
15
|
end
|
data/lib/fantasy-irc/irc.rb
CHANGED
@@ -54,6 +54,9 @@ module Fantasy
|
|
54
54
|
if not @connected then
|
55
55
|
raise "not connected to a server!"
|
56
56
|
end
|
57
|
+
|
58
|
+
# remove everything after a newline
|
59
|
+
s.gsub!(/\n.*$/, "")
|
57
60
|
puts "<-- #{s}"
|
58
61
|
@data[:socket].puts "#{s}\n"
|
59
62
|
end
|
@@ -108,7 +111,8 @@ module Fantasy
|
|
108
111
|
|
109
112
|
elsif (tok[1] == "JOIN") then
|
110
113
|
# user joined
|
111
|
-
|
114
|
+
room_name = tok[2].gsub(/^:/, '') # remove leadig : (on some networks, but not all!)
|
115
|
+
room = self.rooms.by_name(room_name)
|
112
116
|
user = self.users.create(tok[0][1,tok[0].length])
|
113
117
|
|
114
118
|
# add user to room and room to user
|
@@ -161,8 +165,8 @@ module Fantasy
|
|
161
165
|
|
162
166
|
puts "!!! user #{user} quit."
|
163
167
|
# remove user from all rooms
|
164
|
-
self.rooms.all.values.each do |
|
165
|
-
|
168
|
+
self.rooms.all.values.each do |r|
|
169
|
+
r.users.delete user
|
166
170
|
end
|
167
171
|
user.reset
|
168
172
|
|
@@ -186,7 +190,6 @@ module Fantasy
|
|
186
190
|
@running = Time.now.to_i
|
187
191
|
last_tick = @running
|
188
192
|
last_ping = @running
|
189
|
-
last_session_ping = @running
|
190
193
|
|
191
194
|
loop do
|
192
195
|
time_now = Time.now
|
data/lib/fantasy-irc/plugins.rb
CHANGED
@@ -12,7 +12,22 @@ module Fantasy
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def load name
|
15
|
-
|
15
|
+
local = File.join(File.dirname($0), "plugins")
|
16
|
+
vendor = File.join(File.dirname(__FILE__), "..", "plugins")
|
17
|
+
[*name].each do |n|
|
18
|
+
file = "#{n}.rb"
|
19
|
+
local_file = File.join(local, file)
|
20
|
+
vendor_file = File.join(vendor, file)
|
21
|
+
if File.exists?(local_file)
|
22
|
+
puts "[plugin] Loading #{file} (local)."
|
23
|
+
Kernel.load local_file
|
24
|
+
elsif File::exists?(vendor_file)
|
25
|
+
puts "[plugin] Loading #{file} (vendor)."
|
26
|
+
Kernel.load vendor_file
|
27
|
+
else
|
28
|
+
puts "[plugin] #{file} could not be found."
|
29
|
+
end
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
33
|
def command command, data, args
|
@@ -56,7 +71,14 @@ class Plugin
|
|
56
71
|
@handlers.each do |pattern, block|
|
57
72
|
if command.match(pattern) then
|
58
73
|
puts "#{block} handles #{command}"
|
59
|
-
|
74
|
+
begin
|
75
|
+
block.call data, args
|
76
|
+
rescue Exception => e
|
77
|
+
puts "#{block} failed with Exception #{e}"
|
78
|
+
puts e.backtrace
|
79
|
+
end
|
80
|
+
|
81
|
+
break
|
60
82
|
end
|
61
83
|
end
|
62
84
|
end
|
data/lib/fantasy-irc/users.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
class HackerSays < Plugin
|
6
|
+
def initialize name
|
7
|
+
super
|
8
|
+
self.handle(/^hackersays$/i) do |data|
|
9
|
+
begin
|
10
|
+
Timeout::timeout(2) {
|
11
|
+
say_quote(data[:room])
|
12
|
+
}
|
13
|
+
rescue Timeout::Error
|
14
|
+
data[:room].say("Request to hackersays.com timed out.")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def say_quote room
|
20
|
+
quote = get_quote()
|
21
|
+
if quote.nil?
|
22
|
+
room.say "Could not fetch a quote. :-("
|
23
|
+
else
|
24
|
+
room.say "\u{201C}#{quote['c']}\u{201D} \u{2014} \002#{quote['a']}\002 \00315[Quote \##{quote['id']}]\003"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def get_quote
|
31
|
+
return JSON::load(open("http://hackersays.com/quote").read)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
plugin = HackerSays.new "hackersays"
|
36
|
+
$bot.plugins.add(plugin)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Magic8Ball < Plugin
|
2
|
+
attr_reader :answers
|
3
|
+
|
4
|
+
def initialize name
|
5
|
+
super
|
6
|
+
|
7
|
+
@answers = [
|
8
|
+
# Positive
|
9
|
+
"It is certain",
|
10
|
+
"It is decidedly so",
|
11
|
+
"Without a doubt",
|
12
|
+
"Yes - definitely",
|
13
|
+
"You may rely on it",
|
14
|
+
"As I see it, yes",
|
15
|
+
"Most likely",
|
16
|
+
"Outlook good",
|
17
|
+
"Yes",
|
18
|
+
"Signs point to yes",
|
19
|
+
# Neutral
|
20
|
+
"Reply hazy, try again",
|
21
|
+
"Ask again later",
|
22
|
+
"Better not tell you now",
|
23
|
+
"Cannot predict now",
|
24
|
+
"Concentrate and ask again",
|
25
|
+
# Negative
|
26
|
+
"Don't count on it",
|
27
|
+
"My reply is no",
|
28
|
+
"My sources say no",
|
29
|
+
"Outlook not so good",
|
30
|
+
"Very doubtful"
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
plugin = Magic8Ball.new "8ball"
|
36
|
+
|
37
|
+
plugin.handle(/^8ball$/i) do |data|
|
38
|
+
data[:room].say plugin.answers.sample
|
39
|
+
end
|
40
|
+
|
41
|
+
$bot.plugins.add(plugin)
|
data/lib/plugins/nettools.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
plugin = Plugin.new "nettools"
|
2
2
|
|
3
3
|
plugin.handle(/^ping$/i) do |data, args|
|
4
|
-
if args.empty?
|
4
|
+
if args.empty?
|
5
5
|
next data[:room].say "ping needs more arguments"
|
6
6
|
end
|
7
7
|
|
8
|
-
if args[0].match(/[^a-z0-9\.-]/i)
|
8
|
+
if args[0].match(/[^a-z0-9\.-]/i)
|
9
9
|
next data[:room].say "invalid characters in argument"
|
10
10
|
end
|
11
11
|
|
12
12
|
Thread.new do
|
13
13
|
ping = `/usr/bin/env ping -w 3 -c 1 -- #{args[0]} 2>&1`
|
14
14
|
|
15
|
-
if ping.match
|
15
|
+
if ping.match(/unknown host (.+)/)
|
16
16
|
data[:room].say "unknown host #{$1}"
|
17
|
-
elsif ping.match
|
17
|
+
elsif ping.match(/^(64 bytes.+)/)
|
18
18
|
data[:room].say "#{$1}"
|
19
|
-
elsif ping.match
|
19
|
+
elsif ping.match(/0 received/m)
|
20
20
|
data[:room].say "no reply :-("
|
21
21
|
else
|
22
22
|
data[:room].say "bogus hostname"
|
@@ -27,11 +27,11 @@ plugin.handle(/^ping$/i) do |data, args|
|
|
27
27
|
end
|
28
28
|
|
29
29
|
plugin.handle(/^host$/i) do |data, args|
|
30
|
-
if args.empty?
|
30
|
+
if args.empty?
|
31
31
|
next data[:room].say "host needs more arguments"
|
32
32
|
end
|
33
33
|
|
34
|
-
if args[0].match(/^a-z0-9\.-/i)
|
34
|
+
if args[0].match(/^a-z0-9\.-/i)
|
35
35
|
next data[:room].say "invalid characters in argument"
|
36
36
|
end
|
37
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fantasy-irc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: array-unique
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.1.1
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: ddate
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.0.0
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.0
|
46
30
|
description: A modular, event-driven IRC client/bot Ruby gem with plugin support
|
47
31
|
email:
|
48
32
|
- v2px@v2px.de
|
@@ -65,6 +49,8 @@ files:
|
|
65
49
|
- lib/fantasy-irc/rooms.rb
|
66
50
|
- lib/fantasy-irc/users.rb
|
67
51
|
- lib/plugins/datetime.rb
|
52
|
+
- lib/plugins/hackersays.rb
|
53
|
+
- lib/plugins/magic8ball.rb
|
68
54
|
- lib/plugins/math.rb
|
69
55
|
- lib/plugins/nettools.rb
|
70
56
|
- lib/plugins/random.rb
|