! /usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
import menu
import settings
import functions as func
import telebot
from telebot import types
from telebot import apihelper
import time
import datetime
import random
import threading
import config
from PIL import Image
import traceback
buy_dict = {}
balance_dict = {}
admin_sending_messages_dict = {}
product_dict = {}
download_dict = {}
def start_bot():
bot = telebot.TeleBot(config.config("bot_token"), threaded=True, num_threads=300)
# Command start
@bot.message_handler(commands=['start'])
def handler_start(message):
chat_id = message.chat.id
resp = func.first_join(user_id=chat_id, name=message.from_user.username, code=message.text[7:])
with open('welcome.jpg', 'rb') as photo:
bot.send_photo(
chat_id=chat_id,
photo=photo,
caption='Добро пожаловать {}!'.format(message.from_user.first_name,),
reply_markup=menu.main_menu()
)
# Command admin
@bot.message_handler(commands=['admin'])
def handler_admin(message):
chat_id = message.chat.id
if str(chat_id) in func.admin_id_manager() or str(chat_id) in func.admin_id_own():
bot.send_message(chat_id, 'Вы перешли в меню админа', reply_markup=menu.admin_menu)
@bot.message_handler(content_types=['text'])
def send_message(message):
if str(message.chat.id) in func.ban():
print('spam')
else:
chat_id = message.chat.id
first_name = message.from_user.first_name
username = message.from_user.username
if message.text in func.btn_menu_list():
conn = sqlite3.connect('base.db')
cursor = conn.cursor()
base = cursor.execute(f'SELECT * FROM buttons WHERE name = "{message.text}"').fetchone()
with open(f'{base[2]}.jpg', 'rb') as photo:
bot.send_photo(
chat_id=chat_id,
photo=photo,
caption=base[1]
)
if message.text == menu.main_menu_btn[0]:
try:
bot.send_message(
chat_id=chat_id,
text=func.info_numbers(chat_id),
reply_markup=func.buy_number_menu()
)
except: pass
if message.text == menu.main_menu_btn[1]:
try:
info = func.profile(chat_id)
msg = settings.profile.format(
id=info[0],
login=f'@{info[1]}',
data=info[2][:19],
balance=info[5]
),
bot.send_message(
chat_id=chat_id,
text=msg)
except Exception as e: pass
if message.text == menu.main_menu_btn[2]:
bot.send_message(
chat_id=chat_id,
text=settings.info,
reply_markup=menu.main_menu(),
parse_mode='html'
)