Friday, September 20, 2024 1:39:49 AM
> settings

Customize


Authenticate

> birb.js
const ESMCommand = require("../esm_command");
const request = require("snekfetch");
module.exports = class ESMCommand_Birb extends ESMCommand {
    constructor(bot) {
        super(bot);

        this.information = {
            name: "birb",
            category: "fun",
            help: "Who doesn't like some high quality birbs?"
        };

        this.configuration = {
            allowedInTextChannels: {
                modifiable: true,
                default: true
            },
            cooldown: {
                modifiable: false,
                default: [5, "seconds"]
            }
        };
    }

    async fromDiscord() {
        try {
            let birbLink = "";
            let count = 0;
            while (this.util.isEmpty(birbLink) && count < 10000) {
                let ret = await request.get("http://www.reddit.com/r/birb/random.json");
                if (ret.ok) {
                    let link = ret.body[0].data.children[0].data.url;
                    if (!this.util.isEmpty(link) && /\.jpg$|\.png$|\.gif$|\.jpeg$/i.test(link)) {
                        birbLink = link;
                        break;
                    }
                }

                count++;
                await this.util.sleep(500);
            }

            if (this.util.isEmpty(birbLink)) {
                throw "Birb timeout";
            }

            this.message.channel.send({
                files: [{
                    attachment: birbLink
                }]
            });
        } catch (err) {
            this.ESMBot.send(this.message.channel, "Hmm... We ran into an error while catching some birbs. Please try again later");
            this.ESMBot.logger.error(err);
        }
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8