· 4 years ago · Apr 18, 2021, 03:46 PM
1registerPlugin({
2 name: "Teamspeak Clanverwaltung",
3 version: "Alpha 0.1",
4 description: "This is a teamspeak management tool for wot clans. Sinusbot needs Admin rights!",
5 author: "_maddiboy",
6 requiredModules: ["backend", "engine", "http", "event", "audio", "media"],
7 engines: ">= 1.0.0",
8
9 vars:[
10 {
11 name: "apiKey",
12 title: "API Key (get one at https://developers.wargaming.net)",
13 type: "string",
14 }, {
15 name: "clanRegion",
16 title: "The Region of the clan",
17 type: "select",
18 options: ["RU","EU","NA","ASIA"],
19 }, {
20 name: "clanTag",
21 title: "Name of the clan (seperate with ';', if there is more than one clan)",
22 type: "string",
23 }, {
24 name: "modules",
25 title: "Use the checkboxes to select which modules you wish to activate",
26 },
27 /* Next Version
28 // Automatic activation
29 {
30 name: "actCheck",
31 title: "Users can automatically activate themselves with a command to the bot. The bot assigns groups of rights based on ingame ranks",
32 type: "checkbox",
33 }, {
34 name: "actCommandRaw",
35 indent: 4,
36 title: "Command, the bot should respond to (without exclamation mark!)",
37 type: "string",
38 conditions: [{
39 field: "actAutomatic",
40 value: true,
41 },
42 ],
43 }, {
44 name: "actGroups",
45 indent: 4,
46 title: "Insert the server group ids in the order from reservist to commander (https://worldoftanks.eu/en/news/general-news/update93-changes-clan-structures/)",
47 type: "strings",
48 conditions: [{
49 field: "actAutomatic",
50 value: true,
51 },
52 ],
53 },*/
54 // New Users Join Alert
55 {
56 name: "alCheck",
57 title: "Server Join Alert, if a new User joins the Server",
58 type: "checkbox",
59 }, {
60 name: "alStandardChannel",
61 indent: 4,
62 title: "Select the standard channel of the server",
63 type: "channel",
64 conditions: [{
65 field: "alCheck",
66 value: true,
67 },
68 ],
69 }, {
70 name: "alGuestGroup",
71 indent: 4,
72 title: "Select the server group id of guests (you can see the id if you hover over the group)",
73 type: "strings",
74 conditions: [{
75 field: "alCheck",
76 value: true,
77 },
78 ],
79 }, {
80 name: "alSupporterId",
81 indent: 4,
82 title: "Select the server group ids, that should be informed (Supporter)",
83 type: "strings",
84 conditions: [{
85 field: "alCheck",
86 value: true,
87 },
88 ],
89 }, {
90 name: "alMessageType",
91 indent: 4,
92 title: "Should the Bot send a private chat message or poke the users?",
93 type: "select",
94 options: [
95 "PM",
96 "Poke",
97 ],
98 conditions: [{
99 field: "alCheck",
100 value: true,
101 },
102 ],
103 }, {
104 name: "alVariable",
105 indent: 5,
106 title: "Variable: &u = Username",
107 conditions: [{
108 field: "alCheck",
109 value: true,
110 },
111 ],
112 }, {
113 name: "alGuestText",
114 indent: 4,
115 title: "Insert the message, the bot should send to the guest. Variable: &u = Username",
116 type: "string",
117 conditions: [{
118 field: "alCheck",
119 value: true,
120 },
121 ],
122 }, {
123 name: "alSupporterText",
124 indent: 4,
125 title: "Insert the message, the bot should send to the Supporter.",
126 type: "string",
127 conditions: [{
128 field: "alCheck",
129 value: true,
130 },
131 ],
132 }, /*{
133 name: "alAfkChannels",
134 indent: 4,
135 title: "Ignore supporters in AFK Channels",
136 type: "array",
137 vars: [
138 {
139 name: "alAfkChannel",
140 title: "AFK Channel - Ignore Supporters",
141 type: "channel",
142 }, {
143 name: "alAfkChannelSub",
144 title: "Ignore sub channels too",
145 type: "checkbox",
146 },
147 ],
148 conditions: [{
149 field: "alCheck",
150 value: true,
151 },
152 ],
153 },*/
154
155 // CPU Save Mode
156 {
157 name: "cpuCheck",
158 title: "Save CPU and bandwith by muting the bot when nobody is listening.",
159 type: "checkbox",
160 },
161
162 // CW Upcoming Battles
163 {
164 name: "cwCheck",
165 title: "List of upcoming battles",
166 type: "checkbox",
167 }, {
168 name: "cwClans",
169 indent: 4,
170 title: "Clan Tags for your cw clans",
171 type: "strings",
172 conditions: [{
173 field: "cwCheck",
174 value: true,
175 },
176 ],
177 }, {
178 name: "cwChannel",
179 indent: 4,
180 title: "Select Channel to display Info",
181 type: "channel",
182 conditions: [{
183 field: "cwCheck",
184 value: true,
185 },
186 ],
187 }, {
188 name: "cwTime",
189 indent: 4,
190 title: "Insert the update time in minutes",
191 type: "string",
192 conditions: [{
193 field: "cwCheck",
194 value: true,
195 },
196 ],
197 }
198 ]
199
200
201
202}, function(sinusbot, config) {
203 //Vers for required Modules
204 var backend = require("backend");
205 var engine = require("engine");
206 var http = require("http");
207 var event = require("event");
208 var audio = require("audio");
209 var media = require("media");
210
211 //Config vars
212 var regionArr = ["ru","eu","na","asia"];
213 //var region = regionArr[config.clanRegion];
214 var key = "?application_id=" + config.apiKey;
215 var apiUrl = "https://api.worldoftanks." + regionArr[config.clanRegion];
216
217 //clan data
218 //var clanName = config.clanTag.split(";");
219 //var clanID = [];
220
221 //Get clan ID
222 /*function getclanData() {
223 var i = 0;
224 config.clanName.forEach(function (id) {
225 http.simpleRequest({
226 method: "GET",
227 timeout: 60000,
228 url: apiUrl + "/wgn/clans/list/" + key + "&game=wot&limit=1&search=" + clanName[i]
229 },
230 function (error, clanResponse) {
231 i = i + 1;
232 var clanData = JSON.parse(clanResponse.data);
233 clanID[i] = clanData.data[0].clan_id;
234 console.log(clanID[i]);
235 }
236 )
237 });
238 }*/
239
240 //######################Autoamtic Activation######################
241 /*event.on("chat", function(tx) {
242 var command = "!" + engine.actCommandRaw;
243 if (config.actAutomatic == true) {
244 if (tx.text.startsWith(command)) {
245 engline.log("Eine Nachricht ist angekommen" + tx.text);
246 }
247 } else {
248 engine.log("Fehlgeschlagen");
249 }
250 });*/
251
252 //######################Server Join Alert (New Users)######################
253 //Event - User joins standard channel
254 event.on("clientMove", function(ev) {
255 if (config.alCheck == true) {
256 if (ev.client.isSelf()) {
257 return;
258 }
259 if (ev.toChannel) {
260 if (ev.toChannel.id() == config.alStandardChannel){
261 if (alCheckGuest(ev.client, config.alGuestGroup)){
262 var clients = backend.getClients();
263 clients.forEach(function(client) {
264 alAlert(client, config.alSupporterId, ev.client);
265 });
266 }
267 }
268 }
269 }
270 });
271
272 //Send Alert to online supporters
273 function alAlert(client, alSupporterId, guestClient){
274 var serverGroups = client.getServerGroups();
275 for (var serverGroup in serverGroups){
276 for (var group in alSupporterId){
277 if (serverGroups[serverGroup].id() == alSupporterId[group]){
278 var newSupporterText = config.alSupporterText.replace("&u", guestClient.name());
279 //var newGuestText = config.alGuestText.replace("&u", guestClient.name());
280 if (config.alMessageType == 0){
281 client.chat(newSupporterText);
282 }else{
283 client.poke(newSupporterText);
284 }
285 return;
286 }
287 }
288 }
289 }
290
291 //Is Supporter AFK? -> Next Version
292 /*function alCheckAFK() {
293
294 }*/
295
296 //Is User a guest?
297 function alCheckGuest(client, alGuestGroup){
298 var serverGroups = client.getServerGroups();
299 for (var serverGroup in serverGroups){
300 if (serverGroups[serverGroup].id() != alGuestGroup){
301 return false;
302 }else{
303 return true;
304 }
305 }
306 return true;
307 }
308
309 //######################CPU Safe Mode######################
310 var csIsMuted = false;
311 event.on("clientMove", function(cs) {
312 if(config.cpuCheck == true) {
313 var csClients = backend.getCurrentChannel().getClientCount();
314
315 if (csClients > 1 && csIsMuted) {
316 //engine.log("Ending CPU Save Mode");
317 audio.setMute(false);
318 csIsMuted = false;
319 } else if (csClients <= 1) {
320 //engine.log("Starting CPU Save Mode");
321 audio.setMute(true);
322 csIsMuted = true;
323 }
324 }
325 })
326
327 //######################CW Battles######################
328 /*var regionArr = ["ru","eu","na","asia"];
329 var region = regionArr[config.clanRegion];
330 var key = "?application_id=" + config.apiKey;cwTags
331 var apiUrl = "https://api.worldoftanks." + region;*/
332 var cwTime = [];
333 var cwTier = [];
334 var cwMap = [];
335 var cwVs = [];
336 var output;
337 var clanList = config.cwClans;
338
339 function cwClanData() {
340 var clanId;
341 var j = 0;
342 config.cwClans.forEach(function (cwClans) {
343 http.simpleRequest({
344 method: "GET",
345 timeout: 60000,
346 url: apiUrl + "/wgn/clans/list/" + key + "&game=wot&language=en&limit=1&search=" + cwClans
347 }, function (error, responseId) {
348 //engine.log("Claninfos erhalten");
349 var clanData = JSON.parse(responseId.data);
350 clanId = clanData.data[0].clan_id;
351 //j = j + 1;
352 output += "[b]Clan " + j + ":[/b] " + clanData.data[0].tag;
353 cwBattles(clanId, j);
354 engine.log("Claninfos verarbeitet");
355 });
356 });
357 }
358
359 function cwBattles(clanId, j) {
360 http.simpleRequest({
361 method: "GET",
362 timeout: 60000,
363 url: apiUrl + "/wot/globalmap/clanbattles/" + key + "&clan_id=" + clanId + "&language=en",
364 },function (error, responseBattle) {
365 //engine.log("Battles erhalten");
366 var battleData = JSON.parse(responseBattle.data);
367 output += " [b]Battle Count:[/b] " + battleData.meta.count;
368 if(battleData.meta.count == 0) {
369 cwMap = [];
370 cwVs = [];
371 engine.log("Battleinfos verarbeitet");
372 cwSetDescription();
373 } else {
374 for (i in battleData) {
375 var timestamp = battleData.data[i].time;
376 var date = new Date(timestamp * 1000);
377 if (date.getMinutes() < 10) {
378 minutes = "0" + date.getMinutes();
379 } else {
380 minutes = date.getMinutes();
381 }
382 var frontId = battleData.data[i].front_id;
383 var provinceId = battleData.data[i].province_id;
384 cwArena(frontId, provinceId, i);
385 var competitorId = battleData.data[i].competitor_id;
386 cwCompetitor(competitorId, i);
387 }
388 for (i in cwTime) {
389 output += "\n"+cwTime[i] + cwTier[i] + cwMap[i] + cwVs[i] + "\n\n";
390 }
391 engine.log("Battleinfos verarbeitet");
392 cwSetDescription();
393 /*if (j == clanList.length) {
394 backend.getChannelByID(config.cwChannel).setDescription(output);
395 engine.log("Channelinfo bearbeitet");
396 j = j + 1;
397 }*/
398 }
399 }
400 )
401 }
402
403 function cwArena(frontId, provinceId, i) {
404 http.simpleRequest({
405 method: "GET",
406 timeout: 60000,
407 url: apiUrl + "/wot/globalmap/provinces/" + key + "&front_id=" + frontId + "&province_id=" + provinceId + "&language=en&fields=arena_name"
408 },function (error, responseProvince) {
409 var provinceData = JSON.parse(responseProvince.data);
410 var battleMap = provinceData.data[0].arena_name;
411 cwMap[i] = " [b]Map:[/b] " + battleMap;
412 engine.log("Arenainfos verarbeitet");
413 return;
414 });
415 }
416
417 function cwCompetitor(competitorId, i) {
418 http.simpleRequest({
419 method: "GET",
420 timeout: 60000,
421 url: apiUrl + "/wot/globalmap/claninfo/" + key + "&clan_id=" + competitorId
422 },function (error, responseCompetitor) {
423 var competitorData = JSON.parse(responseCompetitor.data);
424 var competitorTag = competitor.data[competitorId].tag;
425 cwVs[i] = " [b] vs:[/b] [url=https://wot-life.com/eu/clan/" + competitorTag + "-" + competitorId + "/]" + competitorTag + "[/url]";
426 engine.log("Competitor verarbeitet");
427 return;
428 });
429 }
430
431 function cwSetDescription(i) {
432 var j = 0;
433 if (config.cwClans[j] == undefined) {
434 backend.getChannelByID(config.cwChannel).setDescription(output);
435 engine.log("Channelinfos bearbeitet");
436 } else {
437 j = j + 1;
438 }
439 }
440
441 setInterval(function refreshCwList() {
442 if (config.cwCheck == true) {
443 output = "[b]Upcoming CW Battles:[/b]\n";
444 cwTime = [];
445 cwTier = [];
446 cwClanData();
447 }
448 }, config.cwTime * 60000);
449
450 //######################New Script######################
451
452 /*
453 To-Do/Plans:
454 * Prüfung/Änderung der Channelbeschreibung CW Battles!!!
455 *
456 • Ticket Box for Script Support
457 • Mail for Guests @JoinAlert
458 • AFK Check for Join Alert
459 • Stop Playing @Safe Mode?
460 • Automatic Acitvation via command?
461 •
462 */
463 });