From 1e9a5c006ab46a2f33b82dec8ab0b8f9efd088f2 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 17 Aug 2021 20:16:22 -0500 Subject: [PATCH] Command to list unused invite codes Instructions also provide details about how the program works. --- lib/customer.rb | 7 +++++++ sgx_jmp.rb | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/customer.rb b/lib/customer.rb index 0ac64db..a1c3614 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -53,6 +53,13 @@ class Customer .then(PaymentMethods.method(:for_braintree_customer)) end + def unused_invites + promise = DB.query_defer(<<~SQL, [customer_id]) + SELECT code FROM unused_invites WHERE creator_id=$1 + SQL + promise.then { |result| result.map { |row| row["code"] } } + end + def stanza_to(stanza) stanza = stanza.dup stanza.to = jid.with(resource: stanza.to&.resource) diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 8347b07..048a86d 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -498,6 +498,30 @@ Command.new( end }.register(self).then(&CommandList.method(:register)) +Command.new( + "invite codes", + "Refer a friend for free credit" +) { + Command.customer.then(&:unused_invites).then do |invites| + if invites.empty? + Command.finish("You have no more invites right now, try again later.") + else + Command.finish do |reply| + reply.form.title = "Unused Invite Codes" + reply.form.instructions = + "Each of these codes is single use and gives the person using " \ + "them a free month of JMP service. You will receive credit " \ + "equivalent to one month of free service if they later become " \ + "a paying customer." + FormTable.new( + invites.map { |i| [i] }, + code: "Invite Code" + ).add_to_form(reply.form) + end + end + end +}.register(self).then(&CommandList.method(:register)) + command :execute?, node: "web-register", sessionid: nil do |iq| StatsD.increment("command", tags: ["node:#{iq.node}"]) -- 2.45.2