-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (37 loc) · 1.27 KB
/
main.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
import random, os
def genText():
with open("outtext.txt", "r") as f:
rl = f.readlines()
i1 = random.randint(0, len(rl)-1)
i2 = i1 + 1 if not i1 + 1 == len(rl) else il - 1
return "{l1}{l2}".format(l1=rl[i1], l2=rl[i2])
class CoinBot:
# Create a constant that contains the default text for the message
COIN_BLOCK = {
"type": "section",
"text": {
"type": "mrkdwn",
"text": (
"Pretending to be Matthew...."
),
},
}
# The constructor for the class. It takes the channel name as the a
# parameter and then sets it as an instance variable
def __init__(self, channel):
self.channel = channel
# Generate a random number to simulate flipping a coin. Then return the
# crafted slack payload with the coin flip message.
def _flip_coin(self):
results = genText()
text = f"{results}"
return {"type": "section", "text": {"type": "mrkdwn", "text": text}},
# Craft and return the entire message payload as a dictionary.
def get_message_payload(self):
return {
"channel": self.channel,
"blocks": [
self.COIN_BLOCK,
*self._flip_coin(),
],
}