Skip to content

Instantly share code, notes, and snippets.

@ssghost
Last active April 2, 2020 10:26
Show Gist options
  • Save ssghost/dd65e0264719817e74b8cb1e85b931fa to your computer and use it in GitHub Desktop.
Save ssghost/dd65e0264719817e74b8cb1e85b931fa to your computer and use it in GitHub Desktop.
If I lost in China for 3 days, this Telegram bot will automatically send my personal information to my best friends for seeking rescues.
from telegram import Bot
from threading import Timer
from eventlet import Timeout
def main(bot):
while True:
update = bot.getUpdates()[-1]
if update.message.text == '/start':
timer = Timer(60*60*24*3, post_alert, args=[bot,update])
timer.start()
chat_id = update.message.chat_id
bot.sendMessage(chat_id=chat_id,text='開始計時')
elif update.message.text == '/cancel':
timer.cancel()
def post_alert(bot,update):
chat_id = update.message.chat_id
text = '@user_name已超過3日失去聯繫,若有意幫助,請在1小時之內,發送"/info"獲取私人信息'
bot.sendMessage(chat_id=chat_id,text=text)
with Timeout(60*60,False):
get_info(bot,update)
def get_info(bot,update):
if update.message == '/info':
user = update.message.effective_user
text = 'tel:111, twitter:@user_name, 常住地:aaa,請把我的信息告訴推特@bbcchinese@nytchinese, 請求以政治迫害案件調查'
bot.sendMessage(user.id,text=text)
if __name__ == '__main__':
bot = Bot(token='Token')
update = bot.getUpdates()[-1]
try:
main(bot)
except:
print('token failed.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment