-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathutils.py
More file actions
52 lines (40 loc) · 1.47 KB
/
utils.py
File metadata and controls
52 lines (40 loc) · 1.47 KB
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
from pycamp_bot.models import Pycamp
from pycamp_bot.logger import logger
def escape_markdown(string):
# See: https://core.telegram.org/bots/api#markdownv2-style
new_string = string
for char in "_*[]()~`>#+-=|{}.!":
new_string = new_string.replace(char, f'\\{char}')
return new_string
def get_slot_weekday_name(slot_day_code):
ISO_WEEKDAY_NAMES = {
0: 'Lunes',
1: 'Martes',
2: 'Miércoles',
3: 'Jueves',
4: 'Viernes',
5: 'Sábado',
6: 'Domingo',
}
pycamp_start_weekday = Pycamp.get(Pycamp.active == True).init.weekday()
# Convert slot day code to a zero-based code, to use it as an
# offset to get the weekday name of the slot
offset = ord(slot_day_code) - ord('A')
day_name = ISO_WEEKDAY_NAMES[pycamp_start_weekday + offset]
return day_name
def active_pycamp_needed(f):
from pycamp_bot.commands.manage_pycamp import get_active_pycamp
async def wrap(*args, **kargs):
update, context = args
_, pycamp = get_active_pycamp()
if pycamp is None:
msg = "🔥 %s: This operation (%s) needs an active PyCamp. Talk to an admin." % (
update.message.from_user.username, str(f.__name__)
)
await context.bot.send_message(
chat_id=update.message.chat_id,
text=msg)
logger.warning(msg)
return
return await f(*args, pycamp=pycamp)
return wrap