ticking_away 0.0.2 → 0.0.3
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 +4 -4
- data/lib/ticking_away.rb +1 -1
- data/lib/ticking_away/bot.rb +3 -3
- data/lib/ticking_away/cinch/plugins/time_info.rb +4 -13
- data/lib/ticking_away/{custom_errors.rb → errors.rb} +2 -1
- data/lib/ticking_away/json_file_storage.rb +8 -6
- data/lib/ticking_away/world_time.rb +17 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c06d94aad03bc4e9947771ec24dd99e561b1d45693b2333147c8dd957ffff87
|
4
|
+
data.tar.gz: c829b7fb99e9afb7c36c6ab81a28a41dbae087ebbe74c52dadb43430d0528588
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91440c550061b71bda6bcd8c730485db7d3dba0f6fcdfe8230efc2c4bf90be90395fee1d75f7a04b0c5f9d463f33eb21b5811d95cd7a2eb6b9037efccc77b6f0
|
7
|
+
data.tar.gz: 191755c7921062d692e4e6344c0056a5b820a4fce35b90cc4077dd918029eddb6ad3ce247aec49f63b1fc3828f86ff8ff488ceefef60e652e478ca7bedb485ba
|
data/lib/ticking_away.rb
CHANGED
data/lib/ticking_away/bot.rb
CHANGED
@@ -20,7 +20,7 @@ module TickingAway
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# Send a string to the Bot in the format of
|
23
|
-
# <user_name>: <message>
|
23
|
+
# <user_name>: <message> or just <message>
|
24
24
|
# Only !timeat <tz_info> and !timepopularity <tz_info or prefix>
|
25
25
|
# commands will return a string response
|
26
26
|
def chat(msg)
|
@@ -64,7 +64,7 @@ module TickingAway
|
|
64
64
|
msg[cmd_length..msg.length]
|
65
65
|
end
|
66
66
|
|
67
|
-
# Generate the time message, returning "unknown
|
67
|
+
# Generate the time message, returning "unknown timezone"
|
68
68
|
# for any unrecognized time zones and logging any uncaught
|
69
69
|
# errors before returning an excuse at random.
|
70
70
|
# Stats will only be incremented if the api call was successful
|
@@ -76,7 +76,7 @@ module TickingAway
|
|
76
76
|
rescue TickingAway::Errors::UnrecognizedTimeZone => e
|
77
77
|
puts e.message
|
78
78
|
'unknown timezone'
|
79
|
-
rescue => e
|
79
|
+
rescue TickingAway::Errors::TimeTravelIsHard => e
|
80
80
|
puts e.message
|
81
81
|
EXCUSES.sample
|
82
82
|
end
|
@@ -35,25 +35,16 @@
|
|
35
35
|
# Copyright © 2021 Jeff Wood
|
36
36
|
#
|
37
37
|
# This program is free software: you can redistribute it and/or modify
|
38
|
-
# it under the terms of the
|
39
|
-
# the Free Software Foundation, either version 3 of the License, or
|
40
|
-
# (at your option) any later version.
|
41
|
-
#
|
42
|
-
# This program is distributed in the hope that it will be useful,
|
43
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
44
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
45
|
-
# GNU Lesser General Public License for more details.
|
46
|
-
#
|
47
|
-
# You should have received a copy of the GNU Lesser General Public License
|
48
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
38
|
+
# it under the terms of the MIT License.
|
49
39
|
require 'cinch'
|
50
40
|
|
51
41
|
module TickingAway
|
52
42
|
class TimeInfo
|
53
43
|
include ::Cinch::Plugin
|
54
44
|
|
55
|
-
|
56
|
-
match
|
45
|
+
# regex needs work
|
46
|
+
match %r{timeat [a-zA-Z0-9_\-/]+}, method: :timeat
|
47
|
+
match %r{timepopularity [a-zA-Z0-9_\-/]+}, method: :timepopularity
|
57
48
|
|
58
49
|
listen_to :connect, method: :on_connect
|
59
50
|
|
@@ -24,20 +24,22 @@ module TickingAway
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# Get the number of times !timeat was called for a
|
27
|
-
# tz_info or prefix. Partial prefix matches count
|
28
|
-
# the total.
|
29
|
-
# If we didn't want them to, it could check the
|
30
|
-
# next char in the key after the .start_with? match. If it's outside the
|
31
|
-
# length or a "/", then the prefix or tz_info matches exactly
|
27
|
+
# tz_info or prefix. Partial prefix matches do not count.
|
32
28
|
def get_stat(stat_name)
|
33
29
|
call_count = 0
|
34
30
|
stats.each do |key, value|
|
35
|
-
call_count += value if key.start_with?(stat_name)
|
31
|
+
call_count += value if key.start_with?(stat_name) && full_match?(stat_name, key)
|
36
32
|
end
|
37
33
|
|
38
34
|
call_count
|
39
35
|
end
|
40
36
|
|
37
|
+
def full_match?(stat_name, key)
|
38
|
+
return true if key.length == stat_name.length || key[stat_name.length] == '/'
|
39
|
+
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
41
43
|
def save_stats
|
42
44
|
File.write(filename, JSON.dump(stats))
|
43
45
|
end
|
@@ -14,19 +14,24 @@ module TickingAway
|
|
14
14
|
def time_at(base_url, tz_info)
|
15
15
|
request_url = "#{base_url}/timezone/#{tz_info}"
|
16
16
|
|
17
|
-
response =
|
17
|
+
response = call_api(request_url)
|
18
18
|
handle_response(response, request_url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call_api(request_url)
|
22
|
+
HTTParty.get(request_url)
|
19
23
|
rescue => e
|
20
|
-
|
21
|
-
raise e
|
24
|
+
raise TickingAway::Errors::TimeTravelIsHard, e.message
|
22
25
|
end
|
23
26
|
|
24
27
|
def handle_response(response, request_url)
|
25
28
|
# Convert JSON response to Hash, handling an empty or nil body
|
26
|
-
parsed_response =
|
29
|
+
parsed_response = parse_response(response.body)
|
27
30
|
|
28
31
|
case response.code
|
29
32
|
when 200
|
33
|
+
raise TickingAway::Errors::UnrecognizedTimeZone, 'Error: non-time response' unless parsed_response.is_a?(Hash)
|
34
|
+
|
30
35
|
puts "Event: Retreived current time for #{parsed_response['timezone']}: #{parsed_response['datetime']}"
|
31
36
|
when 404
|
32
37
|
# Differentiate between an unknown location response and a random 404 by checking the response body
|
@@ -34,14 +39,20 @@ module TickingAway
|
|
34
39
|
raise TickingAway::Errors::UnrecognizedTimeZone, "Error: Unrecognized Time Zone #{request_url}"
|
35
40
|
end
|
36
41
|
|
37
|
-
raise TickingAway::Errors::
|
42
|
+
raise TickingAway::Errors::TimeTravelIsHard, "Error: 404 response for #{request_url}"
|
38
43
|
else
|
39
|
-
raise "Error: #{response.code} #{parsed_response}"
|
44
|
+
raise TickingAway::Errors::TimeTravelIsHard, "Error: #{response.code} #{parsed_response}"
|
40
45
|
end
|
41
46
|
|
42
47
|
# Convert the time from a RFC3339 formatted string to a Time object
|
43
48
|
Time.parse(parsed_response['datetime'])
|
44
49
|
end
|
50
|
+
|
51
|
+
def parse_response(body)
|
52
|
+
JSON.parse(body)
|
53
|
+
rescue => e
|
54
|
+
raise TickingAway::Errors::TimeTravelIsHard, e.message
|
55
|
+
end
|
45
56
|
end
|
46
57
|
end
|
47
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ticking_away
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Wood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cinch
|
@@ -104,7 +104,7 @@ files:
|
|
104
104
|
- lib/ticking_away/bot.rb
|
105
105
|
- lib/ticking_away/chat_bot.rb
|
106
106
|
- lib/ticking_away/cinch/plugins/time_info.rb
|
107
|
-
- lib/ticking_away/
|
107
|
+
- lib/ticking_away/errors.rb
|
108
108
|
- lib/ticking_away/json_file_storage.rb
|
109
109
|
- lib/ticking_away/world_time.rb
|
110
110
|
homepage: https://github.com/woodjeffrey2/ticking_away
|