コード例 #1
0
 public bool ClearAlarms()
 {
     SetPreviewImage(null);
     if (AlarmManager != null)
     {
         AlarmManager.Clear();
         mCurIndex = -1;
         UpdateFormState();
     }
     return(true);
 }
コード例 #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);
        }