End of work done during cafe, forgot to commit until now
This commit is contained in:
parent
4fc78930d5
commit
10ff9e65f0
2 changed files with 140 additions and 5 deletions
30
funcs.py
30
funcs.py
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
from typing import Any
|
||||
|
||||
|
||||
|
@ -5,3 +6,32 @@ def toBool(thing: Any) -> bool:
|
|||
if type(thing) == str:
|
||||
return thing.lower() in ["yes", "true", "on", "one", "1", "y", "t"]
|
||||
return bool(thing)
|
||||
|
||||
|
||||
def blacklist(userid: str):
|
||||
return userid not in [
|
||||
"U08BFAYDQ49",
|
||||
"U0782516RDE",
|
||||
"U07B4QD9F61",
|
||||
"U061GB9JUP7",
|
||||
"U06LWT5MHGQ",
|
||||
"U07373D8R7X",
|
||||
"U0890970LUT",
|
||||
"U07LEF1PBTM",
|
||||
"U080S1GNHNK",
|
||||
"U036UQD2893",
|
||||
"U07NJEABDGV",
|
||||
"U012K5ASJ90",
|
||||
"U0851ALFKTR",
|
||||
"U08DX7KD5K3",
|
||||
"UM1L1C38X",
|
||||
"U06MENEABV4",
|
||||
"U019S6AH18F",
|
||||
"U06MJDZHTK7",
|
||||
"U08B8USKT29",
|
||||
"U07ATH6TW95",
|
||||
"U078FB76K5F",
|
||||
"U07NGBJUDRD",
|
||||
"U07NVCHT6TZ",
|
||||
"U071THMU8HH",
|
||||
]
|
||||
|
|
115
main.py
115
main.py
|
@ -1,11 +1,14 @@
|
|||
import os, sys, logging
|
||||
#!/usr/bin/python3
|
||||
# pyright:reportMissingImports=false
|
||||
import os, sys, logging, random
|
||||
from slack_bolt import App, Complete, Fail
|
||||
from slack_bolt.adapter.socket_mode import SocketModeHandler
|
||||
from dotenv import load_dotenv
|
||||
from logs import log
|
||||
from traceback import format_exc
|
||||
from funcs import toBool
|
||||
from funcs import toBool, blacklist
|
||||
|
||||
random.seed()
|
||||
load_dotenv()
|
||||
|
||||
for requiredVar in ["SLACK_BOT_TOKEN", "SLACK_SIGNING_SECRET", "PORT"]:
|
||||
|
@ -27,6 +30,17 @@ client = app.client
|
|||
log("Connected to slack")
|
||||
|
||||
|
||||
@app.function("template")
|
||||
def template(inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger):
|
||||
try:
|
||||
raise NotImplementedError()
|
||||
except:
|
||||
log(format_exc(), "ERROR")
|
||||
fail(
|
||||
"An error occured app-side trying to process the `template` workflow step. Please contact <@U06JLP2R8JV> about this issue."
|
||||
)
|
||||
|
||||
|
||||
@app.function("convert_user_to_channel")
|
||||
def useridToChannel(
|
||||
inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger
|
||||
|
@ -67,7 +81,7 @@ def getMessageContent(
|
|||
|
||||
|
||||
@app.function("get_users_from_group")
|
||||
def getMessageContent(
|
||||
def getUsersFromGroup(
|
||||
inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger
|
||||
):
|
||||
try:
|
||||
|
@ -77,7 +91,9 @@ def getMessageContent(
|
|||
]
|
||||
)
|
||||
message = ""
|
||||
if inputs["include_names"]:
|
||||
if inputs.get("exclude_blacklisted", False):
|
||||
result["users"] = list(filter(blacklist, result["users"]))
|
||||
if inputs.get("include_names", False):
|
||||
for user in result["users"]:
|
||||
userData = client.users_info(user=user)["user"]
|
||||
name = (
|
||||
|
@ -101,6 +117,95 @@ def getMessageContent(
|
|||
)
|
||||
|
||||
|
||||
@app.function("get_random_user_from_list")
|
||||
def getRandomUserFromList(
|
||||
inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger
|
||||
):
|
||||
try:
|
||||
users = []
|
||||
for item in inputs["users"][0]["elements"][0]["elements"]:
|
||||
if item["type"] == "user":
|
||||
users.append(item["user_id"])
|
||||
if inputs.get("exclude_blacklisted", False):
|
||||
users = list(filter(blacklist, users))
|
||||
if debug:
|
||||
log(str(users), "DEBUG")
|
||||
random.seed()
|
||||
complete({"user": random.choice(users)})
|
||||
except:
|
||||
log(format_exc(), "ERROR")
|
||||
fail(
|
||||
"An error occured app-side trying to process the `get_random_user_from_list` workflow step. Please contact <@U06JLP2R8JV> about this issue."
|
||||
)
|
||||
|
||||
|
||||
@app.function("get_random_user_from_group")
|
||||
def getRandomUserFromGroup(
|
||||
inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger
|
||||
):
|
||||
try:
|
||||
users = client.usergroups_users_list(usergroup=inputs["user_group"])["users"]
|
||||
if inputs.get("exclude_blacklisted", False):
|
||||
users = list(filter(blacklist, users))
|
||||
if debug:
|
||||
log(str(users), "DEBUG")
|
||||
random.seed()
|
||||
complete({"user": random.choice(users)})
|
||||
except:
|
||||
log(format_exc(), "ERROR")
|
||||
fail(
|
||||
"An error occured app-side trying to process the `get_random_user_from_group` workflow step. Please contact <@U06JLP2R8JV> about this issue."
|
||||
)
|
||||
|
||||
|
||||
@app.function("get_random_user_from_channel")
|
||||
def getRandomUserFromChannel(
|
||||
inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger
|
||||
):
|
||||
try:
|
||||
users = []
|
||||
data = client.conversations_members(channel=inputs["channel"], limit=200)
|
||||
users.extend(data["members"])
|
||||
while data["response_metadata"]["next_cursor"]:
|
||||
data = client.conversations_members(
|
||||
channel=inputs["channel"],
|
||||
limit=200,
|
||||
cursor=data["response_metadata"]["next_cursor"],
|
||||
)
|
||||
users.extend(data["members"])
|
||||
if inputs.get("exclude_blacklisted", False):
|
||||
users = list(filter(blacklist, users))
|
||||
if debug:
|
||||
log(str(users), "DEBUG")
|
||||
random.seed()
|
||||
complete({"user": random.choice(users)})
|
||||
except:
|
||||
log(format_exc(), "ERROR")
|
||||
fail(
|
||||
"An error occured app-side trying to process the `get_random_user_from_channel` workflow step. Please contact <@U06JLP2R8JV> about this issue."
|
||||
)
|
||||
|
||||
|
||||
@app.function("get_random_channel")
|
||||
def getRandomChannel(
|
||||
inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger
|
||||
):
|
||||
try:
|
||||
channels = []
|
||||
for item in inputs["channels"][0]["elements"][0]["elements"]:
|
||||
if item["type"] == "channel":
|
||||
channels.append(item["channel_id"])
|
||||
if debug:
|
||||
log(str(channels), "DEBUG")
|
||||
random.seed()
|
||||
complete({"channel": random.choice(channels)})
|
||||
except:
|
||||
log(format_exc(), "ERROR")
|
||||
fail(
|
||||
"An error occured app-side trying to process the `get_random_channel` workflow step. Please contact <@U06JLP2R8JV> about this issue."
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
log(f"Starting bot on port {os.environ.get('PORT')}")
|
||||
app.start(port=int(os.environ["PORT"])) # type: ignore [arg-type]
|
||||
app.start(port=int(os.environ["PORT"]))
|
||||
|
|
Loading…
Add table
Reference in a new issue