2024-06-25 05:50:52 -07:00
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
|
|
|
user_states = {}
|
|
|
|
|
|
|
|
|
|
|
|
def update_user_state(user_id, state):
|
|
|
|
user_states[user_id] = state
|
|
|
|
|
|
|
|
|
|
|
|
def get_user_state(user_id):
|
|
|
|
return user_states.get(user_id, None)
|
|
|
|
|
|
|
|
|
|
|
|
def send_message(message, destination, interface):
|
|
|
|
max_payload_size = 200
|
|
|
|
for i in range(0, len(message), max_payload_size):
|
|
|
|
chunk = message[i:i + max_payload_size]
|
2024-07-22 11:53:04 -07:00
|
|
|
try:
|
|
|
|
d = interface.sendText(
|
|
|
|
text=chunk,
|
|
|
|
destinationId=destination,
|
2024-09-24 05:12:32 -07:00
|
|
|
wantAck=True,
|
2024-07-22 11:53:04 -07:00
|
|
|
wantResponse=False
|
|
|
|
)
|
2024-09-24 03:45:33 -07:00
|
|
|
destid = get_node_id_from_num(destination, interface)
|
2024-09-27 06:32:58 -07:00
|
|
|
chunk = chunk.replace('\n', '\\n')
|
|
|
|
logging.info(f"Sending message to user '{get_node_short_name(destid, interface)}' ({destid}) with sendID {d.id}: \"{chunk}\"")
|
2024-07-22 11:53:04 -07:00
|
|
|
except Exception as e:
|
|
|
|
logging.info(f"REPLY SEND ERROR {e.message}")
|
|
|
|
|
|
|
|
|
2024-06-25 05:50:52 -07:00
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
|
|
def get_node_info(interface, short_name):
|
|
|
|
nodes = [{'num': node_id, 'shortName': node['user']['shortName'], 'longName': node['user']['longName']}
|
|
|
|
for node_id, node in interface.nodes.items()
|
2024-07-04 08:42:29 -07:00
|
|
|
if node['user']['shortName'].lower() == short_name]
|
2024-06-25 05:50:52 -07:00
|
|
|
return nodes
|
|
|
|
|
|
|
|
|
|
|
|
def get_node_id_from_num(node_num, interface):
|
|
|
|
for node_id, node in interface.nodes.items():
|
|
|
|
if node['num'] == node_num:
|
|
|
|
return node_id
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def get_node_short_name(node_id, interface):
|
|
|
|
node_info = interface.nodes.get(node_id)
|
|
|
|
if node_info:
|
|
|
|
return node_info['user']['shortName']
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def send_bulletin_to_bbs_nodes(board, sender_short_name, subject, content, unique_id, bbs_nodes, interface):
|
|
|
|
message = f"BULLETIN|{board}|{sender_short_name}|{subject}|{content}|{unique_id}"
|
|
|
|
for node_id in bbs_nodes:
|
|
|
|
send_message(message, node_id, interface)
|
|
|
|
|
|
|
|
|
|
|
|
def send_mail_to_bbs_nodes(sender_id, sender_short_name, recipient_id, subject, content, unique_id, bbs_nodes,
|
|
|
|
interface):
|
|
|
|
message = f"MAIL|{sender_id}|{sender_short_name}|{recipient_id}|{subject}|{content}|{unique_id}"
|
|
|
|
logging.info(f"SERVER SYNC: Syncing new mail message {subject} sent from {sender_short_name} to other BBS systems.")
|
|
|
|
for node_id in bbs_nodes:
|
|
|
|
send_message(message, node_id, interface)
|
|
|
|
|
|
|
|
|
|
|
|
def send_delete_bulletin_to_bbs_nodes(bulletin_id, bbs_nodes, interface):
|
|
|
|
message = f"DELETE_BULLETIN|{bulletin_id}"
|
|
|
|
for node_id in bbs_nodes:
|
|
|
|
send_message(message, node_id, interface)
|
|
|
|
|
|
|
|
|
|
|
|
def send_delete_mail_to_bbs_nodes(unique_id, bbs_nodes, interface):
|
|
|
|
message = f"DELETE_MAIL|{unique_id}"
|
|
|
|
logging.info(f"SERVER SYNC: Sending delete mail sync message with unique_id: {unique_id}")
|
|
|
|
for node_id in bbs_nodes:
|
|
|
|
send_message(message, node_id, interface)
|
2024-07-04 20:46:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
def send_channel_to_bbs_nodes(name, url, bbs_nodes, interface):
|
|
|
|
message = f"CHANNEL|{name}|{url}"
|
|
|
|
for node_id in bbs_nodes:
|
|
|
|
send_message(message, node_id, interface)
|