Example #1
0
        private async void addButton_Click(object sender, RoutedEventArgs e)
        {
            string      selected = "";
            TriggerType type;

            try
            {
                selected = ((ListBoxItem)triggersListBox.SelectedValue).Name;
            }
            catch (Exception) { return; }

            ChatCommand    cc  = new ChatCommand();
            ChatCommandAPI cca = new ChatCommandAPI();
            ChatReply      cr  = new ChatReply();
            DoormatOptions _do = new DoormatOptions();

            TriggerOptionsBase tob = new TriggerOptionsBase();

            switch (selected)
            {
            case "kickTrigger":
            case "banTrigger":
            case "isUpTrigger":
            case "playGameTrigger":
            case "chooseTrigger":
            case "helpTrigger":
            {
                ChatCommandWindow   window = new ChatCommandWindow();
                ContentDialogResult result = await window.ShowAsync();

                if (result == ContentDialogResult.Primary && window.CC != null)
                {
                    MainOptionsWindow   mow = new MainOptionsWindow();
                    ContentDialogResult r1  = await mow.ShowAsync();

                    if (r1 == ContentDialogResult.Primary && mow.MO != null)
                    {
                        cc = window.CC;

                        type = (TriggerType)Enum.Parse(typeof(TriggerType), char.ToUpper(selected[0]) + selected.Substring(1));
                        addedTriggersListBox.Items.Add(string.Format("{0} - {1}", cc.Name, type.ToString()));

                        tob.ChatCommand = cc;
                        tob.Name        = cc.Name;
                        tob.Type        = type;
                        tob.MainOptions = mow.MO;
                        BaseTrigger trigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + type.ToString()), type, cc.Name, tob);
                        Bot.Triggers.Add(trigger);
                    }
                }
            }
            break;

            case "chatReplyTrigger":
            {
                ChatReplyWindow     window = new ChatReplyWindow();
                ContentDialogResult result = await window.ShowAsync();

                if (result == ContentDialogResult.Primary && window.CR != null)
                {
                    MainOptionsWindow   mow = new MainOptionsWindow();
                    ContentDialogResult r1  = await mow.ShowAsync();

                    if (r1 == ContentDialogResult.Primary && mow.MO != null)
                    {
                        cr   = window.CR;
                        type = (TriggerType)Enum.Parse(typeof(TriggerType), char.ToUpper(selected[0]) + selected.Substring(1));

                        tob.ChatReply   = cr;
                        tob.Name        = cr.Name;
                        tob.Type        = type;
                        tob.MainOptions = mow.MO;
                        addedTriggersListBox.Items.Add(string.Format("{0} - {1}", cr.Name, type.ToString()));
                        BaseTrigger trigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + type.ToString()), type, cr.Name, tob);
                        Bot.Triggers.Add(trigger);
                    }
                }
            }
            break;

            case "doormatTrigger":
            {
                DoormatOptionsWindow window = new DoormatOptionsWindow();
                ContentDialogResult  result = await window.ShowAsync();

                if (result == ContentDialogResult.Primary && window.DO != null)
                {
                    MainOptionsWindow   mow = new MainOptionsWindow();
                    ContentDialogResult r1  = await mow.ShowAsync();

                    if (r1 == ContentDialogResult.Primary && mow.MO != null)
                    {
                        _do = window.DO;

                        type = (TriggerType)Enum.Parse(typeof(TriggerType), char.ToUpper(selected[0]) + selected.Substring(1));
                        addedTriggersListBox.Items.Add(string.Format("{0} - {1}", _do.Name, type.ToString()));

                        tob.DoormatOptions = _do;
                        tob.Name           = _do.Name;
                        tob.Type           = type;
                        tob.MainOptions    = mow.MO;
                        BaseTrigger trigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + type.ToString()), type, _do.Name, tob);
                        Bot.Triggers.Add(trigger);
                    }
                }
            }
            break;

            case "cSGOStatTrigger":
            {
                ChatCommandAPIWindow window = new ChatCommandAPIWindow();
                ContentDialogResult  result = await window.ShowAsync();

                if (result == ContentDialogResult.Primary && window.CCAPI != null)
                {
                    ChatCommandWindow   ccw = new ChatCommandWindow();
                    ContentDialogResult r2  = await ccw.ShowAsync();

                    if (r2 == ContentDialogResult.Primary && ccw.CC != null)
                    {
                        MainOptionsWindow   mow = new MainOptionsWindow();
                        ContentDialogResult r1  = await mow.ShowAsync();

                        if (r1 == ContentDialogResult.Primary && mow.MO != null)
                        {
                            cca             = window.CCAPI;
                            cca.ChatCommand = ccw.CC;

                            type = (TriggerType)Enum.Parse(typeof(TriggerType), char.ToUpper(selected[0]) + selected.Substring(1));
                            addedTriggersListBox.Items.Add(string.Format("{0} - {1}", cca.ChatCommand.Name, type.ToString()));

                            tob.ChatCommandAPI             = cca;
                            tob.ChatCommandAPI.ChatCommand = cca.ChatCommand;
                            tob.Name        = cca.ChatCommand.Name;
                            tob.Type        = type;
                            tob.MainOptions = mow.MO;
                            BaseTrigger trigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + type.ToString()), type, _do.Name, tob);
                            Bot.Triggers.Add(trigger);
                        }
                    }
                }
            }
            break;
            }
        }
Example #2
0
        private async void editButton_Click(object sender, RoutedEventArgs e)
        {
            if (addedTriggersListBox.SelectedIndex == -1)
            {
                MessageDialog dialog = new MessageDialog("You must select a trigger to edit from the box to the right.", "Error");
                await dialog.ShowAsync();
            }
            else
            {
                BaseTrigger trigger = Bot.Triggers[addedTriggersListBox.SelectedIndex];
                switch (trigger.Type)
                {
                case TriggerType.ChatReplyTrigger:
                {
                    ChatReplyWindow     crw    = new ChatReplyWindow(trigger.Options.ChatReply);
                    ContentDialogResult result = await crw.ShowAsync();

                    if (result == ContentDialogResult.Primary)
                    {
                        MainOptionsWindow   mow     = new MainOptionsWindow(trigger.Options.MainOptions);
                        ContentDialogResult result1 = await mow.ShowAsync();

                        if (result1 == ContentDialogResult.Primary)
                        {
                            TriggerOptionsBase options = new TriggerOptionsBase()
                            {
                                Name        = crw.CR.Name,
                                Type        = TriggerType.ChatReplyTrigger,
                                ChatReply   = crw.CR,
                                MainOptions = mow.MO
                            };
                            addedTriggersListBox.Items[addedTriggersListBox.SelectedIndex] = options.Name + " - " + options.Type.ToString();
                            StorageFile oldFile = await Bot.triggerDir.GetFileAsync(trigger.Name + ".json");

                            await oldFile.DeleteAsync();

                            BaseTrigger newTrigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + options.Type.ToString()), options.Type, options.Name, options);
                            await newTrigger.SaveTrigger();

                            Bot.Triggers.Remove(trigger);
                            trigger = null;
                            Bot.Triggers.Add(newTrigger);
                        }
                    }
                }
                break;

                case TriggerType.DoormatTrigger:
                {
                    DoormatOptionsWindow dow    = new DoormatOptionsWindow(trigger.Options.DoormatOptions);
                    ContentDialogResult  result = await dow.ShowAsync();

                    if (result == ContentDialogResult.Primary)
                    {
                        MainOptionsWindow   mow     = new MainOptionsWindow(trigger.Options.MainOptions);
                        ContentDialogResult result1 = await mow.ShowAsync();

                        if (result1 == ContentDialogResult.Primary)
                        {
                            TriggerOptionsBase options = new TriggerOptionsBase()
                            {
                                Name           = dow.DO.Name,
                                Type           = TriggerType.DoormatTrigger,
                                DoormatOptions = dow.DO,
                                MainOptions    = mow.MO
                            };
                            addedTriggersListBox.Items[addedTriggersListBox.SelectedIndex] = options.Name + " - " + options.Type.ToString();
                            StorageFile oldFile = await Bot.triggerDir.GetFileAsync(trigger.Name + ".json");

                            await oldFile.DeleteAsync();

                            BaseTrigger newTrigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + options.Type.ToString()), options.Type, options.Name, options);
                            await newTrigger.SaveTrigger();

                            Bot.Triggers.Remove(trigger);
                            trigger = null;
                            Bot.Triggers.Add(newTrigger);
                        }
                    }
                }
                break;

                case TriggerType.IsUpTrigger:
                case TriggerType.KickTrigger:
                case TriggerType.PlayGameTrigger:
                {
                    ChatCommandWindow   ccw    = new ChatCommandWindow(trigger.Options.ChatCommand);
                    ContentDialogResult result = await ccw.ShowAsync();

                    if (result == ContentDialogResult.Primary)
                    {
                        MainOptionsWindow   mow     = new MainOptionsWindow(trigger.Options.MainOptions);
                        ContentDialogResult result1 = await mow.ShowAsync();

                        if (result1 == ContentDialogResult.Primary)
                        {
                            TriggerOptionsBase options = new TriggerOptionsBase()
                            {
                                Name        = ccw.CC.Name,
                                Type        = trigger.Type,
                                ChatCommand = ccw.CC,
                                MainOptions = mow.MO
                            };
                            addedTriggersListBox.Items[addedTriggersListBox.SelectedIndex] = options.Name + " - " + options.Type.ToString();
                            StorageFile oldFile = await Bot.triggerDir.GetFileAsync(trigger.Name + ".json");

                            await oldFile.DeleteAsync();

                            BaseTrigger newTrigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("Chaos.Triggers." + options.Type.ToString()), options.Type, options.Name, options);
                            await newTrigger.SaveTrigger();

                            Bot.Triggers.Remove(trigger);
                            trigger = null;
                            Bot.Triggers.Add(newTrigger);
                        }
                    }
                }
                break;
                }
            }
        }