Exemple #1
0
    async def cyanide(self, ctx, *, date: str = None):
        """Displays the Cyanide & Happiness comic for the passed date (MM-DD-YYYY) if found."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        if not date:
            # Auto to today's date
            date = dt.datetime.today().strftime("%m-%d-%Y")

        if not self.dateIsValid(date):
            msg = 'Usage: `{}cyanide "[date MM-DD-YYYY]"`'.format(ctx.prefix)
            await self.bot.send_message(channel, msg)
            return

        # Can't be after this date.
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "01-26-2005"

        if not self.isDateBetween(date, firstDate, todayDate):
            msg = "Date out of range. Must be between {} and {}".format(
                firstDate, todayDate)
            await self.bot.send_message(channel, msg)
            return

        dateDict = self.dateDict(date)
        # Get Arvhive URL
        getURL = "http://explosm.net/comics/archive/" + dateDict[
            'Year'] + "/" + dateDict['Month']

        gotComic = False
        imageHTML = ComicHelper.getImageHTML(getURL)
        if imageHTML:
            imagePage = ComicHelper.getCHURL(
                imageHTML, dateDict['Year'] + "." + dateDict['Month'] + "." +
                dateDict['Day'])
            if imagePage:
                comicHTML = ComicHelper.getImageHTML(imagePage)
                if comicHTML:
                    imageURL = ComicHelper.getCHImageURL(comicHTML)
                    if imageURL:
                        gotComic = True

        if not gotComic:
            msg = 'No comic found for *{}*'.format(date)
            await self.bot.send_message(channel, msg)
            return

        imageDisplayName = "Cyanide & Happiness " + dateDict[
            'Year'] + "-" + dateDict['Month'] + "-" + dateDict['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #2
0
    async def randcyanide(self, ctx):
        """Randomly picks and displays a Cyanide & Happiness comic."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        # Can't be after this date.
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "01-26-2005"

        # Get a random Julian date between the first comic and today
        gotComic = False
        tries = 0
        while not gotComic:

            if tries >= 10:
                break

            date = self.getRandDateBetween(firstDate, todayDate)

            # Get Arvhive URL
            getURL = "http://explosm.net/comics/archive/" + date[
                'Year'] + "/" + date['Month']

            # Retrieve html and info
            imageHTML = ComicHelper.getImageHTML(getURL)
            if imageHTML:
                imagePage = ComicHelper.getCHURL(
                    imageHTML,
                    date['Year'] + "." + date['Month'] + "." + date['Day'])
                if imagePage:
                    comicHTML = ComicHelper.getImageHTML(imagePage)
                    if comicHTML:
                        imageURL = ComicHelper.getCHImageURL(comicHTML)
                        if imageURL:
                            gotComic = True

            tries += 1

        if tries >= 10:
            msg = 'Failed to find working link.'
            await self.bot.send_message(channel, msg)
            return

        imageDisplayName = "Cyanide & Happiness " + date['Year'] + "-" + date[
            'Month'] + "-" + date['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #3
0
	async def randxkcd(self, ctx):
		"""Displays a random XKCD comic."""
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.server
		
		if not self.canDisplay(server):
			return
		
		# Must be a comic number
		archiveURL = "http://xkcd.com/archive/"
		archiveHTML = ComicHelper.getImageHTML(archiveURL)
		newest = int(ComicHelper.getNewestXKCD(archiveHTML))
		
		# Start a loop to find a comic
		gotComic = False
		tries = 0
		while not gotComic:
	
			if tries >= 10:
				break
		
			# Build our url
			date = random.randint(1, newest)
			comicURL = "http://xkcd.com/" + str(date) + "/"

			# now we get the actual comic info
			imageHTML = ComicHelper.getImageHTML(comicURL)
		
			if imageHTML:
				gotComic = True
			
			tries += 1
			
		if tries >= 10:
			msg = 'Failed to find working link.'
			await self.bot.send_message(channel, msg)
			return
		
		# Got a comic link
		imageURL = ComicHelper.getXKCDImageURL(imageHTML)
		imageDisplayName = ComicHelper.getXKCDImageTitle(imageHTML)
		title = '{} *({})*'.format(imageDisplayName, date)

		# Download Image
		await GetImage.get(imageURL, self.bot, channel, title)
Exemple #4
0
    async def peanuts(self, ctx, *, date: str = None):
        """Displays the Peanuts comic for the passed date (MM-DD-YYYY) if found."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        if not date:
            # Auto to today
            date = dt.datetime.today().strftime("%m-%d-%Y")

        if not self.dateIsValid(date):
            msg = 'Usage: `{}peanuts "[date MM-DD-YYYY]"`'.format(ctx.prefix)
            await self.bot.send_message(channel, msg)
            return

        # Can't be after this date.
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "10-02-1950"

        if not self.isDateBetween(date, firstDate, todayDate):
            msg = "Date out of range. Must be between {} and {}".format(
                firstDate, todayDate)
            await self.bot.send_message(channel, msg)
            return

        dateDict = self.dateDict(date)

        # Get URL
        getURL = "http://www.gocomics.com/printable/peanuts/" + dateDict[
            'Year'] + "/" + dateDict['Month'] + "/" + dateDict['Day']

        # Retrieve html and info
        imageHTML = ComicHelper.getImageHTML(getURL)

        # Comment out to test
        '''if imageHTML == None:
			msg = 'No comic found for *{}*'.format(date)
			await self.bot.send_message(channel, msg)
			return'''

        imageURL = ComicHelper.getPeanutsImageURL(imageHTML)

        if not imageURL:
            msg = 'No comic found for *{}*'.format(date)
            await self.bot.send_message(channel, msg)
            return

        imageDisplayName = "Day " + dateDict['Year'] + "-" + dateDict[
            'Month'] + "-" + dateDict['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #5
0
    async def gmg(self, ctx, *, date: str = None):
        """Displays the Garfield Minus Garfield comic for the passed date (MM-DD-YYYY) if found."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.guild

        if not self.canDisplay(server):
            return

        if not date:
            # Auto to today
            date = dt.datetime.today().strftime("%m-%d-%Y")

        if not self.dateIsValid(date):
            msg = 'Usage: `{}gmg "[date MM-DD-YYYY]"`'.format(ctx.prefix)
            await channel.send(msg)
            return

        # Can't be after this date.
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "02-13-2008"

        if not self.isDateBetween(date, firstDate, todayDate):
            msg = "Date out of range. Must be between {} and {}".format(
                firstDate, todayDate)
            await channel.send(msg)
            return

        dateDict = self.dateDict(date)

        # Get URL
        getURL = "http://garfieldminusgarfield.net/day/" + dateDict[
            'Year'] + "/" + dateDict['Month'] + "/" + dateDict['Day']

        # Retrieve html and info
        imageHTML = ComicHelper.getImageHTML(getURL)

        # Comment out to test
        '''if imageHTML == None:
			msg = 'No comic found for *{}*'.format(date)
			await channel.send(msg)
			return'''

        imageURL = ComicHelper.getGMGImageURL(imageHTML)

        if not imageURL:
            msg = 'No comic found for *{}*'.format(date)
            await channel.send(msg)
            return

        imageDisplayName = "Day " + dateDict['Year'] + "-" + dateDict[
            'Month'] + "-" + dateDict['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #6
0
    async def calvin(self, ctx, *, date: str = None):
        """Displays the Calvin & Hobbes comic for the passed date (MM-DD-YYYY) if found."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        if not date:
            # Auto to the last Calvin & Hobbes comic
            date = "12-31-1995"

        if not self.dateIsValid(date):
            msg = 'Usage: `{}calvin "[date MM-DD-YYYY]"`'.format(ctx.prefix)
            await self.bot.send_message(channel, msg)
            return

        # Can't be after this date.
        todayDate = "12-31-1995"
        # Can't be before this date.
        firstDate = "11-18-1985"

        if not self.isDateBetween(date, firstDate, todayDate):
            msg = "Date out of range. Must be between {} and {}".format(
                firstDate, todayDate)
            await self.bot.send_message(channel, msg)
            return

        dateDict = self.dateDict(date)
        # Get URL
        getURL = "http://marcel-oehler.marcellosendos.ch/comics/ch/" + dateDict[
            'Year'] + "/" + dateDict['Month'] + "/" + dateDict[
                'Year'] + dateDict['Month'] + dateDict['Day'] + ".gif"

        # Retrieve html and info
        imageHTML = ComicHelper.getImageHTML(getURL)

        if not imageHTML:
            msg = 'No comic found for *{}*'.format(date)
            await self.bot.send_message(channel, msg)
            return

        imageDisplayName = "Calvin & Hobbes " + dateDict[
            'Year'] + "-" + dateDict['Month'] + "-" + dateDict['Day']
        # Download Image
        await GetImage.get(getURL, self.bot, channel, imageDisplayName)
Exemple #7
0
	async def randilbert(self, ctx):
		"""Randomly picks and displays a Dilbert comic."""
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.server
		
		if not self.canDisplay(server):
			return
		
		# Get some preliminary values
		todayDate = dt.datetime.today().strftime("%m-%d-%Y")
		# Can't be before this date.
		firstDate = "04-16-1989"

		# Start a loop to find a comic
		gotComic = False
		tries = 0
		while not gotComic:
	
			if tries >= 10:
				break
		
			# Try to get a valid comic
			date      = self.getRandDateBetween(firstDate, todayDate)
			url       = self.buildDilbertURL(date)
			imageHTML = ComicHelper.getImageHTML(url)
			
			if imageHTML:
				# Got it!
				gotComic = True
				
			# Increment try counter
			tries += 1	
		
		if tries >= 10:
			msg = 'Failed to find working link.'
			await self.bot.send_message(channel, msg)
			return
		
		# Got a comic link
		imageURL  = ComicHelper.getImageURL(imageHTML)
		imageDisplayName = ComicHelper.getImageTitle(imageHTML)
		
		# Download Image
		await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #8
0
    async def randpeanuts(self, ctx):
        """Randomly picks and displays a Peanuts comic."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        # Can't be after this date.
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "10-02-1950"

        # Get a random Julian date between the first comic and today
        gotComic = False
        tries = 0
        while not gotComic:

            if tries >= 10:
                break

            date = self.getRandDateBetween(firstDate, todayDate)
            # Get URL
            getURL = "http://www.gocomics.com/printable/peanuts/" + date[
                'Year'] + "/" + date['Month'] + "/" + date['Day']
            # Retrieve html and info
            imageHTML = ComicHelper.getImageHTML(getURL)

            if imageHTML:
                imageURL = ComicHelper.getPeanutsImageURL(imageHTML)
                if imageURL:
                    gotComic = True

            tries += 1

        if tries >= 10:
            msg = 'Failed to find working link.'
            await self.bot.send_message(channel, msg)
            return

        imageDisplayName = "Day " + date['Year'] + "-" + date[
            'Month'] + "-" + date['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #9
0
    async def randcalvin(self, ctx):
        """Randomly picks and displays a Calvin & Hobbes comic."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        # Can't be after this date.
        todayDate = "12-31-1995"
        # Can't be before this date.
        firstDate = "11-18-1985"

        gotComic = False
        tries = 0
        while not gotComic:

            if tries >= 10:
                break

            date = self.getRandDateBetween(firstDate, todayDate)
            # Get URL
            getURL = "http://marcel-oehler.marcellosendos.ch/comics/ch/" + date[
                'Year'] + "/" + date['Month'] + "/" + date['Year'] + date[
                    'Month'] + date['Day'] + ".gif"

            # Retrieve html and info
            imageHTML = ComicHelper.getImageHTML(getURL)

            if imageHTML:
                imageURL = getURL
                gotComic = True

            tries += 1

        if tries >= 10:
            msg = 'Failed to find working link.'
            await self.bot.send_message(channel, msg)
            return

        imageDisplayName = "Calvin & Hobbes " + date['Year'] + "-" + date[
            'Month'] + "-" + date['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #10
0
    async def randgarfield(self, ctx):
        """Randomly picks and displays a Garfield comic."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.guild

        if not self.canDisplay(server):
            return

        # Can't be after this date.
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "06-19-1978"

        # Get a random Julian date between the first comic and today
        gotComic = False
        tries = 0
        while not gotComic:

            if tries >= 10:
                break

            date = self.getRandDateBetween(firstDate, todayDate)
            # Get URL
            getURL = "https://garfield.com/comic/" + date['Year'] + "/" + date[
                'Month'] + "/" + date['Day']
            # Retrieve html and info
            imageHTML = ComicHelper.getImageHTML(getURL)

            if imageHTML:
                imageURL = ComicHelper.getGImageURL(imageHTML)
                if imageURL:
                    gotComic = True

            tries += 1

        if tries >= 10:
            msg = 'Failed to find working link.'
            await channel.send(msg)
            return

        imageDisplayName = "Day " + date['Year'] + "-" + date[
            'Month'] + "-" + date['Day']
        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #11
0
    async def dilbert(self, ctx, *, date: str = None):
        """Displays the Dilbert comic for the passed date (MM-DD-YYYY)."""

        channel = ctx.message.channel
        author = ctx.message.author
        server = ctx.message.server

        if not self.canDisplay(server):
            return

        if not date:
            # Auto to today's date
            date = dt.datetime.today().strftime("%m-%d-%Y")

        if not self.dateIsValid(date):
            msg = 'Usage: `{}dilbert "[date MM-DD-YYYY]"`'.format(ctx.prefix)
            await self.bot.send_message(channel, msg)
            return

        # Can't be after this date
        todayDate = dt.datetime.today().strftime("%m-%d-%Y")
        # Can't be before this date.
        firstDate = "04-16-1989"

        if not self.isDateBetween(date, firstDate, todayDate):
            msg = "Date out of range. Must be between {} and {}".format(
                firstDate, todayDate)
            await self.bot.send_message(channel, msg)
            return

        # Build our url and check if it's valid
        url = self.buildDilbertURL(self.dateDict(date))
        imageHTML = ComicHelper.getImageHTML(url)

        if not imageHTML:
            msg = 'No comic found for *{}*'.format(date)
            await self.bot.send_message(channel, msg)
            return

        # Got a comic link
        imageURL = ComicHelper.getImageURL(imageHTML)
        imageDisplayName = ComicHelper.getImageTitle(imageHTML)

        # Download Image
        await GetImage.get(imageURL, self.bot, channel, imageDisplayName)
Exemple #12
0
	async def xkcd(self, ctx, date : str = None):
		"""Displays the XKCD comic for the passed date (MM-DD-YYYY) or comic number if found."""
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.server
		
		if not self.canDisplay(server):
			return
			
		if not date:
			# Auto to today's date
			date = dt.datetime.today().strftime("%m-%d-%Y")
			
		if not self.dateIsValid(date):
			# If it's an int - let's see if it fits
			try:
				date = int(date)
			except:
				msg = 'Usage: `$xkcd "[date MM-DD-YYYY]"`'
				await self.bot.send_message(channel, msg)
				return
			# Must be a comic number
			archiveURL = "http://xkcd.com/archive/"
			archiveHTML = ComicHelper.getImageHTML(archiveURL)
			newest = int(ComicHelper.getNewestXKCD(archiveHTML))
			if int(date) > int(newest) or int(date) < 1:
				msg = "Comic out of range. Must be between 1 and {}".format(newest)
				await self.bot.send_message(channel, msg)
				return
			comicURL = "/" + str(date) + "/"
		else:
			# Can't be after this date.
			todayDate = dt.datetime.today().strftime("%m-%d-%Y")
			# Can't be before this date.
			firstDate = "01-01-2006"

			if not self.isDateBetween(date, firstDate, todayDate):
				msg = "Date out of range. Must be between {} and {}".format(firstDate, todayDate)
				await self.bot.send_message(channel, msg)
				return
			# Get date in a dict (Month, Day, Year)
			dateDict = self.dateDict(date)
			# Get URL
			archiveURL = "http://xkcd.com/archive/"
			archiveHTML = ComicHelper.getImageHTML(archiveURL)

			xkcdDate = "{}-{}-{}".format(int(dateDict['Year']), int(dateDict['Month']), int(dateDict['Day']))
			comicURL = ComicHelper.getXKCDURL( archiveHTML, xkcdDate )
		
		if not comicURL:
			msg = 'No comic found for *{}*'.format(date)
			await self.bot.send_message(channel, msg)
			return
		
		comicNumber = comicURL.replace('/', '').strip()
		comicURL = "http://xkcd.com" + comicURL

		# now we get the actual comic info
		imageHTML = ComicHelper.getImageHTML(comicURL)
		imageURL = ComicHelper.getXKCDImageURL(imageHTML)
		imageDisplayName = ComicHelper.getXKCDImageTitle(imageHTML)
		title = '{} *({})*'.format(imageDisplayName, comicNumber)
		# Download Image
		await GetImage.get(imageURL, self.bot, channel, title)