File size: 5,307 Bytes
ef22ec8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import plugin from '../../lib/plugins/plugin.js';
import { segment } from "oicq";
import { FrameToFrame, createEvent } from "../py-plugin/core/client/client.js";
import { imageUrlToBuffer } from "../py-plugin/core/util/transform.js";

// !!!注意:此插件实现生成表情包功能需依赖[宵鸟py-plugin](https://gitee.com/realhuhu/py-plugin)的头像表情包模块

// 插件使用中如果遇到问题可@渔火反馈   渔糕就读的幼稚园:134086404
// 云崽插件库:https://gitee.com/yhArcadia/Yunzai-Bot-plugins-index (码云)     https://github.com/yhArcadia/Yunzai-Bot-plugins-index (GitHub)


export class newcomer extends plugin {
  constructor() {
    super({
      name: '欢迎新人',
      dsc: '新人入群欢迎',
      /** https://oicqjs.github.io/oicq/#events */
      event: 'notice.group.increase',
      priority: 4000
    })
  }

  /** 接受到消息都会执行一次 */
  async accept() {

    /** 定义入群欢迎内容 */
    let msg = '欢迎新人!';
    /** 冷却cd 30s */
    let cd = 30;

    if (this.e.user_id == Bot.uin) { return }

    /** cd */
    let key = `Yz:newcomers:${this.e.group_id}`;
    if (await redis.get(key)) { return }
    redis.set(key, '1', { EX: cd });

    /** 回复 */
    await this.reply([
      segment.at(this.e.user_id),
      // segment.image(),
      msg
    ])

    // 搓新人头像===============================\\
    let increasemem = ["_jiujiu", "_tightly", "_anyasuki", "_petpet", "_pat", "_play"];
    let imgbf = await imageUrlToBuffer(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${this.e.user_id}`);
    FrameToFrame({
      _package: "petpet",
      _handler: increasemem[Math.floor(Math.random() * increasemem.length)],
      params: {
        // event: await createEvent(this.e),
        event: {
          // sender: this.e.user_id,
          sender: {
            qq: this.e.user_id.toString(),
            name: "233",
            card: "233",
            sex: "233",
            age: "233",
            area: "233",
            level: "233",
            role: "233",
            title: "233",
          },
          atList: [{
            qq: this.e.user_id.toString(),
            name: this.e.user_id.toString(),
          }],
          imageList: [imgbf],
          msg: "",
          group: null
        },
        message: ""
      },
      onData: (error, response) => {
        if (error) {
          console.error(error.details);
        } else {
          this.reply(segment.image(response.image));
        }
      },
    });

    // // 生成搓新人的头像表情包
    // let url = `https://api.dlut-cc.live/emoji/?flag=_&qq=${this.e.user_id}&target=${this.e.user_id}&group=${this.e.group_id}&args=${encodeURI("搓")}&master=${cfg.masterQQ[0]}`
    // console.log(url);
    // //let response = await fetch(url); //调用接口获取数据
    // let response = await axios.get(url, { timeout: 20000 }); //调用接口获取数据
    // //const res = await response.json(); //结果json字符串转对象
    // const res = await response.data; //结果json字符串转对象
    // if (res.success == "true") {
    //   await this.reply([segment.at(this.e.user_id), segment.text(msg), segment.image(res.url)])
    // }
    // else {
    //   await this.reply([segment.at(this.e.user_id),segment.text(msg)])
    // }
  }
}

export class outNotice extends plugin {
  constructor() {
    super({
      name: '退群通知',
      dsc: 'xxx永远离开了我们',
      event: 'notice.group.decrease'
    })

    /** 退群提示词 */
    this.tips = '永远离开了我们。。'
  }

  async accept() {
    if (this.e.user_id == Bot.uin) {
      return
    }
    let name, msg;
    if (this.e.member) {
      name = this.e.member.card || this.e.member.nickname
    }

    if (name) {
      msg = `${name}(${this.e.user_id}) ${this.tips}`
    } else {
      msg = `${this.e.user_id} ${this.tips}`
    }



    // 缅怀旧人头像=============================================================================\\
    let decreasemem = ["_hammer", "_thump", "_rip", "_eat"];
    let imgbf = await imageUrlToBuffer(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${this.e.user_id}`);
    FrameToFrame({
      _package: "petpet",
      _handler: decreasemem[Math.floor(Math.random() * decreasemem.length)],
      params: {
        // event: await createEvent(this.e),
        event: {
          // sender: this.e.user_id,
          sender: {
            qq: this.e.user_id.toString(),
            name: "233",
            card: "233",
            sex: "233",
            age: "233",
            area: "233",
            level: "233",
            role: "233",
            title: "233",
          },
          atList: [{
            qq: this.e.user_id.toString(),
            name: this.e.user_id.toString(),
          }],
          imageList: [imgbf],
          msg: "",
          group: null
        },
        message: "缅怀"
      },
      onData: (error, response) => {
        if (error) {
          console.error(error.details);
        } else {
          this.reply(segment.image(response.image));
        }
      },
    });
    // =======================================================================//

    logger.mark(`[退出通知]${this.e.logText} ${msg}`);
    await this.reply(msg);
  }
}