-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
55 lines (41 loc) · 1.56 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from flask import Flask, request
import telebot
TOKEN = '882043411:AAHbosubZ3D2us2aZPgnXMAhMGozTFWmtOc'
bot = telebot.TeleBot(TOKEN)
server = Flask(__name__)
bot = telebot.TeleBot(token=TOKEN)
server = Flask(__name__)
def findat(msg):
# from a list of texts, it finds the one with the '@' sign
for i in msg:
if '@' in i:
return i
@bot.message_handler(commands=['start']) # welcome message handler
def send_welcome(message):
bot.reply_to(message, '(placeholder text)')
@bot.message_handler(commands=['help']) # help message handler
def send_welcome(message):
bot.reply_to(message, 'ALPHA = FEATURES MAY NOT WORK')
@bot.message_handler(func=lambda msg: msg.text is not None and '@' in msg.text)
# lambda function finds messages with the '@' sign in them
# in case msg.text doesn't exist, the handler doesn't process it
def at_converter(message):
texts = message.text.split()
at_text = findat(texts)
if at_text == '@': # in case it's just the '@', skip
pass
else:
insta_link = "https://instagram.com/{}".format(at_text[1:])
bot.reply_to(message, insta_link)
@server.route('/' + TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
@server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url='https://mighty-savannah-48884.herokuapp.com/' + TOKEN)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))