<commit_before>import praw
from discord.ext import commands


class Reddit:
    """Class for reddit functions and commands."""
    def __init__(self, bot):
        self.client = bot
        self.prawclient = praw.Reddit(client_id=bot.rid,
                                      client_secret=bot.rsc,
                                      user_agent="dave:v104:t3rr0r_f3rr3t")
        self.fstr = "Image: {}\nTitle = {}\nComments = https://redd.it/{}\n"

    def prawin(self, sub, sort, time="day"):
        """Praw-Based function, reads from reddit.
           Always returns top/first post for given sort.
        """
        subreddit = self.prawclient.subreddit(str(sub))
        prop = {"title": "", "img": "", "id": "", "adult": subreddit.over18}
        if sort == "top":
            posts = subreddit.top(time, limit=1)
        elif sort == "new":
            posts = subreddit.new(limit=1)
        elif sort == "rising":
            posts = subreddit.rising(limit=1)
        elif sort == "hot":
            posts = subreddit.hot(limit=1)
        for post in posts:
            prop["title"] = str(post.title)
            prop["img"] = str(post.url)
            prop["id"] = str(post.id)
        return prop

    def nsfwGuard(self, post, channelname):
        """Provides nsfw guard."""
        if post["adult"]:
            if "nsfw" in channelname:
                return self.fstr.format(post["img"],
                                        post["title"],
                                        post["id"])
            else:
                return "E: Subreddit is NSFW, but command is from SFW channel."
        else:
            return self.fstr.format(post["img"],
                                    post["title"],
                                    post["id"])

    @commands.command(pass_context=True)
    async def reddit(self, ctx, sub: str, sort: str):
        """Gets first post in <sub>, sorted by <sort>.
           If sort is top, time limit is day.
           Valid sorts are:
           top, new, rising, hot.
           If the subreddit is 18+, bot will not post in channels without
           "nsfw" in their name.
        """
        msg = await self.client.say("Getting post.")
        post = self.prawin(sub, sort)
        reply = self.nsfwGuard(post, ctx.message.channel.name)<commit_msg>Make !reddit run inside of a loop executor.<commit_after>import praw
from discord.ext import commands


class Reddit:
    """Class for reddit functions and commands."""
    def __init__(self, bot):
        self.client = bot
        self.prawclient = praw.Reddit(client_id=bot.rid,
                                      client_secret=bot.rsc,
                                      user_agent="dave:testing:t<PASSWORD>")
        self.fstr = "Image: {}\nTitle = {}\nComments = https://redd.it/{}\n"

    def prawin(self, sub, sort, time="day"):
        """Praw-Based function, reads from reddit.
           Always returns top/first post for given sort.
        """
        subreddit = self.prawclient.subreddit(str(sub))
        prop = {"title": "", "img": "", "id": "", "adult": subreddit.over18}
        if sort == "top":
            posts = subreddit.top(time, limit=1)
        elif sort == "new":
            posts = subreddit.new(limit=1)
        elif sort == "rising":
            posts = subreddit.rising(limit=1)
        elif sort == "hot":
            posts = subreddit.hot(limit=1)
        for post in posts:
            prop["title"] = str(post.title)
            prop["img"] = str(post.url)
            prop["id"] = str(post.id)
        return prop

    def nsfwGuard(self, post, channelname):
        """Provides nsfw guard."""
        if post["adult"]:
            if "nsfw" in channelname:
                return self.fstr.format(post["img"],
                                        post["title"],
                                        post["id"])
            else:
                return "E: Subreddit is NSFW, but command is from SFW channel."
        else:
            return self.fstr.format(post["img"],
                                    post["title"],
                                    post["id"])

    @commands.command(pass_context=True)
    async def reddit(self, ctx, sub: str, sort: str):
        """Gets first post in <sub>, sorted by <sort>.
           If sort is top, time limit is day.
           Valid sorts are:
           top, new, rising, hot.
           If the subreddit is 18+, bot will not post in channels without
           "nsfw" in their name.
        """
        msg = await self.client.say("Getting post.")
        post = await self.client.loop.run_in_executor(None,
                                                      self.prawin,
                                                      sub,
                                                      sort)
        reply = await self.client.loop.run_in_executor(None,
                                                       self.nsfwGuard,
                                                       post,
                                                       ctx.message.channel.name)
{'fraction_non_alphanumeric': 0.11817824892029839, 'fraction_numerical': 0.004515115822536317, 'mean_word_length': 1.3852996254681649, 'pattern_counts': {'":': 16, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '198528', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1344, 'n_words': 368}