Skip to content

Commit

Permalink
Add USER_ID environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
captaincolonelfox committed Oct 27, 2022
1 parent 732b9d7 commit aa06384
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ Built on top of [aiogram](https://github.com/aiogram/aiogram)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

## Env

(*REQUIRED*)

- API_TOKEN - Bot token from BotFather

(*OPTIONAL*)
- USER_ID - To give access only to specific user id (default: empty = all users)
- SENTRY_DSN - To send unhandled exceptions to Sentry (default: empty = no reports)
- ENVIRONMENT - Sentry environment variable (default: Local)
- USER_AGENT - To override user-agent used to download videos (default: random every time)


## Local

```bash
Expand Down
13 changes: 11 additions & 2 deletions bot/handlers/messages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from aiogram.dispatcher.filters import IDFilter
from aiogram.types import Message
from bot import dp, bot
from bot import bot, dp
from bot.api import TikTokAPI
from settings import USER_ID


TikTok = TikTokAPI(
Expand All @@ -12,7 +14,14 @@
)


@dp.message_handler()
def filter_message_handler(user_id: str):
if user_id:
return dp.message_handler(IDFilter(user_id=user_id))
else:
return dp.message_handler()


@filter_message_handler(USER_ID)
async def get_message(message: Message):
async for video in TikTok.handle_message(message):
if not video: continue
Expand Down
3 changes: 2 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

API_TOKEN = os.environ.get('API_TOKEN')
API_TOKEN = os.getenv('API_TOKEN')
USER_ID = os.getenv('USER_ID')
SENTRY_DSN = os.getenv('SENTRY_DSN')
ENVIRONMENT = os.getenv('ENVIRONMENT', 'Local')
USER_AGENT = os.getenv('USER_AGENT')

0 comments on commit aa06384

Please sign in to comment.