stevefolder/folder.rb
2022-02-11 16:33:24 -05:00

96 lines
1.7 KiB
Ruby

require 'pstore'
class Folder
def initialize()
@steves = []
@fallen = []
@submissions = []
@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 close()
self.update()
end
def num_subs()
@submissions.length
end
def add_steve(uid)
@steves.append(uid)
end
def curse(user)
if @steves.include?(user.id)
@steves.delete(user.id)
@fallen.append(user.id)
end
end
def bless(user)
if @fallen.include?(user.id)
@steves.append(user.id)
@fallen.delete(user.id)
end
end
def steve?(user)
return (@steves.include?(user) or @fallen.include?(user))
end
def submit(sub)
sub.set_id(@idgen)
@submissions.append(sub)
@idgen = @idgen + 1
end
def harass_steve()
if @steves.length <= 0
return nil
end
target = @steves.sample
if @submissions.length <= 0
return nil
end
message = @submissions.sample
i = 0
until message.sender != target or i == 10 do
message = @submissions.sample
i = i + 1
end
if i == 5 or message.sender == target
return nil
end
@submissions.delete(message)
if message.local and not File.exist?(message.content)
return nil
end
return target,message
end
end
class Submission
def initialize(content,local,sender)
@local = local
@content = content
@sender = sender
end
def set_id(i)
@id = i
end
attr_reader :local,:content,:sender,:id
end