Clarify a few messages, improve replying to threads, etc.

This commit is contained in:
Firepup Sixfifty 2024-06-04 16:37:19 -05:00
parent d6ec1f9251
commit 83007f8243
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA

35
main.py
View file

@ -6,7 +6,7 @@ import firepup650 as fp
input = fp.replitInput
fp.replitCursor = fp.bcolors.REPLIT + ">>>" + fp.bcolors.RESET
fp.replitCursor = fp.bcolors.REPLIT + ">>>" + fp.bcolors.RESET # Totally not hijacking one of my functions to use ;P
load_dotenv()
@ -14,36 +14,41 @@ for requiredVar in ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN"]:
if not os.environ.get(requiredVar):
raise ValueError(f'Missing required environment variable "{requiredVar}". Please create a .env file in the same directory as this script and define it.')
# Initializes your app with your bot token and socket mode handler
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
client = app.client
# Start your app
if __name__ == "__main__":
print("^D at any time to terminate program")
while 1:
chan = input("Channel")
chan = input("Channel ID")
try:
print("^C to change channel")
while 1:
thread = input("Reply to a thread?").lower().startswith("y")
thread = input("Reply to a thread? (y|N)").lower().startswith("y")
ts = None
if thread:
hasID = input("Do you have the TS ID?").lower().startswith("y")
hasID = input("Do you have the TS ID? (y|N))").lower().startswith("y")
if not hasID:
try:
print("Getting the last 50 messages for threading options...")
res = client.conversations_history(
channel=chan, inclusive=True, limit=1
channel=chan, inclusive=True, limit=50
)
found = res["messages"][0]
print(found)
messages = res["messages"]
texts = {}
for i in range(len(messages)):
texts[f'{messages[i]["text"]} ({messages[i]["ts"]})'] = i
found = messages[fp.menu(texts, "Please select the message to reply to as a thread")]
ts = found["ts"]
except Exception as E:
print(f"Exception: {E}")
break
else:
ts = input("TS ID")
print("^C to change thread/channel")
while 1:
msg = input("Message")
print("^C to change/exit thread (^C twice if you want to change channel)")
try:
while 1:
msg = input("[THREAD] Message (Raw text, not blocks)")
try:
print(
client.chat_postMessage(
@ -52,7 +57,11 @@ if __name__ == "__main__":
)
except Exception as E:
print(f"Exception: {E}")
msg = input("Message")
except KeyboardInterrupt:
print()
if ts:
continue
msg = input("Message (Raw text, not blocks)")
try:
print(client.chat_postMessage(channel=chan, text=msg))
except Exception as E: