koishi-plugin-chatclip 0.0.0-stage → 1.0.0
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/dist/index.js +1 -0
- package/dist/style.css +1 -0
- package/lib/collect.d.ts +92 -0
- package/lib/commands.d.ts +9 -0
- package/lib/config.d.ts +31 -0
- package/lib/console.d.ts +60 -0
- package/lib/db.d.ts +141 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +1679 -0
- package/lib/render/html.d.ts +8 -0
- package/lib/render/index.d.ts +16 -0
- package/lib/render/text.d.ts +16 -0
- package/lib/types.d.ts +1 -0
- package/package.json +72 -4
- package/readme.md +136 -0
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{send as f,icons as ke}from"@koishijs/client";import{defineComponent as G,openBlock as c,createElementBlock as y,createElementVNode as a,ref as h,computed as q,reactive as be,onMounted as _e,resolveComponent as g,resolveDirective as we,createBlock as D,withCtx as i,createVNode as t,withKeys as J,createTextVNode as o,toDisplayString as u,withDirectives as he,Fragment as L,createCommentVNode as B,renderList as Y}from"vue";const Ce={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 512 512"},Ve=G({name:"BookmarksOutline",render:function($,C){return c(),y("svg",Ce,C[0]||(C[0]=[a("path",{d:"M128 80V64a48.14 48.14 0 0 1 48-48h224a48.14 48.14 0 0 1 48 48v368l-80-64",fill:"none",stroke:"currentColor","stroke-linejoin":"round","stroke-width":"32"},null,-1),a("path",{d:"M320 96H112a48.14 48.14 0 0 0-48 48v352l152-128l152 128V144a48.14 48.14 0 0 0-48-48z",fill:"none",stroke:"currentColor","stroke-linejoin":"round","stroke-width":"32"},null,-1)]))}}),xe={class:"page"},ze={class:"toolbar"},$e={class:"filters"},Se={class:"batchbar"},Ue={class:"hint"},Ne={class:"footer"},De={class:"meta"},Le={key:0,class:"degraded"},je={class:"message-head"},Ie={class:"ordinal"},Me={class:"role"},Oe={class:"sender"},Be={class:"time"},Re={class:"message-body"},Te={class:"attachments"},Ae=["href"],Ee=["src"],He={key:1,class:"file"},Ke=G({__name:"page",setup(z){const $=h(false),C=h([]),j=h(0),S=h(1),R=h(20),Q=h(null),V=h([]),U=q(()=>V.value.map(l=>l.id)),M=q(()=>V.value.filter(l=>l.deleted)),s=be({keyword:"",from:"",visibility:"all",deleted:"all",range:null}),O=h(false),p=h(null);function I(l){if(!l)return"";const e=new Date(l);if(isNaN(e.getTime()))return"";const d=r=>String(r).padStart(2,"0");return`${e.getFullYear()}-${d(e.getMonth()+1)}-${d(e.getDate())} ${d(e.getHours())}:${d(e.getMinutes())}`}function W(l){return l==="public"?"公开":l==="channel"?"本群可见":"仅自己"}function X(l){return l==="main"?"主消息":l==="quote"?"引用":"转发"}function Z(l){return l.type==="img"||l.type==="image"}function ee(l){return(l??"").replace(/\[(图片|视频|语音|文件)\]/g,"").replace(/[ \t]+/g," ").trim()||"[无文字内容]"}function le(l){return l.filename?l.filename:l.type==="file"?"[文件]":l.type==="video"?"[视频]":"[语音]"}async function k(){var l,e,d,r;$.value=true;try{const b=await f("chatclip/list",{keyword:s.keyword||void 0,from:s.from||void 0,visibility:s.visibility,deleted:s.deleted,start:(e=(l=s.range)==null?void 0:l[0])==null?void 0:e.toISOString(),end:(r=(d=s.range)==null?void 0:d[1])==null?void 0:r.toISOString(),page:S.value,pageSize:R.value});if(!b)return;C.value=b.items,j.value=b.total,V.value=[]}finally{$.value=false}}function te(l){V.value=l}function x(){S.value=1,k()}function ne(){s.keyword="",s.from="",s.visibility="all",s.deleted="all",s.range=null,x()}async function T(l){const e=await f("chatclip/get",l.id);e&&(p.value=e,O.value=true)}async function ae(l){await f("chatclip/remove",l.id),l.deleted=true,k()}async function ie(l){await f("chatclip/restore",l.id),l.deleted=false,k()}async function oe(l){var d;if(!l.deleted){alert("只有已经软删除的收藏才能硬删除。");return}if(!confirm(`硬删除 ${l.key}?消息与附件记录会一并删除,无法恢复。`))return;const e=await f("chatclip/purge",{ids:[l.id]});(d=e==null?void 0:e.ids)!=null&&d.length||alert("硬删除失败:这条收藏还不是软删除状态。"),k()}async function se(){U.value.length&&confirm(`把选中的 ${U.value.length} 条放进回收站?`)&&(await f("chatclip/removeMany",U.value),k())}async function de(){U.value.length&&(await f("chatclip/restoreMany",U.value),k())}async function re(){const l=M.value.map(e=>e.id);if(!l.length){alert("选中的行里没有已软删除的收藏。");return}confirm(`硬删除选中的 ${l.length} 条?无法恢复。`)&&(await f("chatclip/purge",{ids:l}),k())}async function ue(){var d;if(!confirm("清空回收站:所有已软删除的收藏都会被永久删除,无法恢复。"))return;const l=await f("chatclip/purge",{all:true}),e=((d=l==null?void 0:l.ids)==null?void 0:d.length)??0;alert(e?`已永久删除 ${e} 条。`:"回收站是空的。"),k()}async function pe(l,e){await f("chatclip/visibility",{id:l.id,visibility:e}),l.visibility=e}async function A(l,e){const d=await f("chatclip/export",{id:l.id,format:e});if(!d)return;const r=new Blob([d],{type:e==="json"?"application/json":"text/html"}),b=URL.createObjectURL(r),N=document.createElement("a");N.href=b,N.download=`${l.key}.${e}`,N.click(),URL.revokeObjectURL(b)}return _e(k),(l,e)=>{const d=g("el-input"),r=g("el-option"),b=g("el-select"),N=g("el-date-picker"),m=g("el-button"),_=g("el-table-column"),E=g("el-tag"),ce=g("el-table"),ve=g("el-pagination"),me=g("el-drawer"),fe=g("k-layout"),ge=we("loading");return c(),D(fe,null,{default:i(()=>{var H,K;return[a("div",xe,[a("div",ze,[e[9]||(e[9]=a("div",{class:"title"},"聊天收藏",-1)),a("div",$e,[t(d,{modelValue:s.keyword,"onUpdate:modelValue":e[0]||(e[0]=n=>s.keyword=n),placeholder:"关键词",clearable:"",style:{width:"160px"},onKeyup:J(x,["enter"])},null,8,["modelValue"]),t(d,{modelValue:s.from,"onUpdate:modelValue":e[1]||(e[1]=n=>s.from=n),placeholder:"发送者",clearable:"",style:{width:"120px"},onKeyup:J(x,["enter"])},null,8,["modelValue"]),t(b,{modelValue:s.visibility,"onUpdate:modelValue":e[2]||(e[2]=n=>s.visibility=n),style:{width:"120px"},onChange:x},{default:i(()=>[t(r,{label:"全部可见性",value:"all"}),t(r,{label:"仅自己",value:"private"}),t(r,{label:"本群可见",value:"channel"}),t(r,{label:"公开",value:"public"})]),_:1},8,["modelValue"]),t(b,{modelValue:s.deleted,"onUpdate:modelValue":e[3]||(e[3]=n=>s.deleted=n),style:{width:"130px"},onChange:x},{default:i(()=>[t(r,{label:"全部状态",value:"all"}),t(r,{label:"仅正常",value:"none"}),t(r,{label:"回收站",value:"only"})]),_:1},8,["modelValue"]),t(N,{modelValue:s.range,"onUpdate:modelValue":e[4]||(e[4]=n=>s.range=n),type:"datetimerange","start-placeholder":"起始时间","end-placeholder":"截止时间",style:{width:"340px"},onChange:x},null,8,["modelValue"]),t(m,{type:"primary",onClick:x},{default:i(()=>[...e[7]||(e[7]=[o("查询",-1)])]),_:1}),t(m,{onClick:ne},{default:i(()=>[...e[8]||(e[8]=[o("重置",-1)])]),_:1})])]),a("div",Se,[a("span",Ue,"已选 "+u(V.value.length)+" 条",1),t(m,{size:"small",disabled:!V.value.length,onClick:se},{default:i(()=>[...e[10]||(e[10]=[o("批量软删除",-1)])]),_:1},8,["disabled"]),t(m,{size:"small",disabled:!V.value.length,onClick:de},{default:i(()=>[...e[11]||(e[11]=[o("批量恢复",-1)])]),_:1},8,["disabled"]),t(m,{size:"small",type:"danger",disabled:!M.value.length,onClick:re},{default:i(()=>[o(" 硬删除选中("+u(M.value.length)+") ",1)]),_:1},8,["disabled"]),e[13]||(e[13]=a("span",{class:"spacer"},null,-1)),t(m,{size:"small",type:"danger",plain:"",onClick:ue},{default:i(()=>[...e[12]||(e[12]=[o("清空回收站",-1)])]),_:1})]),he((c(),D(ce,{ref_key:"tableRef",ref:Q,data:C.value,"row-key":"id",size:"small",stripe:"",style:{width:"100%"},onRowDblclick:T,onSelectionChange:te},{default:i(()=>[t(_,{type:"selection",width:"42"}),t(_,{prop:"key",label:"ID",width:"92"}),t(_,{prop:"sender",label:"发送者",width:"130","show-overflow-tooltip":""}),t(_,{prop:"preview",label:"内容","min-width":"240","show-overflow-tooltip":""}),t(_,{prop:"messageCount",label:"条数",width:"70",align:"center"}),t(_,{label:"可见性",width:"120"},{default:i(({row:n})=>[t(b,{"model-value":n.visibility,size:"small",onChange:w=>pe(n,w)},{default:i(()=>[t(r,{label:"仅自己",value:"private"}),t(r,{label:"本群可见",value:"channel"}),t(r,{label:"公开",value:"public"})]),_:1},8,["model-value","onChange"])]),_:1}),t(_,{label:"来源",width:"150","show-overflow-tooltip":""},{default:i(({row:n})=>[o(u(n.source),1)]),_:1}),t(_,{label:"收藏时间",width:"160"},{default:i(({row:n})=>[o(u(I(n.createdAt)),1)]),_:1}),t(_,{label:"状态",width:"80",align:"center"},{default:i(({row:n})=>[n.deleted?(c(),D(E,{key:0,type:"info",size:"small"},{default:i(()=>[...e[14]||(e[14]=[o("已删除",-1)])]),_:1})):(c(),D(E,{key:1,type:"success",size:"small"},{default:i(()=>[...e[15]||(e[15]=[o("正常",-1)])]),_:1}))]),_:1}),t(_,{label:"操作",width:"250",fixed:"right"},{default:i(({row:n})=>[t(m,{link:"",type:"primary",size:"small",onClick:w=>T(n)},{default:i(()=>[...e[16]||(e[16]=[o("查看",-1)])]),_:1},8,["onClick"]),t(m,{link:"",type:"primary",size:"small",onClick:w=>A(n,"json")},{default:i(()=>[...e[17]||(e[17]=[o("JSON",-1)])]),_:1},8,["onClick"]),t(m,{link:"",type:"primary",size:"small",onClick:w=>A(n,"html")},{default:i(()=>[...e[18]||(e[18]=[o("HTML",-1)])]),_:1},8,["onClick"]),n.deleted?(c(),y(L,{key:1},[t(m,{link:"",type:"warning",size:"small",onClick:w=>ie(n)},{default:i(()=>[...e[20]||(e[20]=[o("恢复",-1)])]),_:1},8,["onClick"]),t(m,{link:"",type:"danger",size:"small",onClick:w=>oe(n)},{default:i(()=>[...e[21]||(e[21]=[o("硬删除",-1)])]),_:1},8,["onClick"])],64)):(c(),D(m,{key:0,link:"",type:"danger",size:"small",onClick:w=>ae(n)},{default:i(()=>[...e[19]||(e[19]=[o("删除",-1)])]),_:1},8,["onClick"]))]),_:1})]),_:1},8,["data"])),[[ge,$.value]]),a("div",Ne,[t(ve,{"current-page":S.value,"onUpdate:currentPage":e[5]||(e[5]=n=>S.value=n),"page-size":R.value,total:j.value,layout:"total, prev, pager, next",onCurrentChange:k},null,8,["current-page","page-size","total"])]),t(me,{modelValue:O.value,"onUpdate:modelValue":e[6]||(e[6]=n=>O.value=n),title:((K=(H=p.value)==null?void 0:H.clip)==null?void 0:K.key)||"收藏详情",size:"560px"},{default:i(()=>{var n,w,F,P;return[p.value?(c(),y(L,{key:0},[a("div",De,[a("div",null,[e[22]||(e[22]=a("span",null,"发送者",-1)),o(u(p.value.clip.ownerName),1)]),a("div",null,[e[23]||(e[23]=a("span",null,"可见性",-1)),o(u(W(p.value.clip.visibility)),1)]),a("div",null,[e[24]||(e[24]=a("span",null,"条数",-1)),o(u(p.value.clip.messageCount),1)]),a("div",null,[e[25]||(e[25]=a("span",null,"来源",-1)),o(u(((n=p.value.clip.meta)==null?void 0:n.channelName)||((w=p.value.clip.meta)==null?void 0:w.guildName)||p.value.clip.channelId),1)]),a("div",null,[e[26]||(e[26]=a("span",null,"收藏时间",-1)),o(u(I(p.value.clip.createdAt)),1)]),a("div",null,[e[27]||(e[27]=a("span",null,"消息时间",-1)),o(u(I((F=p.value.messages[0])==null?void 0:F.timestamp)),1)])]),(P=p.value.clip.degraded)!=null&&P.length?(c(),y("div",Le," ⚠️ 降级:"+u(p.value.clip.degraded.join(", ")),1)):B("v-if",true),e[29]||(e[29]=a("div",{class:"section-title"},"消息",-1)),(c(true),y(L,null,Y(p.value.messages,(v,ye)=>(c(),y("div",{key:v.id,class:"message"},[a("div",je,[a("span",Ie,u(ye+1),1),a("span",Me,u(X(v.role)),1),a("span",Oe,u(v.nickname||v.username||v.userId),1),a("span",Be,u(I(v.timestamp)),1)]),a("div",Re,u(ee(v.content)),1)]))),128)),p.value.attachments.length?(c(),y(L,{key:1},[e[28]||(e[28]=a("div",{class:"section-title"},"附件",-1)),a("div",Te,[(c(true),y(L,null,Y(p.value.attachments,v=>(c(),y("a",{key:v.id,href:v.url,target:"_blank",class:"attachment"},[Z(v)?(c(),y("img",{key:0,src:v.url},null,8,Ee)):(c(),y("span",He,u(le(v)),1))],8,Ae))),128))])],64)):B("v-if",true)],64)):B("v-if",true)]}),_:1},8,["modelValue","title"])])]}),_:1})}}}),Fe=(z,$)=>{const C=z.__vccOpts||z;for(const[j,S]of $)C[j]=S;return C},Pe=Fe(Ke,[["__scopeId","data-v-ae1664b3"]]);ke.register("chatclip",Ve);const Ye=z=>{z.page({name:"聊天收藏",path:"/chatclip",icon:"chatclip",component:Pe})};export{Ye as default};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.page[data-v-ae1664b3]{padding:16px 20px;display:flex;flex-direction:column;gap:12px;height:100%}.toolbar[data-v-ae1664b3]{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.title[data-v-ae1664b3]{font-size:18px;font-weight:600}.filters[data-v-ae1664b3]{display:flex;gap:8px;flex-wrap:wrap;align-items:center}.footer[data-v-ae1664b3]{display:flex;justify-content:flex-end}.batchbar[data-v-ae1664b3]{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 12px;border-radius:8px;background:var(--bg2);font-size:13px}.batchbar .hint[data-v-ae1664b3]{color:var(--fg3);margin-right:4px}.batchbar .spacer[data-v-ae1664b3]{flex:1}.meta[data-v-ae1664b3]{display:grid;grid-template-columns:1fr 1fr;gap:8px 16px;margin-bottom:16px;font-size:13px}.meta span[data-v-ae1664b3]{color:var(--fg3);margin-right:8px}.degraded[data-v-ae1664b3]{background:var(--bg2);border-radius:6px;padding:8px 12px;font-size:13px;color:#c07a00;margin-bottom:16px}.section-title[data-v-ae1664b3]{font-weight:600;margin:16px 0 8px}.message[data-v-ae1664b3]{border-left:3px solid var(--k-color-primary);padding:6px 0 6px 12px;margin-bottom:10px}.message-head[data-v-ae1664b3]{display:flex;gap:8px;align-items:center;font-size:13px;color:var(--fg3)}.ordinal[data-v-ae1664b3]{font-weight:600;color:var(--k-color-primary)}.role[data-v-ae1664b3]{background:var(--bg2);border-radius:4px;padding:0 6px}.sender[data-v-ae1664b3]{color:var(--fg2)}.message-body[data-v-ae1664b3]{margin-top:4px;white-space:pre-wrap;word-break:break-word}.attachments[data-v-ae1664b3]{display:flex;flex-wrap:wrap;gap:8px}.attachment img[data-v-ae1664b3]{width:96px;height:96px;object-fit:cover;border-radius:6px}.attachment .file[data-v-ae1664b3]{display:inline-block;padding:6px 10px;background:var(--bg2);border-radius:6px;font-size:13px}.fixed{position:fixed}.grid{display:grid}.inline-block{display:inline-block}.flex{display:flex}.flex-wrap{flex-wrap:wrap}
|
package/lib/collect.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Context, Element, Session } from 'koishi';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
import { Clip, ClipMeta, ElementJSON, Role, Snapshot, Visibility } from './db';
|
|
4
|
+
export declare function isMedia(type: string): boolean;
|
|
5
|
+
export declare function serialize(el: Element): ElementJSON;
|
|
6
|
+
export declare function toElement(json: ElementJSON): Element;
|
|
7
|
+
export declare function cloneElements(elements: Element[]): Element[];
|
|
8
|
+
/** 纯文本表示,用于搜索与文字视图。 */
|
|
9
|
+
export declare function elementsText(elements: Element[]): string;
|
|
10
|
+
export interface PendingAttachment {
|
|
11
|
+
index: number;
|
|
12
|
+
type: string;
|
|
13
|
+
assetsUrl?: string;
|
|
14
|
+
originalUrl: string;
|
|
15
|
+
filename?: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
expired: boolean;
|
|
18
|
+
/** 转存被跳过的原因,例如 image-too-large */
|
|
19
|
+
note?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PendingSnapshot {
|
|
22
|
+
role: Role;
|
|
23
|
+
quoteDepth: number;
|
|
24
|
+
depth: number;
|
|
25
|
+
parentId?: string;
|
|
26
|
+
messageId: string;
|
|
27
|
+
userId: string;
|
|
28
|
+
username: string;
|
|
29
|
+
nickname?: string;
|
|
30
|
+
avatar?: string;
|
|
31
|
+
content: string;
|
|
32
|
+
elements: ElementJSON[];
|
|
33
|
+
timestamp: Date;
|
|
34
|
+
degraded: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface CollectedClip {
|
|
37
|
+
platform: string;
|
|
38
|
+
channelId: string;
|
|
39
|
+
guildId?: string;
|
|
40
|
+
messageId: string;
|
|
41
|
+
ownerId: string;
|
|
42
|
+
ownerName: string;
|
|
43
|
+
visibility: Visibility;
|
|
44
|
+
degraded: string[];
|
|
45
|
+
meta: ClipMeta;
|
|
46
|
+
messages: PendingSnapshot[];
|
|
47
|
+
attachments: PendingAttachment[];
|
|
48
|
+
}
|
|
49
|
+
export declare function parseCQ(text: string): Element[];
|
|
50
|
+
export declare function parseSegments(input: any): Element[];
|
|
51
|
+
/** 展开合并转发;拿不到时返回 null,由调用方标记降级。 */
|
|
52
|
+
export declare function expandForward(bot: any, id: string, limit: number): Promise<any[] | null>;
|
|
53
|
+
export interface CollectSource {
|
|
54
|
+
platform: string;
|
|
55
|
+
channelId: string;
|
|
56
|
+
guildId?: string;
|
|
57
|
+
guildName?: string;
|
|
58
|
+
channelName?: string;
|
|
59
|
+
ownerId: string;
|
|
60
|
+
ownerName: string;
|
|
61
|
+
bot: any;
|
|
62
|
+
/** 要被收藏的那条消息 */
|
|
63
|
+
message: any;
|
|
64
|
+
/** 它的直接引用 */
|
|
65
|
+
quote?: any;
|
|
66
|
+
}
|
|
67
|
+
export declare function sourceFromSession(session: Session, message?: any, quote?: any): CollectSource;
|
|
68
|
+
/**
|
|
69
|
+
* 消息 → 待写入的 Clip。只做读取与转存,不碰数据库。
|
|
70
|
+
*/
|
|
71
|
+
export declare function collectClip(ctx: Context, config: Config, source: CollectSource, visibility: Visibility): Promise<CollectedClip>;
|
|
72
|
+
export interface PersistResult {
|
|
73
|
+
clip: Clip;
|
|
74
|
+
existing: boolean;
|
|
75
|
+
/** 之前软删除过、这次重新收藏把它从回收站拉了回来 */
|
|
76
|
+
restored?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 「条数」的口径:引用链、转发展开的每一条各算一条;
|
|
80
|
+
* 主消息只有在**带文字**(或没有转发)时才算一条 —— 纯转发的空壳不计。
|
|
81
|
+
*/
|
|
82
|
+
export declare function countMessages(messages: {
|
|
83
|
+
role: Role;
|
|
84
|
+
content: string;
|
|
85
|
+
}[]): number;
|
|
86
|
+
/** 幂等写入:唯一键命中就返回已有记录。 */
|
|
87
|
+
export declare function persistClip(ctx: Context, data: CollectedClip): Promise<PersistResult>;
|
|
88
|
+
export declare function loadClip(ctx: Context, id: number): Promise<{
|
|
89
|
+
clip: Clip;
|
|
90
|
+
messages: Snapshot[];
|
|
91
|
+
attachments: any[];
|
|
92
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context, Session } from 'koishi';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
import { Clip } from './db';
|
|
4
|
+
export declare function applyCommands(ctx: Context, config: Config): void;
|
|
5
|
+
export declare const HELP_TEXT: string;
|
|
6
|
+
/** private 只有本人能看;channel 本群可见;public 谁都能看。 */
|
|
7
|
+
export declare function canSee(clip: Clip, session: Session, config: Config): boolean;
|
|
8
|
+
/** 未加载 database 的 User 表时 session.user 会退化成 never,这里统一兜底。 */
|
|
9
|
+
export declare function authorityOf(session: Session): number;
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Schema } from 'koishi';
|
|
2
|
+
/** 默认字体:优先系统中文字体,渲染中文不会掉成方块。 */
|
|
3
|
+
export declare const DEFAULT_FONT = "-apple-system, \"PingFang SC\", \"Microsoft YaHei\", \"Noto Sans CJK SC\", sans-serif";
|
|
4
|
+
export interface Config {
|
|
5
|
+
/** 默认可见性,成员可用 -s 覆盖 */
|
|
6
|
+
defaultVisibility: 'private' | 'channel' | 'public';
|
|
7
|
+
/** 引用链最大层数,0 = 不采集引用 */
|
|
8
|
+
quoteDepth: number;
|
|
9
|
+
/** 合并转发展开层数,0 = 不展开 */
|
|
10
|
+
forwardDepth: number;
|
|
11
|
+
/** 单次展开的转发条数上限 */
|
|
12
|
+
forwardLimit: number;
|
|
13
|
+
allowPrivate: boolean;
|
|
14
|
+
allowGroup: boolean;
|
|
15
|
+
/** 是否把图片/文件转存到 assets */
|
|
16
|
+
storage: boolean;
|
|
17
|
+
/** 单个附件大小上限(MB),超过则只留原链接 */
|
|
18
|
+
maxAssetSize: number;
|
|
19
|
+
/** 转存到本地 assets 的图片大小上限(MB),0 = 不限 */
|
|
20
|
+
maxLocalImageSize: number;
|
|
21
|
+
/** 渲染使用的字体族 */
|
|
22
|
+
fontFamily: string;
|
|
23
|
+
/** clip show --text 时最多跟发几张图片,0 = 不跟发 */
|
|
24
|
+
textImageLimit: number;
|
|
25
|
+
pageSize: number;
|
|
26
|
+
/** 每人收藏上限,0 = 不限 */
|
|
27
|
+
maxClipsPerUser: number;
|
|
28
|
+
/** 渲染画布宽度 */
|
|
29
|
+
imageWidth: number;
|
|
30
|
+
}
|
|
31
|
+
export declare const Config: Schema<Config>;
|
package/lib/console.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
export interface ConsoleQuery {
|
|
4
|
+
keyword?: string;
|
|
5
|
+
from?: string;
|
|
6
|
+
start?: string;
|
|
7
|
+
end?: string;
|
|
8
|
+
visibility?: string;
|
|
9
|
+
channelId?: string;
|
|
10
|
+
ownerId?: string;
|
|
11
|
+
/** all = 正常 + 回收站,none = 只看正常(默认),only = 只看回收站 */
|
|
12
|
+
deleted?: 'all' | 'none' | 'only';
|
|
13
|
+
page?: number;
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ClipRow {
|
|
17
|
+
id: number;
|
|
18
|
+
key: string;
|
|
19
|
+
sender: string;
|
|
20
|
+
preview: string;
|
|
21
|
+
messageCount: number;
|
|
22
|
+
visibility: string;
|
|
23
|
+
source: string;
|
|
24
|
+
channelId: string;
|
|
25
|
+
createdAt: number;
|
|
26
|
+
deleted: boolean;
|
|
27
|
+
}
|
|
28
|
+
declare module '@koishijs/console' {
|
|
29
|
+
interface Events {
|
|
30
|
+
'chatclip/list'(query: ConsoleQuery): Promise<{
|
|
31
|
+
items: ClipRow[];
|
|
32
|
+
total: number;
|
|
33
|
+
}>;
|
|
34
|
+
'chatclip/get'(id: number): Promise<any>;
|
|
35
|
+
'chatclip/remove'(id: number): Promise<boolean>;
|
|
36
|
+
'chatclip/removeMany'(ids: number[]): Promise<{
|
|
37
|
+
ids: number[];
|
|
38
|
+
}>;
|
|
39
|
+
'chatclip/restore'(id: number): Promise<boolean>;
|
|
40
|
+
'chatclip/restoreMany'(ids: number[]): Promise<{
|
|
41
|
+
ids: number[];
|
|
42
|
+
}>;
|
|
43
|
+
'chatclip/purge'(payload: {
|
|
44
|
+
ids?: number[];
|
|
45
|
+
all?: boolean;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
ids: number[];
|
|
48
|
+
skipped: number[];
|
|
49
|
+
}>;
|
|
50
|
+
'chatclip/visibility'(payload: {
|
|
51
|
+
id: number;
|
|
52
|
+
visibility: string;
|
|
53
|
+
}): Promise<boolean>;
|
|
54
|
+
'chatclip/export'(payload: {
|
|
55
|
+
id: number;
|
|
56
|
+
format: 'json' | 'html';
|
|
57
|
+
}): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export declare function applyConsole(ctx: Context, config: Config): void;
|
package/lib/db.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
export type Visibility = 'private' | 'channel' | 'public';
|
|
3
|
+
export type Role = 'main' | 'quote' | 'forward';
|
|
4
|
+
/** 元素序列化后的形态,数据库里只存它,渲染时再还原成 h 元素。 */
|
|
5
|
+
export interface ElementJSON {
|
|
6
|
+
type: string;
|
|
7
|
+
attrs: Record<string, any>;
|
|
8
|
+
children: (ElementJSON | string)[];
|
|
9
|
+
}
|
|
10
|
+
export interface ClipMeta {
|
|
11
|
+
guildName?: string;
|
|
12
|
+
channelName?: string;
|
|
13
|
+
/** group = 群聊,private = 私聊 */
|
|
14
|
+
kind?: 'group' | 'private';
|
|
15
|
+
}
|
|
16
|
+
export interface Clip {
|
|
17
|
+
id: number;
|
|
18
|
+
/** 展示编号:1..N 连续,硬删除后会重排。id 是数据库主键,不对外露出。 */
|
|
19
|
+
no?: number;
|
|
20
|
+
platform: string;
|
|
21
|
+
channelId: string;
|
|
22
|
+
guildId?: string;
|
|
23
|
+
messageId: string;
|
|
24
|
+
ownerId: string;
|
|
25
|
+
ownerName: string;
|
|
26
|
+
visibility: Visibility;
|
|
27
|
+
messageCount: number;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
deletedAt?: Date;
|
|
30
|
+
degraded: string[];
|
|
31
|
+
meta: ClipMeta;
|
|
32
|
+
}
|
|
33
|
+
export interface Snapshot {
|
|
34
|
+
id: number;
|
|
35
|
+
clipId: number;
|
|
36
|
+
seq: number;
|
|
37
|
+
role: Role;
|
|
38
|
+
/** 引用链层数(main = 0) */
|
|
39
|
+
quoteDepth: number;
|
|
40
|
+
/** 合并转发的嵌套层数(main = 0,第一层转发 = 1) */
|
|
41
|
+
depth: number;
|
|
42
|
+
parentId?: string;
|
|
43
|
+
messageId: string;
|
|
44
|
+
userId: string;
|
|
45
|
+
username: string;
|
|
46
|
+
nickname?: string;
|
|
47
|
+
avatar?: string;
|
|
48
|
+
content: string;
|
|
49
|
+
elements: ElementJSON[];
|
|
50
|
+
timestamp: Date;
|
|
51
|
+
degraded: string[];
|
|
52
|
+
}
|
|
53
|
+
export interface Attachment {
|
|
54
|
+
id: number;
|
|
55
|
+
clipId: number;
|
|
56
|
+
messageRowId: number;
|
|
57
|
+
type: string;
|
|
58
|
+
assetsUrl?: string;
|
|
59
|
+
originalUrl: string;
|
|
60
|
+
filename?: string;
|
|
61
|
+
size?: number;
|
|
62
|
+
expired: boolean;
|
|
63
|
+
/** 转存被跳过的原因,例如 image-too-large */
|
|
64
|
+
note?: string;
|
|
65
|
+
}
|
|
66
|
+
declare module 'koishi' {
|
|
67
|
+
interface Tables {
|
|
68
|
+
'chatclip_clip': Clip;
|
|
69
|
+
'chatclip_message': Snapshot;
|
|
70
|
+
'chatclip_attachment': Attachment;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export declare const TABLES: {
|
|
74
|
+
readonly clip: "chatclip_clip";
|
|
75
|
+
readonly message: "chatclip_message";
|
|
76
|
+
readonly attachment: "chatclip_attachment";
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 三张表一次建好。minato 不会补建 unique,也不会给已存在的表加索引,
|
|
80
|
+
* 所以字段和索引必须一次性声明完整(见 docs/adr/0004)。
|
|
81
|
+
*/
|
|
82
|
+
export declare function applyTables(ctx: Context): void;
|
|
83
|
+
export interface ClipQuery {
|
|
84
|
+
ownerId?: string;
|
|
85
|
+
channelId?: string;
|
|
86
|
+
channelIds?: string[];
|
|
87
|
+
visibility?: Visibility[];
|
|
88
|
+
keyword?: string;
|
|
89
|
+
from?: string[];
|
|
90
|
+
start?: Date;
|
|
91
|
+
end?: Date;
|
|
92
|
+
includeDeleted?: boolean;
|
|
93
|
+
/** 只看已软删除的(控制台「回收站」) */
|
|
94
|
+
deletedOnly?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 关键词 / 发送者都落在 chatclip_message 上,所以先算出允许的 clipId 集合,
|
|
98
|
+
* 再回到 clip 表分页。返回 null 表示"不限制"。
|
|
99
|
+
*/
|
|
100
|
+
export declare function resolveClipIds(ctx: Context, query: ClipQuery): Promise<number[] | null>;
|
|
101
|
+
export declare function buildClipQuery(query: ClipQuery, clipIds: number[] | null): any;
|
|
102
|
+
export interface ClipPage {
|
|
103
|
+
items: Clip[];
|
|
104
|
+
total: number;
|
|
105
|
+
}
|
|
106
|
+
export declare function queryClips(ctx: Context, query: ClipQuery, page?: number, pageSize?: number): Promise<ClipPage>;
|
|
107
|
+
export declare function escapeRegex(text: string): string;
|
|
108
|
+
export interface PurgeResult {
|
|
109
|
+
/** 真正被硬删除的收藏 id */
|
|
110
|
+
ids: number[];
|
|
111
|
+
/** 因为还没软删除而被跳过的 id */
|
|
112
|
+
skipped: number[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 硬删除:只允许已经软删除的收藏,连消息行与附件行一起删掉。
|
|
116
|
+
* 传 all = true 时清空整个回收站。
|
|
117
|
+
*/
|
|
118
|
+
export declare function purgeClips(ctx: Context, options?: {
|
|
119
|
+
ids?: number[];
|
|
120
|
+
all?: boolean;
|
|
121
|
+
}): Promise<PurgeResult>;
|
|
122
|
+
/**
|
|
123
|
+
* 把展示编号重排成 1..N(按收藏时间升序)。
|
|
124
|
+
* 硬删除后会留下空缺,这里补齐:删掉 #A0003 之后,原来的 #A0004 就变成 #A0003。
|
|
125
|
+
*/
|
|
126
|
+
export declare function renumberClips(ctx: Context): Promise<number>;
|
|
127
|
+
/** 新收藏的展示编号 = 当前最大编号 + 1 */
|
|
128
|
+
export declare function nextClipNo(ctx: Context): Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* `clip show` / `clip rm` / `clip export` 的入参:先按展示编号找,找不到再按主键找,
|
|
131
|
+
* 这样硬删除重排之后旧编号也不会指错人。
|
|
132
|
+
*/
|
|
133
|
+
export declare function resolveClipRef(ctx: Context, input: string): Promise<Clip | undefined>;
|
|
134
|
+
/** 展示用编号:优先展示编号,老数据没有 no 时退回主键 */
|
|
135
|
+
export declare function clipNo(clip: {
|
|
136
|
+
no?: number;
|
|
137
|
+
id: number;
|
|
138
|
+
}): number;
|
|
139
|
+
/** `#A1031` / `A1031` / `a1031` / `1031` → 1031 */
|
|
140
|
+
export declare function parseClipId(input: string): number | null;
|
|
141
|
+
export declare function formatClipId(id: number): string;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
import './types';
|
|
4
|
+
export declare const name = "chatclip";
|
|
5
|
+
export * from './config';
|
|
6
|
+
export { Config } from './config';
|
|
7
|
+
export declare const inject: {
|
|
8
|
+
required: string[];
|
|
9
|
+
optional: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare const usage = "\n\u5F15\u7528\u4E00\u6761\u6D88\u606F\u540E\u53D1\u9001 `clip` \u5373\u53EF\u6536\u85CF\uFF1B`clip list` \u67E5\u770B\u6536\u85CF\u5939\uFF0C`clip show \u7F16\u53F7` \u6E32\u67D3\u5355\u6761\u3002\n- \u56FE\u7247\u9700\u8981 `assets` \u63D2\u4EF6\uFF08assets-local / assets-s3 \u5747\u53EF\uFF09\uFF1B\n- \u56FE\u7247\u6E32\u67D3\u9700\u8981 `puppeteer` \u63D2\u4EF6\uFF0C\u672A\u542F\u7528\u65F6\u81EA\u52A8\u964D\u7EA7\u4E3A\u6587\u5B57\u3002";
|
|
12
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
13
|
+
/**
|
|
14
|
+
* koishi 的 loader 在应用插件时会安装一层 `$filter` 包装:
|
|
15
|
+
* `fork.parent.filter = (session) => parent.filter(session) && ...`(@koishijs/loader/src/shared.ts:350)。
|
|
16
|
+
* 某些重载路径(控制台改配置、HMR、插件被反复 apply)会让包装指向自身,
|
|
17
|
+
* 于是任意一次 `ctx.filter(session)` 都会栈溢出,表现为命令解析时抛出
|
|
18
|
+
* `RangeError: Maximum call stack size exceeded`。命令的 `match()` 恰好会调用
|
|
19
|
+
* `cmd.ctx.filter(session)`,所以这里先探测一次,发现自引用就回退成「不过滤」。
|
|
20
|
+
*/
|
|
21
|
+
export declare function protectFilter(ctx: Context): void;
|