Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import telebot
import time
import wikipedia
botToken = "711824241:AAG9l7W716ua0OQ-FDp320y9dD82gWG5p5Q"
bot = telebot.TeleBot(token=botToken) # botToken
def find_at(msg):
for text in msg:
if "@" in text:
return text
def find(msg):
for text in msg:
if "wiki" in text:
return text
"""by giving command /start the bot will list all the its features"""
@bot.message_handler(commands=["start"]) # list of strings
def sendWelcome(message):
bot.reply_to(message, "Welcome! Here is a list of things I can do: \n"
"Use '@' followed by any username to get back an Instagram profile. Or \n"
"Type anything followed by 'wiki' to get a summary and a link to the your query")
"""if the text message is not empty and it has the @ sign then the bot will reply with a link"""
@bot.message_handler(func=lambda msg: msg.text is not None and "@" in msg.text)
def at_answer(message):
textChat = message.text.split()
at_text = find_at(textChat)
bot.reply_to(message, "https://instagram.com/{}".format(at_text[1:]))
"""From Kevin Einsenberg 21/01/2018 at https://www.youtube.com/watch?v=jhFsFZXZbu4"""
""" if the bot can find the keyword wiki in the message it will return a summary of the query"""
@bot.message_handler(func=lambda msg: "wiki" in msg.text)
def wikiInfo(message):
textChat = message.text.split()
page = wikipedia.page(str(textChat[:-1])) # it till get everything before the keyword wiki
url = page.url # converts to a link using the page name
bot.reply_to(message, wikipedia.summary(str(textChat[:-1]), sentences=3)) # too keep it short only 3 sentences
"""allows the user to click a Wikipedia link"""
bot.reply_to(message, "You can check the link below to know more")
bot.reply_to(message, url)
"""From wikipedia api at https://wikipedia.readthedocs.io/en/latest/quickstart.html"""
while True:
try:
bot.polling()
except Exception:
time.sleep(15)