コード例 #1
0
ファイル: Comic.py プロジェクト: skylarr1227/sky-cogs
    async def randilbert(self, ctx):
        """Randomly picks and displays a Dilbert comic."""

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

        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 = await ComicHelper.getImageHTML(url)

            if imageHTML:
                # Got it!
                gotComic = True

            # Increment try counter
            tries += 1

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

        # Got a comic link
        imageURL = ComicHelper.getImageURL(imageHTML)
        imageDisplayName = ComicHelper.getImageTitle(imageHTML)
        if imageDisplayName.lower().startswith("dilbert comic for "):
            d = imageDisplayName.split(" ")[-1].split("-")
            imageDisplayName = "Dilbert Comic for {}-{}-{}".format(
                d[1], d[2], d[0])

        # Download Image
        if not imageURL.lower().startswith("http"):
            imageURL = "https:" + imageURL
        await Message.Embed(title=imageDisplayName,
                            image=imageURL,
                            url=imageURL,
                            color=ctx.author).send(ctx)
コード例 #2
0
ファイル: Comic.py プロジェクト: skylarr1227/sky-cogs
    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.guild

        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 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 = "04-16-1989"

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

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

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

        # Got a comic link
        imageURL = ComicHelper.getImageURL(imageHTML)
        imageDisplayName = ComicHelper.getImageTitle(imageHTML)
        if imageDisplayName.lower().startswith("dilbert comic for "):
            d = imageDisplayName.split(" ")[-1].split("-")
            imageDisplayName = "Dilbert Comic for {}-{}-{}".format(
                d[1], d[2], d[0])

        # Download Image
        if not imageURL.lower().startswith("http"):
            imageURL = "https:" + imageURL
        await Message.Embed(title=imageDisplayName,
                            image=imageURL,
                            url=imageURL,
                            color=ctx.author).send(ctx)
コード例 #3
0
ファイル: Comic.py プロジェクト: Goldfish64/CorpBot.py
	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)
コード例 #4
0
ファイル: Comic.py プロジェクト: Siju21/discordbot
    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)