|
| 1 | +import logging |
| 2 | + |
| 3 | +from aiohttp import web |
| 4 | +from slack import methods |
| 5 | +from slack import commands |
| 6 | +from slack.events import Message |
| 7 | + |
| 8 | +from pyslackersweb.util.log import ContextAwareLoggerAdapter |
| 9 | + |
| 10 | +logger = ContextAwareLoggerAdapter(logging.getLogger(__name__)) |
| 11 | + |
| 12 | + |
| 13 | +async def admin(request: web.Request, command: commands.Command) -> None: |
| 14 | + data = { |
| 15 | + "trigger_id": command["trigger_id"], |
| 16 | + "dialog": { |
| 17 | + "callback_id": "tell_admin", |
| 18 | + "title": "Message the admin team", |
| 19 | + "elements": [ |
| 20 | + { |
| 21 | + "label": "Message", |
| 22 | + "name": "message", |
| 23 | + "type": "textarea", |
| 24 | + "value": command["text"], |
| 25 | + } |
| 26 | + ], |
| 27 | + }, |
| 28 | + } |
| 29 | + await request.app["slack_client"].query(url=methods.DIALOG_OPEN, data=data) |
| 30 | + |
| 31 | + |
| 32 | +async def snippet(request: web.Request, command: commands.Command) -> None: |
| 33 | + """Post a message to the current channel about using snippets and backticks to visually |
| 34 | + format code.""" |
| 35 | + response = Message() |
| 36 | + response["channel"] = command["channel_id"] |
| 37 | + response["unfurl_links"] = False |
| 38 | + |
| 39 | + response["text"] = ( |
| 40 | + "Please use the snippet feature, or backticks, when sharing code. \n" |
| 41 | + "To include a snippet, click the :paperclip: on the left and hover over " |
| 42 | + "`Create new...` then select `Code or text snippet`.\n" |
| 43 | + "By wrapping the text/code with backticks (`) you get:\n" |
| 44 | + "`text formatted like this`\n" |
| 45 | + "By wrapping a multiple line block with three backticks (```) you can get:\n" |
| 46 | + ) |
| 47 | + |
| 48 | + await request.app["slack_client"].query(url=methods.CHAT_POST_MESSAGE, data=response) |
| 49 | + |
| 50 | + response["text"] = ( |
| 51 | + "```\n" |
| 52 | + "A multiline codeblock\nwhich is great for short snippets!\n" |
| 53 | + "```\n" |
| 54 | + "For more information on snippets, click " |
| 55 | + "<https://get.slack.help/hc/en-us/articles/204145658-Create-a-snippet|here>.\n" |
| 56 | + "For more information on inline code formatting with backticks click " |
| 57 | + "<https://get.slack.help/hc/en-us/articles/202288908-Format-your-messages#inline-code|here>." |
| 58 | + ) |
| 59 | + |
| 60 | + await request.app["slack_client"].query(url=methods.CHAT_POST_MESSAGE, data=response) |
0 commit comments