· 4 years ago · Apr 18, 2021, 04:32 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 engine.log(config.cwClans);
338 engine.log(config.cwClans.length);
339 //var clanList = config.cwClans;
340
341 function cwClanData() {
342 var clanId;
343 var j = 1;
344 config.cwClans.forEach(function (cwClans) {
345 http.simpleRequest({
346 method: "GET",
347 timeout: 60000,
348 url: apiUrl + "/wgn/clans/list/" + key + "&game=wot&language=en&limit=1&search=" + cwClans
349 }, function (error, responseId) {
350 //engine.log("Claninfos erhalten");
351 var clanData = JSON.parse(responseId.data);
352 clanId = clanData.data[0].clan_id;
353 //j = j + 1;
354 output += "[b]Clan " + j + ":[/b] " + clanData.data[0].tag;
355 cwBattles(clanId, j);
356 engine.log("Claninfos verarbeitet");
357 });
358 });
359 }
360
361 function cwBattles(clanId, j) {
362 http.simpleRequest({
363 method: "GET",
364 timeout: 60000,
365 url: apiUrl + "/wot/globalmap/clanbattles/" + key + "&clan_id=" + clanId + "&language=en",
366 },function (error, responseBattle) {
367 //engine.log("Battles erhalten");
368 var battleData = JSON.parse(responseBattle.data);
369 output += " [b]Battle Count:[/b] " + battleData.meta.count;
370 if(battleData.meta.count == 0) {
371 cwMap = [];
372 cwVs = [];
373 engine.log("Battleinfos verarbeitet");
374 cwSetDescription();
375 } else {
376 for (i in battleData) {
377 var timestamp = battleData.data[i].time;
378 var date = new Date(timestamp * 1000);
379 if (date.getMinutes() < 10) {
380 minutes = "0" + date.getMinutes();
381 } else {
382 minutes = date.getMinutes();
383 }
384 var frontId = battleData.data[i].front_id;
385 var provinceId = battleData.data[i].province_id;
386 cwArena(frontId, provinceId, i);
387 var competitorId = battleData.data[i].competitor_id;
388 cwCompetitor(competitorId, i);
389 }
390 for (i in cwTime) {
391 output += "\n"+cwTime[i] + cwTier[i] + cwMap[i] + cwVs[i] + "\n\n";
392 }
393 engine.log("Battleinfos verarbeitet");
394 cwSetDescription();
395 /*if (j == clanList.length) {
396 backend.getChannelByID(config.cwChannel).setDescription(output);
397 engine.log("Channelinfo bearbeitet");
398 j = j + 1;
399 }*/
400 }
401 }
402 )
403 }
404
405 function cwArena(frontId, provinceId, i) {
406 http.simpleRequest({
407 method: "GET",
408 timeout: 60000,
409 url: apiUrl + "/wot/globalmap/provinces/" + key + "&front_id=" + frontId + "&province_id=" + provinceId + "&language=en&fields=arena_name"
410 },function (error, responseProvince) {
411 var provinceData = JSON.parse(responseProvince.data);
412 var battleMap = provinceData.data[0].arena_name;
413 cwMap[i] = " [b]Map:[/b] " + battleMap;
414 engine.log("Arenainfos verarbeitet");
415 return;
416 });
417 }
418
419 function cwCompetitor(competitorId, i) {
420 http.simpleRequest({
421 method: "GET",
422 timeout: 60000,
423 url: apiUrl + "/wot/globalmap/claninfo/" + key + "&clan_id=" + competitorId
424 },function (error, responseCompetitor) {
425 var competitorData = JSON.parse(responseCompetitor.data);
426 var competitorTag = competitor.data[competitorId].tag;
427 cwVs[i] = " [b] vs:[/b] [url=https://wot-life.com/eu/clan/" + competitorTag + "-" + competitorId + "/]" + competitorTag + "[/url]";
428 engine.log("Competitor verarbeitet");
429 return;
430 });
431 }
432
433 function cwSetDescription() {
434 var j = 0;
435 engine.log("SetDescription aufgerufen");
436 if (j == config.cwClans.length) {
437 backend.getChannelByID(config.cwChannel).setDescription(output);
438 engine.log("Channelinfos bearbeitet");
439 } else {
440 engine.log("Fehlgeschlagen");
441 j = j + 1;
442 }
443 }
444
445 setInterval(function refreshCwList() {
446 if (config.cwCheck == true) {
447 output = "[b]Upcoming CW Battles:[/b]\n";
448 cwTime = [];
449 cwTier = [];
450 cwClanData();
451 }
452 }, 10000);
453
454 //######################New Script######################
455
456 /*
457 To-Do/Plans:
458 * Prüfung/Änderung der Channelbeschreibung CW Battles!!!
459 *
460 • Ticket Box for Script Support
461 • Mail for Guests @JoinAlert
462 • AFK Check for Join Alert
463 • Stop Playing @Safe Mode?
464 • Automatic Acitvation via command?
465 •
466 */
467 });