Add links parsing in message (without need to type commands)
This commit is contained in:
parent
f14f148901
commit
d9d6ef0a70
13
commands.py
13
commands.py
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import irc
|
import irc
|
||||||
from config import pygbot as c
|
from config import pygbot as c
|
||||||
from config import changeobj
|
from config import changeobj
|
||||||
|
@ -46,6 +47,18 @@ def bot_command_parser(config, bot, user, channel, message):
|
||||||
yt.gettitle(bot, channel, message)
|
yt.gettitle(bot, channel, message)
|
||||||
elif message.split()[0] == (c.prefix + "t") or message.split()[0] == (c.prefix + "title"):
|
elif message.split()[0] == (c.prefix + "t") or message.split()[0] == (c.prefix + "title"):
|
||||||
web.gettitle(bot, channel, message)
|
web.gettitle(bot, channel, message)
|
||||||
|
else:
|
||||||
|
parseiflink(bot, channel, message)
|
||||||
|
|
||||||
|
def parseiflink(bot, channel, message):
|
||||||
|
for i in message.split():
|
||||||
|
messagehaslink = re.search("http.*://", i)
|
||||||
|
if messagehaslink != None:
|
||||||
|
isyoutubelink = re.search("youtu.*be.*", i)
|
||||||
|
if isyoutubelink != None:
|
||||||
|
yt.sendyttitle(bot, channel, i)
|
||||||
|
else:
|
||||||
|
web.sendtitle(bot, channel, i)
|
||||||
|
|
||||||
def configure(config, bot, channel, message):
|
def configure(config, bot, channel, message):
|
||||||
try:
|
try:
|
||||||
|
|
17
web.py
17
web.py
|
@ -5,13 +5,20 @@ from bs4 import BeautifulSoup
|
||||||
def gettitle(bot, channel, message):
|
def gettitle(bot, channel, message):
|
||||||
try:
|
try:
|
||||||
link = ' '.join(message.split()[1:])
|
link = ' '.join(message.split()[1:])
|
||||||
iflinkok = re.search("^http", link)
|
iflinkok = re.search("^http.*://", link)
|
||||||
if iflinkok != None:
|
if iflinkok != None:
|
||||||
page = requests.get(link)
|
sendtitle(bot, channel, link)
|
||||||
soup = BeautifulSoup(page.text, 'html.parser')
|
|
||||||
title = soup.title.string
|
|
||||||
bot.send(channel, title)
|
|
||||||
else:
|
else:
|
||||||
bot.send(channel, "Failed to get title")
|
bot.send(channel, "Failed to get title")
|
||||||
except:
|
except:
|
||||||
bot.send(channel, "Failed to get title")
|
bot.send(channel, "Failed to get title")
|
||||||
|
|
||||||
|
def sendtitle(bot, channel, link):
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
17
youtube.py
17
youtube.py
|
@ -5,13 +5,20 @@ from bs4 import BeautifulSoup
|
||||||
def gettitle(bot, channel, message):
|
def gettitle(bot, channel, message):
|
||||||
try:
|
try:
|
||||||
link = ' '.join(message.split()[1:])
|
link = ' '.join(message.split()[1:])
|
||||||
iflinkok = re.search("^http", link)
|
iflinkok = re.search("^http.*://", link)
|
||||||
if iflinkok != None:
|
if iflinkok != None:
|
||||||
page = requests.get(link)
|
sendyttitle(bot, channel, link)
|
||||||
soup = BeautifulSoup(page.text, 'html.parser')
|
|
||||||
title = soup.find("meta", itemprop="name")["content"]
|
|
||||||
bot.send(channel, title)
|
|
||||||
else:
|
else:
|
||||||
bot.send(channel, "Failed to get title")
|
bot.send(channel, "Failed to get title")
|
||||||
except:
|
except:
|
||||||
bot.send(channel, "Failed to get title")
|
bot.send(channel, "Failed to get title")
|
||||||
|
|
||||||
|
def sendyttitle(bot, channel, link):
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue