Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
65 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
|
||
|
||
|
||
|