Compare commits

..

No commits in common. "c8cb828b7009104570433d6f200374bf5f64c932" and "ce6be5dc705cda3d790b06e55fea16b2622cfc53" have entirely different histories.

2 changed files with 27 additions and 40 deletions

2
.gitignore vendored
View file

@ -1,3 +1 @@
.env
__pycache__/**
cache.py

65
main.py
View file

@ -1,4 +1,4 @@
import os, sys
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from dotenv import load_dotenv
@ -22,42 +22,31 @@ print("Establishing a connection to slack...")
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
client = app.client
userMappings = {}
try:
if "--no-cache" in sys.argv:
raise ImportError("User requested to skip cache")
print("Trying to load user mappings from cache...")
from cache import userMappings
except ImportError:
users_list = []
print("Cache load failed, falling back to full load from slack...")
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}")
del pages
print("Building user mappings now, this shouldn't take long...")
userMappings = {}
for user in users_list:
userMappings[f"<@{user['id']}>"] = (
f"<@{user['profile']['display_name']}>"
if user["profile"]["display_name"]
else f"<@{user['id']}>"
)
print("All mappings generated, writing cache file now...")
with open("cache.py", "w") as cacheFile:
cacheFile.write(f"userMappings = {userMappings}")
print("Cache saved.")
print("Building a list of users, please stand by.")
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(userMappings))
print("User mappings loaded. User count:", len(user_mappings))
if __name__ == "__main__":
print("^D at any time to terminate program")
@ -85,8 +74,8 @@ if __name__ == "__main__":
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 userMappings:
label = label.replace(user, userMappings[user])
for user in user_mappings:
label = label.replace(user, user_mappings[user])
texts[label] = i
found = messages[
fp.menu(