add pstore persistence

This commit is contained in:
stryan 2022-02-05 15:32:14 -05:00
parent a15ff0dbcd
commit 5aade75594
2 changed files with 25 additions and 2 deletions

View File

@ -1,9 +1,26 @@
require 'pstore'
class Folder
def initialize()
@steves = []
@fallen = []
@submissions = []
@idgen = 1
@db = PStore.new("submission_db.pstore")
@db.transaction do
@idgen = @db.fetch('id',default=1)
@submissions = @db.fetch('subs',[])
end
end
def update()
@db.transaction do
@db['id'] = @idgen
@db['subs'] = @submissions
end
end
def num_subs()
@submissions.length
end
def add_steve(uid)

View File

@ -44,7 +44,11 @@ bot.message(private: true,contains: "!folder rise") do |event|
end
bot.message(private: true, contains: "!folder help") do |event|
event.respond("Commands: rise,fall,help")
event.respond("Commands: rise,fall,help,status")
end
bot.message(private: true, contains: "!folder status") do |event|
event.respond("Stevefolder has #{folder.num_subs} submissions")
end
bot.message(private: true) do |event|
@ -87,6 +91,7 @@ bot.message(private: true) do |event|
event.respond("Submission #{i} accepted")
i= i+1
end
folder.update()
end
@ -117,4 +122,5 @@ loop do
else
steve.pm(msg.content)
end
folder.update()
end