Esempio n. 1
0
        private void SelectedIndexChangedEvent(ComboBox combo,
                                               SettingsList <StaticMod> listSettingsMods, IList <ExplicitMod> listExplicitMods,
                                               IList <ComboBox> listCombo, IList <int> listSelectedIndex, int indexAA,
                                               bool selectEither)
        {
            int selectedIndexLast = listSelectedIndex[indexAA];

            if (AddItemSelected(combo))
            {
                StaticMod itemNew = listSettingsMods.NewItem(this, null, null);
                if (!Equals(itemNew, null))
                {
                    listSettingsMods.Add(itemNew);
                    string itemAdd = (string)combo.SelectedItem;
                    LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, itemNew.GetKey(),
                              selectEither);
                    // If the selection was not successfully set to the new modification,
                    // return to the previous selection.
                    if (Equals(combo.SelectedItem, itemAdd))
                    {
                        combo.SelectedIndex = selectedIndexLast;
                    }
                }
                else
                {
                    // Reset the selected index before edit was chosen.
                    combo.SelectedIndex = selectedIndexLast;
                }
            }
            else if (EditCurrentSelected(combo))
            {
                StaticMod itemEdit;
                if (listSettingsMods.TryGetValue((string)combo.Items[selectedIndexLast], out itemEdit))
                {
                    StaticMod itemNew = listSettingsMods.EditItem(this, itemEdit, listSettingsMods, null);
                    if (!Equals(itemNew, null))
                    {
                        int i = listSettingsMods.IndexOf(itemEdit);
                        listSettingsMods[i] = itemNew;
                        LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, itemNew.GetKey(),
                                  selectEither);
                    }
                }
                combo.SelectedIndex = selectedIndexLast;
            }
            else if (EditListSelected(combo))
            {
                IEnumerable <StaticMod> listNew = listSettingsMods.EditList(this, null);
                if (listNew != null)
                {
                    listSettingsMods.Clear();
                    listSettingsMods.AddRange(listNew);

                    string selectedItemLast = null;
                    if (selectedIndexLast != -1)
                    {
                        selectedItemLast = combo.Items[selectedIndexLast].ToString();
                    }
                    LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, selectedItemLast,
                              selectEither);
                }
                else
                {
                    // Reset the selected index before edit was chosen.
                    combo.SelectedIndex = selectedIndexLast;
                }
            }
            listSelectedIndex[indexAA] = combo.SelectedIndex;
        }
Esempio n. 2
0
        //Discord Server connected
        private Task Client_GuildAvailable(GuildCreateEventArgs e)
        {
            Console.WriteLine($"Discord Server: {e.Guild.Name} {e.Guild.Id}");

            if (e.Guild.Id == FactomServerID)  //Factom's Discord server
            {
                Factom_BotAlert = e.Guild.Channels.FirstOrDefault(x => x.Id == FactomOperatorAlertChannel);
                if (Factom_BotAlert == null)
                {
                    Console.WriteLine("Warning: Factom ID not found");
                    //We will try finding the name instead.
                    Factom_BotAlert = e.Guild.Channels.FirstOrDefault(x => x.Name.Contains(FactomOperatorAlertChannelString));
                }
                if (Factom_BotAlert == null)
                {
                    SendAlert("Warning: Factom operators-alarts not found");
                }
                else
                {
                    Console.WriteLine($"Factom Alert channel: {Factom_BotAlert.Name}");

                    var me = e.Guild.Members.FirstOrDefault(x => x.Id == _client.CurrentUser.Id);
                    if (me != null)
                    {
                        var permissions = Factom_BotAlert.PermissionsFor(me);
                        if (permissions.HasPermission(Permissions.AccessChannels))
                        {
                            AlarmManager.Clear(AlarmNoFactomChannel);
                        }
                    }
                    else
                    {
                        SendAlert("Warning: My user not found in Discord");
                    }
                }
            }
            else
            {
                string alertChannelString;
                if (SettingsList.TryGetValue("Discord-AlertsChannel", out alertChannelString))
                {
                    alertChannelString = alertChannelString.ToLower().Replace("#", "");
#if DEBUG
                    Our_BotAlert = e.Guild.Channels.FirstOrDefault(x => x.Name.Contains("bot-in-debug"));
                    if (Our_BotAlert == null)
                    {
                        Our_BotAlert = e.Guild.Channels.FirstOrDefault(x => x.Name == alertChannelString);
                    }
#else
                    Our_BotAlert = e.Guild.Channels.FirstOrDefault(x => x.Name == alertChannelString);
                    if (Our_BotAlert != null)
                    {
                        Console.WriteLine($"Our Alert channel: {Our_BotAlert.Name}");
                        if (clsVersion.VersionChangeFlag)
                        {
                            Bot.Our_BotAlert.SendMessageAsync($":drum: Welcome! (removing version number because it's causing it not to compile) :trumpet:");
                        }
                        else
                        {
                            Bot.Our_BotAlert.SendMessageAsync("Hello :innocent:");
                        }

                        if (TextBuffer.Length > 0)
                        {
                            Our_BotAlert.SendMessageAsync(TextBuffer.ToString()).ContinueWith((x) => { TextBuffer.Clear(); });
                        }
                    }
                    else
                    {
                        Console.WriteLine($"ERROR: Can't find AlertChannel {alertChannelString}");
                    }
#endif
                }
                else
                {
                    SendAlert("Warning: Factom operators-alarts not found");
                    Console.WriteLine("Warning: Discord-AlertsChannel not set");
                }
            }

            // since this method is not async, let's return
            // a completed task, so that no additional work
            // is done
            return(Task.CompletedTask);
        }