Add TelegramWallet to bots

This commit is contained in:
Jesse C. Fisher 2023-12-02 16:32:39 +00:00 committed by TheNeedful-DO
parent dd9872bd4a
commit 363986d4fd
4 changed files with 28 additions and 14 deletions

View File

@ -32,7 +32,7 @@ class Bot < ActiveRecord::Base
# eval(IO.read('./app/models/commands/fortune.rb'), binding)
case message.text
when /^\/fortune/i
response_text = `fortune -a`
response_text = `fortune`
begin
bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: response_text, parse_mode: "Markdown")
rescue
@ -72,23 +72,37 @@ class Bot < ActiveRecord::Base
end
end
case message.text
when /^\/fortune/i
response_text = `fortune`
begin
bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: response_text, parse_mode: "Markdown")
rescue
puts "Error from fortune"
end
end
case message.text
when /^\/wallet/i, '/mywallet'
# mywallet(message.from.id, bot, message)
# unless get_wallet(message.from.id)
# create_wallet(message.from.id, bot, message)
# end
telegram_wallet = get_or_create_telegram_wallet(message.from.id)
response_text = "Hello #{message.from.first_name}
ICP Account Id:
```
#{telegram_wallet.get_icp_id}
```
ICP Principal:
```
#{telegram_wallet.get_icp_principal}
```
"
begin
bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: response_text, parse_mode: "Markdown")
rescue
puts "Error from mywallet"
end
end
end
end
end
def get_or_create_telegram_wallet(telegram_id)
telegram_wallet = TelegramWallet.where(telegram_id: telegram_id).first_or_initialize
telegram_wallet.save
return telegram_wallet
end
end

View File

@ -1,5 +1,5 @@
class TelegramWallet < ActiveRecord::Base
def icprincipal
def get_icp_principal
return self.icp_principal if self.icp_principal
if self.icp_id.nil?
if !self.telegram_id.nil?
@ -27,7 +27,7 @@ class TelegramWallet < ActiveRecord::Base
end
return self.icp_principal
end
def icid
def get_icp_id
return self.icp_id if self.icp_id
if self.icp_principal.nil?
if !self.telegram_id.nil?

View File

@ -1,7 +1,7 @@
class CreateTelegramWallet < ActiveRecord::Migration[6.1]
def change
create_table :telegram_wallets do |t|
t.integer :telegram_id, null: false
t.string :telegram_id, null: false
t.string :icp_id
t.string :icp_principal

View File

@ -203,7 +203,7 @@ ActiveRecord::Schema.define(version: 2023_12_01_182512) do
end
create_table "telegram_wallets", force: :cascade do |t|
t.integer "telegram_id", null: false
t.string "telegram_id", null: false
t.string "icp_id"
t.string "icp_principal"
t.datetime "created_at", precision: 6, null: false