class Lita::Handlers::OnewheelIou
Constants
- REDIS_KEY
Public Instance Methods
add_iou(response)
click to toggle source
# File lib/lita/handlers/onewheel-iou.rb, line 9 def add_iou(response) ower = response.user.name owee = response.matches[0][0] key = REDIS_KEY + ".#{ower}" iou_count = redis.hget(key, owee).to_i iou_count += 1 redis.hset(key, owee, iou_count) response.reply "#{ower} now owes #{owee} #{iou_count} #{beer_icons iou_count.to_i }." end
beer_icons(count)
click to toggle source
# File lib/lita/handlers/onewheel-iou.rb, line 55 def beer_icons(count) str = '' 0..count.times do str += "🍺" end str end
remove_iou(response)
click to toggle source
# File lib/lita/handlers/onewheel-iou.rb, line 19 def remove_iou(response) ower = response.user.name owee = response.matches[0][0] key = REDIS_KEY + ".#{ower}" iou_count = redis.hget(key, owee).to_i if iou_count > 0 iou_count -= 1 if iou_count == 0 redis.hdel(key, owee) response.reply "#{ower} has fully paid back #{owee}." else redis.hset(key, owee, iou_count) response.reply "#{ower} now owes #{owee} #{iou_count} #{beer_icons iou_count.to_i }." end end end
show_ious(response)
click to toggle source
# File lib/lita/handlers/onewheel-iou.rb, line 37 def show_ious(response) ower = response.user.name key = REDIS_KEY + ".#{ower}" ious = redis.hgetall(key) if ious.length == 0 response.reply "#{ower} owes nothing." else reply_str = "#{ower} owes" data_str = '' ious.each do |nick, num| data_str += " #{nick} #{beer_icons num.to_i}," #beer#{(num.to_i > 1)? 's' : ''}, end data_str.sub! /,$/, '' response.reply reply_str + data_str end end