File size: 1,836 Bytes
af5a34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { sendSocketList, Config, Version } from '../../components/index.js'

Bot.on('request', async e => {
    if (sendSocketList.length == 0) return false
    let other = {}
    switch (e.request_type) {
        case 'friend':
            other.request_type = 'friend'
            switch (e.sub_type) {
                case 'add':
                    if (!Config.friendAdd) return false
                    break;
                default:
                    return false
            }
            break;
        case 'group':
            other.request_type = 'group'
            other.group_id = e.group_id
            switch (e.sub_type) {
                case 'invite':
                    if (!Config.groupInvite) return false
                    other.sub_type = 'invite'
                    break;
                case 'add':
                    if (!Config.groupAdd) return false
                    other.sub_type = 'add'
                    break;

                default:
                    return false;
            }
            break;

        default:
            return false;
    }

    let msg = {
        time: e.time,
        self_id: e.self_id,
        post_type: 'request',
        flag: e.flag,
        user_id: e.user_id,
        comment: e.comment,
        ...other
    }
    msg = JSON.stringify(msg)
    sendSocketList.forEach(i => {
        if (i.status == 1) {
            switch (Number(i.type)) {
                case 1:
                case 2:
                    if (Version.isTrss) {
                        if (i.uin != e.self_id) return
                        if (!Version.protocol.some(i => i == e.bot?.version?.name)) return
                    }
                    i.ws.send(msg)
                    break;
                default:
                    break;
            }
        }
    })
})