-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
64 lines (55 loc) · 1.6 KB
/
example.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
from typing import List
from slash_slack import Enum, Flag, Float, SlashSlack, String, UnknownLengthList
from slash_slack.blocks import _make_block_message
slash = SlashSlack(
dev=True,
description="A python framework for slack slash bots.",
acknowledge_response="Working on your request...",
)
app = slash.get_fast_api()
@slash.command(
"echo",
summary="Echo",
help="Returns the provided text (made upper or lower case)",
)
def test_fn(
content: str = String(help="The content which will be echoed"),
upper: bool = Flag(help="Converts the input text to all UPPERCASE"),
lower: bool = Flag(help="Converts the input text to all lowercase"),
):
if upper:
return content.upper()
if lower:
return content.lower()
return content
@slash.command(
"math",
summary="Performs basic arithmetic between two numbers",
acknowledge_response="Responding to a math request...",
)
def math_fn(
x: float = Float(help="A number."),
symbol: str = Enum(
values={"*", "+", "-", "/"}, help="The arithmetic operation to use."
),
y: float = Float(help="A number."),
):
if symbol == "*":
return x * y
if symbol == "+":
return x + y
if symbol == "-":
return x - y
if symbol == "/":
return x / y
@slash.command(
"avg",
summary="Return the average of the given numbers",
help="EX: `avg 90 100 110.9`",
)
def unknown(
nums: List[float] = UnknownLengthList(
arg_type=Float(), help="The numbers to average."
),
):
return f"The avg of the given numbers is {sum(nums) / len(nums)}"