forked from dexpiper/connect-support-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
49 lines (39 loc) · 1.22 KB
/
views.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
from jinja2 import Environment, PackageLoader, select_autoescape
from common.unicode import emoji
# setting Jinja2-specified params
env = Environment(
loader=PackageLoader('views'),
autoescape=select_autoescape()
)
env.trim_blocks = True
env.lstrip_blocks = True
#
# Message templates
#
def hello(username: str):
"""
Render basic hello template
"""
template = env.get_template('hello.jinja2')
return template.render(username=username, emoji=emoji)
def user_connected(message: object):
"""
Send the info about user connected
"""
template = env.get_template('user_connected.jinja2')
return template.render(message=message, emoji=emoji)
def redirect_user_message(message: object, add_id: bool = True):
"""
Resend user's message to the admins.
This func by default will add user_id to the message.
It is used to ensure that user_id will not be lost
in the chain of the replies.
"""
user_id_suffix = (
f'\n{emoji["magniglass"]} <i>id={message.from_user.id}</i>'
)
template = env.get_template('resend_to_admins.jinja2')
rendered = template.render(message=message, emoji=emoji)
if add_id:
return rendered + user_id_suffix
return rendered