4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/bitbot/plugin/tip.rb', line 4
def on_tip(m, recipient, amount, message)
user_id = db.get_or_create_user_id_for_username(m.user.user)
recipient_ircuser = m.channel.users.keys.find {|u| u.name == recipient }
unless recipient_ircuser
m.user.msg("Could not find #{recipient} in the channel list.")
return
end
recipient_user_id = db.get_or_create_user_id_for_username(recipient_ircuser.user)
satoshi = (amount.to_f * 10**8).to_i
if satoshi <= 0
m.user.msg("Cannot send a negative amount.")
return
end
begin
db.create_transaction_from_tip(user_id, recipient_user_id, satoshi, message)
rescue Bitbot::InsufficientFundsError
m.reply "Insufficient funds! It's the thought that counts.", true
return
end
m.reply "[✔] Verified: ".irc(:grey).irc(:bold) +
m.user.user.irc(:bold) +
" ➜ ".irc(:grey) +
satoshi_with_usd(satoshi) +
" ➜ ".irc(:grey) +
recipient_ircuser.user.irc(:bold)
m.user.msg "You just sent " +
recipient_ircuser.user.irc(:bold) + " " +
satoshi_with_usd(satoshi) +
" in " +
m.channel.name.irc(:bold) +
" bringing your balance to " +
satoshi_with_usd(db.get_balance_for_user_id(user_id)) +
"."
recipient_ircuser.msg m.user.user.irc(:bold) +
" just sent you " +
satoshi_with_usd(satoshi) +
" in " +
m.channel.name.irc(:bold) +
" bringing your balance to " +
satoshi_with_usd(db.get_balance_for_user_id(recipient_user_id)) +
". Type 'help' to list bitbot commands."
end
|