From 438d9f5f6085df73ab5aa8a62f3f0fad275c4480 Mon Sep 17 00:00:00 2001 From: Seenko Date: Fri, 13 Jan 2017 11:23:39 -0200 Subject: [PATCH] [Streams] Handle both channel names and URLs (#575) --- cogs/streams.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cogs/streams.py b/cogs/streams.py index 31087fc3d..3d5979697 100644 --- a/cogs/streams.py +++ b/cogs/streams.py @@ -5,6 +5,7 @@ from .utils.chat_formatting import * from .utils import checks from __main__ import send_cmd_help import os +import re import time import aiohttp import asyncio @@ -28,6 +29,8 @@ class Streams: async def hitbox(self, stream: str): """Checks if hitbox stream is online""" stream = escape_mass_mentions(stream) + regex = r'^(https?\:\/\/)?(www\.)?(hitbox\.tv\/)' + stream = re.sub(regex, '', stream) online = await self.hitbox_online(stream) if online is True: await self.bot.say("http://www.hitbox.tv/{}/" @@ -43,6 +46,8 @@ class Streams: async def twitch(self, ctx, stream: str): """Checks if twitch stream is online""" stream = escape_mass_mentions(stream) + regex = r'^(https?\:\/\/)?(www\.)?(twitch\.tv\/)' + stream = re.sub(regex, '', stream) online = await self.twitch_online(stream) if online is True: await self.bot.say("http://www.twitch.tv/{} " @@ -62,6 +67,8 @@ class Streams: async def beam(self, stream: str): """Checks if beam stream is online""" stream = escape_mass_mentions(stream) + regex = r'^(https?\:\/\/)?(www\.)?(beam\.pro\/)' + stream = re.sub(regex, '', stream) online = await self.beam_online(stream) if online is True: await self.bot.say("https://beam.pro/{} is online!".format(stream)) @@ -83,6 +90,8 @@ class Streams: async def twitch_alert(self, ctx, stream: str): """Adds/removes twitch alerts from the current channel""" stream = escape_mass_mentions(stream) + regex = r'^(https?\:\/\/)?(www\.)?(twitch\.tv\/)' + stream = re.sub(regex, '', stream) channel = ctx.message.channel check = await self.twitch_online(stream) if check == 404: @@ -132,6 +141,8 @@ class Streams: async def hitbox_alert(self, ctx, stream: str): """Adds/removes hitbox alerts from the current channel""" stream = escape_mass_mentions(stream) + regex = r'^(https?\:\/\/)?(www\.)?(hitbox\.tv\/)' + stream = re.sub(regex, '', stream) channel = ctx.message.channel check = await self.hitbox_online(stream) if check is None: @@ -176,6 +187,8 @@ class Streams: async def beam_alert(self, ctx, stream: str): """Adds/removes beam alerts from the current channel""" stream = escape_mass_mentions(stream) + regex = r'^(https?\:\/\/)?(www\.)?(beam\.pro\/)' + stream = re.sub(regex, '', stream) channel = ctx.message.channel check = await self.beam_online(stream) if check is None: