From 9a6ddce8dfdb43c32207ca565ed1b4c42ef689f2 Mon Sep 17 00:00:00 2001 From: SwissCorePy <51398037+SwissCorePy@users.noreply.github.com> Date: Thu, 3 Jun 2021 19:06:53 +0200 Subject: [PATCH] Added the function `unix_time` --- telebot/util.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/telebot/util.py b/telebot/util.py index bb19831..ea39b81 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -6,6 +6,7 @@ import threading import traceback import warnings import functools +import time import queue as Queue import logging @@ -214,6 +215,25 @@ def extract_command(text): return text.split()[0].split('@')[0][1:] if is_command(text) else None +def unix_time(seconds=0, minutes=0, hours=0, days=0): + """ + Returns UNIX time + given paramenters + This is useful to restrict or kick a chat member. Just use it as parameter `until_date`. + + Examples: + bot.kick_chat_member(chat_id, user_id, until_date=unix_time(days=1)): bans a chat member for 1 day + bot.kick_chat_member(chat_id, user_id, until_date=unix_time(seconds=45)): bans a chat member for 45 seconds + + :param seconds: how many seconds from now + :param minutes: how many minutes from now + :param hours: how many hours from now + :param days: how many days from now + :return: UNIX time + """ + t = seconds + (60 * minutes) + (3600 * hours) + (86400 * days) + return (int(t + time.time())) + + def split_string(text, chars_per_string): """ Splits one string into multiple strings, with a maximum amount of `chars_per_string` characters per string.