Compare commits
4 Commits
6ffae054c0
...
1a0341b3dd
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a0341b3dd | |||
| e1fdbcb60c | |||
| c1d13f208a | |||
| 2f6e3b6c15 |
@ -1,3 +1,3 @@
|
||||
en:
|
||||
start: "Hello, {message.from_user.full_name}"
|
||||
help: ""
|
||||
help: "Just simple bot, which greets the user. Use /start"
|
||||
|
||||
@ -3,6 +3,7 @@ from telebot.storage import StateMemoryStorage, StateRedisStorage
|
||||
|
||||
from .handlers import register_handlers
|
||||
from .middlewares import setup_middlewares
|
||||
from .filters import add_custom_filters
|
||||
|
||||
|
||||
def create_bot(config, logger, i18n):
|
||||
@ -29,4 +30,7 @@ def create_bot(config, logger, i18n):
|
||||
logger.debug("Registering handlers")
|
||||
register_handlers(bot)
|
||||
|
||||
logger.debug("Adding custom filters")
|
||||
add_custom_filters(bot, config)
|
||||
|
||||
return bot
|
||||
|
||||
@ -21,7 +21,7 @@ class Config:
|
||||
# state storage
|
||||
SS_TYPE: str = os.getenv("SS_TYPE", "memory").lower()
|
||||
SS_REDIS_HOST: str = os.getenv("SS_REDIS_HOST")
|
||||
SS_REDIS_PORT: int = int(os.getenv("SS_REDIS_PORT"), 6379)
|
||||
SS_REDIS_PORT: int = int(os.getenv("SS_REDIS_PORT", 6379))
|
||||
SS_REDIS_DB: int = int(os.getenv("SS_REDIS_DB", 0))
|
||||
SS_REDIS_PASS: str = os.getenv("SS_REDIS_PASS")
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
from telebot import TeleBot
|
||||
from telebot.custom_filters import StateFilter
|
||||
|
||||
from .isowner import IsOwnerFilter
|
||||
|
||||
|
||||
def add_custom_filters(bot: TeleBot, config):
|
||||
bot.add_custom_filter(StateFilter(bot))
|
||||
bot.add_custom_filter(IsOwnerFilter(config.OWNER_ID))
|
||||
12
mybot/filters/isowner.py
Normal file
12
mybot/filters/isowner.py
Normal file
@ -0,0 +1,12 @@
|
||||
from telebot.custom_filters import SimpleCustomFilter
|
||||
from telebot.types import Message
|
||||
|
||||
|
||||
class IsOwnerFilter (SimpleCustomFilter):
|
||||
key = "is_owner"
|
||||
|
||||
def __init__(self, owner_id: int):
|
||||
self.owner_id: int = owner_id
|
||||
|
||||
def check(self, message: Message):
|
||||
return message.from_user.id == self.owner_id
|
||||
1
mybot/keyboards.py
Normal file
1
mybot/keyboards.py
Normal file
@ -0,0 +1 @@
|
||||
# keyboards will be defined here
|
||||
Loading…
x
Reference in New Issue
Block a user