public Settings AddWebhookNotification(string name, string uri, string payload, string restorePayload = "")
 {
     Webhooks.Add(new WebHookNotification
     {
         Name            = name,
         Uri             = uri,
         Payload         = payload,
         RestoredPayload = restorePayload
     });
     return(this);
 }
Пример #2
0
 public Settings AddWebhookNotification(string name, string uri, string payload, string restorePayload = "", Func <UIHealthReport, bool> shouldNotifyFunc = null, Func <UIHealthReport, string> customMessageFunc = null, Func <UIHealthReport, string> customDescriptionFunc = null)
 {
     Webhooks.Add(new WebHookNotification
     {
         Name                  = name,
         Uri                   = uri,
         Payload               = payload,
         RestoredPayload       = restorePayload,
         ShouldNotifyFunc      = shouldNotifyFunc,
         CustomMessageFunc     = customMessageFunc,
         CustomDescriptionFunc = customDescriptionFunc
     });
     return(this);
 }
        public Settings AddWebhookNotification(string name, string uri, string payload, string restorePayload = "")
        {
            if (!Uri.TryCreate(uri, UriKind.Absolute, out Uri absoluteUri))
            {
                throw new ArgumentException($"Invalid uri: {uri}");
            }

            Webhooks.Add(new WebHookNotification
            {
                Name            = name,
                Uri             = absoluteUri,
                Payload         = payload,
                RestoredPayload = restorePayload
            });
            return(this);
        }
Пример #4
0
        void btnWebhookAdd_Click(object sender, MVControlEventArgs e)
        {
            try
            {
                // Webhooks need names
                if (edtName.Text.Length <= 0)
                {
                    throw new Exception("Webhooks need to have names.");
                }

                // Either the URL or the PayloadFormatString should have an @ symbol, but just warn
                if (!(edtName.Text.Contains("@") || edtPayload.Text.Contains("@")))
                {
                    Util.WriteToChat("Warning: Neither your URL or JSON had an @ symbol in them which means your webhooks will trigger without a message.");
                }

                // Stop if the name isn't unique
                if (Webhooks != null && Webhooks.Count > 0)
                {
                    List <Webhook> found = Webhooks.FindAll(w => w.Name == edtName.Text);

                    if (found.Count > 0)
                    {
                        throw new Exception("A webhook with this name already exists");
                    }
                }

                Webhook webhook = new Webhook(edtName.Text, edtURL.Text, (string)chcMethod.Data[chcMethod.Selected], edtPayload.Text);
                Webhooks.Add(webhook);

                RefreshWebhooksList();
                RefreshEventTriggerWebhookChoice();
                RefreshTimedTriggerWebhookChoice();
                RefreshChatTriggerWebhookChoice();
                SaveSettings();
            }
            catch (Exception ex)
            {
                Util.WriteToChat("Error adding new Webhook: " + ex.Message);
                Util.LogError(ex);
            }
        }
Пример #5
0
        public bool DrawConfigUI()
        {
            var drawConfig = true;

            var scale = ImGui.GetIO().FontGlobalScale;

            var modified = false;

            ImGui.SetNextWindowSize(new Vector2(360 * scale, 350), ImGuiCond.FirstUseEver);
            ImGui.SetNextWindowSizeConstraints(new Vector2(360 * scale, 350), new Vector2(560 * scale, 650));
            ImGui.Begin($"{plugin.Name} Config", ref drawConfig, ImGuiWindowFlags.NoCollapse);

#if DEBUG
            var alwaysShowAlert = AlwaysShowAlert;
            if (ImGui.Checkbox("Debug: Always Alert", ref alwaysShowAlert))
            {
                AlwaysShowAlert = alwaysShowAlert;
                Save();
            }

            if (ImGui.Button("Debug: Print All Alerts"))
            {
                foreach (var r in plugin.RouletteList)
                {
                    if (r.ContentRouletteRoleBonus.Row > 0)
                    {
                        try {
                            plugin.ShowAlert(r, Roulettes[r.RowId], PreferredRole.Tank);
                            plugin.ShowAlert(r, Roulettes[r.RowId], PreferredRole.Healer);
                            plugin.ShowAlert(r, Roulettes[r.RowId], PreferredRole.DPS);
                        } catch (Exception ex) {
                            PluginLog.LogError(ex.ToString());
                        }
                    }
                }
            }
#endif

            var inGameAlerts = InGameAlert;
            if (ImGui.Checkbox("Send alerts in game chat.", ref inGameAlerts))
            {
                InGameAlert = inGameAlerts;
                Save();
            }

            ImGui.SameLine();
            ImGui.SetNextItemWidth(150);

            var selectedDetails = ChatType.GetDetails();

            if (ImGui.BeginCombo("###chatType", ChatType == XivChatType.None ? "Any" : (selectedDetails == null ? ChatType.ToString() : selectedDetails.FancyName)))
            {
                foreach (var chatType in ((XivChatType[])Enum.GetValues(typeof(XivChatType))))
                {
                    var details = chatType.GetDetails();

                    if (ImGui.Selectable(chatType == XivChatType.None ? "Any" : (details == null ? chatType.ToString() : details.FancyName), chatType == ChatType))
                    {
                        ChatType = chatType;
                        Save();
                    }

                    if (chatType == ChatType)
                    {
                        ImGui.SetItemDefaultFocus();
                    }
                }

                ImGui.EndCombo();
            }

            var webhookAlerts = WebhookAlert;
            if (ImGui.Checkbox("Send alerts to webhook.", ref webhookAlerts))
            {
                WebhookAlert = webhookAlerts;
                Save();
            }

            ImGui.SameLine();
            if (ImGui.SmallButton("Setup Webhooks"))
            {
                showWebhookWindow = true;
            }

            ImGui.Separator();
            ImGui.Columns(6, "###cols", false);
            ImGui.SetColumnWidth(0, 40f * scale);
            ImGui.SetColumnWidth(1, ImGui.GetWindowWidth() - 240f * scale);
            ImGui.SetColumnWidth(2, 40f * scale);
            ImGui.SetColumnWidth(3, 40f * scale);
            ImGui.SetColumnWidth(4, 40f * scale);
            ImGui.SetColumnWidth(5, 80f * scale);

            ImGui.NextColumn();
            ImGui.Text("Roulette");
            ImGui.NextColumn();
            ImGui.Text("T");
            ImGui.NextColumn();
            ImGui.Text("H");
            ImGui.NextColumn();
            ImGui.Text("D");
            ImGui.NextColumn();
            ImGui.Text("Current");
            ImGui.NextColumn();

            ImGui.Separator();

            if (plugin.RouletteList != null)
            {
                foreach (var r in plugin.RouletteList.Where(r => r != null && r.ContentRouletteRoleBonus != null && r.ContentRouletteRoleBonus.Row > 0))
                {
                    var rCfg = Roulettes.ContainsKey(r.RowId) ? Roulettes[r.RowId] : new RouletteConfig();
                    modified = ImGui.Checkbox($"###rouletteEnabled{r.RowId}", ref rCfg.Enabled) || modified;
                    ImGui.NextColumn();

                    ImGui.Text(r.Name);
                    ImGui.NextColumn();
                    modified = ImGui.Checkbox($"###rouletteTankEnabled{r.RowId}", ref rCfg.Tank) || modified;
                    ImGui.NextColumn();
                    modified = ImGui.Checkbox($"###rouletteHealerEnabled{r.RowId}", ref rCfg.Healer) || modified;
                    ImGui.NextColumn();
                    modified = ImGui.Checkbox($"###rouletteDPSEnabled{r.RowId}", ref rCfg.DPS) || modified;
                    ImGui.NextColumn();

                    if (plugin.LastPreferredRoleList != null)
                    {
                        var currentRole = plugin.LastPreferredRoleList.Get(r.ContentRouletteRoleBonus.Row);
                        ImGui.Text(currentRole.ToString());
                    }

                    ImGui.NextColumn();

                    Roulettes[r.RowId] = rCfg;
                }
            }

            ImGui.Columns(1);

            ImGui.End();

            if (modified)
            {
                Save();
            }


            if (showWebhookWindow)
            {
                ImGui.Begin($"{plugin.Name}: Webhooks", ref showWebhookWindow);

                ImGui.TextWrapped($"Add webhook urls here to have {plugin.Name} send alerts somewhere else, like discord.");

                ImGui.TextColored(new Vector4(0.5f, 0.5f, 1f, 1f), "Discord Webhook Guide");
                if (ImGui.IsItemHovered())
                {
                    ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
                }

                if (ImGui.IsItemClicked(0))
                {
                    Process.Start("https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks");
                }

                for (var i = 0; i < Webhooks.Count; i++)
                {
                    var url = Webhooks[i];
                    ImGui.SetNextItemWidth(-1);
                    if (ImGui.InputText($"###webhook{i}", ref url, 1024))
                    {
                        Webhooks[i] = url;
                        Save();
                    }
                }

                if (ImGui.SmallButton("Add Webhook"))
                {
                    Webhooks.Add("");
                }

                ImGui.End();
            }


            return(drawConfig);
        }