-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesst.py
39 lines (33 loc) · 1.23 KB
/
tesst.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
import time
import telebot
TOKEN = "your bot token here"
bot = telebot.TeleBot(token=TOKEN)
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)
while True:
try:
bot.polling(none_stop=True)
# ConnectionError and ReadTimeout because of possible timout of the requests library
# maybe there are others, therefore Exception
except Exception:
time.sleep(15)