forked from Team-Silver-Sphere/SquadJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbl-info.js
More file actions
159 lines (147 loc) · 4.69 KB
/
cbl-info.js
File metadata and controls
159 lines (147 loc) · 4.69 KB
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
import GraphQLRequest from 'graphql-request';
import DiscordBasePlugin from './discord-base-plugin.js';
const { request, gql } = GraphQLRequest;
export default class CBLInfo extends DiscordBasePlugin {
static get description() {
return (
'The <code>CBLInfo</code> plugin alerts admins when a harmful player is detected joining their server based ' +
'on data from the <a href="https://communitybanlist.com/">Community Ban List</a>.'
);
}
static get defaultEnabled() {
return true;
}
static get optionsSpecification() {
return {
...DiscordBasePlugin.optionsSpecification,
channelID: {
required: true,
description: 'The ID of the channel to alert admins through.',
default: '',
example: '667741905228136459'
},
threshold: {
required: false,
description:
'Admins will be alerted when a player has this or more reputation points. For more information on ' +
'reputation points, see the ' +
'<a href="https://communitybanlist.com/faq">Community Ban List\'s FAQ</a>',
default: 6
}
};
}
constructor(server, options, connectors) {
super(server, options, connectors);
this.onPlayerConnected = this.onPlayerConnected.bind(this);
}
async mount() {
this.server.on('PLAYER_CONNECTED', this.onPlayerConnected);
}
async unmount() {
this.server.removeEventListener('PLAYER_CONNECTED', this.onPlayerConnected);
}
async onPlayerConnected(info) {
try {
const steamID = this.isValid(info, '<steamID>');
if(!steamID) {
return;
};
const data = await request(
'https://communitybanlist.com/graphql',
gql`
query Search($id: String!) {
steamUser(id: $id) {
id
name
avatarFull
reputationPoints
riskRating
reputationRank
lastRefreshedInfo
lastRefreshedReputationPoints
lastRefreshedReputationRank
activeBans: bans(orderBy: "created", orderDirection: DESC, expired: false) {
edges {
cursor
node {
id
}
}
}
expiredBans: bans(orderBy: "created", orderDirection: DESC, expired: true) {
edges {
cursor
node {
id
}
}
}
}
}
`,
{ id: steamID }
);
if (!data.steamUser) {
this.verbose(
2,
`Player ${info.player.name} (Steam ID: ${steamID}) is not listed in the Community Ban List.`
);
return;
}
if (data.steamUser.reputationPoints < this.options.threshold) {
this.verbose(
2,
`Player ${info.player.name} (Steam ID: ${steamID}) has a reputation below the threshold.`
);
return;
}
const embed = this.buildEmbed()
.setColor('#ffc40b')
.setTitle(`${info.player.name} is a potentially harmful player!`)
.setAuthor({
name: 'Community Ban List',
iconURL: 'https://communitybanlist.com/static/media/cbl-logo.caf6584e.png',
url: 'https://communitybanlist.com/'
})
.setDescription(`[${info.player.name}](https://communitybanlist.com/search/${steamID}) has ${data.steamUser.reputationPoints} reputation points on the Community Ban List and is therefore a potentially harmful player.`)
.setThumbnail(data.steamUser.avatarFull)
.addFields(
{
name: 'Reputation Points',
value: `${data.steamUser.reputationPoints} (${
data.steamUser.reputationPointsMonthChange || 0
} from this month)`,
inline: true
},
{
name: 'Risk Rating',
value: `${data.steamUser.riskRating} / 10`,
inline: true
},
{
name: 'Reputation Rank',
value: `#${data.steamUser.reputationRank}`,
inline: true
},
{
name: 'Active Bans',
value: `${data.steamUser.activeBans.edges.length}`,
inline: true
},
{
name: 'Expired Bans',
value: `${data.steamUser.expiredBans.edges.length}`,
inline: true
}
)
.setFooter({ text: 'Powered by SquadJS and the Community Ban List', iconURL: null });
await this.sendDiscordMessage({ embeds: [embed] });
} catch (err) {
this.verbose(
1,
`Failed to fetch Community Ban List data for player ${info.name} (Steam ID: ${info.steamID}): `,
err
);
}
}
}