Пример #1
0
        private void API_SendTextMessage(string webhookURL, string content, bool tts, Action <int> foreignCallback = null)
        {
            FancyMessage message = new FancyMessage(content, tts, null);
            var          payload = message.toJSON();

            Request(webhookURL, payload, (Callback) => foreignCallback.Invoke(Callback));
        }
Пример #2
0
        private void HandleMessage(string name, string message)
        {
            string       discordMessage = GetLang("PlayerChatFormat", null, name, message);
            FancyMessage dmessage       = new FancyMessage(discordMessage, ChatTTS, null);
            var          payload        = dmessage.toJSON();

            Request(ChatURL, payload);
        }
Пример #3
0
        private void MessageCommand(IPlayer player, string command, string[] args)
        {
            if (!MessageEnabled)
            {
                return;
            }
            if (args.Length < 1)
            {
                SendMessage(player, GetLang("MessageSyntax", player.Id));
                return;
            }
            if (OnCooldown(player, CooldownType.MessageCooldown))
            {
                var time = (storedData.Players[player.Id].messageCooldown.AddSeconds(MessageCooldown) - DateTime.UtcNow).Seconds;
                SendMessage(player, GetLang("Cooldown", player.Id, time));

                return;
            }
            var           text   = string.Join(" ", args.ToArray());
            List <Fields> fields = new List <Fields>();

            fields.Add(new Fields(GetLang("Embed_MessagePlayer"), $"[{ player.Name }](https://steamcommunity.com/profiles/{player.Id})", true));
            fields.Add(new Fields(GetLang("Embed_MessageMessage"), text, false));
            FancyMessage message = new FancyMessage(MessageAlert, false, new FancyMessage.Embeds[1] {
                new FancyMessage.Embeds(GetLang("Embed_MessageTitle"), MessageColor, fields)
            });
            var payload = message.toJSON();

            Request(MessageURL, payload, (Callback) =>
            {
                if (Callback == 200 || Callback == 204)
                {
                    SendMessage(player, GetLang("MessageSent", player.Id));
                    if (storedData.Players.ContainsKey(player.Id))
                    {
                        storedData.Players[player.Id].messageCooldown = DateTime.UtcNow;
                    }
                    else
                    {
                        storedData.Players.Add(player.Id, new PlayerData());
                        storedData.Players[player.Id].messageCooldown = DateTime.UtcNow;
                    }
                    if (MessageLogToConsole)
                    {
                        Puts($"MESSAGE ({player.Name}/{player.Id}) : {text}");
                    }
                }
                else if (Callback != 429)
                {
                    SendMessage(player, GetLang("MessageNotSent", player.Id));
                }
            });
        }
Пример #4
0
        private void API_SendTextMessage(string webhookURL, string content, bool tts = false)
        {
            FancyMessage message = new FancyMessage(content, tts, null);
            var          payload = message.toJSON();

            Request(webhookURL, payload, (Callback) =>
            {
                if (!(Callback == 200 || Callback == 204 || Callback == 429))
                {
                    PrintError($"FAILED TO SEND REQUEST CODE {Callback}");
                }
            });
        }
Пример #5
0
        private void API_SendFancyMessage(string webhookURL, string embedName, string json, string content = null, int embedColor = 3329330)
        {
            FancyMessage message = new FancyMessage(content, false, new FancyMessage.Embeds[1] {
                new FancyMessage.Embeds(embedName, embedColor, JsonConvert.DeserializeObject <List <Fields> >(json))
            });
            var payload = message.toJSON();

            Request(webhookURL, payload, (Callback) =>
            {
                if (!(Callback == 200 || Callback == 204 || Callback == 429))
                {
                    PrintError($"FAILED TO SEND REQUEST CODE {Callback}");
                }
            });
        }
Пример #6
0
        private void API_SendFancyMessage(string webhookURL, string embedName, int embedColor, string json, Action <int> foreignCallback = null)
        {
            List <Fields> fields = new List <Fields>();
            JArray        Jarray = (JArray)JsonConvert.DeserializeObject(json);

            foreach (var field in Jarray)
            {
                fields.Add(new Fields(field["name"].ToString(), field["value"].ToString(), bool.Parse(field["inline"].ToString())));
            }
            if (embedColor == 0)
            {
                embedColor = 3329330;
            }
            FancyMessage message = new FancyMessage(null, false, new FancyMessage.Embeds[1] {
                new FancyMessage.Embeds(embedName, 3329330, fields)
            });
            var payload = message.toJSON();

            Request(webhookURL, payload, (Callback) => foreignCallback.Invoke(Callback));
        }
Пример #7
0
        private void ReportCommand(IPlayer player, string command, string[] args)
        {
            if ((player.Name == "Server Console") | !player.IsConnected)
            {
                return;
            }
            if (ReportEnabled == false)
            {
                SendMessage(player, GetLang("Disabled", player.Id));
                return;
            }
            if (storedData.Players.ContainsKey(player.Id))
            {
                if (storedData.Players[player.Id].ReportDisabled)
                {
                    SendMessage(player, GetLang("ReportDisallowed", player.Id));
                    return;
                }
            }
            else
            {
                storedData.Players.Add(player.Id, new PlayerData());
            }
            if (OnCooldown(player, CooldownType.ReportCooldown))
            {
                var time = (storedData.Players[player.Id].reportCooldown.AddSeconds(ReportCooldown) - DateTime.UtcNow).Seconds;
                SendMessage(player, GetLang("Cooldown", player.Id, time));
                return;
            }
            if (args.Length < 2)
            {
                SendMessage(player, GetLang("ReportSyntax", player.Id));
                return;
            }
            List <string> reason = args.Skip(1).ToList();
            var           target = GetPlayer(args[0], player, true);

            if (target != null)
            {
                if (player.Equals(target))
                {
                    SendMessage(player, GetLang("ToSelf", player.Id));
                    return;
                }
                string[] targetName = target.Name.Split(' ');
                if (targetName.Length > 1)
                {
                    for (int x = 0; x < targetName.Length - 1; x++)
                    {
                        if (reason[x].Equals(targetName[x + 1]))
                        {
                            reason.RemoveAt(x);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (reason.Count < 1)
                {
                    SendMessage(player, GetLang("ReportTooShort", player.Id));
                    return;
                }
                string finalReason = string.Join(" ", reason.ToArray());
                if (storedData.Players.ContainsKey(target.Id))
                {
                    storedData.Players[target.Id].reports++;
                }
                else
                {
                    storedData.Players.Add(target.Id, new PlayerData());
                    storedData.Players[target.Id].reports++;
                }
                var           status = target.IsConnected ? lang.GetMessage("Online", null) : lang.GetMessage("Offline", null);
                List <Fields> fields = new List <Fields>();
                fields.Add(new Fields(GetLang("Embed_ReportTarget"), $"[{target.Name}](https://steamcommunity.com/profiles/{target.Id})", true));
                fields.Add(new Fields(GetLang("Embed_ReportPlayer"), $"[{player.Name}](https://steamcommunity.com/profiles/{player.Id})", true));
                fields.Add(new Fields(GetLang("Embed_ReportStatus"), status, true));
                fields.Add(new Fields(GetLang("Embed_ReportReason"), finalReason, false));
                fields.Add(new Fields(GetLang("Embed_ReportCount"), storedData.Players[target.Id].reports.ToString(), true));
                FancyMessage message = new FancyMessage(ReportAlert, false, new FancyMessage.Embeds[1] {
                    new FancyMessage.Embeds(GetLang("Embed_MessageTitle"), ReportColor, fields)
                });
                Request(ReportURL, message.toJSON(), (Callback) =>
                {
                    if (Callback == 200 || Callback == 204)
                    {
                        SendMessage(player, GetLang("ReportSent", player.Id));
                        if (storedData.Players.ContainsKey(player.Id))
                        {
                            storedData.Players[player.Id].reportCooldown = DateTime.UtcNow;
                        }
                        else
                        {
                            storedData.Players.Add(player.Id, new PlayerData());
                            storedData.Players[player.Id].reportCooldown = DateTime.UtcNow;
                        }
                        if (ReportLogToConsole)
                        {
                            Puts($"REPORT ({player.Name}/{player.Id}) -> ({target.Name}/{target.Id}): {finalReason}");
                        }
                    }
                    else if (Callback != 429)
                    {
                        SendMessage(player, GetLang("ReportNotSent", player.Id));
                    }
                });
            }
        }