Class: Civility
- Inherits:
-
Thor
- Object
- Thor
- Civility
- Defined in:
- lib/civility.rb,
lib/civility/ext.rb,
lib/civility/gmr.rb,
lib/civility/ext/slack.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'5'
- SAVE_DIRECTORY =
"/Documents/Aspyr/Sid\ Meier\'s\ Civilization\ 5/Saves/hotseat/"
- FILE_PREFIX =
'civility'
- FILE_EXT =
'Civ5Save'
- CONFIG_FILE =
'.civility.yml'
Instance Method Summary collapse
- #auth(auth_key = nil) ⇒ Object
- #complete(*name) ⇒ Object
- #games ⇒ Object
-
#initialize(*args) ⇒ Civility
constructor
A new instance of Civility.
- #play(*name) ⇒ Object
- #slack(status, bot_token = nil, channel_name = nil, next_player_name = nil, game_name = nil) ⇒ Object
Constructor Details
Instance Method Details
#auth(auth_key = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/civility.rb', line 22 def auth(auth_key = nil) if auth_key.nil? auth_url = Civility::GMR.auth_url puts "Grab your Authentication Key from #{auth_url}" system('open', auth_url) else @gmr = Civility::GMR.new(auth_key) @config[:version] = VERSION @config[:auth] = auth_key @config[:user] = user self.config = @config puts "Hello, #{user['PersonaName']}, your auth is all configured!" end end |
#complete(*name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/civility.rb', line 60 def complete(*name) name = name.join(' ') return missing_auth_error unless auth_key game = game_by_name(name) return missing_game_error(name) unless game path = save_path(game) response = @gmr.upload(game['CurrentTurn']['TurnId'], File.read(path)) case response['ResultType'] when 0 puts "UnexpectedError: #{response}" when 1 puts "You earned #{response['PointsEarned']} points completing #{game['Name']} from #{path}" notify_slack(game) if @config[:slack] when 2 puts "It's not your turn" when 3 puts 'You already submitted your turn' else puts 'UnexpectedError' end end |
#games ⇒ Object
39 40 41 42 |
# File 'lib/civility.rb', line 39 def games return missing_auth_error unless auth_key output_games sync_games end |
#play(*name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/civility.rb', line 46 def play(*name) name = name.join(' ') return missing_auth_error unless auth_key game = game_by_name(name) return missing_game_error(name) unless game path = save_path(game) data = @gmr.download(game['GameId']) save_file(path, data) puts "Saved #{game['Name']} to #{path}" sync_games end |
#slack(status, bot_token = nil, channel_name = nil, next_player_name = nil, game_name = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/civility.rb', line 83 def slack(status, bot_token = nil, channel_name = nil, next_player_name = nil, game_name = nil) if status == 'on' if [bot_token, channel_name, next_player_name, game_name].any?(&:nil?) puts 'Bot token, channel name, next player name, and game name are required' puts '$ civility slack on xoxb-123xyz awecome_channel sam awesome civ 5 game' else game = game_by_name(game_name) return missing_game_error(name) unless game @config[:slack] = {} if @config[:slack].nil? @config[:slack].merge!( game['GameId'] => { channel_name: channel_name, bot_token: bot_token, next_player_name: next_player_name } ) puts "Slack integration enabled for #{game_name}" end else @config.delete(:slack) puts 'Slack integration disabled' end self.config = @config end |