public async Task SetGuildUpdate(string guildName) { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } guildName = guildName.Trim(); var result = IResolver.Current.MongoDBRepository.SendGuildToQueue(guildName).Result; if (result != null) { retStr = string.Format("\nGuild {0} added to queue. Please be patient, I need tons of time to retrieve data!!!", guildName); } else { retStr = string.Format("\nGuild {0} not added to queue!!!!!"); } await ReplyAsync($"{retStr}"); }
public async Task Prune(string countMessagesToDelete) { bool rowsIsNumber = int.TryParse(countMessagesToDelete, out int rows); if (!rowsIsNumber) { await ReplyAsync($"If you want to specify how many results want, you have to put a number as a parameter! '{rows}' is not a number!"); return; } string retStr = ""; //await Context.Message.DeleteAsync(); //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } var messagesToDelete = await Context.Channel.GetMessagesAsync(rows).Flatten(); await Context.Channel.DeleteMessagesAsync(messagesToDelete); var lastmessage = await Context.Channel.SendMessageAsync($"`{Context.User.Username} deleted {messagesToDelete.Count()} messages`"); await Task.Delay(2000); await lastmessage.DeleteAsync(); }
public async Task SetCharacterConfigUpdate() { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.SendCharacterConfigToQueue().Result; if (result != null) { retStr = "\nCharacter config update added to queue. Please be patient, I need some time to retrieve data!!!"; } else { retStr = string.Format("\nNot added to queue!!!!!"); } await ReplyAsync($"{retStr}"); }
public async Task RemoveQueue(string name) { name = name.Trim().ToLower(); string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.RemoveFromQueue(name).Result; if (result != null) { retStr += $"\nQueue row for '**{name}**' was removed!\n"; retStr += string.Format("\nId:**{0}**", result.Id.ToString()); retStr += string.Format("\nName:**{0}**", result.Name); retStr += string.Format("\nStatus:**{0}**", result.Status.ToString()); retStr += string.Format("\nType:**{0}**", result.Type); } else { retStr = "Not updated. Probably something is wrong with your command!"; } await ReplyAsync($"{retStr}"); }
public async Task GetStats() { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } //get from cache if possible and exit sub string functionName = "stats-players"; string key = "all"; retStr = cacheClient.GetMessageFromModuleCache(functionName, key); if (!string.IsNullOrWhiteSpace(retStr)) { await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.GetAllPlayersNoCharactersNoShips().Result; if (result != null) { //if (result.FirstOrDefault().LoadedFromCache) retStr += CacheClient.GetCachedDataRepositoryMessage(); if (result.FirstOrDefault().LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } retStr += string.Format("\nTotal players loaded to DB : **{0}** ", result.Count()); retStr += string.Format("\nSWGoH date - Latest: **{0}** - Oldest: **{1}** ", result.OrderByDescending(p => p.SWGoHUpdateDate).Take(1).FirstOrDefault().SWGoHUpdateDate, result.OrderBy(p => p.SWGoHUpdateDate).Take(1).FirstOrDefault().SWGoHUpdateDate); retStr += string.Format("\nDB date - Latest: **{0}** - Oldest: **{1}** ", result.OrderByDescending(p => p.EntryUpdateDate).Take(1).FirstOrDefault().EntryUpdateDate, result.OrderBy(p => p.EntryUpdateDate).Take(1).FirstOrDefault().EntryUpdateDate); } else { retStr = string.Format("\nSomething is wrong with stats -p!!!"); } await ReplyAsync($"{retStr}"); await cacheClient.AddToModuleCache(functionName, key, retStr); }
public async Task AddAlias(string characterFullName, string alias) { characterFullName = characterFullName.Trim(); alias = alias.Trim(); string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.SetCharacterAlias(characterFullName, alias.ToLower()).Result; if (result != null) { retStr += $"\nNew alias '**{alias}**' for '**{characterFullName}**' was added!\n"; retStr += string.Format("\nName:**{0}**", result.Name); retStr += string.Format("\nCommand:**{0}**", result.Command != null ? result.Command.Length == 0 ? "empty!!!" : result.Command : "empty!!!"); retStr += string.Format("\nSWGoH url:**{0}**", result.SWGoHUrl); string aliases = ""; int countAliases = 0; foreach (var _alias in result.Aliases) { countAliases += 1; aliases += _alias; if (countAliases != result.Aliases.Count()) { aliases += ", "; } } retStr += string.Format("\nAliases: [**{0}**]", aliases.Count() > 0 ? aliases : "empty!!!"); } else { retStr = "Not updated. Probably something is wrong with your command!"; } await ReplyAsync($"{retStr}"); }
public async Task GetAllPlayers() { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.GetAllPlayersNoCharactersNoShips().Result; if (result != null) { //if (result.FirstOrDefault().LoadedFromCache) retStr += CacheClient.GetCachedDataRepositoryMessage(); if (result.FirstOrDefault().LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } retStr += string.Format("\nTotal players loaded to DB : **{0}**\n", result.Count()); result = result.OrderBy(p => p.GuildName).ThenByDescending(p => p.SWGoHUpdateDate).ToList(); foreach (var player in result) { //retStr += string.Format("\nGuild : ***{4}*** - PlayerName : ***{0}***({1}) - SWGoHUpdate: ***{2}*** - DBUpdate: ***{3}*** ", player.PlayerName,player.PlayerNameInGame,player.LastSwGohUpdated,player.LastClassUpdated,player.GuildName); retStr += string.Format("\nGuild : ***{3}*** - PlayerName : ***{0}***({1}) - SWGoHUpdate: ***{2}***", player.PlayerName, player.PlayerNameInGame, player.SWGoHUpdateDate, player.GuildName); if (retStr.Length > 1800) { await ReplyAsync($"{retStr}"); retStr = ""; } } } else { retStr = string.Format("\nSomething is wrong with stats -p!!!"); } await ReplyAsync($"{retStr}"); }
public async Task HelpAsync(string command) { var applicationSettings = IResolver.Current.ApplicationSettings.GetBotSettings(); //check if user is in role in order to proceed with the action var adminRole = applicationSettings.DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); var result = _service.Search(Context, command); if (!result.IsSuccess) { await ReplyAsync($"Sorry, I couldn't find a command like **{command}**."); return; } if ((!userAllowed && result.Commands.FirstOrDefault().Command.Module.Remarks.ToLower() == "admin")) { await ReplyAsync($"Sorry, I couldn't find a command like **{command}** that you can check for details."); return; } var prefix = applicationSettings.DiscordSettings.Prefix; var builder = new EmbedBuilder(); foreach (var match in result.Commands) { var cmd = match.Command; if (cmd.Aliases.Count > 0 && cmd.Aliases[0] != "help") //dont give help for help command :p and not admin { builder.AddField(x => { x.Name = string.Join(", ", cmd.Name); x.Value = string.Concat( cmd.Parameters.Count > 0 ? $"**Parameters**: {string.Join(", ", cmd.Parameters.Select(p => p.Name))}\n" : string.Empty, $"**Summary**: {cmd.Summary}\n", $"**Usage**: {prefix}{cmd.Remarks}"); x.IsInline = false; }); } } await ReplyAsync("", false, builder.Build()); }
public async Task Roll() { //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { var retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } Random rand1 = new Random(); int roll = rand1.Next(0, 1000); await ReplyAsync($"{this.Context.User.Username} rolled {roll}!!!!!"); }
public async Task HelpAdminAsync() { var applicationSettings = IResolver.Current.ApplicationSettings.GetBotSettings(); //check if user is in role in order to proceed with the action var adminRole = applicationSettings.DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { var retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } string prefix = applicationSettings.DiscordSettings.Prefix; var builder = new EmbedBuilder() { Color = new Color(114, 137, 218), Title = $"**{applicationSettings.GeneralSettings.ApplicationName} Commands**", Description = $"***Use {prefix}help <commandname> for details***" }; foreach (var module in _service.Modules.Where(p => p.Remarks?.ToLower() == "admin")) { foreach (var cmd in module.Commands) { if (cmd.Aliases.Count > 0 && !cmd.Aliases[0].Contains("help")) //dont give help for help command :p { builder.AddField(x => { x.Name = string.Join(" | ", cmd.Aliases); x.Value = $"{cmd.Summary}\n"; x.IsInline = false; }); } } } await ReplyAsync("", false, builder.Build()); }
public async Task CheckDiagnostics() { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } Process currentProc = Process.GetCurrentProcess(); var threads = currentProc.Threads; long totalBytesOfMemoryUsed = currentProc.WorkingSet64; long privateMemorySize64 = currentProc.PrivateMemorySize64; long nonpagedSystemMemorySize64 = currentProc.NonpagedSystemMemorySize64; long pagedMemorySize64 = currentProc.PagedMemorySize64; long pagedSystemMemorySize64 = currentProc.PagedSystemMemorySize64; long peakPagedMemorySize64 = currentProc.PeakPagedMemorySize64; long peakVirtualMemorySize64 = currentProc.PeakVirtualMemorySize64; long virtualMemorySize64 = currentProc.VirtualMemorySize64; retStr += string.Format("\nMemory : {0} - Threads : {1}\n", totalBytesOfMemoryUsed.ToString("#,##0,Kb", CultureInfo.InvariantCulture), threads.Count); retStr += $"\nPrivateMemorySize64 : {privateMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; retStr += $"\nNonpagedSystemMemorySize64 : {nonpagedSystemMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; retStr += $"\nPagedMemorySize64 : {pagedMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; retStr += $"\nPagedSystemMemorySize64 : {pagedSystemMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; retStr += $"\nPeakPagedMemorySize64 : {peakPagedMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; retStr += $"\nPeakVirtualMemorySize64 : {peakVirtualMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; retStr += $"\nVirtualMemorySize64 : {virtualMemorySize64.ToString("#,##0,Kb", CultureInfo.InvariantCulture)}"; await ReplyAsync($"{retStr}"); }
public async Task CheckDiagnostics() { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } Process currentProc = Process.GetCurrentProcess(); var threads = currentProc.Threads; long memoryUsed = currentProc.PrivateMemorySize64; retStr += string.Format("\nMemory : {0} - Threads : {1}", memoryUsed.ToString("#,##0,Kb", CultureInfo.InvariantCulture), threads.Count); await ReplyAsync($"{retStr}"); }
public async Task GetQueue(string resultsRows = "10") { bool rowsIsNumber = int.TryParse(resultsRows, out int rows); if (!rowsIsNumber) { await ReplyAsync($"If you want to specify how many results want, you have to put a number as third parameter! '{rows}' is not a number!"); return; } string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.GetQueue().Result; if (result == null) { await ReplyAsync($"Problem!! Cannot get queue!!!"); return; } else { await ReplyAsync($"I Found **{result.Count()} total entries in queue!**"); } var guildQueues = result.Where(p => p.Type == QueueType.Guild).OrderByDescending(p => p.Status).ThenBy(p => p.NextRunDate).Take(rows); var playerQueues = result.Where(p => p.Type == QueueType.Player).OrderByDescending(p => p.Status).ThenBy(p => p.NextRunDate).Take(rows); if (guildQueues.Count() > 0) { retStr += "\n**--------Guild Queue--------**"; foreach (var guild in guildQueues) { retStr += string.Format("\nGuild : **{0}** - Status : **{1}** - Next Run : **{2}**(UTC){3}" , guild.Name , guild.Status , guild.NextRunDate?.ToString("yyyy-MM-dd HH:mm") , string.IsNullOrWhiteSpace(guild.ProcessingBy) ? "" : string.Format(" - Processing started by : {0} at {1}(UTC)", guild.ProcessingBy, guild.ProcessingStartDate?.ToString("yyyy-MM-dd HH:mm"))); } } if (playerQueues.Count() > 0) { retStr += "\n\n**--------Player Queue--------**"; } var processingPlayer = playerQueues.Where(p => p.Status == QueueStatus.Processing); var pendingPlayer = playerQueues.Where(p => p.Status == QueueStatus.PendingProcess); var failedPlayer = playerQueues.Where(p => p.Status == QueueStatus.Failed); if (processingPlayer.Count() > 0) { retStr += "\n**--Processing**"; } foreach (var queuePlayer in processingPlayer) { retStr += string.Format("\nPlayer : **{0}** - Status : **{1}** - Processing started by {3} at **{2}**(UTC)", queuePlayer.Name, queuePlayer.Status, queuePlayer.ProcessingStartDate?.ToString("yyyy-MM-dd HH:mm"), queuePlayer.ProcessingBy); if (retStr.Length > 1800) { await ReplyAsync($"{retStr}"); retStr = ""; } } if (pendingPlayer.Count() > 0) { retStr += "\n**--Pending Process**"; } foreach (var queuePlayer in pendingPlayer) { retStr += string.Format("\nPlayer : **{0}** - Status : **{1}** - Next Run : **{2}**(UTC)", queuePlayer.Name, queuePlayer.Status, queuePlayer.NextRunDate?.ToString("yyyy-MM-dd HH:mm")); if (retStr.Length > 1800) { await ReplyAsync($"{retStr}"); retStr = ""; } } if (failedPlayer.Count() > 0) { retStr += "\n**--Failed**"; } foreach (var queuePlayer in failedPlayer) { retStr += string.Format("\nPlayer : **{0}** - Status : **{1}** - Next Run : **{2}**(UTC)", queuePlayer.Name, queuePlayer.Status, queuePlayer.NextRunDate?.ToString("yyyy-MM-dd HH:mm")); if (retStr.Length > 1800) { await ReplyAsync($"{retStr}"); retStr = ""; } } if (retStr.Length == 0) { await ReplyAsync("Empty queue!!!!"); return; } await ReplyAsync($"{retStr}"); }