@xiaozhedesu/koishi-plugin-ohayo
Version:
211 lines (207 loc) • 8.03 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
Config: () => Config,
apply: () => apply,
logger: () => logger,
name: () => name
});
module.exports = __toCommonJS(src_exports);
var import_koishi = require("koishi");
// src/Tools.ts
var Tools;
((Tools2) => {
function getRandomInt(min, max) {
if (min > max) {
let tmp = min;
min = max;
max = tmp;
}
return Math.floor(Math.random() * (max - min + 1) + min);
}
Tools2.getRandomInt = getRandomInt;
__name(getRandomInt, "getRandomInt");
function roll(args) {
let length = args.length;
return args[getRandomInt(0, length - 1)];
}
Tools2.roll = roll;
__name(roll, "roll");
function deleteSelfAdd(content, id) {
const startIndex = content.indexOf("<at");
const endIndex = content.indexOf("/>");
if (startIndex !== -1 && endIndex !== -1) {
const startIdIndex = content.indexOf('id="');
const endIdIndex = content.indexOf('" ') === -1 ? content.indexOf('"/') : content.indexOf('" ');
if (startIdIndex !== -1 && endIdIndex !== -1 && content.substring(startIdIndex + 4, endIdIndex) === id) {
content = content.substring(endIndex + 3);
}
}
return content;
}
Tools2.deleteSelfAdd = deleteSelfAdd;
__name(deleteSelfAdd, "deleteSelfAdd");
})(Tools || (Tools = {}));
// src/index.ts
var name = "ohayo";
var logger = new import_koishi.Logger("ohayo");
var Config = import_koishi.Schema.object({});
var ohayo = ["ohayo", "哦哈哟", "早", "早安呀", "你也早", "早上好", "早尚郝"];
var aisatsuURL = "https://api.lolimi.cn/API/image-zw/api.php";
var ohayoMemo = {};
function isOhayo(message) {
const ohayoMessage = ["早", "早上好", "ohayo", "哦哈哟", "zao", "起床", "起了"];
return ohayoMessage.indexOf(message) !== -1;
}
__name(isOhayo, "isOhayo");
function isOyasumi(message) {
const oyasumiMessage = ["晚", "wan", "oyasumi", "哦呀斯密", "睡觉", "睡了", "眠了"];
return oyasumiMessage.indexOf(message) !== -1;
}
__name(isOyasumi, "isOyasumi");
var DailyTask;
((DailyTask2) => {
let clearOhayoData;
function init() {
const now = /* @__PURE__ */ new Date();
const time_6am = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 6, now.getMinutes(), now.getSeconds());
if (time_6am.getTime() < now.getTime()) {
time_6am.setDate(time_6am.getDate() + 1);
}
const diff_6am = time_6am.getTime() - now.getTime();
setTimeout(() => {
ohayoMemo = {};
clearOhayoData = setInterval(() => {
ohayoMemo = {};
}, 24 * 60 * 60 * 1e3);
}, diff_6am);
}
DailyTask2.init = init;
__name(init, "init");
function stop() {
clearInterval(clearOhayoData);
}
DailyTask2.stop = stop;
__name(stop, "stop");
})(DailyTask || (DailyTask = {}));
function apply(ctx, config) {
ctx.on("message", (session) => {
if (isOhayo(session.content)) {
session.execute("早安");
}
if (isOyasumi(session.content)) {
session.execute("晚安");
}
});
ctx.middleware((session, next) => {
session.content = Tools.deleteSelfAdd(session.content, session.bot.selfId);
return next();
}, true);
DailyTask.init();
ctx.on("dispose", () => {
DailyTask.stop();
});
ctx.command("早安").action(async ({ session }) => {
const now = /* @__PURE__ */ new Date();
const nowHour = now.getHours();
const nowMinute = now.getMinutes();
if (ohayoMemo[session.userId] === void 0) {
ohayoMemo[session.userId] = {
hasOhayo: true,
ohayoTime: now,
hasOyasumi: false,
oyasumiTime: /* @__PURE__ */ new Date()
};
} else if (ohayoMemo[session.userId].hasOhayo) {
return `今天你已经早安过了哦`;
}
let message = `${ohayo[Tools.getRandomInt(0, ohayo.length - 1)]},现在是北京时间${String(nowHour).padStart(2, "0")}:${String(nowMinute).padStart(2, "0")},你是今天第${Object.keys(ohayoMemo).length}个起床的哦。
`;
if (nowHour < 6) {
message += `你起得真早哇,或者你还没睡?不要熬夜哦`;
} else if (nowHour < 12) {
message += `祝你有一个愉快的早晨。`;
} else if (nowHour < 18) {
message += `都下午啦,起床后想做些什么呢`;
} else {
message += `已经是晚上了,这么晚起床是想直接睡觉吗`;
}
session.send(message);
if (nowHour >= 6 && nowHour < 12) {
session.send(await (0, import_koishi.h)("image", { src: aisatsuURL }));
}
});
ctx.command("晚安").action(async ({ session }) => {
const now = /* @__PURE__ */ new Date();
const nowHour = now.getHours();
const nowMinute = now.getMinutes();
let wakeTime;
if (ohayoMemo[session.userId] === void 0) {
return `你还没有早安哦,先道早安吧`;
} else if (ohayoMemo[session.userId].hasOyasumi) {
return `今天你已经晚安过了哦`;
} else {
ohayoMemo[session.userId].hasOyasumi = true;
ohayoMemo[session.userId].oyasumiTime = now;
wakeTime = Math.ceil((ohayoMemo[session.userId].oyasumiTime.getTime() - ohayoMemo[session.userId].ohayoTime.getTime()) / 1e3);
}
let message = `晚安,现在是北京时间${String(nowHour).padStart(2, "0")}:${String(nowMinute).padStart(2, "0")},`;
message += `你今日的清醒时间为${Math.floor(wakeTime / 60 / 60)}时${Math.floor(wakeTime / 60 % 60)}分${wakeTime % 60}秒,`;
if (nowHour < 6) {
message += `下次别熬夜了哦`;
} else if (nowHour < 12) {
message += `这个点道晚安,你不会是选在上课时间睡觉吧`;
} else if (nowHour < 18) {
message += `现在作为睡觉时间稍微有点早了,你没有什么想做的事了吗`;
} else if (nowHour >= 18) {
message += `要保持精致睡眠哦`;
}
session.send(message);
if (nowHour >= 18 || nowHour < 6) {
session.send(await (0, import_koishi.h)("image", { src: aisatsuURL }));
}
});
ctx.command("报时", "回复当前时间").usage("使用北京时间").action(({ session }) => {
const now = /* @__PURE__ */ new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
const date = now.getDate();
const day = ["日", "一", "二", "三", "四", "五", "六"][now.getDay()];
const hour = now.getHours();
const minute = now.getMinutes();
return `现在是${year}年${month}月${date}日,星期${day},北京时间${hour}:${String(minute).padStart(2, "0")}。`;
});
ctx.command("帮我选 [..args]", "拿不定主意试试让bot帮你选吧").alias("roll").usage("将想要选择的选项使用空格隔开,bot将会随机选择其一,如果什么都不传则返回0-10之间的随机数").action(({ session }, ...args) => {
if (args.length === 0) {
return `这边建议您选择 ${Tools.getRandomInt(1, 10)} 呢`;
}
return `这边建议您选择 ${Tools.roll(args)} 呢`;
});
logger.info("open success");
}
__name(apply, "apply");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Config,
apply,
logger,
name
});