-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added telegram id restriction; Added tweet length check
Signed-off-by: avaakash <[email protected]>
- Loading branch information
Showing
8 changed files
with
97 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Validation and Security checks | ||
""" | ||
from functools import wraps | ||
|
||
from settings import get_env | ||
|
||
def restricted(func): | ||
"""Restrict usage of func to allowed users only and replies if necessary""" | ||
allowed_ids = get_env()["telegram_allowed_ids"] | ||
@wraps(func) | ||
def wrapped(update, context, *args, **kwargs): | ||
user_id = str(update.effective_user.id) | ||
if user_id not in allowed_ids: | ||
print(f"WARNING: Unauthorized access denied for {user_id}") | ||
update.message.reply_text('You are not allowed to use this bot! Please leave.') | ||
return None # quit function | ||
return func(update, context, *args, **kwargs) | ||
return wrapped | ||
|
||
def check_tweet_length(tweet): | ||
""" Checks if the tweet is within the allowed length""" | ||
print("Tweet Length: " + str(len(tweet))) | ||
if len(tweet) > 240: | ||
return False | ||
return True |