-
Notifications
You must be signed in to change notification settings - Fork 15
/
cowsay.py
92 lines (75 loc) · 1.75 KB
/
cowsay.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
"""
Makes a cute animal repeat the last message.
Good bwoi.
"""
import textwrap
import random
from formatting import code_block
__author__ = ('Smurphicus')
COMMAND = 'cowsay'
animals = [
"""
\ ^__^
\ (oo)\_______
(__)\ )\/\\
||----w |
|| ||
"""
,
"""
\ .--.
\ |o_o |
|:_/ |
// \\ \\
(| | )
/'\\_ _/`\\
\\___)=(___/
"""
,
"""
\ / <` '> \\
\ ( / @ @ \ )
\(_ _\_/_ _)/
(\ `-/ \-' /)
"===\ /==="
.==')___(`==.
.=' `=.
"""
,
"""
\ .~~,
\ ,_-( 9 )
'-'==( ___\)
( ( . /
\\ '-` /
'-j~`
:="
"""
]
def normalize_text(str):
lines = textwrap.wrap(str, 24)
return [line.ljust(len(max(lines, key=len))) for line in lines]
def get_border(line_count, index):
if line_count == 1:
return ["<", ">"]
elif index == 0:
return ["/", "\\"]
elif index == line_count - 1:
return ["\\", "/"]
else:
return ["|", "|"]
def bubble_message(text):
bubble = []
normalized_text = normalize_text(text)
border_size = len(normalized_text[0])
bubble.append(" " + "_" * border_size)
for index, line in enumerate(normalized_text):
border = get_border(len(normalized_text), index)
bubble.append("%s %s %s" % (border[0], line, border[1]))
bubble.append(" " + "-" * border_size)
return "\n".join(bubble)
def main(bot, author_id, message, thread_id, thread_type, **kwargs):
message = bot.fetchThreadMessages(thread_id=thread_id, limit=2)[1]
cow_message = code_block(bubble_message(
message.text) + random.choice(animals))
bot.sendMessage(cow_message, thread_id=thread_id, thread_type=thread_type)