add pstore persistence
This commit is contained in:
parent
a15ff0dbcd
commit
5aade75594
19
folder.rb
19
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)
|
||||
|
8
main.rb
8
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
|
||||
|
Loading…
Reference in New Issue
Block a user