Testing an interactive message thing
This commit is contained in:
parent
2d84d40060
commit
b1d7642dce
21
main.py
21
main.py
|
|
@ -44,6 +44,9 @@ def main() -> None:
|
||||||
# Add automatic updating of users
|
# Add automatic updating of users
|
||||||
wrap.add_passive(periodicals.Updatinator(wrap, 120))
|
wrap.add_passive(periodicals.Updatinator(wrap, 120))
|
||||||
|
|
||||||
|
# Do test.
|
||||||
|
wrap.add_passive(periodicals.TestPassive())
|
||||||
|
|
||||||
# Add nagloop
|
# Add nagloop
|
||||||
wrap.add_passive(periodicals.NotifyJobs())
|
wrap.add_passive(periodicals.NotifyJobs())
|
||||||
wrap.add_passive(periodicals.RemindJobs())
|
wrap.add_passive(periodicals.RemindJobs())
|
||||||
|
|
@ -53,24 +56,6 @@ def main() -> None:
|
||||||
event_handling = wrap.handle_events()
|
event_handling = wrap.handle_events()
|
||||||
passive_handling = wrap.run_passives()
|
passive_handling = wrap.run_passives()
|
||||||
both = asyncio.gather(event_handling, passive_handling)
|
both = asyncio.gather(event_handling, passive_handling)
|
||||||
#
|
|
||||||
# wrap.send_message("test", "#botzone", blocks=[
|
|
||||||
# {
|
|
||||||
# "type": "actions",
|
|
||||||
# "block_id": "test_block_id",
|
|
||||||
# "elements": [
|
|
||||||
# {
|
|
||||||
# "type": "button",
|
|
||||||
# "action_id": "test_action_id",
|
|
||||||
# "text": {
|
|
||||||
# "type": "plain_text",
|
|
||||||
# "text": "Send payload",
|
|
||||||
# "emoji": False
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
# ])
|
|
||||||
|
|
||||||
event_loop.run_until_complete(both)
|
event_loop.run_until_complete(both)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
import hooks
|
import hooks
|
||||||
|
import slack_util
|
||||||
from plugins import identifier, job_commands, house_management
|
from plugins import identifier, job_commands, house_management
|
||||||
import client
|
import client
|
||||||
|
|
||||||
|
|
@ -125,6 +126,7 @@ class Updatinator(hooks.Passive):
|
||||||
"""
|
"""
|
||||||
Periodically updates the channels and users in the slack
|
Periodically updates the channels and users in the slack
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, wrapper_to_update: client.ClientWrapper, interval_seconds: int):
|
def __init__(self, wrapper_to_update: client.ClientWrapper, interval_seconds: int):
|
||||||
self.wrapper_target = wrapper_to_update
|
self.wrapper_target = wrapper_to_update
|
||||||
self.interval = interval_seconds
|
self.interval = interval_seconds
|
||||||
|
|
@ -135,3 +137,74 @@ class Updatinator(hooks.Passive):
|
||||||
self.wrapper_target.update_channels()
|
self.wrapper_target.update_channels()
|
||||||
self.wrapper_target.update_users()
|
self.wrapper_target.update_users()
|
||||||
await asyncio.sleep(self.interval)
|
await asyncio.sleep(self.interval)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPassive(hooks.Passive):
|
||||||
|
"""
|
||||||
|
Stupid shit
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def run(self) -> None:
|
||||||
|
lifespan = 600
|
||||||
|
post_interval = 60
|
||||||
|
|
||||||
|
def make_interactive_msg():
|
||||||
|
# Send the message and recover the ts
|
||||||
|
response = client.get_slack().send_message("Select an option:", "#botzone", blocks=[
|
||||||
|
{
|
||||||
|
"type": "actions",
|
||||||
|
"block_id": "button_test",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"action_id": "alpha_button",
|
||||||
|
"text": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Alpha",
|
||||||
|
"emoji": False
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"action_id": "beta_button",
|
||||||
|
"text": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Beta",
|
||||||
|
"emoji": False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
])
|
||||||
|
msg_ts = response["ts"]
|
||||||
|
|
||||||
|
# Make our mappings
|
||||||
|
button_responses = {
|
||||||
|
"alpha_button": "You clicked alpha. Good work.",
|
||||||
|
"beta_button": "You clicked beta. You must be so proud."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make our callbacks
|
||||||
|
async def on_click(event: slack_util.Event, response: str):
|
||||||
|
# Edit the message to show the result.
|
||||||
|
client.get_slack().edit_message(response, event.conversation.conversation_id, event.message.ts, None)
|
||||||
|
|
||||||
|
def on_expire():
|
||||||
|
client.get_slack().edit_message("Timed out", "#botzone", msg_ts, None)
|
||||||
|
|
||||||
|
# Add a listener
|
||||||
|
listener = hooks.InteractionListener(on_click,
|
||||||
|
button_responses,
|
||||||
|
client.get_slack().get_conversation_by_name("#botzone"),
|
||||||
|
msg_ts,
|
||||||
|
lifespan,
|
||||||
|
on_expire)
|
||||||
|
client.get_slack().add_hook(listener)
|
||||||
|
|
||||||
|
# Iterate editing the message every 10 seconds, forever
|
||||||
|
while True:
|
||||||
|
make_interactive_msg()
|
||||||
|
await asyncio.sleep(post_interval)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue