C#:
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Configuration;
namespace Oxide.Plugins {
[Info("StatusVK", "nate", "1.0.0")]
[Description("Статус сервера для вашей группы ВК")]
public class StatusVK : RustPlugin {
#region Config
private int UpdTimer = 30;
string VKTokenApp = "";
string GroupID = "";
string MaxPlayer = "120";
string Message;
public int count = 0;
protected override void LoadDefaultConfig() {
PrintWarning("Создание нового файла конфигурации...");
}
private void LoadConfigValues() {
GetConfig("VK - Token", ref VKTokenApp);
GetConfig("VK - ID группы", ref GroupID);
GetConfig("Сколько слотов на сервере", ref MaxPlayer);
GetConfig("Время обновления статуса", ref UpdTimer);
SaveConfig();
}
private void GetConfig<T>(string Key, ref T var) {
if (Config[Key] != null) {
var = (T)Convert.ChangeType(Config[Key], typeof(T));
}
Config[Key] = var;
}
#endregion
#region OxideHooks
void Loaded() {
LoadConfigValues();
}
private void Init() {
timer.Once(UpdTimer, () => SendStatus());
}
#endregion
private static DateTime TimeCreatedSave = SaveRestore.SaveCreatedTime.Date;
#region Functions
private void SendStatus() {
Message = "Статус сервера: ✔, Онлайн: "+BasePlayer.activePlayerList.Count+""+MaxPlayer+", Спящих: "+BasePlayer.sleepingPlayerList.Count+", Заходят: "+ServerMgr.Instance.connectionQueue.joining.Count+",\nВайп был: "+TimeCreatedSave.Date.ToString(@"dd.MM")+"+В 15.00 по МСК+";
webrequest.EnqueuePost("https://api.vk.com/method/status.set", "group_id="+GroupID+"&text="+Message+"&access_token="+VKTokenApp+"&v=5.83", (code, response) => GetCallback(code, response), this);
timer.Once(UpdTimer, () => SendStatus());
}
[ConsoleCommand("update.status")]
private void CmdUpdateVk(ConsoleSystem.Arg arg) {
SendStatus();
}
void GetCallback(int code, string response) {
if (!response.Contains("error")) {
PrintWarning("Статус обновлен!");
}
else {
PrintWarning($"статус не изменен.Ошибка: {response}");
LogToFile("errors", $"[{DateTime.Now}] Статус не изменен.Ошибка: {response}", this);
}
}
#endregion
}
}