{"size": 2392, "ext": "js", "max_stars_repo_path": "src/main.js", "max_stars_repo_name": "ConchbrainClub/GroupBot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main.js", "max_issues_repo_name": "ConchbrainClub/GroupBot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main.js", "max_forks_repo_name": "ConchbrainClub/GroupBot", "max_forks_repo_forks_event_min_datetime": "2021-01-16T13:14:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-16T13:14:08.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.0, "max_line_length": 86, "alphanum_fraction": 0.5280100334}
const { createClient } = require("oicq");
const fs = require("fs");

let info = JSON.parse(fs.readFileSync("config.json"));
let currentUser = new Array();

const bot = createClient(info.account);

bot.on("system.login.slider", () => {
    process.stdin.once("data", input => {
        bot.sliderLogin(input);
    });
});

bot.on("message", data => {

    if (!data.group_id) {
        return;
    }

    currentUser.forEach((user) => {
        if (user.id == data.sender.user_id) {
            
            let index = currentUser.indexOf(user);
            currentUser.splice(index, 1);

            if (new Date().getTime() < user.expires) {
                handlerMessage(data);
                return;
            }
        }
    });

    let pattern = /\[(.*)]/;
    let info = pattern.exec(data.raw_message)[0];
    if (info.includes("@ConchBrainBot")) {
        handlerMessage(data, info);
    }

});

function handlerMessage(data, info) {
    console.log(data);
    let flag = false;
    currentUser.forEach((user) => {
        if(user.id == data.sender.user_id)
            flag = true;
    });

    if (!flag)
        currentUser.push({
            "id": data.sender.user_id,
            "expires": new Date().getTime() + 1000 * 60
        });

    let message = data.raw_message.replace(info, "").trim();

    if (new RegExp("再见|拜拜").test(message)) {
        currentUser.forEach((user) => {
            if (user.id == data.sender.user_id) {
                let index = currentUser.indexOf(user);
                currentUser.splice(index, 1);
                return;
            }
        });
        bot.sendGroupMsg(data.group_id, "拜拜" + data.sender.nickname);
        return;
    }

    let pluginConfigs = JSON.parse(fs.readFileSync("./src/pattern.json").toString());
    pluginConfigs.forEach((config) => {

        if (new RegExp(config.pattern).test(message)) {

            let plugin = require("./plugins/" + config.plugin);

            if (!plugin) {
                let index = pluginConfigs.indexOf(config.plugin);
                pluginConfigs.splice(index, 1);
                fs.writeFileSync("./src/pattern.json", JSON.stringify(pluginConfigs));
                return;
            }

            plugin.exec(data.sender, message, (replay) => {
                bot.sendGroupMsg(data.group_id, replay);
            });

        }
    });
}

bot.login(info.password);