-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot.py
51 lines (34 loc) · 1.15 KB
/
bot.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# filters
from tgbot.filters.admin_filter import AdminFilter
# handlers
from tgbot.handlers.admin import admin_user
from tgbot.handlers.spam_command import anti_spam
from tgbot.handlers.user import any_user
# middlewares
from tgbot.middlewares.antiflood_middleware import antispam_func
# states
from tgbot.states.register_state import Register
# utils
from tgbot.utils.database import Database
# telebot
from telebot import TeleBot
# config
from tgbot import config
db = Database()
# remove this if you won't use middlewares:
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
# I recommend increasing num_threads
bot = TeleBot(config.TOKEN, num_threads=5)
def register_handlers():
bot.register_message_handler(admin_user, commands=['start'], admin=True, pass_bot=True)
bot.register_message_handler(any_user, commands=['start'], admin=False, pass_bot=True)
bot.register_message_handler(anti_spam, commands=['spam'], pass_bot=True)
register_handlers()
# Middlewares
bot.register_middleware_handler(antispam_func, update_types=['message'])
# custom filters
bot.add_custom_filter(AdminFilter())
def run():
bot.infinity_polling()
run()