using System; using System.Text; using System.Collections.Generic; using System.Linq; using Oxide.Core.Plugins; using Oxide.Core.Libraries; using Facepunch; namespace Oxide.Plugins { [Info("APDiscordOnline", "VORON", "0.0.2")] [Description("Sends online players list to Discord via webhook in multiple languages with customizable embed colors")] public class APDiscordOnline : CovalencePlugin { private string webhookUrl = "https://discord.com/api/webhooks/your_webhook_url"; private int updateInterval = 300; private string selectedLanguage = "en"; private string staticColor = "16777215"; private bool useRandomColor = false; private readonly Dictionary> messages = new Dictionary> { ["en"] = new Dictionary { ["NoPlayers"] = "No players online to send.", ["PlayerList"] = "**Online Players List:**", ["Error"] = "Failed to send message to Discord (Code: {0}): {1}" }, ["ru"] = new Dictionary { ["NoPlayers"] = "Нет игроков онлайн для отправки.", ["PlayerList"] = "**Список игроков онлайн:**", ["Error"] = "Не удалось отправить сообщение в Discord (Код: {0}): {1}" }, ["uk"] = new Dictionary { ["NoPlayers"] = "Немає гравців онлайн для відправки.", ["PlayerList"] = "**Список гравців онлайн:**", ["Error"] = "Не вдалося надіслати повідомлення в Discord (Код: {0}): {1}" }, ["pl"] = new Dictionary { ["NoPlayers"] = "Brak graczy online do wysłania.", ["PlayerList"] = "**Lista graczy online:**", ["Error"] = "Nie udało się wysłać wiadomości do Discord (Kod: {0}): {1}" } }; protected override void LoadDefaultConfig() { Config["WebhookUrl"] = webhookUrl; Config["UpdateInterval"] = updateInterval; Config["Language"] = selectedLanguage; Config["EmbedColor"] = staticColor; Config["UseRandomColor"] = useRandomColor; SaveConfig(); } private void OnServerInitialized() { webhookUrl = Config["WebhookUrl"]?.ToString() ?? webhookUrl; updateInterval = Convert.ToInt32(Config["UpdateInterval"] ?? updateInterval); selectedLanguage = Config["Language"]?.ToString() ?? selectedLanguage; staticColor = Config["EmbedColor"]?.ToString() ?? staticColor; useRandomColor = Convert.ToBoolean(Config["UseRandomColor"] ?? useRandomColor); if (!messages.ContainsKey(selectedLanguage)) { PrintWarning($"Language '{selectedLanguage}' not supported. Defaulting to 'en'."); selectedLanguage = "en"; } timer.Every(updateInterval, SendOnlinePlayersToDiscord); } private void SendOnlinePlayersToDiscord() { var players = BasePlayer.activePlayerList; if (players.Count == 0) { Puts(GetMessage("NoPlayers")); return; } var stringList = Facepunch.Pool.Get>(); try { stringList.Add(GetMessage("PlayerList")); foreach (var player in players) { stringList.Add($"{player.displayName} - `{player.userID}`"); } var message = string.Join("\n", stringList); SendDiscordMessage(message); } finally { stringList.Clear(); Facepunch.Pool.FreeList(ref stringList); } } private void SendDiscordMessage(string message) { var embedColor = useRandomColor ? GetRandomColor() : staticColor; string jsonPayload = $@" {{ ""embeds"": [ {{ ""description"": ""{EscapeJson(message)}"", ""color"": {embedColor} }} ] }}"; webrequest.Enqueue( webhookUrl, jsonPayload, (code, response) => { if (code != 204) { Puts(string.Format(GetMessage("Error"), code, response)); } }, this, RequestMethod.POST, new Dictionary { ["Content-Type"] = "application/json" } ); } private string GetMessage(string key) { if (messages[selectedLanguage].TryGetValue(key, out var value)) { return value; } return messages["en"].TryGetValue(key, out var fallback) ? fallback : "Message not found."; } private string EscapeJson(string text) { return text .Replace("\\", "\\\\") .Replace("\"", "\\\"") .Replace("\n", "\\n") .Replace("\r", "\\r"); } private string GetRandomColor() { Random random = new Random(); return random.Next(0, 16777215).ToString(); } } }