def post_report(state): if state.type == "view_submission": modal_state = get_modal_state(state.payload) login = modal_state["report.student"]["selected_option"]["value"] description = modal_state["report.description"]["value"] blocks = get_report_blocks(login, description, state.user) send_message(state, text=f"{state.user} reported {login}", blocks=blocks)
def process_leodagan(state, message): texts_to_test = find_code_blocks(message) blocks = [] for text in texts_to_test: leodagan_result = launch_leodagan(text).decode("utf-8") if not leodagan_result: leodagan_result = "La netiquette est conforme." blocks.append(SectionBlock(Text(f"```{leodagan_result}```"))) if blocks: send_message(state, text="Léodagan report", blocks=repr(blocks))
def post_photo(state: SlackState): stalker = state.user photo_slug = state.text blocks = get_photo_blocks(photo_slug, settings.PHOTO_FSTRING.format(photo_slug), stalker) send_message(state, text=f"Picture of {photo_slug}", blocks=blocks) requests.post(state.response_url, json={ "delete_original": "true", })
def delete(state): poll = Poll.objects.get(id=state.text) if not state.user.has_permissions and state.user != poll.creator: send_ephemeral(state, f"You are not the creator of this poll.") return logger.debug( settings.SLACK_CLIENT.chat_delete( ts=state.ts, channel=poll.channel.id, )) send_message(state, f"A poll was deleted by {state.user.slack_username}") poll.delete()
def create_poll(state, name, choices, params): poll = Poll.objects.create( name=name, creator=state.user, channel=state.channel, unique_choice="unique" in params, anonymous="annon" in params, visible_results="annon" not in params, open_choice="open" in params, ) for index, choice in enumerate(choices): poll.choices.create(index=index, text=choice) try: send_message(state, text=f"Poll: {poll.name}", blocks=poll.slack_blocks) except slack.errors.SlackApiError as e: poll.delete() raise e