2022-02-05 15:32:14 -05:00
|
|
|
require 'pstore'
|
|
|
|
|
2022-02-04 18:48:09 -05:00
|
|
|
class Folder
|
|
|
|
def initialize()
|
|
|
|
@steves = []
|
|
|
|
@fallen = []
|
|
|
|
@submissions = []
|
2022-02-05 15:32:14 -05:00
|
|
|
@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
|
|
|
|
|
2022-02-11 16:33:24 -05:00
|
|
|
def close()
|
|
|
|
self.update()
|
2022-02-11 16:39:43 -05:00
|
|
|
puts "folder closed"
|
2022-02-11 16:33:24 -05:00
|
|
|
end
|
|
|
|
|
2022-02-05 15:32:14 -05:00
|
|
|
def num_subs()
|
|
|
|
@submissions.length
|
2022-02-04 18:48:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_steve(uid)
|
|
|
|
@steves.append(uid)
|
|
|
|
end
|
|
|
|
|
|
|
|
def curse(user)
|
2022-02-04 19:22:06 -05:00
|
|
|
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
|
2022-02-04 18:48:09 -05:00
|
|
|
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
|
2022-02-11 16:33:17 -05:00
|
|
|
until message.sender != target or i == 10 do
|
2022-02-04 19:22:06 -05:00
|
|
|
message = @submissions.sample
|
|
|
|
i = i + 1
|
|
|
|
end
|
2022-02-05 15:47:00 -05:00
|
|
|
if i == 5 or message.sender == target
|
2022-02-04 18:48:09 -05:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
@submissions.delete(message)
|
2022-02-04 19:22:06 -05:00
|
|
|
if message.local and not File.exist?(message.content)
|
2022-02-04 18:48:09 -05:00
|
|
|
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
|
|
|
|
|