{"size": 1529, "ext": "js", "max_stars_repo_path": "classes/message.js", "max_stars_repo_name": "AshyBoxy/discord-bread", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "classes/message.js", "max_issues_repo_name": "AshyBoxy/discord-bread", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classes/message.js", "max_forks_repo_name": "AshyBoxy/discord-bread", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.58, "max_line_length": 129, "alphanum_fraction": 0.5297580118}
const fetch = require("node-fetch");

const Channel = require("./channel");
const User = require("./user");

class Message {
    constructor(messageData, client) {
        this.client = client;
        this.content = messageData.content;
        this.id = messageData.id;
        this.channel = messageData.channel_id;
        this.user = new User(messageData.author, client);
        this.sendChannel = async (message) => {
            let data = await fetch(`https://discordapp.com/api/v6/channels/${messageData.channel_id}/messages`, {
                "method": "POST", "body": JSON.stringify({
                    "content": message
                }),
                headers: { "Content-Type": "application/json", "Authorization": `Bot ${client._token}` }
            });
            data = await data.json();
            return data;
        }
        this.react = async (emojiName, emojiId) => {
            let emoji = `${emojiName}:${emojiId}`;

            if (!emojiId) emoji = emojiName;

            emoji = require("querystring").escape(emoji);

            await fetch(`https://discordapp.com/api/v6/channels/${this.channel.id}/messages/${this.id}/reactions/${emoji}/@me`, {
                "method": "PUT",
                "headers": {
                    "Authorization": `Bot ${client._token}`
                }
            });

            return;
        }

    }

    async init() {
        this.channel = await this.client.getChannel(this.channel);
        return true;
    }

}

module.exports = Message;
