public async Task RestartWarning(string _time = "5", string _reason = null, string _length = null) { await CleanupFiles(false); string restart = "restart"; if (_reason != null) { _reason = $" due to {_reason}"; } if (_length != null) { _length = $" for {_length} hours"; restart = "shut down"; } List <Task> sendMessage = new List <Task>(); foreach (ulong serv in Program.servChanID.Keys.ToList()) { SocketGuild guild = Context.Client.GetGuild(serv); SocketTextChannel channel = guild.GetTextChannel(Program.servChanID[serv]); if (PermissionChecker.HasSend(guild, channel)) { sendMessage.Add(channel.SendMessageAsync($"Attention! Bot's server will {restart} in {_time} minutes{_length}{_reason}.")); } } await Task.WhenAll(sendMessage.ToArray()); }
public async Task Announcement(string announceMessage) { await CleanupFiles(false); List <Task> sendMessage = new List <Task>(); foreach (ulong serv in Program.servChanID.Keys.ToList()) { SocketGuild guild = Context.Client.GetGuild(serv); SocketTextChannel channel = guild.GetTextChannel(Program.servChanID[serv]); if (PermissionChecker.HasSend(guild, channel)) { sendMessage.Add(channel.SendMessageAsync($"Attention! {announceMessage}")); } } await Task.WhenAll(sendMessage.ToArray()); }
public async Task ExitAttentionBot(string _reason = null, string _length = null) { await CleanupFiles(false); if (_reason != null) { _reason = $" due to {_reason}"; } if (_length == null) { _length = "restarting"; } else { _length = $"offline for {_length} hours"; } List <Task> sendMessage = new List <Task>(); foreach (ulong serv in Program.servChanID.Keys.ToList()) { SocketGuild guild = Context.Client.GetGuild(serv); SocketTextChannel channel = guild.GetTextChannel(Program.servChanID[serv]); if (PermissionChecker.HasSend(guild, channel)) { sendMessage.Add(channel.SendMessageAsync($"Attention! Bot's server is now {_length}{_reason}.")); } } await Task.WhenAll(sendMessage.ToArray()); if (Program.isConsole) { Console.WriteLine("Attention! Bot Offline"); } Thread.Sleep(1000); Environment.Exit(0); }