Compare commits
No commits in common. "586ef2cfc1a8fb80140e6d5355c7943b4b69f822" and "b2151a373c179a78a26db3a5a6cf2646a5b3dc81" have entirely different histories.
586ef2cfc1
...
b2151a373c
1 changed files with 21 additions and 78 deletions
83
main.py
83
main.py
|
@ -6,95 +6,42 @@ import firepup650 as fp
|
||||||
|
|
||||||
input = fp.replitInput
|
input = fp.replitInput
|
||||||
|
|
||||||
fp.replitCursor = (
|
fp.replitCursor = fp.bcolors.REPLIT + ">>>" + fp.bcolors.RESET
|
||||||
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"]:
|
print(dir(fp))
|
||||||
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.'
|
|
||||||
)
|
|
||||||
|
|
||||||
print("Establishing a connection to slack...")
|
# Initializes your app with your bot token and socket mode handler
|
||||||
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
|
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
|
||||||
client = app.client
|
client = app.client
|
||||||
|
|
||||||
print("Building a list of users, please stand by.")
|
# Start your app
|
||||||
users_list = []
|
|
||||||
cursor = "N/A"
|
|
||||||
pages = 0
|
|
||||||
while cursor:
|
|
||||||
data = ""
|
|
||||||
if cursor != "N/A":
|
|
||||||
data = client.users_list(cursor=cursor, limit=1000)
|
|
||||||
else:
|
|
||||||
data = client.users_list(limit=1000)
|
|
||||||
cursor = data["response_metadata"]["next_cursor"]
|
|
||||||
users_list.extend(data["members"])
|
|
||||||
pages += 1
|
|
||||||
print(f"Pages of users loaded: {pages}")
|
|
||||||
print("All pages loaded, generating user mappings now.")
|
|
||||||
del pages
|
|
||||||
user_mappings = {}
|
|
||||||
for user in users_list:
|
|
||||||
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))
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("^D at any time to terminate program")
|
|
||||||
while 1:
|
while 1:
|
||||||
chan = input("Channel ID")
|
chan = input("Channel")
|
||||||
try:
|
try:
|
||||||
print("^C to change channel")
|
print("^C to change channel")
|
||||||
while 1:
|
while 1:
|
||||||
thread = input("Reply to a thread? (y|N)").lower().startswith("y")
|
thread = input("Reply to a thread?").lower().startswith("y")
|
||||||
ts = None
|
ts = None
|
||||||
if thread:
|
if thread:
|
||||||
hasID = (
|
hasID = input("Do you have the TS ID?").lower().startswith("y")
|
||||||
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..."
|
|
||||||
)
|
|
||||||
res = client.conversations_history(
|
res = client.conversations_history(
|
||||||
channel=chan, inclusive=True, limit=50
|
channel=chan, inclusive=True, limit=1
|
||||||
)
|
)
|
||||||
messages = res["messages"]
|
found = res["messages"][0]
|
||||||
texts = {}
|
print(found)
|
||||||
print("Building messages, this might take a little bit...")
|
|
||||||
for i in range(len(messages)):
|
|
||||||
label = f'{messages[i]["text"]} ({messages[i]["ts"]})'
|
|
||||||
for user in user_mappings:
|
|
||||||
label = label.replace(user, user_mappings[user])
|
|
||||||
texts[label] = i
|
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
ts = input("TS ID")
|
ts = input("TS ID")
|
||||||
print(
|
print("^C to change thread/channel")
|
||||||
"^C to change/exit thread (^C twice if you want to change channel)"
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
while 1:
|
while 1:
|
||||||
msg = input("[THREAD] Message (Raw text, not blocks)")
|
msg = input("Message")
|
||||||
try:
|
try:
|
||||||
print(
|
print(
|
||||||
client.chat_postMessage(
|
client.chat_postMessage(
|
||||||
|
@ -103,11 +50,7 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
except Exception as E:
|
except Exception as E:
|
||||||
print(f"Exception: {E}")
|
print(f"Exception: {E}")
|
||||||
except KeyboardInterrupt:
|
msg = input("Message")
|
||||||
print()
|
|
||||||
if ts:
|
|
||||||
continue
|
|
||||||
msg = input("Message (Raw text, not blocks)")
|
|
||||||
try:
|
try:
|
||||||
print(client.chat_postMessage(channel=chan, text=msg))
|
print(client.chat_postMessage(channel=chan, text=msg))
|
||||||
except Exception as E:
|
except Exception as E:
|
||||||
|
|
Loading…
Reference in a new issue