Answer the question
In order to leave comments, you need to log in
Why is C# ignoring validation?
I create a "bot" that changes the name of the conversation. But on the server, his roof is blown off and he doesn’t seem to pass the test, it turns out that he changes the name many times to the same one. And when I run the project in Visual Studio, everything is fine, and the name changes when it fails the check. Part of the code below.
Repeats every 2 seconds to "cycle" the bot.
TimerCallback a = new TimerCallback(Bot);
Timer timer = new Timer(a, 0, 0, 2000);
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
// устанавливаем метод обратного вызова
TimerCallback tm = new TimerCallback(Bot);
// создаем таймер
Timer timer = new Timer(tm, 0, 0, 2000);
}
public static void Bot(object obj)
{
string url = "https://api.vk.com/method/messages.getChat?access_token=TOKEN&chat_id=1";
WebClient webClient = new WebClient();
var response = webClient.DownloadString(url);
var json = Encoding.UTF8.GetString(Encoding.GetEncoding(1251).GetBytes(response));
JObject j = JObject.Parse(json);
string title = (string)j["response"]["title"];
int users = j["response"]["users"].Count();
string name = "Тест, нас " + users;
if (title != name)
{
url = "https://api.vk.com/method/messages.editChat?access_token=TOKEN&chat_id=1&title=" + name;
webClient = new WebClient();
response = webClient.DownloadString(url);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question