<commit_before>import discord
import re
import xkcd
from discord.ext import commands
from sys import argv
from urllib.parse import urlparse

class xkcdparse:
    """
    xkcd parser.
    """
    def __init__(self, bot):
        self.bot = bot
        print('Addon "{}" loaded'.format(self.__class__.__name__))

    async def embed_xkcd_comic(self, comicnum):
        comic = xkcd.getComic(comicnum)
        embed = discord.Embed(title="{}: {}".format(comicnum, comic.getTitle()), url="https://xkcd.com/{}".format(comicnum), color=discord.Color.blue())
        embed.set_image(url=comic.getImageLink())
        embed.set_footer(text=comic.getAltText())
        return embed

    @commands.command()
    async def xkcd(self, comicnum):
        """Show xkcd comic by number. Use "latest" to show the latest comic."""
        if comicnum == "latest":
            await self.bot.say("", embed=await self.embed_xkcd_comic(xkcd.getLatestComicNum()))
        else:
            await self.bot.say("", embed=await self.embed_xkcd_comic(comicnum))

    async def on_message(self, message):
        # http://stackoverflow.com/questions/839994/extracting-a-url-in-python
        urls = re.findall(r'(https?://\S+)', message.content)
        for url in urls:
            ps = urlparse(url)
            if ps.netloc == "xkcd.com" or ps.netloc == "www.xkcd.com":
                comicnum = ps.path.replace('/', '')
                await self.bot.send_message(message.channel, embed=await self.embed_xkcd_comic(comicnum))

def setup(bot):
    bot.add_cog(xkcdparse(bot))<commit_msg>.xkcd can show random comic<commit_after>import discord
import re
import xkcd
from discord.ext import commands
from sys import argv
from urllib.parse import urlparse

class xkcdparse:
    """
    xkcd parser.
    """
    def __init__(self, bot):
        self.bot = bot
        print('Addon "{}" loaded'.format(self.__class__.__name__))

    async def embed_xkcd_comic(self, comic):
        embed = discord.Embed(title="{}: {}".format(comic.number, comic.getTitle()), url="https://xkcd.com/{}".format(comic.number), color=discord.Color.blue())
        embed.set_image(url=comic.getImageLink())
        embed.set_footer(text=comic.getAltText())
        return embed

    @commands.command()
    async def xkcd(self, comicnum):
        """Show xkcd comic by number. Use "latest" to show the latest comic."""
        if comicnum == "latest":
            await self.bot.say("", embed=await self.embed_xkcd_comic(xkcd.getLatestComic()))
        elif comicnum == "random":
            await self.bot.say("", embed=await self.embed_xkcd_comic(xkcd.getRandomComic()))
        else:
            await self.bot.say("", embed=await self.embed_xkcd_comic(xkcd.getComic(comicnum)))

    async def on_message(self, message):
        # http://stackoverflow.com/questions/839994/extracting-a-url-in-python
        urls = re.findall(r'(https?://\S+)', message.content)
        for url in urls:
            ps = urlparse(url)
            if ps.netloc == "xkcd.com" or ps.netloc == "www.xkcd.com":
                comicnum = ps.path.replace('/', '')
                await self.bot.send_message(message.channel, embed=await self.embed_xkcd_comic(xkcd.getComic(comicnum)))

def setup(bot):
    bot.add_cog(xkcdparse(bot))
{'fraction_non_alphanumeric': 0.14276960784313725, 'fraction_numerical': 0.003676470588235294, 'mean_word_length': 2.9242788461538463, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4780545', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1097, 'n_words': 214}