Skip to content
Permalink
Browse files
Update and rename chatBotIG.py to chatBot_ig_and_wiki.py
  • Loading branch information
izekoro committed Nov 22, 2018
1 parent 93d7b9e commit 05418d51fd593112ecda3192d7a08757ad20b858
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 37 deletions.

This file was deleted.

@@ -0,0 +1,65 @@
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)





0 comments on commit 05418d5

Please sign in to comment.