-
Notifications
You must be signed in to change notification settings - Fork 5
/
starter.py
119 lines (87 loc) · 3 KB
/
starter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""Starter examples."""
import os
from time import sleep
from phial import Attachment, Phial, Response, command
from phial.wrappers import Command
slackbot = Phial(os.getenv("SLACK_API_TOKEN", "NONE"), {"hotReload": True})
@slackbot.command("ping")
def ping() -> str:
"""A command which replies with a message."""
return "Pong"
@slackbot.command("pong")
def pong() -> str:
"""
A command which replies with a message.
It has a mutiline docstring.
"""
return "Ping"
@slackbot.command("hi <name>")
def hi(name: str) -> Response:
"""A command with an argument which replies to a message."""
return Response(text="Hello {0}".format(name), channel=command.channel)
@slackbot.command("add <x> <y>")
@slackbot.alias("add <x>")
def add(x: int, y: int = 5) -> str:
"""Add two numbers."""
return str(x + y)
@slackbot.command("hello <name> <from_>")
def hello(name: str, from_: str) -> Response:
"""A command with two arguments which replies to a message."""
return Response(
text="Hi {0}, from {1}".format(name, from_), channel=command.channel
)
@slackbot.command("react")
def react() -> Response:
"""A command that reacts to the original message."""
return Response(
reaction="x", channel=command.channel, original_ts=command.timestamp
)
@slackbot.command("upload")
def upload() -> Attachment:
"""A command that uploads a set file."""
project_dir = os.path.dirname(__file__)
file_path = os.path.join(project_dir, "phial.png")
return Attachment(
channel=command.channel, filename="example.txt", content=open(file_path, "rb")
)
@slackbot.command("reply")
def reply() -> Response:
"""A command that replies to the original message in a thread."""
return Response(
text="this is a thread", channel=command.channel, original_ts=command.timestamp
)
@slackbot.command("caseSensitive", case_sensitive=True)
def case_sensitive() -> str:
"""A command which replies with a message."""
return "You typed caseSensitive"
@slackbot.command("messageWithAttachment")
def get_message_with_attachment() -> Response:
"""
A command that posts a message with a Slack attachment.
Read more: https://api.slack.com/docs/message-attachments
"""
return Response(
channel=command.channel,
attachments=[
{
"title": "Here's the title of the attachment",
"text": "...and here's the text",
"footer": "Teeny tiny footer text",
}
],
)
@slackbot.command("long")
def long() -> str:
"""Command that sleeps for 5 seconds."""
sleep(5)
return "Well that took a while"
@slackbot.command("hidden", hide_from_help_command=True)
def hidden() -> str:
"""A command that is hidden from the default help command."""
return "Suprise"
@slackbot.fallback_command()
def fallback_command(command: Command) -> str:
"""A fall back command."""
return "Thats not a command"
if __name__ == "__main__":
slackbot.run()