From 5aade75594e57e33756a134418355a034fd8ea02 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 5 Feb 2022 15:32:14 -0500 Subject: [PATCH] add pstore persistence --- folder.rb | 19 ++++++++++++++++++- main.rb | 8 +++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/folder.rb b/folder.rb index 900bc23..a2502ee 100644 --- a/folder.rb +++ b/folder.rb @@ -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) diff --git a/main.rb b/main.rb index 202b88b..b32fccd 100755 --- a/main.rb +++ b/main.rb @@ -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