koishi-plugin-cocoyyy-console 1.0.8 → 1.0.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -322,10 +322,7 @@ function getMenuList(command = null, functionConfig) {
|
|
|
322
322
|
case "rbq":
|
|
323
323
|
if (!functionConfig.rbq_flag)
|
|
324
324
|
return "*人功能已关闭";
|
|
325
|
-
return
|
|
326
|
-
*人功能菜单:
|
|
327
|
-
联系管理人员配置群内指定用户,在群内@指定用户,会触发*人功能
|
|
328
|
-
如果遇到问题请联系开发人员。`;
|
|
325
|
+
return getRbqFuncMenu(command);
|
|
329
326
|
default:
|
|
330
327
|
return `[所有命令都需要@bot]
|
|
331
328
|
当前可用功能列表:
|
|
@@ -383,6 +380,35 @@ function getTagFuncMenu(command = null) {
|
|
|
383
380
|
输入对应指令使用标签功能,如果遇到问题请联系开发人员。`;
|
|
384
381
|
}
|
|
385
382
|
__name(getTagFuncMenu, "getTagFuncMenu");
|
|
383
|
+
var rbqFuncMenuList = [
|
|
384
|
+
{
|
|
385
|
+
name: "rbqlist",
|
|
386
|
+
description: "查看rbq列表",
|
|
387
|
+
command: "rbqlist"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
name: "rbqadd",
|
|
391
|
+
description: "添加rbq (3个上限)",
|
|
392
|
+
command: "rbqadd [QQ号]"
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: "rbqinstead",
|
|
396
|
+
description: "替换已存在rbq",
|
|
397
|
+
command: "rbqinstead [已存在QQ号] [替换QQ号]"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: "rbqadd_txt",
|
|
401
|
+
description: "添加自定义文本",
|
|
402
|
+
command: "rbqadd_txt [文本] [目标QQ号(可选)]"
|
|
403
|
+
}
|
|
404
|
+
];
|
|
405
|
+
function getRbqFuncMenu(command = null) {
|
|
406
|
+
return `[所有命令都需要@bot]
|
|
407
|
+
*人功能菜单:
|
|
408
|
+
${rbqFuncMenuList.map((item) => item.command + ": " + item.description).join("\n ")}
|
|
409
|
+
输入对应指令使用*人功能,如果遇到问题请联系开发人员。`;
|
|
410
|
+
}
|
|
411
|
+
__name(getRbqFuncMenu, "getRbqFuncMenu");
|
|
386
412
|
function registerMenuCommands(ctx, connected, functionConfig) {
|
|
387
413
|
ctx.command("help <参数>", "帮助菜单").action(async ({ session }, ...args) => {
|
|
388
414
|
if (!dev_mode) {
|
|
@@ -866,32 +892,414 @@ function registerRepeatMiddleware(ctx, config) {
|
|
|
866
892
|
}
|
|
867
893
|
__name(registerRepeatMiddleware, "registerRepeatMiddleware");
|
|
868
894
|
|
|
869
|
-
// src/services/rbq_func/
|
|
895
|
+
// src/services/rbq_func/rbq_command.ts
|
|
870
896
|
var import_koishi8 = require("koishi");
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
897
|
+
|
|
898
|
+
// src/models/rbq_persons.ts
|
|
899
|
+
var import_sequelize5 = require("sequelize");
|
|
900
|
+
var RbqPersonModel = class extends import_sequelize5.Model {
|
|
901
|
+
static {
|
|
902
|
+
__name(this, "RbqPersonModel");
|
|
903
|
+
}
|
|
904
|
+
id;
|
|
905
|
+
guild_id;
|
|
906
|
+
uid_list;
|
|
907
|
+
createtime;
|
|
908
|
+
};
|
|
909
|
+
var inited3 = false;
|
|
910
|
+
function getRbqPersonModel() {
|
|
911
|
+
const sequelize2 = getSequelize();
|
|
912
|
+
if (!inited3) {
|
|
913
|
+
RbqPersonModel.init(
|
|
914
|
+
{
|
|
915
|
+
id: {
|
|
916
|
+
type: import_sequelize5.DataTypes.INTEGER.UNSIGNED,
|
|
917
|
+
allowNull: false,
|
|
918
|
+
autoIncrement: true,
|
|
919
|
+
primaryKey: true
|
|
920
|
+
},
|
|
921
|
+
guild_id: {
|
|
922
|
+
type: import_sequelize5.DataTypes.STRING(128),
|
|
923
|
+
allowNull: false
|
|
924
|
+
},
|
|
925
|
+
uid_list: {
|
|
926
|
+
type: import_sequelize5.DataTypes.STRING(128),
|
|
927
|
+
allowNull: false
|
|
928
|
+
},
|
|
929
|
+
createtime: {
|
|
930
|
+
type: import_sequelize5.DataTypes.DATE,
|
|
931
|
+
allowNull: false,
|
|
932
|
+
defaultValue: import_sequelize5.DataTypes.NOW,
|
|
933
|
+
field: "createtime",
|
|
934
|
+
set(value) {
|
|
935
|
+
if (typeof value === "number") {
|
|
936
|
+
const ts = value > 1e12 ? value : value * 1e3;
|
|
937
|
+
this.setDataValue("createtime", new Date(ts));
|
|
938
|
+
} else {
|
|
939
|
+
this.setDataValue("createtime", value);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
sequelize: sequelize2,
|
|
946
|
+
tableName: "rbq_persons",
|
|
947
|
+
modelName: "RbqPerson",
|
|
948
|
+
timestamps: false,
|
|
949
|
+
underscored: false
|
|
950
|
+
}
|
|
951
|
+
);
|
|
952
|
+
inited3 = true;
|
|
953
|
+
}
|
|
954
|
+
return RbqPersonModel;
|
|
955
|
+
}
|
|
956
|
+
__name(getRbqPersonModel, "getRbqPersonModel");
|
|
957
|
+
|
|
958
|
+
// src/services/rbq_func/rbq_service.ts
|
|
959
|
+
var import_sequelize7 = require("sequelize");
|
|
960
|
+
|
|
961
|
+
// src/models/rbq_content.ts
|
|
962
|
+
var import_sequelize6 = require("sequelize");
|
|
963
|
+
var RbqContentModel = class extends import_sequelize6.Model {
|
|
964
|
+
static {
|
|
965
|
+
__name(this, "RbqContentModel");
|
|
966
|
+
}
|
|
967
|
+
id;
|
|
968
|
+
guild_id;
|
|
969
|
+
content;
|
|
970
|
+
tag_uid;
|
|
971
|
+
createtime;
|
|
972
|
+
};
|
|
973
|
+
var inited4 = false;
|
|
974
|
+
function getRbqContentModel() {
|
|
975
|
+
const sequelize2 = getSequelize();
|
|
976
|
+
if (!inited4) {
|
|
977
|
+
RbqContentModel.init(
|
|
978
|
+
{
|
|
979
|
+
id: {
|
|
980
|
+
type: import_sequelize6.DataTypes.INTEGER.UNSIGNED,
|
|
981
|
+
allowNull: false,
|
|
982
|
+
autoIncrement: true,
|
|
983
|
+
primaryKey: true
|
|
984
|
+
},
|
|
985
|
+
guild_id: {
|
|
986
|
+
type: import_sequelize6.DataTypes.STRING(128),
|
|
987
|
+
allowNull: false
|
|
988
|
+
},
|
|
989
|
+
content: {
|
|
990
|
+
type: import_sequelize6.DataTypes.STRING(512),
|
|
991
|
+
allowNull: false
|
|
992
|
+
},
|
|
993
|
+
tag_uid: {
|
|
994
|
+
type: import_sequelize6.DataTypes.STRING(128),
|
|
995
|
+
allowNull: true
|
|
996
|
+
},
|
|
997
|
+
createtime: {
|
|
998
|
+
type: import_sequelize6.DataTypes.DATE,
|
|
999
|
+
allowNull: false,
|
|
1000
|
+
defaultValue: import_sequelize6.DataTypes.NOW,
|
|
1001
|
+
field: "createtime",
|
|
1002
|
+
set(value) {
|
|
1003
|
+
if (typeof value === "number") {
|
|
1004
|
+
const ts = value > 1e12 ? value : value * 1e3;
|
|
1005
|
+
this.setDataValue("createtime", new Date(ts));
|
|
1006
|
+
} else {
|
|
1007
|
+
this.setDataValue("createtime", value);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
sequelize: sequelize2,
|
|
1014
|
+
tableName: "rbq_content",
|
|
1015
|
+
modelName: "RbqContent",
|
|
1016
|
+
timestamps: false,
|
|
1017
|
+
underscored: false
|
|
1018
|
+
}
|
|
1019
|
+
);
|
|
1020
|
+
inited4 = true;
|
|
1021
|
+
}
|
|
1022
|
+
return RbqContentModel;
|
|
1023
|
+
}
|
|
1024
|
+
__name(getRbqContentModel, "getRbqContentModel");
|
|
1025
|
+
|
|
1026
|
+
// src/services/rbq_func/rbq_service.ts
|
|
1027
|
+
var personMap = /* @__PURE__ */ new Map();
|
|
1028
|
+
async function check_in_group(ctx, session, uid) {
|
|
1029
|
+
const bot = ctx.bots[session.uid] || Object.values(ctx.bots)[0];
|
|
1030
|
+
if (!bot) return { result: false, error: "未找到可用的机器人实例" };
|
|
1031
|
+
if (bot.platform !== "onebot") return { result: false, error: "当前平台不支持该操作" };
|
|
1032
|
+
try {
|
|
1033
|
+
const guildId = session.guildId;
|
|
1034
|
+
const memberList = await bot.getGuildMemberList(guildId);
|
|
1035
|
+
const members = memberList.data;
|
|
1036
|
+
if (!members?.length) {
|
|
1037
|
+
return { result: false, error: `群 ${guildId} 未获取到成员` };
|
|
1038
|
+
}
|
|
1039
|
+
const result = members.find((t) => t.user?.id === uid);
|
|
1040
|
+
if (!result) {
|
|
1041
|
+
return { result: false, error: `群 ${guildId} 未找到成员 ${uid}` };
|
|
1042
|
+
}
|
|
1043
|
+
return { result: true, error: null };
|
|
1044
|
+
} catch (err) {
|
|
1045
|
+
console.error(err);
|
|
1046
|
+
return { result: false, error: `检查群成员失败:${err.message}` };
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
__name(check_in_group, "check_in_group");
|
|
1050
|
+
function findPersonByUid(uid, guild_id) {
|
|
1051
|
+
const Rbq = getRbqPersonModel();
|
|
1052
|
+
return Rbq.findOne({
|
|
1053
|
+
where: {
|
|
1054
|
+
guild_id,
|
|
1055
|
+
[import_sequelize7.Op.or]: [
|
|
1056
|
+
{ uid_list: { [import_sequelize7.Op.like]: `%${uid}%` } }
|
|
1057
|
+
]
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
__name(findPersonByUid, "findPersonByUid");
|
|
1062
|
+
function findGuildRecord(guild_id) {
|
|
1063
|
+
const Rbq = getRbqPersonModel();
|
|
1064
|
+
return Rbq.findOne({
|
|
1065
|
+
where: {
|
|
1066
|
+
guild_id
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
__name(findGuildRecord, "findGuildRecord");
|
|
1071
|
+
async function init_person() {
|
|
1072
|
+
try {
|
|
1073
|
+
const Rbq = getRbqPersonModel();
|
|
1074
|
+
const existed = await Rbq.findAll();
|
|
1075
|
+
if (!existed) return;
|
|
1076
|
+
existed.forEach(async (item) => {
|
|
1077
|
+
const guild_id = item.get("guild_id");
|
|
1078
|
+
const uid_list = item.get("uid_list");
|
|
1079
|
+
personMap.set(guild_id, uid_list.split(";"));
|
|
1080
|
+
});
|
|
1081
|
+
return true;
|
|
1082
|
+
} catch (e) {
|
|
1083
|
+
logger.error("[init_person Error]: " + e?.message || String(e));
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
__name(init_person, "init_person");
|
|
1088
|
+
async function create_person(guild_id, uid) {
|
|
1089
|
+
try {
|
|
1090
|
+
const Rbq = getRbqPersonModel();
|
|
1091
|
+
let existed = await findPersonByUid(uid, guild_id);
|
|
1092
|
+
if (existed) {
|
|
1093
|
+
throw new Error("already existed!");
|
|
1094
|
+
}
|
|
1095
|
+
let guildRecord = await findGuildRecord(guild_id);
|
|
1096
|
+
if (guildRecord) {
|
|
1097
|
+
let uidList = guildRecord.get("uid_list");
|
|
1098
|
+
if (uidList != null) {
|
|
1099
|
+
const list = uidList.split(";");
|
|
1100
|
+
if (list.length >= 3) {
|
|
1101
|
+
return { result: false, error: "已满,需要替换已有rbq!" };
|
|
1102
|
+
}
|
|
1103
|
+
if (!list.includes(uid)) list.push(uid);
|
|
1104
|
+
uidList = list.join(";");
|
|
1105
|
+
} else {
|
|
1106
|
+
uidList = uid;
|
|
1107
|
+
}
|
|
1108
|
+
guildRecord.set("uid_list", uidList);
|
|
1109
|
+
await guildRecord.save();
|
|
1110
|
+
personMap.set(guild_id, uidList.split(";"));
|
|
1111
|
+
return { result: true, error: null };
|
|
1112
|
+
} else {
|
|
1113
|
+
const now = new Date(Date.now() + 8 * 60 * 60 * 1e3);
|
|
1114
|
+
guildRecord = await Rbq.create({
|
|
1115
|
+
guild_id,
|
|
1116
|
+
uid_list: uid,
|
|
1117
|
+
createtime: now
|
|
1118
|
+
});
|
|
1119
|
+
personMap.set(guild_id, [uid]);
|
|
1120
|
+
}
|
|
1121
|
+
return { result: true, error: null };
|
|
1122
|
+
} catch (e) {
|
|
1123
|
+
logger.error("[create_rbq Error]: " + e?.message || String(e));
|
|
1124
|
+
return { result: false, error: e?.message || String(e) };
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
__name(create_person, "create_person");
|
|
1128
|
+
async function get_person_list(guild_id) {
|
|
1129
|
+
const Rbq = getRbqPersonModel();
|
|
1130
|
+
try {
|
|
1131
|
+
const existed = await findGuildRecord(guild_id);
|
|
1132
|
+
if (!existed) {
|
|
1133
|
+
throw new Error("not found record in " + guild_id);
|
|
1134
|
+
}
|
|
1135
|
+
return existed.get("uid_list").split(";");
|
|
1136
|
+
} catch (e) {
|
|
1137
|
+
logger.error("[get_rbq_list Error]: " + e?.message || String(e));
|
|
1138
|
+
return [];
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
__name(get_person_list, "get_person_list");
|
|
1142
|
+
async function instead_person(guild_id, source_uid, target_uid) {
|
|
1143
|
+
try {
|
|
1144
|
+
const Rbq = getRbqPersonModel();
|
|
1145
|
+
const existed = await findGuildRecord(guild_id);
|
|
1146
|
+
if (!existed) {
|
|
1147
|
+
throw new Error("not found record in " + guild_id);
|
|
1148
|
+
}
|
|
1149
|
+
let uidList = existed.get("uid_list");
|
|
1150
|
+
if (uidList == null) {
|
|
1151
|
+
throw new Error("not found source_uid in " + guild_id);
|
|
1152
|
+
}
|
|
1153
|
+
let list = uidList.split(";");
|
|
1154
|
+
if (!list.includes(source_uid)) {
|
|
1155
|
+
throw new Error("not found source_uid in " + guild_id);
|
|
1156
|
+
}
|
|
1157
|
+
uidList = uidList.replaceAll(source_uid, target_uid);
|
|
1158
|
+
existed.set("uid_list", uidList);
|
|
1159
|
+
await existed.save();
|
|
1160
|
+
personMap.set(guild_id, uidList.split(";"));
|
|
1161
|
+
return { result: true, error: null };
|
|
1162
|
+
} catch (e) {
|
|
1163
|
+
logger.error("[instead_person Error]: " + e?.message || String(e));
|
|
1164
|
+
return { result: false, error: e?.message || String(e) };
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
__name(instead_person, "instead_person");
|
|
1168
|
+
function get_person_map() {
|
|
1169
|
+
return personMap;
|
|
1170
|
+
}
|
|
1171
|
+
__name(get_person_map, "get_person_map");
|
|
1172
|
+
async function create_content(guild_id, content, tar_uid) {
|
|
1173
|
+
try {
|
|
1174
|
+
const RbqContent = getRbqContentModel();
|
|
1175
|
+
const now = new Date(Date.now() + 8 * 60 * 60 * 1e3);
|
|
1176
|
+
let contentRecord = await RbqContent.create({
|
|
1177
|
+
guild_id,
|
|
1178
|
+
content,
|
|
1179
|
+
tag_uid: tar_uid,
|
|
1180
|
+
createtime: now
|
|
1181
|
+
});
|
|
1182
|
+
return { result: true, error: null };
|
|
1183
|
+
} catch (e) {
|
|
1184
|
+
logger.error("[create_content Error]: " + e?.message || String(e));
|
|
1185
|
+
return { result: false, error: e?.message || String(e) };
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
__name(create_content, "create_content");
|
|
1189
|
+
async function get_content_list(guild_id, tar_uid) {
|
|
1190
|
+
try {
|
|
1191
|
+
const RbqContent = getRbqContentModel();
|
|
1192
|
+
const existed = await RbqContent.findAll({
|
|
1193
|
+
where: {
|
|
1194
|
+
guild_id,
|
|
1195
|
+
tag_uid: null
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
let result_list = [];
|
|
1199
|
+
result_list.push(...existed.map((item) => item.get("content")).filter(Boolean));
|
|
1200
|
+
if (tar_uid) {
|
|
1201
|
+
const tar_existed = await RbqContent.findAll({
|
|
1202
|
+
where: {
|
|
1203
|
+
guild_id,
|
|
1204
|
+
tag_uid: tar_uid
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
result_list.push(...tar_existed.map((item) => item.get("content")).filter(Boolean));
|
|
1208
|
+
}
|
|
1209
|
+
return result_list;
|
|
1210
|
+
} catch (e) {
|
|
1211
|
+
logger.error("[get_content_list Error]: " + e?.message || String(e));
|
|
1212
|
+
return [];
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
__name(get_content_list, "get_content_list");
|
|
1216
|
+
|
|
1217
|
+
// src/services/rbq_func/rbq_command.ts
|
|
1218
|
+
function registerRbqCommands(ctx, connected) {
|
|
1219
|
+
init_person();
|
|
1220
|
+
ctx.command("rbqlist", "查看rbq列表").action(async ({ session }, ...args) => {
|
|
1221
|
+
if (!dev_mode) {
|
|
1222
|
+
if (!connected) return;
|
|
1223
|
+
if (!is_at_bot(session)) return;
|
|
1224
|
+
}
|
|
1225
|
+
const list = await get_person_list(session.guildId);
|
|
1226
|
+
return `当前群聊rbq列表:
|
|
1227
|
+
${list.join(",")}`;
|
|
1228
|
+
});
|
|
1229
|
+
ctx.command("rbqadd <参数>", "添加rbq").action(async ({ session }, ...args) => {
|
|
1230
|
+
if (!dev_mode) {
|
|
1231
|
+
if (!connected) return;
|
|
1232
|
+
if (!is_at_bot(session)) return;
|
|
1233
|
+
}
|
|
1234
|
+
const uid = args?.[0];
|
|
1235
|
+
if (!uid) return "请提供正确格式,如:@bot rbqadd [QQ号]";
|
|
1236
|
+
let exec = await check_in_group(ctx, session, uid);
|
|
1237
|
+
if (!exec.result)
|
|
1238
|
+
return `${uid}不在当前群聊中`;
|
|
1239
|
+
exec = await create_person(session.guildId, uid);
|
|
1240
|
+
if (!exec.result)
|
|
1241
|
+
return `添加rbq失败:${exec.error}`;
|
|
1242
|
+
return `已添加rbq:${uid}`;
|
|
1243
|
+
});
|
|
1244
|
+
ctx.command("rbqinstead <参数>", "替换rbq").action(async ({ session }, ...args) => {
|
|
1245
|
+
if (!dev_mode) {
|
|
1246
|
+
if (!connected) return;
|
|
1247
|
+
if (!is_at_bot(session)) return;
|
|
1248
|
+
}
|
|
1249
|
+
const source_uid = args?.[0];
|
|
1250
|
+
const target_uid = args?.[1];
|
|
1251
|
+
if (!source_uid || !target_uid) return "请提供正确格式,如:@bot rbqinstead [已存在QQ号] [替换QQ号]";
|
|
1252
|
+
let exec = await check_in_group(ctx, session, target_uid);
|
|
1253
|
+
if (!exec.result)
|
|
1254
|
+
return `${target_uid}不在当前群聊中`;
|
|
1255
|
+
exec = await instead_person(session.guildId, source_uid, target_uid);
|
|
1256
|
+
if (!exec.result)
|
|
1257
|
+
return `替换rbq失败:${exec.error}`;
|
|
1258
|
+
return `已替换rbq:${source_uid} -> ${target_uid}`;
|
|
1259
|
+
});
|
|
1260
|
+
ctx.command("rbqadd_txt <参数>", "添加自定义文本").action(async ({ session }, ...args) => {
|
|
1261
|
+
if (!dev_mode) {
|
|
1262
|
+
if (!connected) return;
|
|
1263
|
+
if (!is_at_bot(session)) return;
|
|
1264
|
+
}
|
|
1265
|
+
const content = args?.[0];
|
|
1266
|
+
const target_uid = args?.[1] ?? null;
|
|
1267
|
+
if (!content) return "请提供正确格式,如:@bot rbqadd_txt [文本] [目标QQ号(可选)]";
|
|
1268
|
+
let exec = await check_in_group(ctx, session, target_uid);
|
|
1269
|
+
if (!exec.result)
|
|
1270
|
+
return `${target_uid}不在当前群聊中`;
|
|
1271
|
+
exec = await create_content(session.guildId, content, target_uid);
|
|
1272
|
+
if (!exec.result)
|
|
1273
|
+
return `添加自定义文本失败:${exec.error}`;
|
|
1274
|
+
return "已添加自定义文本";
|
|
1275
|
+
});
|
|
1276
|
+
ctx.middleware(async (session, next) => {
|
|
874
1277
|
const { guildId, elements } = session;
|
|
875
1278
|
if (ctx.bots[session.uid]) return next();
|
|
876
|
-
|
|
1279
|
+
const personMap2 = get_person_map();
|
|
1280
|
+
const rbqList = personMap2.get(guildId);
|
|
1281
|
+
if (!rbqList || rbqList.length === 0) return next();
|
|
877
1282
|
const atElements = elements?.filter((el) => el.type === "at") || [];
|
|
878
1283
|
if (atElements.length === 0) return next();
|
|
879
|
-
const
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1284
|
+
const matchedUid = atElements.find((el) => {
|
|
1285
|
+
const targetUid = el.attrs?.id;
|
|
1286
|
+
return targetUid && rbqList.includes(targetUid);
|
|
1287
|
+
})?.attrs?.id;
|
|
1288
|
+
if (!matchedUid) return next();
|
|
1289
|
+
try {
|
|
1290
|
+
const contents = await get_content_list(guildId, matchedUid);
|
|
1291
|
+
if (contents && contents.length > 0) {
|
|
1292
|
+
const random = new import_koishi8.Random(() => Math.random());
|
|
1293
|
+
let result = contents[random.int(0, contents.length)];
|
|
1294
|
+
session.send((0, import_koishi8.h)("at", { id: matchedUid }) + " " + result);
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
} catch (error) {
|
|
1298
|
+
logger.error("[rbq middleware] Error:", error);
|
|
1299
|
+
}
|
|
892
1300
|
});
|
|
893
1301
|
}
|
|
894
|
-
__name(
|
|
1302
|
+
__name(registerRbqCommands, "registerRbqCommands");
|
|
895
1303
|
|
|
896
1304
|
// src/services/test_command.ts
|
|
897
1305
|
function registerTestCommands(ctx) {
|
|
@@ -925,8 +1333,8 @@ var Config = import_koishi9.Schema.object({
|
|
|
925
1333
|
function_config: FunctionConfigSchema.description("功能开关配置"),
|
|
926
1334
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
927
1335
|
tag_config: SaveConfigSchema.description("tag图片保存配置"),
|
|
928
|
-
repeat_config: RepeatConfigSchema.description("复读配置")
|
|
929
|
-
rbq_config:
|
|
1336
|
+
repeat_config: RepeatConfigSchema.description("复读配置")
|
|
1337
|
+
// rbq_config:my_config.RbqConfigSchema.description('*人配置')
|
|
930
1338
|
});
|
|
931
1339
|
var logger = new import_koishi9.Logger(name);
|
|
932
1340
|
var savePath = null;
|
|
@@ -939,6 +1347,8 @@ async function apply(ctx, config) {
|
|
|
939
1347
|
if (connected) {
|
|
940
1348
|
await getTagsModel().sync();
|
|
941
1349
|
await getImgsModel().sync();
|
|
1350
|
+
await getRbqPersonModel().sync();
|
|
1351
|
+
await getRbqContentModel().sync();
|
|
942
1352
|
}
|
|
943
1353
|
savePath = resolveTagBaseDir(config?.tag_config);
|
|
944
1354
|
registerMenuCommands(ctx, connected, config.function_config);
|
|
@@ -947,7 +1357,7 @@ async function apply(ctx, config) {
|
|
|
947
1357
|
if (config.function_config.repeat_flag)
|
|
948
1358
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
949
1359
|
if (config.function_config.rbq_flag)
|
|
950
|
-
|
|
1360
|
+
registerRbqCommands(ctx, connected);
|
|
951
1361
|
if (dev_mode)
|
|
952
1362
|
registerTestCommands(ctx);
|
|
953
1363
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Model, Optional } from 'sequelize';
|
|
2
|
+
export interface RbqContentAttributes {
|
|
3
|
+
id: number;
|
|
4
|
+
guild_id: string;
|
|
5
|
+
content: string;
|
|
6
|
+
tag_uid: string;
|
|
7
|
+
createtime: Date;
|
|
8
|
+
}
|
|
9
|
+
export type RbqContentCreationAttributes = Optional<RbqContentAttributes, 'id' | 'createtime'>;
|
|
10
|
+
export declare class RbqContentModel extends Model<RbqContentAttributes, RbqContentCreationAttributes> implements RbqContentAttributes {
|
|
11
|
+
id: number;
|
|
12
|
+
guild_id: string;
|
|
13
|
+
content: string;
|
|
14
|
+
tag_uid: string;
|
|
15
|
+
createtime: Date;
|
|
16
|
+
}
|
|
17
|
+
export declare function getRbqContentModel(): typeof RbqContentModel;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Model, Optional } from 'sequelize';
|
|
2
|
+
export interface RbqPersonAttributes {
|
|
3
|
+
id: number;
|
|
4
|
+
guild_id: string;
|
|
5
|
+
uid_list: string;
|
|
6
|
+
createtime: Date;
|
|
7
|
+
}
|
|
8
|
+
export type RbqPersonCreationAttributes = Optional<RbqPersonAttributes, 'id' | 'createtime'>;
|
|
9
|
+
export declare class RbqPersonModel extends Model<RbqPersonAttributes, RbqPersonCreationAttributes> implements RbqPersonAttributes {
|
|
10
|
+
id: number;
|
|
11
|
+
guild_id: string;
|
|
12
|
+
uid_list: string;
|
|
13
|
+
createtime: Date;
|
|
14
|
+
}
|
|
15
|
+
export declare function getRbqPersonModel(): typeof RbqPersonModel;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
import { Context } from 'koishi';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Context, Session } from 'koishi';
|
|
2
|
+
declare function check_in_group(ctx: Context, session: Session, uid: string): Promise<{
|
|
3
|
+
result: boolean;
|
|
4
|
+
error: string;
|
|
5
|
+
}>;
|
|
6
|
+
declare function init_person(): Promise<boolean>;
|
|
7
|
+
declare function create_person(guild_id: string, uid: string): Promise<{
|
|
8
|
+
result: boolean;
|
|
9
|
+
error: string;
|
|
10
|
+
}>;
|
|
11
|
+
declare function get_person_list(guild_id: string): Promise<string[]>;
|
|
12
|
+
declare function instead_person(guild_id: string, source_uid: string, target_uid: string): Promise<{
|
|
13
|
+
result: boolean;
|
|
14
|
+
error: string;
|
|
15
|
+
}>;
|
|
16
|
+
declare function get_person_map(): Map<string, string[]>;
|
|
17
|
+
declare function create_content(guild_id: string, content: string, tar_uid: string | null): Promise<{
|
|
18
|
+
result: boolean;
|
|
19
|
+
error: string;
|
|
20
|
+
}>;
|
|
21
|
+
declare function get_content_list(guild_id: string, tar_uid: string | null): Promise<string[]>;
|
|
22
|
+
export { init_person, check_in_group, create_person, get_person_list, instead_person, get_person_map, create_content, get_content_list };
|