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 class Folder
def initialize() def initialize()
@steves = [] @steves = []
@fallen = [] @fallen = []
@submissions = [] @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 end
def add_steve(uid) def add_steve(uid)

View File

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