-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimezone.py
32 lines (28 loc) · 1006 Bytes
/
timezone.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
"""Timezones"""
from telegram import Bot, Update
import pendulum
import core
from pytzdata.exceptions import TimezoneNotFound
TIMEFORMAT = '%A %d%tof %B %Y %H:%M:%S'
PLUGINVERSION = 2
# Always name this variable as `plugin`
# If you dont, module loader will fail to load the plugin!
plugin = core.Plugin()
@plugin.command(command="/tz",
description="Sends info about specifed zone(for example:Europe/Moscow)",
inline_supported=True,
required_args=1,
hidden=False)
def timezonecmd(_: Bot, update: Update, user, args):
"""
Example usage:
User: /tz Europe/Moscow
Bot: Europe/Moscow: Friday 18 of August 2017 08:21:04
"""
timezone = " ".join(args)
try:
timezone = pendulum.now(timezone)
except (TimezoneNotFound, ValueError):
return core.message("⚠You specifed unknown timezone", failed=True)
else:
return core.message(timezone.timezone_name + ": " + timezone.format(TIMEFORMAT))