Skip to content

Commit

Permalink
added talkative mode and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonp committed Jul 23, 2014
1 parent 35d2aee commit d255071
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 47 deletions.
34 changes: 21 additions & 13 deletions botconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@
#
# LIVE CONFIG INFO

configure do |c|
c.nick = "botspade"
c.server = "irc.twitch.tv"
c.port = 6667
c.password = "oauth:cbr74bjxkfc5r24lqs0yph44fgbgam7" # Get yours here: http://twitchapps.com/tmi/
c.verbose = true
end

#
# TEST CONFIG INFO

#configure do |c|
# c.nick = "botspade"
# c.server = "irc.twitch.tv"
# c.server = "0.0.0.0"
# c.port = 6667
# c.password = "oauth:cbr74bjxkfc5r24lqs0yph44fgbgam7" # Get yours here: http://twitchapps.com/tmi/
# 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
# they check in? What is your name, so that the bot customizes?
#
# Note: need to move these to the DB / Options table

helpers do

Expand All @@ -48,12 +51,17 @@
@checkin_points = 4

# How long should bets remain active before auto-closing? Default is 5 minutes.
# NOT IMPLEMENTED YET
@bets_auto_close_in = 5 # minutes
@bets_auto_close_in = 5 # time in minutes

# What is your twitch username? This is the "channel" your bot needs to join.
# The channel MUST begin with '#'
@botchan = "#watchspade"

# If you turn talkative mode OFF (!talkative in chat to toggle), you also need to
# say where folks can see their points... where you put index.pnp!
#
@talkative = true
@leaderboard_location = "http://watchspade.com/botspade/"

# 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.
Expand Down
Binary file modified botspade.db
Binary file not shown.
96 changes: 65 additions & 31 deletions botspade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,28 @@
# An expensive way to pretend like I have a daemon
# check for latent processes and execute them
def fake_daemon
if Time.now.utc.to_i > @betstimer.to_i + 300 && @betsopen == TRUE

# The toggle bets timer
@timegap = @bets_auto_close_in * 60
if Time.now.utc.to_i > @betstimer.to_i + @timegap.to_i && @betsopen == TRUE
@betsopen = FALSE
msg channel, "Bets are now closed. GL."
end

end

def save_data
msg channel, "success" if File.write('pointsdb.txt', @pointsdb.to_json) && File.write('checkindb.txt', @checkindb.to_json) && File.write('viewerdb.txt', @viewerdb.to_json) && File.write('gamesdb.txt', @gamesdb.to_json)
end
#
# Deprecating...
#
#
# def save_data
# msg channel, "success" if File.write('pointsdb.txt', @pointsdb.to_json) && File.write('checkindb.txt', #@checkindb.to_json) && File.write('viewerdb.txt', @viewerdb.to_json) && File.write('gamesdb.txt', @gamesdb.to_json)
# end

def save_data_silent
File.write('pointsdb.txt', @pointsdb.to_json) && File.write('checkindb.txt', @checkindb.to_json) && File.write('viewerdb.txt', @viewerdb.to_json) && File.write('gamesdb.txt', @gamesdb.to_json)
fake_daemon
end
# def save_data_silent
# File.write('pointsdb.txt', @pointsdb.to_json) && File.write('checkindb.txt', @checkindb.to_json) && #File.write('viewerdb.txt', @viewerdb.to_json) && File.write('gamesdb.txt', @gamesdb.to_json)
# fake_daemon
# end

def take_points(person, points)
# Newer Fancy Way
Expand Down Expand Up @@ -155,12 +163,25 @@ def pretty_uptime
end

def user_is_an_admin?(user)
if @admins_array.include?(user)
streamer = @botchan
streamer[0] = ''
puts "checking admin for: #{streamer}"
check_this_user = get_user(user)
if (check_this_user[6] == 1) || check_this_user == streamer
return true
else
return false
end
end

def talkative?
if @talkative == true
return true
else
return false
end
end

end


Expand All @@ -172,7 +193,7 @@ def user_is_an_admin?(user)


on :channel, /^!changelog/i do
msg channel, "v0.7: SQLite implemented. !bet checks for input. !update, !lookup, !remove working. Fixed db crashes."
msg channel, "v0.8: Fixed db crashes. Added points leaderboard: http://watchspade.com/botspade/"
end

on :channel, /^!beard/i do
Expand Down Expand Up @@ -232,6 +253,18 @@ def user_is_an_admin?(user)
msg channel, "#{@botmaster} uses BotSpade. Get your own bot: http://github.com/jasonp/botspade"
end

on :channel, /^!talkative/i do
if user_is_an_admin?(nick)
if @talkative == true
@talkative = false
msg channel, "Talkative mode off."
else
@talkative = true
msg channel, "Talkative mode on."
end
end
end

on :channel, /^!stats$/i do
wins_losses = get_wins_losses
wincount = wins_losses[0]
Expand Down Expand Up @@ -312,9 +345,11 @@ def user_is_an_admin?(user)
end

on :channel, /^!dump$/i do
user = get_user(nick)
db_get_all_open_bets
msg channel, "Dumped"
if user_is_an_admin?(nick)
user = get_user(nick)
db_get_all_open_bets
msg channel, "Dumped"
end
end

on :channel, /^!lookup (.*) (.*)/i do |first, last|
Expand All @@ -336,14 +371,14 @@ def user_is_an_admin?(user)
lookup_value = person_hash[attribute]
msg channel, "#{person}: #{lookup_value}"
else
msg channel, "Sorry, nothing in the viewer database for that!"
msg channel, "Sorry, nothing in the viewer database for that!" if talkative?
end
else
msg channel, "#{person}: Empty profile!"
msg channel, "#{person}: Empty profile!" if talkative?
end # if person_hash
end
else
msg channel, "Sorry, nothing in the viewer database for that!"
msg channel, "Sorry, nothing in the viewer database for that!" if talkative?
end
end

Expand All @@ -361,7 +396,7 @@ def user_is_an_admin?(user)
db_set_profile(user[0], person_hash)
msg channel, "#{attribute} removed for #{nick}"
else
msg channel, "I don't see anything to remove!"
msg channel, "I don't see anything to remove!" if talkative?
end
end
end
Expand All @@ -378,17 +413,18 @@ def user_is_an_admin?(user)
#

on :channel, /^!bet$/i do
fake_daemon
bet_status = ""
if @betsopen == TRUE
bet_status = "(Bets are open right now)"
else
bet_status = "(Bets are closed right now)"
end
msg channel, "Usage: !bet [points] [win/loss/tie] e.g. !bet 15 loss #{bet_status}"
fake_daemon
end

on :channel, /^!bet (.*) (.*)/i do |first, last|
fake_daemon
bet_amount = first.to_i
win_loss = last.downcase
user = get_user(nick)
Expand All @@ -405,19 +441,18 @@ def user_is_an_admin?(user)
else
db_create_bet(user[0], numerical_bet, bet_amount, 0)
take_points(nick, bet_amount)
msg channel, "#{nick}: Bet recorded."
msg channel, "#{nick}: Bet recorded." if talkative?
end
else
msg channel, "Whoops, #{nick} it looks like you don't have enough points!"
end
else
msg channel, "You can only bet for: win, loss, tie. Check spelling!"
msg channel, "You can only bet for: win, loss, tie. Check spelling!"
end #check for not win/loss/tie
end
else
msg channel, "Sorry, bets aren't open right now."
end
fake_daemon
end

on :channel, /^!reportgame (.*)/i do |first|
Expand Down Expand Up @@ -468,18 +503,14 @@ def user_is_an_admin?(user)
if @betsopen == FALSE
@betsopen = TRUE
@betstimer = Time.now.utc
msg channel, "Betting is now open for 5 minutes. Place your bets: !bet [points] [win/loss/tie]"
msg channel, "Betting is now open for #{@bets_auto_close_in} minutes. Place your bets: !bet [points] [win/loss/tie]"
elsif @betsopen == TRUE
@betsopen = FALSE
msg channel, "Betting is now closed. GL."
end
end
end

#on :channel, /^!1v1$/i do
# msg channel, "Usage: !1v1 [win/loss] - all 1v1 bets are for 2 points, but cost nothing"
#end

# Method for users to give points to other viewers
# !give user points

Expand Down Expand Up @@ -628,7 +659,7 @@ def user_is_an_admin?(user)
msg channel, "Thanks for checking in, #{nick}! You have been given #{@checkin_points} #{@botmaster} Points! [Total check-ins: #{total_checkins}]"
end
else
msg channel, "#{nick} checked in already, no #{@botmaster} Points given."
msg channel, "#{nick} checked in already, no #{@botmaster} Points given." if talkative?
end
else
if write_user(nick)
Expand All @@ -646,19 +677,22 @@ def user_is_an_admin?(user)
if (user)
if user[2] > 0
userpoints = user[2].to_s
msg channel, "#{nick} has #{userpoints} #{@botmaster} Points."
msg channel, "#{nick} has #{userpoints} #{@botmaster} Points." if talkative?
else
msg channel, "Sorry, it doesn't look like you have any #{@botmaster} Points!"
msg channel, "Sorry, it doesn't look like you have any #{@botmaster} Points!" if talkative?
end
else
if write_user(nick)
newuser = get_user(nick)
if db_checkins_get(newuser[0])
give_points(nick, @checkin_points)
msg channel, "#{nick}: Welcome! You have been checked-in and given #{@checkin_points} #{@botmaster} Points! [Total check-ins: 1]"
msg channel, "#{nick}: Welcome! You have been checked-in and given #{@checkin_points} #{@botmaster} Points! [Total check-ins: 1]" if talkative?
end
end
end
end
if !talkative?
msg channel, "You can check your points here: #{@leaderboard_location}"
end
fake_daemon
end

Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
#
# You need to set the correct path for the database file on line 61
# for this to work!
#
# for this to work! Place this file in a web-accessible part of your server,
# e.g. /var/www/example.com/public_html/leaderboard/index.php
#

?>
Expand Down
8 changes: 7 additions & 1 deletion test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_it
msg channel, "!lookup test country"

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

puts "get an index"
msg channel, "!lookup index"
Expand All @@ -102,6 +102,12 @@ def test_it

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

puts "talkative toggle"
msg channel, "!talkative"

puts "seeing if it talks"
msg channel, "!checkin"
end


Expand Down

0 comments on commit d255071

Please sign in to comment.