fix reading multiple messages (readm)

This commit is contained in:
John Burwell 2023-04-23 18:00:27 -05:00
parent 977d2c956c
commit 14e2cb12d4

View File

@ -64,7 +64,7 @@ class BBS():
commands = [ commands = [
# (name, aliases, helpmsg, function, {arg: {arg attributes}, ...}) # (name, aliases, helpmsg, function, {arg: {arg attributes}, ...})
('bye', ['b', 'q'], 'Sign off and disconnect', self.bye, {}), ('bye', ['b', 'q'], 'Sign off and disconnect', self.bye, {}),
('delete', ['k', 'd'], 'Delete a message', self.delete, ('delete', ['d', 'k'], 'Delete a message', self.delete,
{'number': {'help': 'The numeric index of the message to delete'}}, {'number': {'help': 'The numeric index of the message to delete'}},
), ),
('deletem', ['dm', 'km'], 'Delete all your messages', self.delete_mine, {}), ('deletem', ['dm', 'km'], 'Delete all your messages', self.delete_mine, {}),
@ -115,7 +115,7 @@ class BBS():
return output return output
def read_multiline(self, prompt): def read_multiline(self, prompt):
output = "" output = []
if prompt: if prompt:
self.write_output(prompt) self.write_output(prompt)
while True: while True:
@ -123,8 +123,8 @@ class BBS():
if line.lower().strip() == "/ex": if line.lower().strip() == "/ex":
break break
else: else:
output += line output.append(line)
return output return ''.join(output)
def write_output(self, output): def write_output(self, output):
sys.stdout.write(output + '\r\n') sys.stdout.write(output + '\r\n')
@ -219,10 +219,16 @@ class BBS():
with Session(self.engine) as session: with Session(self.engine) as session:
statement = select(Message).where(Message.recipient == self.calling_station) statement = select(Message).where(Message.recipient == self.calling_station)
result = session.execute(statement) result = session.execute(statement)
for message in result.all(): messages = result.all()
count = len(messages)
if count > 0:
self.write_output(f"Reading {count} messages:")
for message in messages:
self.print_message(message) self.print_message(message)
self.write_output("Enter to continue") self.write_output("Enter to continue...")
sys.stdin.readline() sys.stdin.readline()
else:
self.write_output(f"No messages to read.")
def send(self, args, is_private=False): def send(self, args, is_private=False):
'''Create a message addressed to another user''' '''Create a message addressed to another user'''