hwping 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12b5f7585b1225c1e90d2a487c2d5f530c272d64
4
- data.tar.gz: d205c225b205e58a8b38f9a51b504a4c32d9e9eb
3
+ metadata.gz: c18dfab7c8e9e20c071cc51f6a36f6d0e2c21c04
4
+ data.tar.gz: 08c791adf1bd917fc072b880c28b4d24d7d65ddf
5
5
  SHA512:
6
- metadata.gz: 6ccd7294ada3df2970c0f203b0968ec47f1e6808dce9d50e8ca60f0eef577d8ea6eef302d4f1e0cd3abaccb78da7d09e8a6ddc896afff95db030d20f42debd95
7
- data.tar.gz: e1cd1ad3cf79e525d3d6804144d252edf0c6c5f41aaf80961739dd668c9341e05b524df3a72ef061c71cbae4cdac5e34d1b97202b67711171088e7baa371abce
6
+ metadata.gz: 1d0d79a4f4dfef09e164812079e186828d2e70f16f29a147e0a76991b83649e32b59eecee8cc8ba0122c5f93dae3401a3e67ac3866bf04b33f79abbb7110b9b1
7
+ data.tar.gz: 6c8c25675325b49a02dd98be552241fbbdc060a633aeaf2f22c1b290690205b14aeae3777a11c5caf875e9536330f4a1349c072b003bd7e8a26f8da5ad4cca20
data/bin/hwping CHANGED
@@ -10,7 +10,7 @@ OptionParser.new do |opts|
10
10
  opts.version = HWPing::VERSION
11
11
  opts.program_name = HWPing::APP_NAME
12
12
  opts.banner = 'Usage: hwping [options]'
13
- opts.on('-c', '--config-file file.yml', "Specify which configuration file you want to use instead of the default config.yml") do |v|
13
+ opts.on('-c', '--config-file file.yml', 'Specify which configuration file you want to use instead of the default config.yml') do |v|
14
14
  options[:config] = v
15
15
  end
16
16
  end.parse!
@@ -19,14 +19,16 @@ end.parse!
19
19
  file = options.fetch(:config, HWPing::CONFIG_FILE)
20
20
  config = YAML.load_file(file)
21
21
 
22
- # Run the application
22
+ # Initialize the application
23
23
  app = HWPing::HWPing.new(config)
24
- app.start
25
24
 
26
25
  # Stop the bot and save the configuration file
27
26
  at_exit do
28
- app.stop
29
27
  File.open(file, 'w') do |f|
30
- YAML.dump(app.config, f)
28
+ f.write(YAML.dump(app.config))
31
29
  end
32
- end
30
+ app.stop
31
+ end
32
+
33
+ # Run the application
34
+ app.start
@@ -2,7 +2,6 @@ require 'cinch'
2
2
 
3
3
  module HWPing
4
4
  class Bot
5
-
6
5
  MESSAGES = {
7
6
  :unauthorized => "Sorry, you're unauthorized to use this bot!",
8
7
  :firing => 'Firing rocket in 5 seconds!',
@@ -28,16 +27,16 @@ module HWPing
28
27
  target set <nick> <right> <up>\n
29
28
  target get <nick>\n
30
29
  target del <nick>\n"
31
- }
30
+ }.freeze
32
31
 
33
32
  # Initialize a bot and return with its Cinch instance
34
33
  def initialize(handler, config = {})
35
- @bot = Cinch::Bot.new do |b|
34
+ @bot = Cinch::Bot.new do
36
35
  configure do |c|
37
36
  c.nick = config.nick
38
37
  c.server = config.server
39
38
  c.port = config.port
40
- c.channels = config.channels.map { |m| "\##{m}"}
39
+ c.channels = config.channels.map { |m| "\##{m}" }
41
40
  end
42
41
 
43
42
  # For channel mesages, just reply with the matching message
@@ -64,4 +63,4 @@ module HWPing
64
63
  @bot.quit
65
64
  end
66
65
  end
67
- end
66
+ end
@@ -1,24 +1,23 @@
1
1
  module HWPing
2
2
  class Config
3
-
4
- attr_reader :server
5
- attr_reader :port
6
- attr_reader :nick
7
- attr_reader :channels
8
- attr_reader :auth
3
+ attr_reader :server
4
+ attr_reader :port
5
+ attr_reader :nick
6
+ attr_reader :channels
7
+ attr_reader :auth
9
8
  attr_accessor :targets
10
9
 
11
10
  def initialize(hash = {})
12
- @server = hash.fetch('server', 'irc.freenode.net')
13
- @port = hash.fetch('port', 6667)
14
- @nick = hash.fetch('nick', 'hwping')
15
- @channels = hash.fetch('channels', ['hwping-test'])
16
- @auth = hash.fetch('auth' , [])
17
- @targets = hash.fetch('targets', [])
11
+ @server = hash.fetch('server', 'irc.freenode.net')
12
+ @port = hash.fetch('port', 6667)
13
+ @nick = hash.fetch('nick', 'hwping')
14
+ @channels = Array(hash.fetch('channels', ['hwping-test']))
15
+ @auth = Array(hash.fetch('auth', []))
16
+ @targets = hash.fetch('targets', {}).to_h
18
17
  end
19
18
 
20
19
  def to_hash
21
20
  Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }]
22
21
  end
23
22
  end
24
- end
23
+ end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module HWPing
2
- VERSION = '0.1'
3
- APP_NAME = 'hwping'
4
- REPO_URL = 'http://github.com/skateman/hwping'
5
- CONFIG_FILE = 'config.yml'
6
- end
3
+ VERSION = '0.2'.freeze
4
+ APP_NAME = 'hwping'.freeze
5
+ REPO_URL = 'http://github.com/skateman/hwping'.freeze
6
+ CONFIG_FILE = 'config.yml'.freeze
7
+ end
@@ -11,9 +11,9 @@ module HWPing
11
11
  # If the event happened in a channel, return just with a symbol
12
12
  def channel(event)
13
13
  if event.message =~ /^hwping,?\s+(.*)\s*$/
14
- if @auth.include?(event.user.to_s)
15
- if @targets.include?($1)
16
- @launcher.point_and_fire(@targets[$1])
14
+ if authorized?(event.user.to_s)
15
+ if @targets.include?(Regexp.last_match(1))
16
+ @launcher.point_and_fire(@targets[Regexp.last_match(1)])
17
17
  return :firing
18
18
  else
19
19
  return :notarget
@@ -26,26 +26,32 @@ module HWPing
26
26
 
27
27
  # If the event happened in a private window, return with an array
28
28
  def private(event)
29
- if @auth.include?(event.user.to_s)
29
+ if authorized?(event.user.to_s)
30
30
  case event.message
31
- when "fire"
31
+ when 'fire'
32
32
  @launcher.fire
33
33
  return [:fire]
34
- when "position"
34
+ when 'position'
35
35
  return @launcher.position.unshift(:position)
36
- when "help"
36
+ when 'help'
37
37
  return [:help]
38
- when "reset"
38
+ when 'reset'
39
39
  @launcher.reset
40
40
  return [:reset]
41
- when "target list"
41
+ when 'target list'
42
42
  return [:target_list, @targets.keys.join(', ')]
43
43
  when /^target set ([^\s]+)( (\d+) (\d+))?$/
44
- @targets[$1] = $2 ? [$3.to_i, $4.to_i] : @launcher.position
45
- return [:target_set, @targets[$1]].flatten
44
+ @targets[Regexp.last_match(1)] = begin
45
+ if Regexp.last_match(2)
46
+ [Regexp.last_match(3).to_i, Regexp.last_match(4).to_i]
47
+ else
48
+ @launcher.position
49
+ end
50
+ end
51
+ return [:target_set, @targets[Regexp.last_match(1)]].flatten
46
52
  when /^target ((get)|(del)) ([^\s]+)$/
47
- if @targets.has_key?($+)
48
- if $1 == "del"
53
+ if @targets.key?($+)
54
+ if Regexp.last_match(1) == 'del'
49
55
  @targets.delete($+)
50
56
  return [:target_del]
51
57
  else
@@ -55,7 +61,7 @@ module HWPing
55
61
  return [:notarget]
56
62
  end
57
63
  when /^((up)|(down)|(left)|(right)) (\d+)$/
58
- @launcher.send($1, $+.to_i)
64
+ @launcher.send(Regexp.last_match(1), $+.to_i)
59
65
  return [:move]
60
66
  else
61
67
  return [:badcommand]
@@ -64,5 +70,14 @@ module HWPing
64
70
  return [:unauthorized]
65
71
  end
66
72
  end
73
+
74
+ private
75
+
76
+ def authorized?(nick)
77
+ @auth.each do |user|
78
+ return true if user =~ /^#{nick}(?:\b?|\S?)/
79
+ end
80
+ false
81
+ end
67
82
  end
68
- end
83
+ end
@@ -1,11 +1,10 @@
1
1
  module HWPing
2
2
  class HWPing
3
-
4
3
  attr_reader :bot
5
4
 
6
5
  def initialize(config = {})
7
6
  @config = Config.new(config)
8
- @launcher = Launcher.connect()
7
+ @launcher = Launcher.connect
9
8
  @handler = Handler.new(@launcher, @config)
10
9
  @bot = Bot.new(@handler, @config)
11
10
  end
@@ -3,13 +3,12 @@ require 'libusb'
3
3
 
4
4
  module HWPing
5
5
  class Launcher
6
-
7
6
  DeviceNotFoundError = Class.new(IOError)
8
7
 
9
8
  DEVICE = {
10
9
  :vendor_id => 0x2123,
11
10
  :product_id => 0x1010
12
- }
11
+ }.freeze
13
12
 
14
13
  COMMANDS = {
15
14
  :down => 0x01,
@@ -20,12 +19,12 @@ module HWPing
20
19
  :stop => 0x20,
21
20
  :on => 0x01,
22
21
  :off => 0x00
23
- }
22
+ }.freeze
24
23
 
25
24
  TARGETS = {
26
25
  :launcher => 0x02,
27
26
  :led => 0x03
28
- }
27
+ }.freeze
29
28
 
30
29
  REQUEST_TYPE = 0x21
31
30
  REQUEST = 0x09
@@ -38,7 +37,7 @@ module HWPing
38
37
  :idProduct => DEVICE[:product_id]
39
38
  ).first
40
39
 
41
- raise DeviceNotFoundError, 'Launcher was not found.' if launcher.nil?
40
+ fail DeviceNotFoundError, 'Launcher was not found.' if launcher.nil?
42
41
  new(launcher)
43
42
  end
44
43
 
@@ -99,18 +98,19 @@ module HWPing
99
98
  update_pos direction, duration
100
99
  end
101
100
 
102
- private
101
+ private
102
+
103
103
  # Send data through USB
104
104
  def send!(target, command)
105
105
  payload = build_payload(target, COMMANDS[command.to_sym])
106
106
 
107
107
  @handle.control_transfer(
108
- bmRequestType: REQUEST_TYPE,
109
- bRequest: REQUEST,
110
- wValue: 0,
111
- wIndex: 0,
112
- dataOut: payload,
113
- timeout: 0
108
+ :bmRequestType => REQUEST_TYPE,
109
+ :bRequest => REQUEST,
110
+ :wValue => 0,
111
+ :wIndex => 0,
112
+ :dataOut => payload,
113
+ :timeout => 0
114
114
  )
115
115
  end
116
116
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hwping
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dávid Halász
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libusb
@@ -16,56 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: 0.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0
26
+ version: 0.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cinch
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.4
33
+ version: 2.3.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.4
40
+ version: 2.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.4
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 10.4.2
61
+ version: 10.5.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 10.4.2
68
+ version: 10.5.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '3.0'
75
+ version: 3.4.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.37.2
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '3.0'
96
+ version: 0.37.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.11.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.11.2
69
111
  description: IRC bot for HW pinging with the Dream Cheeky Thunder missile launcher
70
112
  email: skateman@skateman.eu
71
113
  executables:
@@ -73,14 +115,14 @@ executables:
73
115
  extensions: []
74
116
  extra_rdoc_files: []
75
117
  files:
76
- - lib/hwping/handler.rb
77
- - lib/hwping/launcher.rb
78
- - lib/hwping/hwping.rb
118
+ - bin/hwping
119
+ - lib/hwping.rb
79
120
  - lib/hwping/bot.rb
80
121
  - lib/hwping/config.rb
81
122
  - lib/hwping/constants.rb
82
- - lib/hwping.rb
83
- - bin/hwping
123
+ - lib/hwping/handler.rb
124
+ - lib/hwping/hwping.rb
125
+ - lib/hwping/launcher.rb
84
126
  homepage: http://github.com/skateman/hwping
85
127
  licenses:
86
128
  - GPL-2
@@ -101,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
143
  version: '0'
102
144
  requirements: []
103
145
  rubyforge_project:
104
- rubygems_version: 2.0.14
146
+ rubygems_version: 2.5.1
105
147
  signing_key:
106
148
  specification_version: 4
107
149
  summary: Hardware Pinger