POO Library


This object implements a simple bulletin-board system; users can post, read, and remove messages referenced by unique numbers. It can serve as a communication system, a book with chapters, an announcement center, etc.

This code was revised on 6/28/97 with several bug fixes.

@create $thing as bbs
@set bbs.editFailMsg = "%1D %1:(tries) to edit a message on %2i, but to no avail."
@set bbs.startEditMsg = "%1D %1:(begins) editing a message on %2i."
@set bbs.endEditMsg = "%1D %1:(puts) the finishing touches on a message for %2d."
@set bbs.abortEditMsg = "%1D %1:(quits) editing a message on %2i."
@set bbs.highnum = 0
@set me.bbs = bbs
;me.bbs.messages = {}   # only way to get dicts past the POO parser!
;me.bbs.msgowners = {}
@delprop me.bbs
@set bbs.f to 1

@newfunc bbs.reset(self)
self.messages = {}
self.msgowners = {}
self.highnum = 0
show( "%1D %1:(resets) %2d.", {1:user, 2:self} )
@setown bbs.reset to None
@setperm bbs.reset to rc
@cmd bbs.reset <this> calls reset()
reset bbs

@newfunc bbs.allowAdd(self,who)
	Return 1 if 'who' can add a message, else return 0.
	In this version: if self.locked is true,
	then only owner can add; else anyone can.
if self.locked: return who == self.owner
return 1

@newfunc postedit(self, who, whatobj, propname, saved) on bbs
# get the message number from our propname
num = string.atoi( string.split(propname, '_')[1] )
if saved: 	
	show( self.endEditMsg, {1:who, 2:self} )
	# copy the message to the messages dictionary
	self.messages[num] = getattr(whatobj,propname)
	show( self.abortEditMsg, {1:who, 2:self} )
# remember to delete the wip message!
# if message is empty, delete it from the board
if not self.messages[num]:
	del self.msgowners[num]
	del self.messages[num]
	if num == self.highnum: self.highnum = self.highnum - 1	

@newfunc edit(self,num=0) on bbs
"""bbs.edit(self): implements the "edit" command"""
if not num:
	# is user allowed to add a message to this?
	if not self.allowAdd(user):
		show(self.editFailMsg, {1:user, 2:self})
	# create a new message
	self.highnum = self.highnum + 1
	num = self.highnum
	self.msgowners[num] = user
	self.messages[num] = ()
	# does chosen message exist?
	if num not in self.messages.keys():
		print "Invalid message number."
	# is user editing his own message?
	if self.msgowners[num] != user and user != self.owner:
		print "That message belongs to " + \
				self.msgowners[num].name + '.'
# make a temporary property to hold the edit buffer
propname = "wip_" + str(num)
setattr(self,propname, self.messages[num])
# ok, start editing!
show( self.startEditMsg, {1:user, 2:self} )
user.startEdit( self, propname, self.postedit )
@set bbs.edit.desc = "edit a message"
@setperm bbs.edit to rc
@cmd bbs.edit <int> on <this> calls edit(%1)
@cmd bbs.post to <this> calls edit()

@newfunc bbs.erase(self,num)
# you can only erase your own message (unless you own this object)
if num not in self.msgowners.keys():
	print "Invalid message number."
elif self.msgowners[num] != user and user != self.owner:
	print "That message belongs to " + self.msgowners[num].name + '.'
	del self.msgowners[num]
	del self.messages[num]
	print "Message", num, "deleted."
@setown bbs.erase to None
@setperm bbs.erase to rc
@cmd bbs.erase <int> on <this> calls erase(%1)
@cmd bbs.erase <int> from <this> calls erase(%1)
@cmd bbs.delete <int> on <this> calls erase(%1)
@cmd bbs.delete <int> from <this> calls erase(%1)

@newfunc bbs.description(self,looker)
# first, get the standard desc, if any
if self.desc: desc = self.desc + '\n'
else: desc = ''
# then append the message list
for num in self.messages.keys():
	try: subj = self.messages[num][0][:60]
	except: subj = "(no subject)"
	desc = desc + "%4d. %-60s %10s\n" % (num, subj, self.msgowners[num].name)
# finally, if there is a "postdesc" property, append that
if self.postdesc: desc = desc + self.postdesc  + '\n'
return desc[:-1]
@set bbs.description.desc = "standard desc plus text"

@newfunc bbs.read(self,num)
if num not in self.messages.keys():
	print "Invalid message number."
	for line in self.messages[num]: print line
@set bbs.read.desc = "read a message"
@cmd bbs.read <int> on <this> calls read(%1)

@edit bbs.help
To prepare a bulletin board simply derive from $pub.misc.bbs,
then reset it (e.g., "reset myBoard").  You can also set the
following properties:

    desc: description to appear before the message list
    locked: if 1, only the owner can add messages

Use "post on bbs" to create a new message, "edit 42 on bbs"
to edit message 42, and "delete 42 on bbs" to delete it
(where "bbs" is the name of the bulletin board object).

beam bbs to $pub.misc


Once this is installed, create new bulletin boards (e.g., @create $pub.misc.bbs as kiosk) then always remember to reset them (e.g., reset kiosk). Use "help $pub.misc.bbs" for more usage information.

Last Updated: 8/14/97 . . . . . . Joe Strout