Formatting

This commit is contained in:
Firepup Sixfifty 2024-06-04 17:18:48 -05:00
parent 22f9a027ec
commit 586ef2cfc1
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA

33
main.py
View file

@ -6,13 +6,17 @@ import firepup650 as fp
input = fp.replitInput input = fp.replitInput
fp.replitCursor = fp.bcolors.REPLIT + ">>>" + fp.bcolors.RESET # Totally not hijacking one of my functions to use ;P fp.replitCursor = (
fp.bcolors.REPLIT + ">>>" + fp.bcolors.RESET
) # Totally not hijacking one of my functions to use ;P
load_dotenv() load_dotenv()
for requiredVar in ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN"]: for requiredVar in ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN"]:
if not os.environ.get(requiredVar): 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.') raise ValueError(
f'Missing required environment variable "{requiredVar}". Please create a .env file in the same directory as this script and define it.'
)
print("Establishing a connection to slack...") print("Establishing a connection to slack...")
app = App(token=os.environ.get("SLACK_BOT_TOKEN")) app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
@ -36,7 +40,11 @@ print("All pages loaded, generating user mappings now.")
del pages del pages
user_mappings = {} user_mappings = {}
for user in users_list: for user in users_list:
user_mappings[f"<@{user['id']}>"] = f"<@{user['profile']['display_name']}>" if user["profile"]["display_name"] else f"<@{user['id']}>" user_mappings[f"<@{user['id']}>"] = (
f"<@{user['profile']['display_name']}>"
if user["profile"]["display_name"]
else f"<@{user['id']}>"
)
print("User mappings loaded. User count:", len(user_mappings)) print("User mappings loaded. User count:", len(user_mappings))
@ -50,10 +58,14 @@ if __name__ == "__main__":
thread = input("Reply to a thread? (y|N)").lower().startswith("y") thread = input("Reply to a thread? (y|N)").lower().startswith("y")
ts = None ts = None
if thread: if thread:
hasID = input("Do you have the TS ID? (y|N))").lower().startswith("y") hasID = (
input("Do you have the TS ID? (y|N))").lower().startswith("y")
)
if not hasID: if not hasID:
try: try:
print("Getting the last 50 messages for threading options...") print(
"Getting the last 50 messages for threading options..."
)
res = client.conversations_history( res = client.conversations_history(
channel=chan, inclusive=True, limit=50 channel=chan, inclusive=True, limit=50
) )
@ -65,14 +77,21 @@ if __name__ == "__main__":
for user in user_mappings: for user in user_mappings:
label = label.replace(user, user_mappings[user]) label = label.replace(user, user_mappings[user])
texts[label] = i texts[label] = i
found = messages[fp.menu(texts, "Please select the message to reply to as a thread")] found = messages[
fp.menu(
texts,
"Please select the message to reply to as a thread",
)
]
ts = found["ts"] ts = found["ts"]
except Exception as E: except Exception as E:
print(f"Exception: {E}") print(f"Exception: {E}")
break break
else: else:
ts = input("TS ID") ts = input("TS ID")
print("^C to change/exit thread (^C twice if you want to change channel)") print(
"^C to change/exit thread (^C twice if you want to change channel)"
)
try: try:
while 1: while 1:
msg = input("[THREAD] Message (Raw text, not blocks)") msg = input("[THREAD] Message (Raw text, not blocks)")