Created
September 22, 2009 21:38
-
-
Save alx/191457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@database = SQLite3::Database.new( "first_bar.db" ) | |
@database.execute( "create table bar_table (tag_id INTEGER PRIMARY KEY, username TEXT, credit NUMERIC, nb_beers NUMERIC);" ) | |
# Admin tag | |
tag_in "d00219a440cf08b8" do | |
puts "Alx phone" | |
puts "select username to add credit:" | |
index = 1 | |
@database.execute("select * from bar_table").each do |row| | |
puts "#{index}: #{row[1]}" | |
index += 1 | |
end | |
row_id = gets | |
tag_id, current_credit = @database.execute("select tag_id, credit from bar_table limit 1, #{row_id - 1}")[1] | |
puts "credit amount:" | |
new_credit = gets | |
@database.execute("update bar_table set credit={current_credit + new_credit} where tag_id = #{tag_id}") | |
end | |
tag_out "d00218c109160996" do | |
puts "pink rabbit" | |
end | |
# unknown tag, it'll add the tag to the bar with RubyMirror.in method | |
unknown_tag do |tag| | |
puts "hey #{tag}, je ne te connais pas, donne moi ton nom pour boire une bière:" | |
username = gets | |
username = username.chomp | |
puts "Merci #{username}, ton nom vient d'être rajouté à la base, combien de crédit as-tu?" | |
credit = gets | |
begin | |
credit = Integer(credit.chomp) | |
rescue ArgumentError | |
puts "Not an integer!" | |
end | |
if credit > 0 | |
puts "T'en bois une tout de suite? il te reste #{credit -= 1} " | |
else | |
puts "oué, bonne blague, essaye encore" | |
end | |
RubyMirror.in(tag) do | |
username, credit, nb_beers = @database.execute("select username, credit, nb_beers from bar_table where tag_id = #{tag}") | |
puts "je t'ai reconnnu #{username}" | |
if nb_beers == credit | |
puts "allez, 'est ta derniere biere, rajoute du credit si t'en veux d'autres" | |
elsif nb_beers == (credit - 1) | |
puts "avant-derniere biere, la prochaine c'est la bonne" | |
elsif nb_beers > credit | |
puts "plus de bieres pour toi, rajoutes du credit" | |
else | |
puts "il te reste {credit - nb_beers} bieres" | |
end | |
@database.execute("update bar_table set nb_beers=#{nb_beers + 1} where tag_id = #{tag}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment