Skip to content

Commit

Permalink
fixed item removal bug, mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonp committed Sep 30, 2014
1 parent 4fa9cf2 commit c00e3bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Binary file modified botspade.db
Binary file not shown.
6 changes: 3 additions & 3 deletions botspade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
@db.execute( "INSERT INTO options ( option, value, timestamp ) VALUES ( ?, ?, ? )", ["talkative", @talkative.to_s, Time.now.utc.to_i])

# bugfix on items & inventory
@db.execute "ALTER TABLE items ADD COLUMN live BOOL;"
@db.execute "ALTER TABLE items ADD COLUMN live TEXT;"
end

# Toggle whether or not bets are allowed
Expand Down Expand Up @@ -329,8 +329,8 @@ def respond_to_commands(message)
item_list = db_get_all_items
item_names = []
item_list.each do |item|
store_listing = item[1] + " (" + item[3] + "pts)" #if item[5] == true
item_names << store_listing
store_listing = item[1] + " (" + item[3] + "pts)"
item_names << store_listing if item[6] == "true"
end
store_inventory = item_names.join(', ')
msg channel, "Shop menu: #{store_inventory} (use !shop [item] for more info)"
Expand Down
12 changes: 9 additions & 3 deletions db_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def db_remove_command(command_id)

#
# Items
# item[0] = id, [1] = name, [2] = description, [3] = price, [4] = ownable, [5] = timestamp
# item[0] = id, [1] = name, [2] = description, [3] = price, [4] = ownable, [5] = timestamp, [6] = live
#
def db_set_item(name, description, price, ownable)
return true if @db.execute( "INSERT INTO items ( name, description, price, ownable, timestamp ) VALUES ( ?, ?, ?, ?, ? )", [name, description, price, ownable, Time.now.utc.to_i])
return true if @db.execute( "INSERT INTO items ( name, description, price, ownable, timestamp, live ) VALUES ( ?, ?, ?, ?, ?, ? )", [name, description, price, ownable, Time.now.utc.to_i, true])
end

def db_get_all_items
Expand All @@ -163,6 +163,8 @@ def db_get_item(item_name)
end
end

# Need to insert new method to check for mutliple items with same name, to allow for removal

def db_get_item_by_id(item_id)
puts "Getting the item by ID: #{item_id}"
the_item = @db.execute( "SELECT * FROM items WHERE id = ?", [item_id])[0]
Expand All @@ -174,8 +176,12 @@ def db_get_item_by_id(item_id)
end
end

#
# Removes item from store but does not "delete" it to prevent inventory errors
#

def db_remove_item(item_id)
return true if @db.execute( "DELETE FROM items WHERE id = ? ", [item_id.to_i] )
return true if @db.execute( "UPDATE items SET live = ? WHERE id = ?", ["false", item_id] )
end

#
Expand Down

0 comments on commit c00e3bc

Please sign in to comment.