<commit_before>const os = require("os");
const Plugin = require("../Plugin");

module.exports = class SetPicture extends Plugin {
    constructor(obj) {
        super(obj);

        this.auth = obj.auth;
    }

    static get plugin() {
        return {
            name: "SetPicture",
            description: "Sets the chat's picture.",
            help: "Send a picture with the caption /setpicture to set the chat's picture."
        };
    }

    get commands() {
        return {
            setpicture: () => "Send a picture with the caption /setpicture to set the chat's picture."
        };
    }

    onPhoto({message}) {
        if (!message.caption)
            return;
        if (message.caption !== "/setpicture")
            return;
        if (!this.auth.isMod(message.from.id, message.chat.id)) {
            this.sendMessage(message.chat.id, "Insufficient privileges.");
            return;
        }
        const fileId = message.photo[message.photo.length - 1].file_id;
        this.downloadFile(fileId, os.tmpdir())
            .then(path => this.setChatPhoto(message.chat.id, path))
            .catch(err => this.sendMessage(message.chat.id, "An error occurred:\n\n" + err));
    }
};<commit_msg>Add /setpicture in reply<commit_after>const os = require("os");
const Plugin = require("../Plugin");

module.exports = class SetPicture extends Plugin {
    constructor(obj) {
        super(obj);

        this.auth = obj.auth;
    }

    static get plugin() {
        return {
            name: "SetPicture",
            description: "Sets the chat's picture.",
            help: "Send a picture with the caption /setpicture to set the chat's picture."
        };
    }

    get commands() {
        return {
            setpicture: ({message}) => {
                if (!message.reply_to_message || !message.reply_to_message.photo)
                    return "Reply to a picture with the caption /setpicture to set the chat's picture.";
                if (!this.auth.isMod(message.from.id, message.chat.id))
                    return "Insufficient privileges.";
                this.setPhoto(message.reply_to_message);
            }
        };
    }

    setPhoto(message) {
        const fileId = message.photo[message.photo.length - 1].file_id;
        this.downloadFile(fileId, os.tmpdir())
            .then(path => this.setChatPhoto(message.chat.id, path))
            .catch(err => this.sendMessage(message.chat.id, "An error occurred:\n\n" + err));
    }

    onPhoto({message}) {
        if (!message.caption)
            return;
        if (!message.caption.startsWith("/setpicture"))
            return;
        if (!this.auth.isMod(message.from.id, message.chat.id)) {
            this.sendMessage(message.chat.id, "Insufficient privileges.");
            return;
        }
        this.setPhoto(message);
    }
};
{'fraction_non_alphanumeric': 0.13167134831460675, 'fraction_numerical': 0.0007022471910112359, 'mean_word_length': 1.9523316062176166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6479933', 'n_tokens_mistral': 818, 'n_tokens_neox': 781, 'n_words': 187}