· 6 years ago · Nov 17, 2019, 04:48 PM
1using OpenQA.Selenium;
2using OpenQA.Selenium.Chrome;
3using System;
4using System.Threading;
5using System.Threading.Tasks;
6using VkNet;
7using VkNet.Enums.SafetyEnums;
8using VkNet.Exception;
9using VkNet.Model;
10using VkNet.Model.RequestParams;
11
12namespace Project_3S_Arena_Framework
13{
14 class Program
15 {
16 public static IWebDriver web;
17 //public static string MyAppToken => "Соси хуй)))))))))"; // Тестовая группа
18 public static string MyAppToken => "Тоже соси хуй"; // Основная группа
19
20 //public static ulong MyGroupId => Шучу; // Тестовая группа
21 public static ulong MyGroupId => Прост иди нахуй; // Основная группа
22
23
24 public static string serverSlot = "null";
25 public static string online = "null";
26 public static int maxOnline = 0;
27 public static int maxOnlineGlobal = 0;
28 public static string timeMaxOnline = "null";
29 public static string MapMaxOnline = "null";
30 public static string player = "null";
31 public static string players = "null";
32 public static string playersFinish = "\nnull";
33 public static string timeMap = "null";
34 public static string serverIp = "null";
35 public static string confa = "null";
36 public static string SBSite = "null";
37 public static string group = "null";
38 public static string map = "null";
39 public static int m = 0, c = 0;
40 public static bool one = true;
41 public static bool playersCheck = true;
42 public static bool onlineCheck = true;
43 public static int playerNum = 1;
44 public static bool starts = true;
45
46 public static string mapping = "";
47 public static bool timeM = true;
48
49 static void Main(string[] args)
50 {
51 Console.BackgroundColor = ConsoleColor.Black;
52 Console.ForegroundColor = ConsoleColor.DarkRed;
53 Console.WriteLine("Запуск программы");
54 var api = new VkApi();
55 api.Authorize(new ApiAuthParams { AccessToken = MyAppToken });
56 Console.WriteLine("Авторизация вк");
57 var random = new Random();
58 var server = api.Groups.GetLongPollServer(MyGroupId);
59
60 Action info = () =>
61 {
62 serverIp = "Говнокод";
63 group = "АИм красавчик ваще";
64 SBSite = "Я стаса рот ебал";
65 confa = "Нету конфы идите нахуй";
66 //
67 map = "null";
68 online = "null";
69 serverSlot = "64";
70 //
71 timeMap = "null";
72 timeMaxOnline = "null";
73 maxOnline = 0;
74 maxOnlineGlobal = 0;
75
76 ChromeDriverService service = ChromeDriverService.CreateDefaultService();
77 service.HideCommandPromptWindow = true;
78 var options = new ChromeOptions();
79 web = new ChromeDriver(service, options);
80 Thread.Sleep(5000);
81 try{ web.Navigate().GoToUrl("тут был какой то сайт где получаешь инфу"); } catch(Exception e) { Console.WriteLine(e); }
82 Console.WriteLine("Запущен цикл инфы");
83 while (true)
84 {
85 try
86 {
87 if (one) {Thread.Sleep(10000); one = false; }
88 Console.WriteLine($"Цикл ОнлайнЧек запущен");
89 while (onlineCheck)
90 {
91 online = web.FindElement(By.XPath("//td[@id='players_1']")).Text;
92 online = online.Replace("/64", "");
93 map = web.FindElement(By.XPath("//td[@id='map_1']")).Text;
94 if(online == "Н/С") { Thread.Sleep(10000); onlineCheck = true; Console.WriteLine("Выдало Н/C"); web.Navigate().Refresh(); Thread.Sleep(20000); } else { onlineCheck = false; }
95 if(map == "Н/С") { Thread.Sleep(10000); onlineCheck = true; Console.WriteLine("Выдало Н/C"); web.Navigate().Refresh(); Thread.Sleep(20000); } else { onlineCheck = false; }
96 }
97 Console.WriteLine($"Цикл ОнлайнЧек окончен");
98 onlineCheck = true;
99 Console.WriteLine($"Онлайн: {online}");
100 Console.WriteLine($"Мапа: {map}");
101 players = "";
102 Console.WriteLine($"Цикл ПлеерсЧек запущен");
103 while (playersCheck)
104 {
105 try
106 {
107 player = web.FindElement(By.XPath($"//tr[@id='player_s1p{playerNum}']/td[@class='p-l-10 p-t-5']")).Text;
108 Console.WriteLine($"Добавлен игрок: {player}, с номером: {playerNum}");
109 }
110 catch(OpenQA.Selenium.NoSuchElementException)
111 {
112 playersFinish = players;
113 player = null;
114 playersCheck = false;
115 }
116 if (player != null)
117 {
118 players = String.Concat(players, $"\n{playerNum}. {player}");
119 }
120 else
121 {
122 //Console.WriteLine(playersFinish);
123 playersFinish = players;
124 player = null;
125 playersCheck = false;
126 }
127 playerNum++;
128 if (playerNum > Convert.ToInt32(serverSlot))
129 {
130 Console.WriteLine("Сработало ограничение списка игроков");
131 playersFinish = players;
132 player = null;
133 playersCheck = false;
134 }
135 }
136 Console.WriteLine($"Цикл ПлеерсЧек закончен");
137 playerNum = 1;
138 playersCheck = true;
139 try
140 {
141 if (maxOnline < Convert.ToInt32(online))
142 {
143 maxOnline = Convert.ToInt32(online);
144 timeMaxOnline = Convert.ToString(DateTime.Now.ToShortTimeString());
145 MapMaxOnline = map;
146 //Console.WriteLine($"Ура максимальный онлайн: {maxOnline} | Дата: {timeMaxOnline} | Дата без переменной: {DateTime.Now}");
147 }
148 if (maxOnlineGlobal < Convert.ToInt32(online))
149 {
150 maxOnlineGlobal = Convert.ToInt32(online);
151 }
152 //Console.WriteLine();
153 if (Convert.ToString(DateTime.Now.ToShortTimeString()) == "0:00") { maxOnline = Convert.ToInt32(online); Console.WriteLine($"Сброс онлайна время 0:00, новое значение: {maxOnline}"); }
154 }
155 catch (FormatException) { Console.WriteLine($"Ошибка 0"); }
156 web.Navigate().Refresh();
157 Thread.Sleep(8000);
158 }
159 catch(OpenQA.Selenium.StaleElementReferenceException) // stale element reference: element is not attached to the page document
160 {
161 Console.WriteLine("Ошибка 1");
162 web.Navigate().Refresh();
163 }
164 catch (OpenQA.Selenium.WebDriverException) // The HTTP request to the remote WebDriver server for URL http://localhost:54440/session/e45921f8ea600b0436667f00eabbe632/element timed out after 60 seconds.
165 {
166 Console.WriteLine("Ошибка 2");
167 try
168 {
169 web.Navigate().Refresh();
170 }
171 catch (WebDriverException)
172 {
173 service.HideCommandPromptWindow = true;
174 web = new ChromeDriver(service, options);
175 web.Navigate().GoToUrl("https://arena.myarena.site/index.php?p=servers&s=0");
176 }
177 }
178 starts = false;
179 }
180 };
181
182 Action timemap = () =>
183 {
184 Console.WriteLine("Цикл чекинга мапинга активирован");
185 while (true)
186 {
187 mapping = map;
188 bool CheckMap = true;
189 while (CheckMap)
190 {
191 if (mapping == map)
192 {
193 timeM = true;
194 CheckMap = true;
195 }
196 else
197 {
198 timeM = false;
199 CheckMap = false;
200 m = 0;
201 c = 0;
202 Console.WriteLine($"Карта сменена с '{mapping}' на '{map}', таймер длительности карты запущен по новой");
203
204 }
205 }
206 }
207 };
208
209 Action timer = () =>
210 {
211 m = 0;
212 c = 0;
213 Console.WriteLine("Цикл timer активирован");
214 while (timeM)
215 {
216
217 if (m <= 60)
218 {
219 m++;
220 }
221 else
222 {
223 m = 0;
224 c++;
225 }
226 Thread.Sleep(60000);
227 timeMap = $"{c}:{m}";
228 Console.WriteLine($"Время: {timeMap}");
229 }
230 };
231
232 Action start = () =>
233 {
234 Console.WriteLine("Цикл LongPollHistory активирован");
235 while (true)
236 {
237 try
238 {
239 var poll = api.Groups.GetBotsLongPollHistory(
240 new BotsLongPollHistoryParams
241 { Server = server.Server, Ts = server.Ts, Key = server.Key, Wait = 1 });
242 if (poll?.Updates == null) continue;
243 server.Ts = poll.Ts;
244 foreach (var update in poll.Updates)
245 {
246 if (update.Type == GroupUpdateType.MessageNew)
247 {
248 Console.WriteLine(new String('=', 30));
249 Console.WriteLine($"Пользователь: {update.Message.FromId}");
250 Console.WriteLine($"Cообщение: {update.Message.Text}");
251 Console.WriteLine($"Время: {update.Message.Date}");
252 Console.WriteLine(new String('=', 30));
253
254 switch (update.Message.Text)
255 {
256 case "/помощь":
257 api.Messages.Send(new MessagesSendParams()
258 {
259 RandomId = random.Next(),
260 UserId = update.Message.PeerId,
261 Message = "Список доступных команд:\n\n?Серверные:\n\t⠀⠀ ?/онлайн\n⠀⠀ ?/игроки\n\n?Общение:\n\t⠀⠀ ?/беседа\n\n?Информационные:\n\t⠀⠀ ✨/группа\n\t⠀⠀ ?/ip\n\t⠀⠀ ?/сб"
262 });
263 break;
264
265 case "/онлайн":
266 api.Messages.Send(new MessagesSendParams()
267 {
268 RandomId = random.Next(),
269 UserId = update.Message.PeerId,
270 Message = $"Игроки онлайн: {online}/{serverSlot}\nМаксимальный онлайн сегодня: {maxOnline} (в {timeMaxOnline}, на карте {MapMaxOnline})\nМаксимальный онлайн за все время: {maxOnlineGlobal}\nТекущая карта: {map}\nВремя текущей карты: ({timeMap}) Ч/М"
271 });
272 break;
273
274 case "/беседа":
275 api.Messages.Send(new MessagesSendParams()
276 {
277 RandomId = random.Next(),
278 UserId = update.Message.PeerId,
279 Message = $"Наша беседа\n\n✞????? ?????✞:\n{confa}"
280 });
281 break;
282
283 case "/ip":
284 api.Messages.Send(new MessagesSendParams()
285 {
286 RandomId = random.Next(),
287 UserId = update.Message.PeerId,
288 Message = $"IP: {serverIp}"
289 });
290 break;
291
292 case "/сб":
293 api.Messages.Send(new MessagesSendParams()
294 {
295 RandomId = random.Next(),
296 UserId = update.Message.PeerId,
297 Message = $"Наш SourceBan:\n{SBSite}"
298 });
299 break;
300
301 case "/группа":
302 api.Messages.Send(new MessagesSendParams()
303 {
304 RandomId = random.Next(),
305 UserId = update.Message.PeerId,
306 Message = $"Основная группа вк сервера:\n{group}"
307 });
308 break;
309
310 case "/игроки":
311 api.Messages.Send(new MessagesSendParams()
312 {
313 RandomId = random.Next(),
314 UserId = update.Message.PeerId,
315 Message = $"Список игроков онлайн [{online}/{serverSlot}]:\n{playersFinish}"
316 });
317 break;
318
319 default:
320 api.Messages.Send(new MessagesSendParams()
321 {
322 RandomId = random.Next(),
323 UserId = update.Message.PeerId,
324 Message = $"Чтобы посмотреть список доступных команд, пропишите: /помощь"
325 });
326 break;
327
328 case "Артур Киреев кто?":
329 api.Messages.Send(new MessagesSendParams()
330 {
331 RandomId = random.Next(),
332 UserId = update.Message.PeerId,
333 Message = $"Гей какой-то которого в жопу поимели))))"
334 });
335 break;
336
337 case "артур киреев кто?":
338 api.Messages.Send(new MessagesSendParams()
339 {
340 RandomId = random.Next(),
341 UserId = update.Message.PeerId,
342 Message = $"Гей какой-то которого в жопу поимели))))"
343 });
344 break;
345
346 case "артур киреев кто":
347 api.Messages.Send(new MessagesSendParams()
348 {
349 RandomId = random.Next(),
350 UserId = update.Message.PeerId,
351 Message = $"Гей какой-то которого в жопу поимели))))"
352 });
353 break;
354 case "Киреев кто?":
355 api.Messages.Send(new MessagesSendParams()
356 {
357 RandomId = random.Next(),
358 UserId = update.Message.PeerId,
359 Message = $"Гей какой-то которого в жопу поимели))))"
360 });
361 break;
362 case "киреев кто?":
363 api.Messages.Send(new MessagesSendParams()
364 {
365 RandomId = random.Next(),
366 UserId = update.Message.PeerId,
367 Message = $"Гей какой-то которого в жопу поимели))))"
368 });
369 break;
370 case "киреев кто":
371 api.Messages.Send(new MessagesSendParams()
372 {
373 RandomId = random.Next(),
374 UserId = update.Message.PeerId,
375 Message = $"Гей какой-то которого в жопу поимели))))"
376 });
377 break;
378 }
379
380 /*api.Messages.Send(new MessagesSendParams()
381 {
382 RandomId = random.Next(),
383 UserId = update.Message.PeerId,
384 Message = update.Message.Text
385 });*/
386 }
387 }
388 }
389 catch (LongPollException exception)
390 {
391 if (exception is LongPollOutdateException outdateException)
392 server.Ts = outdateException.Ts;
393 else
394 {
395 server = api.Groups.GetLongPollServer(MyGroupId);
396 }
397 }
398 catch (Exception e)
399 {
400 Console.WriteLine(e.Message);
401 }
402 }
403 };
404
405 Task.Run(() => info());
406 while (starts) { }
407 Console.WriteLine("Остатки запускаются");
408 Task.Run(() => timer());
409 Task.Run(() => timemap());
410 start();
411 Console.WriteLine("Конец");
412 }
413 }
414}