@q78kg/koishi-plugin-text-censor 1.0.10 → 1.0.12
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.cjs +2 -2
- package/lib/index.d.ts +2 -7
- package/lib/index.mjs +2 -2
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var x=Object.create;var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var
|
|
2
|
-
`).map(i=>i.trim()).filter(i=>i&&!i.startsWith("//")&&!i.startsWith("#"));
|
|
1
|
+
var x=Object.create;var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},p=(t,e,r,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of b(e))!v.call(t,s)&&s!==r&&l(t,s,{get:()=>e[s],enumerable:!(c=y(e,s))||c.enumerable});return t};var h=(t,e,r)=>(r=t!=null?x(S(t)):{},p(e||!t||!t.__esModule?l(r,"default",{value:t,enumerable:!0}):r,t)),C=t=>p(l({},"__esModule",{value:!0}),t);var D={};w(D,{default:()=>W});module.exports=C(D);var n=require("koishi"),o=require("node:fs"),f=require("node:path"),d=require("@q78kg/mint-filter"),u=h(require("@koishijs/censor"),1),W={name:"text-censor",Config:n.Schema.intersect([n.Schema.object({textDatabase:n.Schema.array(n.Schema.tuple([n.Schema.string().default("data/text-censor/censor.txt")])).description("\u654F\u611F\u8BCD\u5E93\u7684\u6587\u4EF6\u8DEF\u5F84\u3002").default([["data/text-censor/censor.txt"]])}),n.Schema.object({removeWords:n.Schema.boolean().description("\u662F\u5426\u76F4\u63A5\u5220\u9664\u654F\u611F\u8BCD\u3002").default(!1),caseStrategy:n.Schema.union(["none","lower","capital"]).description("\u654F\u611F\u8BCD\u5904\u7406\u65F6\u7684\u5927\u5C0F\u5199\u7B56\u7565\u3002").default("none")})]),apply(t,e){let r=[];for(let[m]of e.textDatabase){let a=(0,f.resolve)(t.baseDir,m);if(!(0,o.existsSync)(a)){t.logger.warn(`dictionary file not found: ${a}, creating a new one.`);let i=(0,f.dirname)(a);(0,o.existsSync)(i)||(0,o.mkdirSync)(i,{recursive:!0}),(0,o.writeFileSync)(a,"")}let g=(0,o.readFileSync)(a,"utf8").split(`
|
|
2
|
+
`).map(i=>i.trim()).filter(i=>i&&!i.startsWith("//")&&!i.startsWith("#"));r=r.concat(g)}if(r.length===0){t.logger.warn("no sensitive words found");return}let c={transform:e.caseStrategy,remove:e.removeWords},s=new d.Mint(r,c);t.plugin(u.default),t.get("censor").intercept({async text(m){return[s.filter(m.content).text]}})}};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { Schema, Context } from 'koishi';
|
|
2
|
-
|
|
3
|
-
declare const name = "text-censor";
|
|
4
1
|
interface Config {
|
|
5
2
|
textDatabase: [string][];
|
|
6
3
|
removeWords: boolean;
|
|
7
|
-
caseStrategy: '
|
|
4
|
+
caseStrategy: 'none' | 'lower' | 'capital';
|
|
8
5
|
}
|
|
9
|
-
declare const Config: Schema<Config>;
|
|
10
|
-
declare function apply(ctx: Context, config: Config): void;
|
|
11
6
|
|
|
12
|
-
export { Config
|
|
7
|
+
export type { Config };
|
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Schema as e}from"koishi";import{existsSync as a,mkdirSync as
|
|
2
|
-
`).map(t=>t.trim()).filter(t=>t&&!t.startsWith("//")&&!t.startsWith("#"));
|
|
1
|
+
import{Schema as e}from"koishi";import{existsSync as a,mkdirSync as m,readFileSync as p,writeFileSync as d}from"node:fs";import{dirname as u,resolve as g}from"node:path";import{Mint as x}from"@q78kg/mint-filter";import y from"@koishijs/censor";var M={name:"text-censor",Config:e.intersect([e.object({textDatabase:e.array(e.tuple([e.string().default("data/text-censor/censor.txt")])).description("\u654F\u611F\u8BCD\u5E93\u7684\u6587\u4EF6\u8DEF\u5F84\u3002").default([["data/text-censor/censor.txt"]])}),e.object({removeWords:e.boolean().description("\u662F\u5426\u76F4\u63A5\u5220\u9664\u654F\u611F\u8BCD\u3002").default(!1),caseStrategy:e.union(["none","lower","capital"]).description("\u654F\u611F\u8BCD\u5904\u7406\u65F6\u7684\u5927\u5C0F\u5199\u7B56\u7565\u3002").default("none")})]),apply(n,i){let o=[];for(let[s]of i.textDatabase){let r=g(n.baseDir,s);if(!a(r)){n.logger.warn(`dictionary file not found: ${r}, creating a new one.`);let t=u(r);a(t)||m(t,{recursive:!0}),d(r,"")}let f=p(r,"utf8").split(`
|
|
2
|
+
`).map(t=>t.trim()).filter(t=>t&&!t.startsWith("//")&&!t.startsWith("#"));o=o.concat(f)}if(o.length===0){n.logger.warn("no sensitive words found");return}let c={transform:i.caseStrategy,remove:i.removeWords},l=new x(o,c);n.plugin(y),n.get("censor").intercept({async text(s){return[l.filter(s.content).text]}})}};export{M as default};
|