· 4 years ago · Apr 18, 2021, 05:42 PM
1registerPlugin({
2 name: "Teamspeak Clanverwaltung",
3 version: "Alpha 0.1",
4 description: "Clanverwaltung für The Force",
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// CW Upcoming Battles
21 {
22 name: "cwCheck",
23 title: "List of upcoming battles",
24 type: "checkbox",
25 }, {
26 name: "cwClans",
27 indent: 4,
28 title: "Clan Tags for your cw clans",
29 type: "strings",
30 conditions: [{
31 field: "cwCheck",
32 value: true,
33 },
34 ],
35 }, {
36 name: "cwChannel",
37 indent: 4,
38 title: "Select Channel to display Info",
39 type: "channel",
40 conditions: [{
41 field: "cwCheck",
42 value: true,
43 },
44 ],
45 }, {
46 name: "cwTime",
47 indent: 4,
48 title: "Insert the update time in minutes",
49 type: "string",
50 conditions: [{
51 field: "cwCheck",
52 value: true,
53 },
54 ],
55 }
56 ]
57
58
59
60}, function(sinusbot, config) {
61 //Vers for required Modules
62 var backend = require("backend");
63 var engine = require("engine");
64 var http = require("http");
65
66 //Config vars
67 var regionArr = ["ru","eu","na","asia"];
68 var key = "?application_id=" + config.apiKey;
69 var apiUrl = "https://api.worldoftanks." + regionArr[config.clanRegion];
70
71 //######################CW Battles######################
72 /*var regionArr = ["ru","eu","na","asia"];
73 var region = regionArr[config.clanRegion];
74 var key = "?application_id=" + config.apiKey;cwTags
75 var apiUrl = "https://api.worldoftanks." + region;*/
76 var cwTime = [];
77 var cwTier = [];
78 var cwMap = [];
79 var cwVs = [];
80 var output;
81
82 function cwClanData() {
83 var clanId;
84 config.cwClans.forEach(function (cwClans) {
85 http.simpleRequest({
86 method: "GET",
87 timeout: 60000,
88 url: apiUrl + "/wgn/clans/list/" + key + "&game=wot&language=en&limit=1&search=" + cwClans
89 }, function (error, responseId) {
90 //engine.log("Claninfos erhalten");
91 var clanData = JSON.parse(responseId.data);
92 clanId = clanData.data[0].clan_id;
93 output += "[b]Clan:[/b] " + clanData.data[0].tag;
94 cwBattles(clanId);
95 engine.log("Claninfos verarbeitet " + clanId);
96 });
97 backend.getChannelByID(config.cwChannel).setDescription(output);
98 });
99 }
100
101 function cwBattles(clanId) {
102 http.simpleRequest({
103 method: "GET",
104 timeout: 60000,
105 url: apiUrl + "/wot/globalmap/clanbattles/" + key + "&clan_id=" + clanId + "&language=en",
106 },function (error, responseBattle) {
107 //engine.log("Battles erhalten");
108 var battleData = JSON.parse(responseBattle.data);
109 output += " [b]Battle Count:[/b] " + battleData.meta.count;
110 if(battleData.meta.count == 0) {
111 cwMap = [];
112 cwVs = [];
113 engine.log("Battleinfos verarbeitet " + clanId);
114 } else {
115 for (i in battleData) {
116 var timestamp = battleData.data[i].time;
117 var date = new Date(timestamp * 1000);
118 if (date.getMinutes() < 10) {
119 minutes = "0" + date.getMinutes();
120 } else {
121 minutes = date.getMinutes();
122 }
123 var frontId = battleData.data[i].front_id;
124 var provinceId = battleData.data[i].province_id;
125 cwArena(frontId, provinceId, i);
126 var competitorId = battleData.data[i].competitor_id;
127 cwCompetitor(competitorId, i);
128 }
129 for (i in cwTime) {
130 output += "\n"+cwTime[i] + cwTier[i] + cwMap[i] + cwVs[i] + "\n\n";
131 }
132 engine.log("Battleinfos verarbeitet");
133 }
134 }
135 )
136 }
137
138 function cwArena(frontId, provinceId, i) {
139 http.simpleRequest({
140 method: "GET",
141 timeout: 60000,
142 url: apiUrl + "/wot/globalmap/provinces/" + key + "&front_id=" + frontId + "&province_id=" + provinceId + "&language=en&fields=arena_name"
143 },function (error, responseProvince) {
144 var provinceData = JSON.parse(responseProvince.data);
145 var battleMap = provinceData.data[0].arena_name;
146 cwMap[i] = " [b]Map:[/b] " + battleMap;
147 engine.log("Arenainfos verarbeitet");
148 return;
149 });
150 }
151
152 function cwCompetitor(competitorId, i) {
153 http.simpleRequest({
154 method: "GET",
155 timeout: 60000,
156 url: apiUrl + "/wot/globalmap/claninfo/" + key + "&clan_id=" + competitorId
157 },function (error, responseCompetitor) {
158 var competitorData = JSON.parse(responseCompetitor.data);
159 var competitorTag = competitor.data[competitorId].tag;
160 cwVs[i] = " [b] vs:[/b] [url=https://wot-life.com/eu/clan/" + competitorTag + "-" + competitorId + "/]" + competitorTag + "[/url]";
161 engine.log("Competitor verarbeitet");
162 return;
163 });
164 }
165
166 setInterval(function refreshCwList() {
167 if (config.cwCheck == true) {
168 output = "[b]Upcoming CW Battles:[/b]\n";
169 cwTime = [];
170 cwTier = [];
171 cwClanData();
172 }
173 }, config.cwTime * 60000);
174
175 //######################New Script######################
176
177 });