fantasy-irc 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -2
- data/Gemfile.lock +13 -11
- data/docs/example.rb +1 -1
- data/fantasy-irc.gemspec +2 -1
- data/lib/fantasy-irc/plugins.rb +3 -1
- data/lib/fantasy-irc/rooms.rb +6 -0
- data/lib/plugins/datetime.rb +30 -0
- data/lib/plugins/math.rb +35 -0
- data/lib/plugins/{corecommands.rb → nettools.rb} +3 -7
- data/lib/plugins/random.rb +30 -0
- metadata +23 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -6,24 +6,26 @@ GEM
|
|
6
6
|
module-cluster
|
7
7
|
array-unique (1.1.1)
|
8
8
|
array-hooked
|
9
|
-
|
9
|
+
ddate (1.0.0)
|
10
|
+
diff-lcs (1.2.1)
|
10
11
|
identifies_as (1.1.0)
|
11
12
|
module-cluster (2.0.5)
|
12
13
|
rake (10.0.3)
|
13
|
-
rspec (2.
|
14
|
-
rspec-core (~> 2.
|
15
|
-
rspec-expectations (~> 2.
|
16
|
-
rspec-mocks (~> 2.
|
17
|
-
rspec-core (2.
|
18
|
-
rspec-expectations (2.
|
19
|
-
diff-lcs (
|
20
|
-
rspec-mocks (2.
|
14
|
+
rspec (2.13.0)
|
15
|
+
rspec-core (~> 2.13.0)
|
16
|
+
rspec-expectations (~> 2.13.0)
|
17
|
+
rspec-mocks (~> 2.13.0)
|
18
|
+
rspec-core (2.13.0)
|
19
|
+
rspec-expectations (2.13.0)
|
20
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
21
|
+
rspec-mocks (2.13.0)
|
21
22
|
|
22
23
|
PLATFORMS
|
23
24
|
ruby
|
24
25
|
|
25
26
|
DEPENDENCIES
|
26
27
|
array-unique (~> 1.1.1)
|
28
|
+
ddate
|
27
29
|
rake (~> 10.0.3)
|
28
|
-
rspec (~> 2.
|
29
|
-
rspec-mocks (~> 2.
|
30
|
+
rspec (~> 2.13.0)
|
31
|
+
rspec-mocks (~> 2.13.0)
|
data/docs/example.rb
CHANGED
data/fantasy-irc.gemspec
CHANGED
@@ -8,8 +8,9 @@ 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.1"
|
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"
|
15
16
|
end
|
data/lib/fantasy-irc/plugins.rb
CHANGED
data/lib/fantasy-irc/rooms.rb
CHANGED
@@ -65,6 +65,7 @@ module Fantasy
|
|
65
65
|
!!@joined
|
66
66
|
end
|
67
67
|
|
68
|
+
# sends a privmsg to the room
|
68
69
|
def say message
|
69
70
|
if @joined == false then
|
70
71
|
raise "Tried to talk to a room (#{name}) we're not in."
|
@@ -74,6 +75,11 @@ module Fantasy
|
|
74
75
|
return self
|
75
76
|
end
|
76
77
|
|
78
|
+
# sends a privmsg with ACTION to the room
|
79
|
+
def me message
|
80
|
+
self.say "\001ACTION #{message}\001"
|
81
|
+
end
|
82
|
+
|
77
83
|
def to_s
|
78
84
|
"#{@name}"
|
79
85
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ddate'
|
2
|
+
plugin = Plugin.new "datetime"
|
3
|
+
|
4
|
+
plugin.handle(/^date$/i) do |data|
|
5
|
+
next data[:room].say Time.now.localtime.strftime "%a, %d %b %Y %T %z"
|
6
|
+
end
|
7
|
+
|
8
|
+
plugin.handle(/^ddate$/i) do |data|
|
9
|
+
ddate = DDate.new
|
10
|
+
data[:room].say "Today is #{ddate.day_of_week_name}, the #{ordinalize(ddate.day_of_month)} day of #{ddate.month} in the YOLD #{ddate.year}"
|
11
|
+
if not ddate.holyday.nil?
|
12
|
+
data[:room].say "Today is also a holyday. It's #{ddate.holyday}! Make sure to tell your boss."
|
13
|
+
end
|
14
|
+
next
|
15
|
+
end
|
16
|
+
|
17
|
+
$bot.plugins.add(plugin)
|
18
|
+
|
19
|
+
def ordinalize number
|
20
|
+
if (11..13).include?(number % 100)
|
21
|
+
"#{number}th"
|
22
|
+
else
|
23
|
+
case number % 10
|
24
|
+
when 1; "#{number}st"
|
25
|
+
when 2; "#{number}nd"
|
26
|
+
when 3; "#{number}rd"
|
27
|
+
else "#{number}th"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/plugins/math.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
plugin = Plugin.new "math"
|
2
|
+
|
3
|
+
# flips a coin which can come up heads or tails
|
4
|
+
plugin.handle(/^pi$/i) do |data|
|
5
|
+
next data[:room].say "\u{03C0} = #{Math::PI}"
|
6
|
+
end
|
7
|
+
|
8
|
+
plugin.handle(/^calc$/i) do |data, args|
|
9
|
+
args_string = args.join(' ')
|
10
|
+
|
11
|
+
args_string.gsub!(/log/, "\000")
|
12
|
+
args_string.gsub!(/sqrt/, "\001")
|
13
|
+
args_string.gsub!(/\^/, "**")
|
14
|
+
args_string.gsub!(/,/, ".")
|
15
|
+
|
16
|
+
if not args_string.match(/^[ 0-9+*\/\.()\-\000\001]+$/)
|
17
|
+
next data[:room].say "Could not parse string."
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
result = Kernel.eval(args_string)
|
22
|
+
rescue Exception => e
|
23
|
+
next data[:room].say "#{e.to_s}"
|
24
|
+
end
|
25
|
+
|
26
|
+
if result.nil?
|
27
|
+
next data[:room].say "undef"
|
28
|
+
elsif result == 42
|
29
|
+
next data[:room].say "the Answer to the Ultimate Question of Life, The Universe, and Everything"
|
30
|
+
else
|
31
|
+
next data[:room].say result.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
$bot.plugins.add(plugin)
|
@@ -1,8 +1,4 @@
|
|
1
|
-
plugin = Plugin.new "
|
2
|
-
|
3
|
-
plugin.handle(/^date$/i) do |data|
|
4
|
-
next data[:room].say Time.now.localtime.strftime "%a, %d %b %Y %T %z"
|
5
|
-
end
|
1
|
+
plugin = Plugin.new "nettools"
|
6
2
|
|
7
3
|
plugin.handle(/^ping$/i) do |data, args|
|
8
4
|
if args.empty? then
|
@@ -14,7 +10,7 @@ plugin.handle(/^ping$/i) do |data, args|
|
|
14
10
|
end
|
15
11
|
|
16
12
|
Thread.new do
|
17
|
-
ping = `/bin/ping -w 3 -c 1 -- #{args[0]} 2>&1`
|
13
|
+
ping = `/usr/bin/env ping -w 3 -c 1 -- #{args[0]} 2>&1`
|
18
14
|
|
19
15
|
if ping.match /unknown host (.+)/ then
|
20
16
|
data[:room].say "unknown host #{$1}"
|
@@ -40,7 +36,7 @@ plugin.handle(/^host$/i) do |data, args|
|
|
40
36
|
end
|
41
37
|
|
42
38
|
Thread.new do
|
43
|
-
host = `/usr/bin/host #{args[0]} 2>&1`
|
39
|
+
host = `/usr/bin/env host #{args[0]} 2>&1`
|
44
40
|
lines = host.split(/\n/)
|
45
41
|
lines.take(3).each do |line|
|
46
42
|
data[:room].say line
|
@@ -0,0 +1,30 @@
|
|
1
|
+
plugin = Plugin.new "random"
|
2
|
+
|
3
|
+
# flips a coin which can come up heads or tails
|
4
|
+
plugin.handle(/^coin$/i) do |data|
|
5
|
+
if rand(2) == 0
|
6
|
+
next data[:room].me "flipped a coin: Came up tails."
|
7
|
+
else
|
8
|
+
next data[:room].me "flipped a coin: Came up heads."
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# generates a pseudo-random number
|
13
|
+
plugin.handle(/^rand$/i) do |data, args|
|
14
|
+
if args.empty?
|
15
|
+
next data[:room].say rand.to_s
|
16
|
+
else
|
17
|
+
next data[:room].say rand(args[0].to_i).to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# chooses an option from a set of option
|
22
|
+
plugin.handle(/^decide$/i) do |data, args|
|
23
|
+
if args.empty?
|
24
|
+
next data[:room].say "What do you want me to decide?"
|
25
|
+
end
|
26
|
+
|
27
|
+
next data[:room].say args.sample
|
28
|
+
end
|
29
|
+
|
30
|
+
$bot.plugins.add(plugin)
|
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.1
|
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-
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: array-unique
|
@@ -27,6 +27,22 @@ 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
|
30
46
|
description: A modular, event-driven IRC client/bot Ruby gem with plugin support
|
31
47
|
email:
|
32
48
|
- v2px@v2px.de
|
@@ -48,7 +64,10 @@ files:
|
|
48
64
|
- lib/fantasy-irc/plugins.rb
|
49
65
|
- lib/fantasy-irc/rooms.rb
|
50
66
|
- lib/fantasy-irc/users.rb
|
51
|
-
- lib/plugins/
|
67
|
+
- lib/plugins/datetime.rb
|
68
|
+
- lib/plugins/math.rb
|
69
|
+
- lib/plugins/nettools.rb
|
70
|
+
- lib/plugins/random.rb
|
52
71
|
- spec/lib/fantasy-event_spec.rb
|
53
72
|
- spec/lib/fantasy-irc_spec.rb
|
54
73
|
- spec/spec_helper.rb
|
@@ -72,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
91
|
version: '0'
|
73
92
|
requirements: []
|
74
93
|
rubyforge_project: fantasy-irc
|
75
|
-
rubygems_version: 1.8.
|
94
|
+
rubygems_version: 1.8.23
|
76
95
|
signing_key:
|
77
96
|
specification_version: 3
|
78
97
|
summary: A modular, event-driven IRC client/bot Ruby gem with plugin support
|