koishi-plugin-welcomego 1.0.0 → 1.0.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.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import type { Context } from 'koishi';
2
2
  import { Schema } from 'koishi';
3
- export declare const name = "welcome";
3
+ export declare const name = "welcomego";
4
+ declare module 'koishi' {
5
+ interface User {
6
+ avatar?: string;
7
+ }
8
+ }
4
9
  export interface Config {
10
+ added: string;
11
+ removed: string;
5
12
  }
6
13
  export declare const Config: Schema<Config>;
7
- export declare function apply(ctx: Context): void;
14
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -26,18 +26,37 @@ __export(src_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(src_exports);
28
28
  var import_koishi = require("koishi");
29
- var name = "welcome";
30
- var Config = import_koishi.Schema.object({});
31
- function apply(ctx) {
32
- ctx.i18n.define("zh-CN", {
33
- added: "欢迎加入群聊!",
34
- removed: "退出了群聊。"
29
+ var name = "welcomego";
30
+ var Config = import_koishi.Schema.object({
31
+ added: import_koishi.Schema.string().default("{at},欢迎加入群聊!").description("加入群聊的模板"),
32
+ removed: import_koishi.Schema.string().default("{username}退出了群聊。").description("退出群聊的模板")
33
+ });
34
+ function apply(ctx, config) {
35
+ ctx.i18n.define("", {
36
+ added: config.added,
37
+ removed: config.removed
35
38
  });
36
- ctx.on("guild-member-added", (session) => {
37
- return session.send(session.text("added", session.author));
39
+ function makeParams(session) {
40
+ const avatar = session.user?.avatar;
41
+ return {
42
+ user: session.user,
43
+ userId: session.userId,
44
+ username: session.username,
45
+ avatar,
46
+ img: import_koishi.h.img(avatar),
47
+ at: import_koishi.h.at(session.userId),
48
+ channel: session.channel,
49
+ channelId: session.channelId,
50
+ guild: session.guild,
51
+ guildId: session.guildId
52
+ };
53
+ }
54
+ __name(makeParams, "makeParams");
55
+ ctx.on("guild-member-added", async (session) => {
56
+ await session.send(session.text("added", makeParams(session)));
38
57
  });
39
- ctx.on("guild-member-removed", (session) => {
40
- return session.send(session.text("removed", session));
58
+ ctx.on("guild-member-removed", async (session) => {
59
+ await session.send(session.text("removed", makeParams(session)));
41
60
  });
42
61
  }
43
62
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-welcomego",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "群聊欢迎告别插件,支持自定义模板",
5
5
  "typings": "lib/index.d.ts",
6
6
  "license": "MIT",