aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuguopei <[email protected]>2020-11-10 09:49:23 +0800
committerliuguopei <[email protected]>2020-11-10 09:49:23 +0800
commitf59cc54b7a2742b45cc359a5a0729ee4640aa3fb (patch)
treebfcee87c2b29776e609d4784e1515f1926aafb5d
parent6aff23b69219ba93b2ba6850a72affc52870c15f (diff)
downloadtelegram-mail-bot-f59cc54b7a2742b45cc359a5a0729ee4640aa3fb.tar.gz
telegram-mail-bot-f59cc54b7a2742b45cc359a5a0729ee4640aa3fb.tar.bz2
telegram-mail-bot-f59cc54b7a2742b45cc359a5a0729ee4640aa3fb.zip
check owner
-rw-r--r--bot.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/bot.py b/bot.py
index b9c84b3..13692ab 100644
--- a/bot.py
+++ b/bot.py
@@ -13,6 +13,11 @@ logger = logging.getLogger(__name__)
bot_token = os.environ['TELEGRAM_TOKEN']
+owner_chat_id = int(os.environ['OWNER_CHAT_ID'])
+
+def is_owner(update: Update) -> bool:
+ return update.message.chat_id == owner_chat_id
+
def handle_large_text(text):
while text:
if len(text) < MAX_MESSAGE_LENGTH:
@@ -28,10 +33,15 @@ def error(update: Update, context: CallbackContext) -> None:
logger.warning('Update "%s" caused error "%s"', update, context.error)
def start_callback(update: Update, context: CallbackContext) -> None:
+ if not is_owner(update):
+ return
msg = "Use /help to get help"
+ # print(update)
update.message.reply_text(msg)
def _help(update: Update, context: CallbackContext) -> None:
+ if not is_owner(update):
+ return
"""Send a message when the command /help is issued."""
help_str = """邮箱设置:
/setting [email protected] password
@@ -47,6 +57,8 @@ def _help(update: Update, context: CallbackContext) -> None:
text=help_str)
def setting_email(update: Update, context: CallbackContext) -> None:
+ if not is_owner(update):
+ return
global email_addr, email_passwd, inbox_num
email_addr = context.args[0]
email_passwd = context.args[1]
@@ -73,6 +85,8 @@ def periodic_task(context: CallbackContext) -> None:
inbox_num = new_inbox_num
def inbox(update: Update, context: CallbackContext) -> None:
+ if not is_owner(update):
+ return
logger.info("received inbox command.")
with EmailClient(email_addr, email_passwd) as client:
global inbox_num
@@ -87,6 +101,8 @@ def inbox(update: Update, context: CallbackContext) -> None:
text=reply_text)
def get_email(update: Update, context: CallbackContext) -> None:
+ if not is_owner(update):
+ return
index = context.args[0]
logger.info("received get command.")
with EmailClient(email_addr, email_passwd) as client: