Main v2 work

This commit is contained in:
Firepup Sixfifty 2025-03-07 08:58:32 -06:00
parent 7f46f78b1e
commit 64474b7354
Signed by: Firepup650
SSH key fingerprint: SHA256:in03N+Byhi/nMAIIKKMxbNMskVXULLrovhGkPNFEsdg

View file

@ -130,6 +130,7 @@ if __name__ == "__main__":
while 1: while 1:
chan = input("Channel ID") chan = input("Channel ID")
try: try:
oldest_ts = ""
try: try:
print( print(
"[INFO] Trying to load the last 50 messages sent in this channel..." "[INFO] Trying to load the last 50 messages sent in this channel..."
@ -138,6 +139,7 @@ if __name__ == "__main__":
channel=chan, inclusive=True, limit=50 channel=chan, inclusive=True, limit=50
) )
buildMessages(res["messages"]) buildMessages(res["messages"])
oldest_ts = res["messages"][0]["ts"]
del res del res
except Exception as E: except Exception as E:
print("[WARN] Exception") print("[WARN] Exception")
@ -187,7 +189,7 @@ if __name__ == "__main__":
try: try:
while 1: while 1:
msg = input( msg = input(
"[THREAD] Message (Raw text, not blocks)" "[THRD] Message (Raw text, not blocks)"
).replace("\\n", "\n") ).replace("\\n", "\n")
try: try:
client.chat_postMessage( client.chat_postMessage(
@ -202,13 +204,50 @@ if __name__ == "__main__":
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
if ts: if ts:
try:
print(f"[INFO] Trying to load messages since {oldest_ts}...")
res = client.conversations_history(
channel=chan, inclusive=True, limit=200, oldest=oldest_ts
)
if len(res["messages"]) > 1:
buildMessages(res["messages"][:-1])
oldest_ts = res["messages"][0]["ts"]
else:
print("[INFO] No new messages")
del res
except Exception as E:
print("[WARN] Exception")
for line in format_exc().split("\n")[:-1]:
print(f"[WARN] {line}")
print(
"[HELP] Does the bot have access to the channel you're trying to see?"
)
continue continue
msg = input("[CHANNEL] Message (Raw text, not blocks)").replace( msg = input("[CHAN] Message (Raw text, not blocks)").replace(
"\\n", "\n" "\\n", "\n"
) )
try: try:
if msg != "":
ts = client.chat_postMessage(channel=chan, text=msg)["ts"] ts = client.chat_postMessage(channel=chan, text=msg)["ts"]
print(f"[INFO] Message sent (to the channel)! (TS ID: {ts})") print(f"[INFO] Message sent (to the channel)! (TS ID: {ts})")
try:
print(f"[INFO] Trying to load messages since {oldest_ts}...")
res = client.conversations_history(
channel=chan, inclusive=True, limit=200, oldest=oldest_ts
)
if len(res["messages"]) > 1:
buildMessages(res["messages"][:-1])
oldest_ts = res["messages"][0]["ts"]
else:
print("[INFO] No new messages")
del res
except Exception as E:
print("[WARN] Exception")
for line in format_exc().split("\n")[:-1]:
print(f"[WARN] {line}")
print(
"[HELP] Does the bot have access to the channel you're trying to see?"
)
except Exception as E: except Exception as E:
print("[WARN] Exception:") print("[WARN] Exception:")
for line in format_exc().split("\n")[:-1]: for line in format_exc().split("\n")[:-1]: