civility 3 → 4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/civility.rb +41 -1
- data/lib/civility/ext.rb +6 -0
- data/lib/civility/ext/slack.rb +37 -0
- data/lib/civility/gmr.rb +1 -1
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3ade38cc74649b6ef0d584613677e929ec52591
|
4
|
+
data.tar.gz: 62ee2085ff12225da1472669b0f2137fe9b267fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae6071278cab83b336f81f1bdc5125a47c9f60b7305b67d7bb0180b4a9ab369015c4fefdaf0254a802897d18d54b1e982d081ebecf8413aef8f19a08dfeae78e
|
7
|
+
data.tar.gz: dcad9e61fbd760a2fc1cf3cf80484f608ce248810e89e82207793f80fee172f5939e51c9dcef133ae1de8e6583c648ec7f0e05fa1a5463f06e2492dd730f6bf5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/civility.rb
CHANGED
@@ -5,7 +5,7 @@ require 'yaml'
|
|
5
5
|
require 'thor'
|
6
6
|
|
7
7
|
class Civility < Thor
|
8
|
-
VERSION = '
|
8
|
+
VERSION = '4'
|
9
9
|
SAVE_DIRECTORY = "/Documents/Aspyr/Sid\ Meier\'s\ Civilization\ 5/Saves/hotseat/"
|
10
10
|
FILE_PREFIX = 'civility'
|
11
11
|
FILE_EXT = 'Civ5Save'
|
@@ -18,6 +18,7 @@ class Civility < Thor
|
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'auth', 'Save auth key'
|
21
|
+
option aliases: :a
|
21
22
|
def auth(auth_key = nil)
|
22
23
|
if auth_key.nil?
|
23
24
|
auth_url = Civility::GMR.auth_url
|
@@ -34,12 +35,14 @@ class Civility < Thor
|
|
34
35
|
end
|
35
36
|
|
36
37
|
desc 'games', 'List your current games'
|
38
|
+
option aliases: :g
|
37
39
|
def games
|
38
40
|
return missing_auth_error unless auth_key
|
39
41
|
output_games sync_games
|
40
42
|
end
|
41
43
|
|
42
44
|
desc 'play', 'Download a game to play'
|
45
|
+
option aliases: :p
|
43
46
|
def play(*name)
|
44
47
|
name = name.join(' ')
|
45
48
|
return missing_auth_error unless auth_key
|
@@ -53,6 +56,7 @@ class Civility < Thor
|
|
53
56
|
end
|
54
57
|
|
55
58
|
desc 'complete', 'Upload a completed turn'
|
59
|
+
option aliases: :c
|
56
60
|
def complete(*name)
|
57
61
|
name = name.join(' ')
|
58
62
|
return missing_auth_error unless auth_key
|
@@ -65,6 +69,7 @@ class Civility < Thor
|
|
65
69
|
puts "UnexpectedError: #{response}"
|
66
70
|
when 1
|
67
71
|
puts "You earned #{response['PointsEarned']} points completing #{game['Name']} from #{path}"
|
72
|
+
notify_slack(game) if @config[:slack]
|
68
73
|
when 2
|
69
74
|
puts "It's not your turn"
|
70
75
|
when 3
|
@@ -74,8 +79,42 @@ class Civility < Thor
|
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
82
|
+
desc 'slack', 'Enable slack integration'
|
83
|
+
def slack(status, bot_token = nil, channel_name = nil, next_player_name = nil, game_name = nil)
|
84
|
+
if status == 'on'
|
85
|
+
if [bot_token, channel_name, next_player_name, game_name].any?(&:nil?)
|
86
|
+
puts 'Bot token, channel name, next player name, and game name are required'
|
87
|
+
puts '$ civility slack on xoxb-123xyz awecome_channel sam awesome civ 5 game'
|
88
|
+
else
|
89
|
+
game = game_by_name(game_name)
|
90
|
+
return missing_game_error(name) unless game
|
91
|
+
@config[:slack].merge!(
|
92
|
+
game['GameId'] => {
|
93
|
+
channel_name: channel_name,
|
94
|
+
bot_token: bot_token,
|
95
|
+
next_player_name: next_player_name
|
96
|
+
}
|
97
|
+
)
|
98
|
+
puts "Slack integration enabled for #{game_name}"
|
99
|
+
end
|
100
|
+
else
|
101
|
+
@config.delete(:slack)
|
102
|
+
puts 'Slack integration disabled'
|
103
|
+
end
|
104
|
+
self.config = @config
|
105
|
+
end
|
106
|
+
|
77
107
|
private
|
78
108
|
|
109
|
+
def notify_slack(game)
|
110
|
+
slack_config = @config[:slack][game['GameId']]
|
111
|
+
return puts 'Slack not configured for game' unless slack_config
|
112
|
+
slack = Civility::Ext::Slack.new(slack_config[:bot_token])
|
113
|
+
message = "@#{slack_config[:next_player_name]}'s turn!"
|
114
|
+
code, body = slack.post_message(slack_config[:channel_name], message, 'Shelly')
|
115
|
+
puts "Error updating Slack: #{body}" unless code == 200
|
116
|
+
end
|
117
|
+
|
79
118
|
def sync_games
|
80
119
|
games = @gmr.games
|
81
120
|
self.config = @config.merge(games: games, updated_at: Time.now.to_i)
|
@@ -164,3 +203,4 @@ class Civility < Thor
|
|
164
203
|
end
|
165
204
|
|
166
205
|
require 'civility/gmr'
|
206
|
+
require 'civility/ext'
|
data/lib/civility/ext.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class Civility
|
6
|
+
class Ext
|
7
|
+
class Slack
|
8
|
+
def initialize(token)
|
9
|
+
@token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
def post_message(channel_name, text, username)
|
13
|
+
params = {
|
14
|
+
token: @token,
|
15
|
+
channel: channel_name,
|
16
|
+
link_names: 1,
|
17
|
+
username: username,
|
18
|
+
icon_emoji: ':robot_face:',
|
19
|
+
text: text
|
20
|
+
}
|
21
|
+
post('https://slack.com/api/chat.postMessage', params)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def post(url, params = {})
|
27
|
+
uri = URI.parse(url)
|
28
|
+
uri.query = URI.encode_www_form(params)
|
29
|
+
http = Net::HTTP.new(uri.host, 443)
|
30
|
+
http.use_ssl = true
|
31
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
32
|
+
response = http.request(request)
|
33
|
+
[response.code.to_i, JSON.parse(response.body)]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/civility/gmr.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abraham Williams
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
EsiR9eCvovV79dCUTm5EBRWaqa7DIAXh+oEHOaAP2btcuDT/kJlg9/YG12YDdX82
|
31
31
|
U6jGnAwybOW/iArJ
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: thor
|
@@ -98,6 +98,8 @@ extra_rdoc_files: []
|
|
98
98
|
files:
|
99
99
|
- bin/civility
|
100
100
|
- lib/civility.rb
|
101
|
+
- lib/civility/ext.rb
|
102
|
+
- lib/civility/ext/slack.rb
|
101
103
|
- lib/civility/gmr.rb
|
102
104
|
homepage: https://github.com/abraham/civility
|
103
105
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|