module RedRoosterAuth
Constants
- STYLE_BANNER
Public Instance Methods
Source
# File lib/red_rooster_auth.rb, line 112 def clear_account(network:, nick:, channel: nil) clear_account_record(network: network, channel: nil, nick: nick) clear_account_record(network: network, channel: channel, nick: nick) unless private_message?(channel) end
Source
# File lib/red_rooster_auth.rb, line 117 def clear_account_record(network:, channel:, nick:) RabbotDb.set_plugin_value( plugin: RedRoosterConfig::PLUGIN_NAME, key: RedRoosterConfig::ACCOUNT_KEY, value: "", network: network, channel: channel, nick: nick ) end
Source
# File lib/red_rooster_auth.rb, line 90 def fetch_account(network:, channel:, nick:) RabbotDb.get_plugin_json( plugin: RedRoosterConfig::PLUGIN_NAME, key: RedRoosterConfig::ACCOUNT_KEY, network: network, channel: channel, nick: nick, default: nil ) end
Source
# File lib/red_rooster_auth.rb, line 187 def format_help_reply [ IrcFormat.report_header(tag: "RR", title: "commands", style: STYLE_BANNER), usage_message, IrcFormat.report_footer("promos first", "redrooster.com.au") ].join("\n") end
Source
# File lib/red_rooster_auth.rb, line 145 def format_login_reply(profile) lines = [ IrcFormat.report_header(tag: "RR", title: "Red Royalty login", style: STYLE_BANNER), "Logged in as #{profile[:display_name]}." ] lines << "Card — #{profile[:card_number]}" if profile[:card_number] unless profile[:loyalty_balance].nil? lines << "Balance — $#{format('%.2f', profile[:loyalty_balance].to_f)}" end lines << IrcFormat.report_footer("redrooster.com.au") lines.join("\n") end
Source
# File lib/red_rooster_auth.rb, line 179 def format_logout_reply [ IrcFormat.report_header(tag: "RR", title: "logged out", style: STYLE_BANNER), "Red Royalty session removed for your nick.", IrcFormat.report_footer("redrooster.com.au") ].join("\n") end
Source
# File lib/red_rooster_auth.rb, line 158 def format_whoami_reply(account) unless account return [ IrcFormat.report_header(tag: "RR", title: "Red Royalty", style: STYLE_BANNER), "Not logged in — use /msg <bot> !redrooster login <token>.", IrcFormat.report_footer("redrooster.com.au") ].join("\n") end lines = [ IrcFormat.report_header(tag: "RR", title: account["display_name"].to_s, style: STYLE_BANNER), "Red Royalty account linked to your nick." ] lines << "Card — #{account["card_number"]}" if account["card_number"] unless account["loyalty_balance"].nil? lines << "Balance — $#{format('%.2f', account["loyalty_balance"].to_f)}" end lines << IrcFormat.report_footer("redrooster.com.au") lines.join("\n") end
Source
# File lib/red_rooster_auth.rb, line 82 def load_account(network:, nick:, channel: nil) account = fetch_account(network: network, channel: nil, nick: nick) return account if account return nil if private_message?(channel) fetch_account(network: network, channel: channel, nick: nick) end
Source
# File lib/red_rooster_auth.rb, line 128 def login_account(network:, nick:, token:, fetch:) profile = verify_token(token, fetch: fetch) return profile unless profile[:success] account = { "token" => token, "display_name" => profile[:display_name], "email" => profile[:email], "mobile" => profile[:mobile], "member_id" => profile[:member_id], "card_number" => profile[:card_number], "loyalty_balance" => profile[:loyalty_balance] } save_account(network: network, nick: nick, account: account) profile end
Source
# File lib/red_rooster_auth.rb, line 18 def login_channel_denied_message "Login is private — use /msg <bot> !redrooster login <token> so your session token is not shown in channel." end
Source
# File lib/red_rooster_auth.rb, line 26 def parse_command(text) stripped = text.to_s.strip return { action: :help } if stripped.empty? if (match = stripped.match(/\Alogin\s+(\S+)\z/i)) return { action: :login, token: match[1] } end return { action: :logout } if stripped.match?(/\Alogout\z/i) return { action: :whoami } if stripped.match?(/\A(?:whoami|status)\z/i) location = RedRoosterStores.parse_location(stripped) return { action: :error, error: location[:error] } if location[:error] { action: :menu, location: location[:location] } end
Source
# File lib/red_rooster_auth.rb, line 43 def parse_member(payload) data = payload.is_a?(String) ? JSON.parse(payload) : payload member = data["data"] || data rescue JSON::ParserError { success: false, error: "Invalid Red Royalty login response" } else if member.nil? || member.empty? return { success: false, error: "Red Royalty login failed — not authorized" } end first = member["firstName"].to_s.strip last = member["lastName"].to_s.strip display_name = [first, last].reject(&:empty?).join(" ") display_name = member["emailAddress"].to_s.strip if display_name.empty? card_number = Array(member["cardNumbers"]).first.to_s.strip card_number = nil if card_number.empty? { success: true, display_name: display_name, email: member["emailAddress"].to_s.strip, mobile: member["mobileNumber"].to_s.strip, member_id: member["memberId"].to_s.strip, card_number: card_number, loyalty_balance: member["loyaltyBalance"] } end
Source
# File lib/red_rooster_auth.rb, line 22 def private_message?(channel) channel.nil? || channel.to_s.strip.empty? end
Source
# File lib/red_rooster_auth.rb, line 101 def save_account(network:, nick:, account:) RabbotDb.set_plugin_json( plugin: RedRoosterConfig::PLUGIN_NAME, key: RedRoosterConfig::ACCOUNT_KEY, value: account, network: network, channel: nil, nick: nick ) end
Source
# File lib/red_rooster_auth.rb, line 14 def usage_message "Usage: !redrooster <location> | /msg <bot> !redrooster login <token> | logout | whoami" end
Source
# File lib/red_rooster_auth.rb, line 72 def verify_token(token, fetch:) body = fetch.call( "#{RedRoosterConfig::MOBILE_SERVICES_URL}customer/member", headers: RedRoosterConfig.default_headers(token: token) ) parse_member(body) rescue StandardError => e { success: false, error: "Red Royalty login failed — #{e.message}" } end