fantasy-irc 0.1.2 → 0.3.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 69e833581314292ab2f67d98c81470e45fb1be24154351a8664014c8598d4fde
4
+ data.tar.gz: affbbb388b46b6e4c8e42341fbe2436db1756bb5c1f61d627a8d1b11cb9444b9
5
+ SHA512:
6
+ metadata.gz: 100efa0d456fd2ad08c4424315cf2e5a146e23a9254147071589cd010d7a06de97ceabbd774e511fcdb79c5c26f21a838d9cbb309db5c4937f774cb737d97956
7
+ data.tar.gz: 81b4d3126bdde58e9c885d851b11dce59754d9c08d3bddd5eb7198daf8415efb43f95e18f625d04c4a63ab9e5829d7772caef1fd657d86224339025ba5488552
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem "array-unique", "~> 1.1.1"
4
- gem "rake"
4
+ gem "rake", ">= 12.3.3"
5
5
 
6
6
  group :test do
7
- gem "rspec"
8
- gem "rspec-mocks"
7
+ gem "rspec", "~> 2.13.0"
8
+ gem "rspec-mocks", "~> 2.13.0"
9
+ gem 'ddate'
9
10
  end
data/Gemfile.lock CHANGED
@@ -1,29 +1,34 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
4
  array-hooked (1.1.4)
5
5
  identifies_as
6
6
  module-cluster
7
7
  array-unique (1.1.1)
8
8
  array-hooked
9
- diff-lcs (1.1.3)
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
- rake (0.9.2.2)
13
- rspec (2.12.0)
14
- rspec-core (~> 2.12.0)
15
- rspec-expectations (~> 2.12.0)
16
- rspec-mocks (~> 2.12.0)
17
- rspec-core (2.12.2)
18
- rspec-expectations (2.12.1)
19
- diff-lcs (~> 1.1.3)
20
- rspec-mocks (2.12.1)
13
+ rake (13.0.3)
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)
27
- rake
28
- rspec
29
- rspec-mocks
28
+ ddate
29
+ rake (>= 12.3.3)
30
+ rspec (~> 2.13.0)
31
+ rspec-mocks (~> 2.13.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.2
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 irc.jdqirc.net in #fantasy where you
26
- can get live help on the gem. Getting answers in a IRC channel can
27
- take some time but as you are reading the README of a IRC gem, you
28
- probably already knew this.
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.jdqirc.net #fantasy
35
- irc://irc.jdqirc.net/fantasy
34
+ irc.freenode.net #fantasy
35
+ irc://irc.freenode.net/fantasy
36
36
 
37
37
  ## Contributing
38
38
 
data/docs/example.rb CHANGED
@@ -5,7 +5,7 @@ require 'fantasy-irc'
5
5
  bot = Fantasy::IRC.new
6
6
 
7
7
  # load some plugins
8
- bot.plugins.load 'corecommands'
8
+ bot.plugins.load 'nettools'
9
9
 
10
10
  # log in once we are connected
11
11
  connected = Proc.new do
@@ -15,7 +15,7 @@ bot.events.by_name('connected').register &connected
15
15
 
16
16
  # join a room and say hi
17
17
  loggedin = Proc.new do
18
- bot.rooms.new("#test").join.say "ohai"
18
+ bot.rooms.new("#test").join.note "ohai"
19
19
  end
20
20
  bot.events.by_name('loggedin').register &loggedin
21
21
 
data/fantasy-irc.gemspec CHANGED
@@ -1,15 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.authors = ["Jens Becker"]
3
3
  s.email = ["v2px@v2px.de"]
4
- s.description = "A modular, event-driven IRC client/bot Ruby gem with plugin support"
5
4
  s.summary = "A modular, event-driven IRC client/bot Ruby gem with plugin support"
6
5
  s.homepage = "http://v2px.github.com/fantasy-irc"
6
+ s.license = 'MIT'
7
7
 
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.1.2"
11
+ s.version = "0.3.0"
12
12
 
13
- s.rubyforge_project = s.name
14
13
  s.add_runtime_dependency "array-unique", "~> 1.1.1"
15
14
  end
data/lib/fantasy-irc.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "fantasy-irc/irc"
2
- require "fantasy-irc/events"
3
- require "fantasy-irc/plugins"
4
- require "fantasy-irc/rooms"
5
- require "fantasy-irc/users"
1
+ require File.expand_path('../fantasy-irc/irc', __FILE__)
2
+ require File.expand_path('../fantasy-irc/events', __FILE__)
3
+ require File.expand_path('../fantasy-irc/plugins', __FILE__)
4
+ require File.expand_path('../fantasy-irc/rooms', __FILE__)
5
+ require File.expand_path('../fantasy-irc/users', __FILE__)
@@ -52,7 +52,7 @@ module Fantasy
52
52
  end
53
53
 
54
54
  @callbacks.each { |uuid, proc|
55
- proc.call(args)
55
+ proc.call(*args)
56
56
  }
57
57
  end
58
58
  end
@@ -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
@@ -79,6 +82,8 @@ module Fantasy
79
82
 
80
83
  @connected = Time.now.to_i
81
84
  self.events.by_name('connected').call
85
+
86
+ return @data[:socket]
82
87
  end
83
88
 
84
89
  def cleanup
@@ -106,7 +111,8 @@ module Fantasy
106
111
 
107
112
  elsif (tok[1] == "JOIN") then
108
113
  # user joined
109
- room = self.rooms.by_name(tok[2][1,tok[2].length])
114
+ room_name = tok[2].gsub(/^:/, '') # remove leadig : (on some networks, but not all!)
115
+ room = self.rooms.by_name(room_name)
110
116
  user = self.users.create(tok[0][1,tok[0].length])
111
117
 
112
118
  # add user to room and room to user
@@ -159,8 +165,8 @@ module Fantasy
159
165
 
160
166
  puts "!!! user #{user} quit."
161
167
  # remove user from all rooms
162
- self.rooms.all.values.each do |room|
163
- room.users.delete user
168
+ self.rooms.all.values.each do |r|
169
+ r.users.delete user
164
170
  end
165
171
  user.reset
166
172
 
@@ -184,7 +190,6 @@ module Fantasy
184
190
  @running = Time.now.to_i
185
191
  last_tick = @running
186
192
  last_ping = @running
187
- last_session_ping = @running
188
193
 
189
194
  loop do
190
195
  time_now = Time.now
@@ -12,12 +12,29 @@ module Fantasy
12
12
  end
13
13
 
14
14
  def load name
15
- Kernel::load "plugins/#{name}.rb"
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
19
- if not args.nil? then
34
+ if not args.nil?
20
35
  args = args.split(' ')
36
+ else
37
+ args = []
21
38
  end
22
39
  @plugins.values.each do |plugin|
23
40
  puts "#{plugin}"
@@ -50,11 +67,18 @@ class Plugin
50
67
  end
51
68
 
52
69
  def handle! command, data, args=[]
53
- puts "trying to handle #{command} with #{data} and #{args}"
70
+ #puts "trying to handle #{command} with #{data} and #{args}"
54
71
  @handlers.each do |pattern, block|
55
72
  if command.match(pattern) then
56
73
  puts "#{block} handles #{command}"
57
- break block.call data, args
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
58
82
  end
59
83
  end
60
84
  end
@@ -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,31 @@ module Fantasy
74
75
  return self
75
76
  end
76
77
 
78
+ # sends a notice to the room
79
+ def note message
80
+ if @joined == false then
81
+ raise "Tried to talk to a room (#{name}) we're not in."
82
+ end
83
+
84
+ @connection.send('NOTICE '+@name+' :'+message)
85
+ return self
86
+ end
87
+
88
+ # sends a privmsg with ACTION to the room
89
+ def me message
90
+ self.say "\001ACTION #{message}\001"
91
+ end
92
+
93
+ # sets a topic in the room
94
+ def topic message
95
+ if @joined == false then
96
+ raise "Tried to set topic in a room (#{name}) we're not in."
97
+ end
98
+
99
+ @connection.send('TOPIC '+@name+' :'+message)
100
+ return self
101
+ end
102
+
77
103
  def to_s
78
104
  "#{@name}"
79
105
  end
@@ -46,6 +46,7 @@ module Fantasy
46
46
  puts "New User #{self.object_id} with name #{@name}"
47
47
  @connection = connection
48
48
  @rooms = Array::Unique.new
49
+ @ignored = false
49
50
  end
50
51
 
51
52
  # resets user information
@@ -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
@@ -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)
@@ -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,26 +1,22 @@
1
- plugin = Plugin.new "corecommands"
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
- if args.empty? then
4
+ if args.empty?
9
5
  next data[:room].say "ping needs more arguments"
10
6
  end
11
7
 
12
- if args[0].match(/[^a-z0-9\.-]/i) then
8
+ if args[0].match(/[^a-z0-9\.-]/i)
13
9
  next data[:room].say "invalid characters in argument"
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
- if ping.match /unknown host (.+)/ then
15
+ if ping.match(/unknown host (.+)/)
20
16
  data[:room].say "unknown host #{$1}"
21
- elsif ping.match /^(64 bytes.+)/ then
17
+ elsif ping.match(/^(64 bytes.+)/)
22
18
  data[:room].say "#{$1}"
23
- elsif ping.match /0 received/m then
19
+ elsif ping.match(/0 received/m)
24
20
  data[:room].say "no reply :-("
25
21
  else
26
22
  data[:room].say "bogus hostname"
@@ -31,16 +27,16 @@ plugin.handle(/^ping$/i) do |data, args|
31
27
  end
32
28
 
33
29
  plugin.handle(/^host$/i) do |data, args|
34
- if args.empty? then
30
+ if args.empty?
35
31
  next data[:room].say "host needs more arguments"
36
32
  end
37
33
 
38
- if args[0].match(/^a-z0-9\.-/i) then
34
+ if args[0].match(/[^a-z0-9\.-]/i)
39
35
  next data[:room].say "invalid characters in argument"
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,33 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasy-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jens Becker
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
11
+ date: 2021-04-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: array-unique
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.1
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.1.1
30
- description: A modular, event-driven IRC client/bot Ruby gem with plugin support
27
+ description:
31
28
  email:
32
29
  - v2px@v2px.de
33
30
  executables: []
@@ -48,32 +45,36 @@ files:
48
45
  - lib/fantasy-irc/plugins.rb
49
46
  - lib/fantasy-irc/rooms.rb
50
47
  - lib/fantasy-irc/users.rb
51
- - lib/plugins/corecommands.rb
48
+ - lib/plugins/datetime.rb
49
+ - lib/plugins/hackersays.rb
50
+ - lib/plugins/magic8ball.rb
51
+ - lib/plugins/math.rb
52
+ - lib/plugins/nettools.rb
53
+ - lib/plugins/random.rb
52
54
  - spec/lib/fantasy-event_spec.rb
53
55
  - spec/lib/fantasy-irc_spec.rb
54
56
  - spec/spec_helper.rb
55
57
  homepage: http://v2px.github.com/fantasy-irc
56
- licenses: []
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
57
61
  post_install_message:
58
62
  rdoc_options: []
59
63
  require_paths:
60
64
  - lib
61
65
  required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
66
  requirements:
64
- - - ! '>='
67
+ - - ">="
65
68
  - !ruby/object:Gem::Version
66
69
  version: '0'
67
70
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
71
  requirements:
70
- - - ! '>='
72
+ - - ">="
71
73
  - !ruby/object:Gem::Version
72
74
  version: '0'
73
75
  requirements: []
74
- rubyforge_project: fantasy-irc
75
- rubygems_version: 1.8.25
76
+ rubygems_version: 3.1.2
76
77
  signing_key:
77
- specification_version: 3
78
+ specification_version: 4
78
79
  summary: A modular, event-driven IRC client/bot Ruby gem with plugin support
79
80
  test_files: []