Last active
April 11, 2023 06:17
-
-
Save RimMirK/8d8e52e7ec567cc724ea9761ef478c3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Импорты | |
| from requests.exceptions import ConnectionError | |
| import telebot, pytz, datetime, times, shutil | |
| from telebot import types | |
| # Определение бота | |
| bot = telebot.TeleBot("TOKEN", parse_mode="MARKDOWN") | |
| bot.set_webhook() | |
| # Убирание кнопок | |
| none = telebot.types.ReplyKeyboardRemove() | |
| def log(name: str | None = None, | |
| command: str | None = None, | |
| message: str | None = None | |
| ) -> None: | |
| mess_date = datetime.datetime.strptime(str(times.now())[:-7], "%Y-%m-%d %H:%M:%S") | |
| tz = pytz.timezone("Etc/GMT-2") | |
| mess_date_utc5 = tz.normalize(mess_date.astimezone(tz)) | |
| time = mess_date_utc5.strftime("%d-%m-%Y %H:%M:%S") | |
| if command != None and name != None: | |
| line = f"[{time}] {name} use /{command}" | |
| elif message != None: | |
| line = f"[{time}] {message}" | |
| else: | |
| raise SyntaxError('Невозможно вывести лог без содержимого') | |
| log = open('E:\codes\TuzikMediaServerBot\log.txt', 'a', encoding="utf-8") | |
| log.write(line+'\n') | |
| log.close() | |
| print(line) | |
| log(message='Скрипт запущен') | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # команда /start | |
| @bot.message_handler(commands=['start']) | |
| def start(message): | |
| pass | |
| # обработчик сообщений, кнопок | |
| @bot.message_handler(content_types=['text']) | |
| def handler(message): | |
| pass | |
| # Обработчик callback | |
| @bot.callback_query_handler(func=lambda c: True) | |
| def callback(c): | |
| pass | |
| # Класс информации о боте | |
| class b: | |
| f = bot.get_me().first_name if bot.get_me().first_name != None else '' | |
| l = bot.get_me().last_name if bot.get_me().last_name != None else '' | |
| u = '@' + bot.get_me().username | |
| # Вывод имени/username бота | |
| print(f"{b.f}{' '+b.l if b.l != '' else ''} | {b.u}".center(shutil.get_terminal_size().columns)) | |
| # Запуск бота | |
| def polling(no_internet_interval: int|float = 15, *args, **qwargs): | |
| try: bot.polling(qwargs) | |
| except ConnectionError: | |
| from time import sleep | |
| sleep(no_internet_interval) | |
| polling() | |
| polling(15, none_stop=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment