package com.yutou.qqbot.models.Commands.System;

import com.yutou.napcat.QQDatabase;
import com.yutou.napcat.handle.Text;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.IdeaTools;
import com.yutou.qqbot.utlis.RedisTools;
import com.yutou.qqbot.utlis.StringUtils;
import com.yutou.napcat.event.MessageEvent;
@UseModel
public class ToolsIdea extends Model {
    @Override
    public boolean isUserPublic() {
        return false;
    }

    @Override
    public String[] getUsePowers() {
        return new String[]{
                QQGroupCommands.QQ_TOOLS_IDEA,
                QQGroupCommands.QQ_TOOLS_IDEA_FILE,
                QQGroupCommands.QQ_TOOLS_IDEA
        };
    }

    @Override
    public String getModelName() {
        return "获取idea激活码";
    }

    @Override
    public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
        super.onMessage(qq, event, isGroup);
        if (QQGroupCommands.QQ_TOOLS_IDEA.equals(msg)) {
            StringBuilder builder = new StringBuilder();
            if (StringUtils.isEmpty(RedisTools.get("ideaUrl"))) {
                builder.append("暂未设置IDEA激活码下载地址");
            } else {
                for (String name : IdeaTools.getIdeaList(RedisTools.get("ideaUrl"))) {
                    builder.append(QQGroupCommands.QQ_TOOLS_IDEA_FILE).append(name).append("\n");
                }
                if (builder.toString().trim().length() == 0) {
                    builder.append("激活码文件中未包含txt文件");
                }
            }
            QQBotManager.getInstance().sendMessage(qq, builder.toString());
        } else {
            if (msg.startsWith(QQGroupCommands.QQ_TOOLS_IDEA_URL)) {
                RedisTools.set("ideaUrl", msg.replace(QQGroupCommands.QQ_TOOLS_IDEA_URL, "").trim());
                QQBotManager.getInstance().sendMessage(qq, "已设定下载地址:" + RedisTools.get("ideaUrl"));
            } else if (msg.startsWith(QQGroupCommands.QQ_TOOLS_IDEA_FILE)) {
                QQBotManager.getInstance().sendMessage(event.isUser(),qq,
                        new Text(msg.replace(QQGroupCommands.QQ_TOOLS_IDEA_FILE, ""))
                        );
              //  QQBotManager.getInstance().sendMessage(qq, IdeaTools.getIdea(event.getMessage().contentToString().replace(QQGroupCommands.QQ_TOOLS_IDEA_FILE, "")));
            }
        }
    }
}
