-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
155 lines (141 loc) · 6.2 KB
/
Program.cs
File metadata and controls
155 lines (141 loc) · 6.2 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
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using xNet;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
namespace MultiThreadCommands
{
class Program
{
public static string Api = "https://api.vk.com/method/";
public static string Token = "", server = "", key = "", ts = "";
public static string ApiVer = "&v=5.80";
//----Переменные для консольных команд-----
public static bool json_mode = false;
//-----------------------------------------
static void Main(string[] args)
{
//----Настройки окна------------
Console.SetWindowSize(130, 10);
Console.Title = "VK Bot";
Console.ForegroundColor = ConsoleColor.Blue;
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
//------------------------------
Console.WriteLine(">> Начало работы...");
Console.WriteLine("");
Bots.CreateList();
Console.WriteLine(" Загружено ботов: " + Bots.List.Count);
Console.WriteLine(" Основной бот: " + Bots.List[0].Name);
Token = Bots.List[0].Token;
Groups.CreateList();
Console.WriteLine(" Бесед загружено: " + Groups.List.Count);
User.CreteList();
Console.WriteLine(" Пользователей загружено: " + User.List.Count);
Console.WriteLine("");
try
{
dynamic getLongPollServer = JObject.Parse(new HttpRequest(Api).Post("messages.getLongPollServer?need_pts=1&lp_version=3&" + Token).ToString());
server = getLongPollServer.response.server;
key = getLongPollServer.response.key;
ts = getLongPollServer.response.ts;
Console.WriteLine("Данные получены");
}
catch
{
Console.WriteLine("Ошибка получения данных");
Console.ReadLine();
Environment.Exit(0);
}
Console.WriteLine("Сервер:" + server + "\nКлюч: " + key + "\nВременной штамп: " + ts);
Console.WriteLine("========================================");
Thread.Sleep(50);
Thread CallBack = new Thread(Program.CallBack);
CallBack.Start();
Thread.Sleep(100);
Thread MessageProcessing = new Thread(Processing.General);
MessageProcessing.Start();
Thread.Sleep(100);
Thread EventProcessing = new Thread(Events.EventTimer);
EventProcessing.Start();
Thread.Sleep(100);
Console.WriteLine("Консоль доступна");
Console.WriteLine("");
while (true)
{
string local_command = Console.ReadLine();
switch (local_command)
{
case "stop":
CallBack.Abort();
MessageProcessing.Abort();
EventProcessing.Abort();
Environment.Exit(0);
break;
case "json":
if(json_mode)
{
json_mode = false;
Console.WriteLine("Json режим деактивирован");
}
else
{
json_mode = true;
Console.WriteLine("Json режим активирован");
}
break;
case "add user":
Console.Write("Name: ");
User.Add(User.List.Count + 1, Console.ReadLine());
break;
case "user count":
Console.WriteLine("Пользователей зарегестрировано: " + User.List.Count);
break;
case "stats":
Console.WriteLine("Сообщений на обработке: " + Messages.List.Count);
Console.WriteLine("Сообщений: " + Messages.MCount);
Console.WriteLine("Команд: " + Messages.CCount);
Console.WriteLine("Команд обработано: " + Messages.FCount);
break;
}
}
}
public static void CallBack()
{
Console.WriteLine("Запущена процедура приёма событий");
while (true)
{
Thread.Sleep(10);
try
{
dynamic requestUserLongPoll = JObject.Parse(new HttpRequest().Post("https://" + server + "?act=a_check&key=" + key + "&ts=" + ts + "&wait=25&mode=2&version=2").ToString());
foreach (JArray update in requestUserLongPoll.updates)
{
Messages.AddMessage(update);
}
ts = requestUserLongPoll.ts;
}
catch (Exception EX)
{
try
{
Console.WriteLine(EX.Message);
Console.WriteLine(EX.StackTrace);
dynamic getLongPollServer = JObject.Parse(new HttpRequest(Api).Post("messages.getLongPollServer?need_pts=1&lp_version=3&" + Token).ToString());
server = getLongPollServer.response.server;
key = getLongPollServer.response.key;
ts = getLongPollServer.response.ts;
Console.WriteLine("Данные получены");
}
catch
{
Console.WriteLine("Ошибка получения данных");
}
}
}
}
}
}