Skip to content

Commit

Permalink
bets in DB and some rudimentary testing options
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonp committed Jul 17, 2014
1 parent 260c04f commit 5a35169
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 58 deletions.
15 changes: 14 additions & 1 deletion botconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# while logged in to your bot's Twitch account).
#

#
# LIVE CONFIG INFO

configure do |c|
c.nick = "botspade"
c.server = "irc.twitch.tv"
Expand All @@ -21,6 +24,16 @@
c.verbose = true
end

#
# TEST CONFIG INFO

#configure do |c|
# c.nick = "botspade"
# c.server = "0.0.0.0"
# c.port = 6667
# c.verbose = true
#end

#############
#
# Whose bot is this? Let's set some customizeations. How many points should people get when
Expand All @@ -45,7 +58,7 @@
# Bot admins. Which users will be able to !togglebets, !savedata, and other admin-only commands?
# follow the example below to add as many admins as you'd like to.
@admins_array = []
@admins_array << "watchspade" # << "another_admin" << "another_one"
@admins_array << "watchspade" << "test" # << "another_admin" << "another_one"

end

Expand Down
Binary file modified botspade.db
Binary file not shown.
78 changes: 21 additions & 57 deletions botspade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,6 @@ def user_is_an_admin?(user)
fake_daemon
end


on :channel, /^!debug/i do
if user_is_an_admin?(nick)
msg channel, "#{@stream_start_time}"
end
end

on :channel, /^!getpoints/i do
msg channel, "You can get #{@botmaster} Points by checking in (!checkin), donating, tweeting (!tweet), & winning bets (!bet for usage). Or you can be given points (!give)."
end
Expand Down Expand Up @@ -461,47 +454,6 @@ def user_is_an_admin?(user)
end # open bets loop
end # if open_bets
end # if report


# if first.downcase == "win"
# db_set_game(1)
# @betsdb.keys.each do |bettor|
# bet_amount = @betsdb[bettor][0]
# win_loss = @betsdb[bettor][1]
# if win_loss == "win"
# winnings = bet_amount * 2
# total_won = total_won + winnings
# winner_count = winner_count + 1
# give_points(bettor, winnings)
# end
# end
# elsif first.downcase == "loss"
# db_set_game(2)
# @betsdb.keys.each do |bettor|
# bet_amount = @betsdb[bettor][0]
# win_loss = @betsdb[bettor][1]
# if win_loss == "loss"
# winnings = bet_amount * 2
# total_won = total_won + winnings
# winner_count = winner_count + 1
# give_points(bettor, winnings)
# end
# end
# elsif first.downcase == "tie"
# db_set_game(3)
# @betsdb.keys.each do |bettor|
# bet_amount = @betsdb[bettor][0]
# win_loss = @betsdb[bettor][1]
# if win_loss == "tie"
# winnings = bet_amount * 2
# total_won = total_won + winnings
# winner_count = winner_count + 1
# give_points(bettor, winnings)
# end
# end
# end
# @betsdb = {}


msg channel, "Bets tallied. #{total_won.to_s} #{@botmaster} Points won and #{total_lost.to_s} #{@botmaster} Points lost by #{number_of_bettors} gambler(s)."
end
Expand Down Expand Up @@ -584,15 +536,18 @@ def user_is_an_admin?(user)

on :channel, /^!referredby (.*)/i do |first|
referrer = first.downcase
if db_user_checkins_count > 0
msg channel, "Hmm, looks like you've checked in here before! Sorry, you only get to be new once!"
user = get_user(nick)
if (user)
msg channel, "Hmm, looks like you've checked in here before! Sorry, you only get to be new once!"
else
if db_checkins_get(@users[nick]['id'])
give_points(nick, @checkin_points)
total_checkins = db_user_checkins_count(@users[nick]['id'])
give_points(nick, 14)
give_points(referrer, 10)
msg channel, "Welcome #{nick}! You & #{referrer} have been awarded 10 #{@botmaster} Points! You have also been checked in for 4 #{@botmaster} Points."
if db_user_generate(nick)
newuser = get_user(nick)
if db_checkins_get(newuser[0])
total_checkins = db_user_checkins_count(user[0])
give_points(nick, 14)
give_points(referrer, 10)
msg channel, "Welcome #{nick}! You & #{referrer} have been awarded 10 #{@botmaster} Points! You have also been checked in for 4 #{@botmaster} Points."
end
end
end
end
Expand Down Expand Up @@ -726,7 +681,16 @@ def user_is_an_admin?(user)
user = get_user(nick)
if (user)
checkins = db_user_checkins_count(user[0])
msg channel, "#{nick}: #{checkins} checkins!"
correct_bets = 0
past_bets = db_get_all_bets_from_user(user[0])
past_bets.each do |past_bet|
if past_bet[4] == 1
correct_bets = correct_bets + 1
end
end
ratio = correct_bets.to_f / past_bets.count.to_f
incorrect_bets = past_bets.count - correct_bets
msg channel, "#{nick}: #{checkins} checkins! Winning bets ratio: #{ratio} with #{correct_bets} correct bets and #{incorrect_bets} incorrect bets."
end
end

Expand Down
11 changes: 11 additions & 0 deletions botspade_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ def db_get_all_open_bets
end
end

def db_get_all_bets_from_user(user_id)
bets = @db.execute( "SELECT * FROM bets WHERE user_id = ?", [user_id] )
if (bets)
puts "#{bets}"
return bets
else
puts "#{user_id} not found in bets db"
return nil
end
end

# Some checkins fucntions
#

Expand Down
118 changes: 118 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
############################################################################
#
# BotSpade Tests
#
# A really roundabout way to do tests: set up a local IRC server
# using brew install ngircd, and simply use a bot to test the bot.
#
# This sucks a lot but whatever. Type "testme" into colloquy when both
# bots are connected. Look for a crash. Best I can do. Ugh.
#

require 'isaac'

configure do |c|
c.nick = "test"
c.server = "0.0.0.0"
c.port = 6667
c.verbose = true
end

############################################################################
#
# Helpers
#

helpers do


def test_it
puts "referred by?"
msg channel, "!referredby watchspade"

puts "testing !checkin"
msg channel, "!checkin"

puts "testing !points"
msg channel, "!points"

puts "giving points"
msg channel, "!give test 10"

puts "betting while not allowed"
msg channel, "!bet 5 win"

puts "toggleing bets"
msg channel, "!togglebets"

puts "making a bet to win"
msg channel, "!bet 1 win"

puts "reporting a win"
msg channel, "!reportgame win"

puts "making a bet to lose"
msg channel, "!bet 1 loss"

puts "reporting a loss"
msg channel, "!reportgame loss"

puts "betting on a tie"
msg channel, "!bet 1 tie"

puts "reporting a tie"
msg channel, "!reportgame tie"

puts "getting a bet wrong"
msg channel, "!bet 1 loss"
msg channel, "!reportgame win"

puts "betting wrong syntax"
msg channel, "!bet tie 5"

puts "taking points"
msg channel, "!take test 2"

puts "time for viewer db"
msg channel, "!update country USA"

puts "lookup the value"
msg channel, "!lookup test country"

puts "lookup a nil value"
msg channel, "!lookup watchsapde fleebleblox"

puts "get an index"
msg channel, "!lookup index"

puts "remove an item"
msg channel, "!remove country"

puts "starting stream"
msg channel, "!startstream"

puts "uptime"
msg channel, "!uptime"

puts "stop the clock"
msg channel, "!endstream"

puts "stats"
msg channel, "!stats"

puts "my own stats"
msg channel, "!statsme"
end


end

on :connect do # test the bot
join "#watchspade"
puts "connected to channel"

end

on :channel, /^testme/ do
test_it
end

0 comments on commit 5a35169

Please sign in to comment.