import got from "got";
import { logger } from "src/logging";
import { Command, ICommandData, Plugin } from "src/model/plugin";
import { tryDo } from "src/util";

@Plugin
export class Inspire {
    @Command({
        type: "mention",
        pattern: "inspire me", 
        documentation: {
            description: "Generates an inspiring quote just for you", 
            example: "inspire me"
        }
    })
    async inspire({ message }: ICommandData): Promise<void> {
        const result = await tryDo(got.get("https://inspirobot.me/api?generate=true"));
        if(!result.ok) {
            logger.error("Failed to get inspiration, error %s", result.error);
            await message.reply("sorry, couldn't get inspiration :(.");
            return;
        }

        const messagePostResult = await tryDo(message.reply("here is a piece of my wisdom:", {
            files: [ result.result.body ]
        }));
        if (!messagePostResult.ok) {
            logger.error("Failed to get inspiration, error %s", messagePostResult.error);
            await message.reply("sorry, couldn't get inspiration :(.");
        }
    }
}