Sha256: 50d076155dd3fdd099b87828757d251294b953ebdf218c53b0479e25036610c8

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

# coding: utf-8

module Bitbot::Prize
  def on_prize(m, recipient, amount, message)
    # Look up sender
    user_id = db.get_or_create_user_id_for_username(m.user.user)

    # Look up recipient
    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)

    # Convert amount to satoshi
    satoshi = str_to_satoshi(amount)
    if satoshi <= 0
      m.user.msg("Cannot send a negative amount.")
      return
    end

    # Attempt the transaction (will raise on InsufficientFunds)
    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 though :).", true
      return
    end

    # Success! Let the room know...
    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)

    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tipjar-0.1.196 lib/bitbot/plugin/prize.rb
tipjar-0.1.195 lib/bitbot/plugin/prize.rb
tipjar-0.1.194 lib/bitbot/plugin/prize.rb
tipjar-0.1.193 lib/bitbot/plugin/prize.rb
tipjar-0.1.192 lib/bitbot/plugin/prize.rb
tipjar-0.1.191 lib/bitbot/plugin/prize.rb
tipjar-0.1.19 lib/bitbot/plugin/prize.rb
tipjar-0.1.18 lib/bitbot/plugin/prize.rb
tipjar-0.1.171 lib/bitbot/plugin/prize.rb