{"size": 1311, "ext": "js", "max_stars_repo_path": "src/functions/auto_meme.js", "max_stars_repo_name": "Xx-Mohit-xX/Lota", "max_stars_repo_stars_event_min_datetime": "2021-09-29T09:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T05:03:09.000Z", "max_issues_repo_path": "src/functions/auto_meme.js", "max_issues_repo_name": "Xx-Mohit-xX/Lota", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/functions/auto_meme.js", "max_forks_repo_name": "Xx-Mohit-xX/Lota", "max_forks_repo_forks_event_min_datetime": "2021-09-28T18:02:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T09:42:38.000Z"}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 34.5, "max_line_length": 106, "alphanum_fraction": 0.5209763539}


const guilds = require(`../schemas/guild`)
const { Client, MessageEmbed } = require('discord.js')
const fetch = require("node-fetch")
/**
 * 
 * @param {Client} client
 */
module.exports = async (client) => {
   
        let subreddits = ["dankmemer","memes","meme"]
        const reddit = subreddits[Math.floor(Math.random() * subreddits.length)]
        const data = await fetch(`https://meme-api.herokuapp.com/gimme/${reddit}`).then(res => res.json())
        if(!data) return;
        const { title, url, postLink, nsfw, subreddit } = data
        const embed = new MessageEmbed()
        .setDescription(`**[${title}](${postLink})**`)
        .setImage(url)
        .setFooter(`Reddit: ${subreddit}`)
        .setColor("RANDOM")

        client.guilds.cache.forEach( async (g) => {
            const guild = await guilds.findOne({guildId: g.id})
            if(guild) {
                if(!guild.auto_meme) return;
                const channel = g.channels.cache.find(c => c.id === guild.auto_meme_channel)
                if(!channel) return;
                if(nsfw) {
                    if(!channel.nsfw) return;
                    channel.send({embeds: [embed]})
                } else {
                    channel.send({embeds: [embed]})
                }
            }
            
        })
}