discord_distance_calculator 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +7 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/discord_distance_bot +4 -0
- data/bin/setup +5 -0
- data/discord_distance_calculator.gemspec +32 -0
- data/lib/discord_distance_calculator.rb +8 -0
- data/lib/discord_distance_calculator/bot.rb +16 -0
- data/lib/discord_distance_calculator/distance_calculator.rb +29 -0
- data/lib/discord_distance_calculator/message_handler.rb +34 -0
- data/lib/discord_distance_calculator/version.rb +3 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3094986bb0f2d6986375cc52576fb037a9f01fd5
|
4
|
+
data.tar.gz: 2d933a4dd4dccc46a93c74a8e2c0b7540dcc3e54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e79534687ddc5198c9b81441de75a75f3b4d6f095d0a60c44d2c5b47670423cfe16f8dbcc1da79ea466beb64c3320159c0b34c7ee7767aed9466a5c622e20c2
|
7
|
+
data.tar.gz: '09851c55a38ec9af11d1d84fdb7a85d989d74e7384aecbd1601ae55f368911edeb19bd757fe1b9f16dd7a734a5aeb07158bce68509157beab40d3c4235750af0'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Ryan Murphy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Discord Distance Calculator
|
2
|
+
|
3
|
+
# What does this do?
|
4
|
+
This is a simple gem that can be setup as a Discord bot to calculate the distance between two geographical points.
|
5
|
+
Distance can be returned in miles and kilometers.
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
First install as a global gem.
|
9
|
+
```
|
10
|
+
gem install discord_distance_calculator
|
11
|
+
```
|
12
|
+
Navigate to your gem path. This will vary based on your ruby version and your ruby environment manager (rbenv or rvm).
|
13
|
+
For example on my machine with rbenv and ruby 2.4.1, it would be installed here:
|
14
|
+
```
|
15
|
+
~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/discord_distance_calculator<version>
|
16
|
+
```
|
17
|
+
Create a `.env` file in this directory. Inside here you will need 3 API keys: A map service key for Geocoder (usually sourced from Google Maps API), a Discord token, and a Discord client id. Insert these into your `.env` file as the following variables:
|
18
|
+
|
19
|
+
```
|
20
|
+
GEOCODER=
|
21
|
+
DISCORD_TOKEN=
|
22
|
+
DISCORD_CLIENT_ID=
|
23
|
+
```
|
24
|
+
|
25
|
+
# Start your bot
|
26
|
+
Now you are ready to start your bot. This will run as a server, so open a new terminal or start it as a daemon.
|
27
|
+
`bundle exec discord_distance_calculator discord_distance_bot`
|
28
|
+
|
29
|
+
The distance calculator will now listen for ```!distance``` along with two parameters representing the two locations.
|
30
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "discord_distance_calculator/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "discord_distance_calculator"
|
8
|
+
spec.version = DiscordDistanceCalculator::VERSION
|
9
|
+
spec.authors = ["Ryan Murphy"]
|
10
|
+
spec.email = ["murjax@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Discord bot for calculating distance}
|
13
|
+
spec.description = %q{Discord Distance Calculator is a bot for calculating direct mileage between two geographic points}
|
14
|
+
spec.homepage = "https://github.com/murjax/Discord-Distance-Calculator"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = "discord_distance_bot"
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "discordrb"
|
25
|
+
spec.add_dependency "geocoder"
|
26
|
+
spec.add_dependency "dotenv"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "pry"
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'discordrb'
|
2
|
+
module DiscordDistanceCalculator
|
3
|
+
class Bot
|
4
|
+
def self.start
|
5
|
+
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN'] , client_id: ENV['DISCORD_CLIENT_ID']
|
6
|
+
puts "This bot's invite URL is #{bot.invite_url}."
|
7
|
+
|
8
|
+
bot.message do |event|
|
9
|
+
handler = DiscordDistanceCalculator::MessageHandler.new(event.message.to_s)
|
10
|
+
event.respond handler.get_response
|
11
|
+
end
|
12
|
+
|
13
|
+
bot.run
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DiscordDistanceCalculator
|
2
|
+
class DistanceCalculator
|
3
|
+
attr_reader :locations
|
4
|
+
|
5
|
+
def initialize(locations)
|
6
|
+
@locations = locations
|
7
|
+
Geocoder.configure(api_key: ENV['GEOCODER'])
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_miles
|
11
|
+
distance = get_distance
|
12
|
+
distance.nan? ? 0 : distance.round(0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_kilometers
|
16
|
+
distance = get_distance
|
17
|
+
distance.nan? ? 0 : (distance * 1.609347218694).round(0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_distance
|
21
|
+
coordinates = get_coordinates
|
22
|
+
Geocoder::Calculations.distance_between(coordinates[0], coordinates[1])
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_coordinates
|
26
|
+
[Geocoder.coordinates(locations[0]),Geocoder.coordinates(locations[1])]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DiscordDistanceCalculator
|
2
|
+
class MessageHandler
|
3
|
+
attr_reader :message, :calculator
|
4
|
+
|
5
|
+
def initialize(message)
|
6
|
+
@message = message
|
7
|
+
@calculator = DistanceCalculator.new(get_locations)
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_command?
|
11
|
+
message.start_with?('!distance')
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_km?
|
15
|
+
message.end_with?(' km')
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_locations
|
19
|
+
parts = message.split(" ")
|
20
|
+
[parts[1], parts[2]]
|
21
|
+
end
|
22
|
+
|
23
|
+
def distance_calculator(unit_type = "mi")
|
24
|
+
unit_type == "mi" ? calculator.get_miles : calculator.get_kilometers
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_response
|
28
|
+
response = "The distance between these two points is"
|
29
|
+
if has_command?
|
30
|
+
has_km? ? "#{response} #{distance_calculator("km")} kilometers." : "#{response} #{distance_calculator} miles."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: discord_distance_calculator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Murphy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: discordrb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: geocoder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.15'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.15'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Discord Distance Calculator is a bot for calculating direct mileage between
|
112
|
+
two geographic points
|
113
|
+
email:
|
114
|
+
- murjax@gmail.com
|
115
|
+
executables:
|
116
|
+
- discord_distance_bot
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/discord_distance_bot
|
129
|
+
- bin/setup
|
130
|
+
- discord_distance_calculator.gemspec
|
131
|
+
- lib/discord_distance_calculator.rb
|
132
|
+
- lib/discord_distance_calculator/bot.rb
|
133
|
+
- lib/discord_distance_calculator/distance_calculator.rb
|
134
|
+
- lib/discord_distance_calculator/message_handler.rb
|
135
|
+
- lib/discord_distance_calculator/version.rb
|
136
|
+
homepage: https://github.com/murjax/Discord-Distance-Calculator
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.6.11
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Discord bot for calculating distance
|
160
|
+
test_files: []
|