Skip to content

Commit

Permalink
global update +_+
Browse files Browse the repository at this point in the history
  • Loading branch information
leonovk committed Nov 2, 2023
1 parent 9a8f5ae commit 8d90ec2
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
run: bundle install
- name: Run cops
run: bundle exec rubocop
- name: Run test
run: rake test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.byebug_history
.examples/
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ source 'https://rubygems.org'

gemspec

gem 'byebug'
gem 'minitest'
gem 'rubocop'
gem 'rubocop-minitest'
9 changes: 8 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
PATH
remote: .
specs:
boaw (0.0.2)
boaw (0.0.3)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
byebug (11.1.3)
json (2.6.3)
language_server-protocol (3.17.0.3)
minitest (5.20.0)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
Expand All @@ -30,6 +32,8 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-minitest (0.33.0)
rubocop (>= 1.39, < 2.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)

Expand All @@ -38,7 +42,10 @@ PLATFORMS

DEPENDENCIES
boaw!
byebug
minitest
rubocop
rubocop-minitest

BUNDLED WITH
2.4.20
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ You can use the library to create various auto-clickers.
boaw = Boaw.new
position = boaw.position # current mouse position {x:1,y:2}
boaw.left_click(position) # clicks with the left mouse button
boaw.right_click(position) # clicks with the right mouse button
```

An example of a simple autoclicker that will allow you to always stay online in any messenger
Expand Down
19 changes: 19 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'rake/testtask'
require_relative 'lib/boaw/version'

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

task :build_and_push do
puts "build boaw #{Boaw::VERSION}"
system 'gem build boaw.gemspec'
file_name = "boaw-#{Boaw::VERSION}.gem"
system "gem push #{file_name} -k rubygems"
File.delete(file_name)
puts 'done'
end
12 changes: 9 additions & 3 deletions lib/boaw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

require_relative 'xdotool/adapter'

# Main class
# The main class from which work with the program begins
class Boaw
attr_reader :adapter

def initialize
@adapter = Xdotool::Adapter.new
end
Expand All @@ -17,4 +15,12 @@ def position
def left_click(position)
adapter.left_click(position)
end

def right_click(position)
adapter.right_click(position)
end

private

attr_reader :adapter
end
2 changes: 1 addition & 1 deletion lib/boaw/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Boaw
VERSION = '0.0.2'
VERSION = '0.0.3'
end
27 changes: 7 additions & 20 deletions lib/xdotool/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
# frozen_string_literal: true

require_relative 'position_parser'

module Xdotool
# Xdotool adapter for mouse control
class Adapter
def position
system('xdotool getmouselocation>temp.txt')

current_position = parse_position
output = IO.popen('xdotool getmouselocation', &:read)

{
x: current_position['x'].to_i,
y: current_position['y'].to_i
}
PositionParser.parse(output)
end

def left_click(position)
system("xdotool mousemove #{position[:x]} #{position[:y]} click 1")
end

private

def parse_position
file = File.open('./temp.txt', 'r')
position = file.gets.scan(/(\w+):(\d+)/).to_h
file.close
delete_temp_file
position
Kernel.system("xdotool mousemove #{position[:x]} #{position[:y]} click 1")
end

def delete_temp_file
File.delete('./temp.txt')
def right_click(position)
Kernel.system("xdotool mousemove #{position[:x]} #{position[:y]} click 3")
end
end
end
15 changes: 15 additions & 0 deletions lib/xdotool/position_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Xdotool
# coordinate position parser from Xdotool
class PositionParser
def self.parse(position)
hash_position = position.scan(/(\w+):(\d+)/).to_h

{
x: hash_position['x'].to_i,
y: hash_position['y'].to_i
}
end
end
end
41 changes: 41 additions & 0 deletions test/lib/boaw_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'minitest/autorun'
require_relative '../test_helper'

class BoawTest < Minitest::Test
def setup
@mock_adapter = Minitest::Mock.new
@boaw = Boaw.new
@boaw.instance_variable_set(:@adapter, @mock_adapter)
@position = { x: 1, y: 2 }
end

def test_position
@mock_adapter.expect(:position, @position)

assert_equal @position, @boaw.position

@mock_adapter.verify
end

def test_left_click
position = @position

@mock_adapter.expect(:left_click, nil, [position])

@boaw.left_click(position)

@mock_adapter.verify
end

def test_right_click
position = @position

@mock_adapter.expect(:right_click, nil, [position])

@boaw.right_click(position)

@mock_adapter.verify
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative '../lib/boaw'

0 comments on commit 8d90ec2

Please sign in to comment.