Compare commits
No commits in common. "c8cb828b7009104570433d6f200374bf5f64c932" and "ce6be5dc705cda3d790b06e55fea16b2622cfc53" have entirely different histories.
c8cb828b70
...
ce6be5dc70
2 changed files with 27 additions and 40 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1 @@
|
||||||
.env
|
.env
|
||||||
__pycache__/**
|
|
||||||
cache.py
|
|
||||||
|
|
65
main.py
65
main.py
|
@ -1,4 +1,4 @@
|
||||||
import os, sys
|
import os
|
||||||
from slack_bolt import App
|
from slack_bolt import App
|
||||||
from slack_bolt.adapter.socket_mode import SocketModeHandler
|
from slack_bolt.adapter.socket_mode import SocketModeHandler
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
@ -22,42 +22,31 @@ print("Establishing a connection to slack...")
|
||||||
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
|
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
|
||||||
client = app.client
|
client = app.client
|
||||||
|
|
||||||
userMappings = {}
|
print("Building a list of users, please stand by.")
|
||||||
try:
|
users_list = []
|
||||||
if "--no-cache" in sys.argv:
|
cursor = "N/A"
|
||||||
raise ImportError("User requested to skip cache")
|
pages = 0
|
||||||
print("Trying to load user mappings from cache...")
|
while cursor:
|
||||||
from cache import userMappings
|
data = ""
|
||||||
except ImportError:
|
if cursor != "N/A":
|
||||||
users_list = []
|
data = client.users_list(cursor=cursor, limit=1000)
|
||||||
print("Cache load failed, falling back to full load from slack...")
|
else:
|
||||||
cursor = "N/A"
|
data = client.users_list(limit=1000)
|
||||||
pages = 0
|
cursor = data["response_metadata"]["next_cursor"]
|
||||||
while cursor:
|
users_list.extend(data["members"])
|
||||||
data = ""
|
pages += 1
|
||||||
if cursor != "N/A":
|
print(f"Pages of users loaded: {pages}")
|
||||||
data = client.users_list(cursor=cursor, limit=1000)
|
print("All pages loaded, generating user mappings now.")
|
||||||
else:
|
del pages
|
||||||
data = client.users_list(limit=1000)
|
user_mappings = {}
|
||||||
cursor = data["response_metadata"]["next_cursor"]
|
for user in users_list:
|
||||||
users_list.extend(data["members"])
|
user_mappings[f"<@{user['id']}>"] = (
|
||||||
pages += 1
|
f"<@{user['profile']['display_name']}>"
|
||||||
print(f"Pages of users loaded: {pages}")
|
if user["profile"]["display_name"]
|
||||||
del pages
|
else f"<@{user['id']}>"
|
||||||
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("User mappings loaded. User count:", len(userMappings))
|
print("User mappings loaded. User count:", len(user_mappings))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("^D at any time to terminate program")
|
print("^D at any time to terminate program")
|
||||||
|
@ -85,8 +74,8 @@ if __name__ == "__main__":
|
||||||
print("Building messages, this might take a little bit...")
|
print("Building messages, this might take a little bit...")
|
||||||
for i in range(len(messages)):
|
for i in range(len(messages)):
|
||||||
label = f'{messages[i]["text"]} ({messages[i]["ts"]})'
|
label = f'{messages[i]["text"]} ({messages[i]["ts"]})'
|
||||||
for user in userMappings:
|
for user in user_mappings:
|
||||||
label = label.replace(user, userMappings[user])
|
label = label.replace(user, user_mappings[user])
|
||||||
texts[label] = i
|
texts[label] = i
|
||||||
found = messages[
|
found = messages[
|
||||||
fp.menu(
|
fp.menu(
|
||||||
|
|
Loading…
Reference in a new issue