def cmd_time(expr, chatid, replyid, msg):
'''/time - Get time for various timezones'''
tzs = list(filter(lambda x: x in pytz.all_timezones_set, expr.split()))
if not tzs:
if chatid > 0:
tzs = [USER_CACHE[msg['from']['id']]['timezone']]
else:
tzs = [row[0] for row in CONN.execute(
'SELECT users.timezone FROM users'
' INNER JOIN user_chats ON users.id = user_chats.user'
' WHERE user_chats.chat = ? GROUP BY users.timezone'
' ORDER BY count(users.timezone) DESC, users.timezone ASC',
(msg['chat']['id'],))]
if tzs:
text = [_('The time is:')]
for tz in tzs:
usertime = datetime.datetime.now(pytz.timezone(tz))
text.append(' '.join((
'??' if tz_is_day(usertime, tz) else '??',
usertime.strftime('%H:%M'), tz
)))
sendmsg('\n'.join(text), chatid, replyid)
else:
sendmsg(_("No timezone specified."), chatid, replyid)
评论列表
文章目录