Fixed error: now sending link error only when command is used
This commit is contained in:
parent
b5c2978e4a
commit
d9bc203053
|
@ -59,9 +59,9 @@ def parseiflink(bot, channel, message):
|
|||
if messagehaslink != None:
|
||||
isyoutubelink = re.search("youtu.*be.*", i)
|
||||
if isyoutubelink != None:
|
||||
yt.sendyttitle(bot, channel, i)
|
||||
yt.sendyttitle(bot, channel, i, False)
|
||||
else:
|
||||
web.sendtitle(bot, channel, i)
|
||||
web.sendtitle(bot, channel, i, False)
|
||||
|
||||
def configure(config, bot, channel, message):
|
||||
try:
|
||||
|
|
7
web.py
7
web.py
|
@ -7,18 +7,19 @@ def gettitle(bot, channel, message):
|
|||
link = ' '.join(message.split()[1:])
|
||||
iflinkok = re.search("^http.*://", link)
|
||||
if iflinkok != None:
|
||||
sendtitle(bot, channel, link)
|
||||
sendtitle(bot, channel, link, True)
|
||||
else:
|
||||
bot.send(channel, "Failed to get title")
|
||||
except:
|
||||
bot.send(channel, "Failed to get title")
|
||||
|
||||
def sendtitle(bot, channel, link):
|
||||
def sendtitle(bot, channel, link, sendonfailed):
|
||||
try:
|
||||
page = requests.get(link)
|
||||
soup = BeautifulSoup(page.text, 'html.parser')
|
||||
title = soup.title.string
|
||||
bot.send(channel, title)
|
||||
except:
|
||||
bot.send(channel, "Failed to get title")
|
||||
if sendonfailed == True:
|
||||
bot.send(channel, "Failed to get title")
|
||||
|
||||
|
|
|
@ -7,18 +7,19 @@ def gettitle(bot, channel, message):
|
|||
link = ' '.join(message.split()[1:])
|
||||
iflinkok = re.search("^http.*://", link)
|
||||
if iflinkok != None:
|
||||
sendyttitle(bot, channel, link)
|
||||
sendyttitle(bot, channel, link, True)
|
||||
else:
|
||||
bot.send(channel, "Failed to get title")
|
||||
except:
|
||||
bot.send(channel, "Failed to get title")
|
||||
|
||||
def sendyttitle(bot, channel, link):
|
||||
def sendyttitle(bot, channel, link, sendonfailed):
|
||||
try:
|
||||
page = requests.get(link)
|
||||
soup = BeautifulSoup(page.text, 'html.parser')
|
||||
title = soup.find("meta", itemprop="name")["content"]
|
||||
bot.send(channel, title)
|
||||
except:
|
||||
bot.send(channel, "Failed to get title")
|
||||
if sendonfailed == True:
|
||||
bot.send(channel, "Failed to get title")
|
||||
|
||||
|
|
Loading…
Reference in New Issue