public async Task <Embed> BuildLockedListAsync(ICommandContext context, CommandSetDetails commandSet) { IDbLockableContext lockContext = await Contexting.FindDbLockableContextAsync(context).ConfigureAwait(false); var embed = new EmbedBuilder() { Color = configParser.EmbedColor, Title = $"{configParser.EmbedPrefix}{configParser.ParseTitle("locked", LockedTitle)}", Description = configParser.ParseDescription("locked", LockedDesc), }; foreach (ModuleDetails module in commandSet) { bool moduleLocked = module.IsModuleLocked(lockContext); /*StringBuilder str = new StringBuilder(); * foreach (CommandDetails command in module) { * string commandLocked = FormatCommandLocked(lockContext, command); * if (!string.IsNullOrEmpty(moduleLocked) || !string.IsNullOrEmpty(commandLocked)) { * str.AppendLine($"{commandLocked}{command.Alias}"); * } * }*/ string lockedCommands = FormatLockedCommandList(lockContext, moduleLocked, module); if (lockedCommands.Length > 0) { embed.AddField($"{FormatModuleLocked(moduleLocked)}{module.Name}", lockedCommands); } } return(embed.Build()); }
/// <summary> /// Gets if the specified command or its module is locked. /// </summary> /// <param name="command">The command to check.</param> /// <param name="lockContext">The lockable context to work with.</param> /// <returns>True if the command or its module is locked.</returns> public static bool IsLocked(this CommandDetails command, IDbLockableContext lockContext) { if (lockContext == null) { return(command.IsLockedByDefault || command.Module.IsLockedByDefault); } return(command.IsCommandLocked(lockContext) || command.Module.IsModuleLocked(lockContext)); }
/// <summary> /// Gets if the specified command is locked. /// </summary> /// <param name="command">The command to check.</param> /// <param name="lockContext">The lockable context to work with.</param> /// <returns>True if the command is locked.</returns> public static bool IsCommandLocked(this CommandDetails command, IDbLockableContext lockContext) { if (lockContext == null) { return(command.IsLockedByDefault); } return(command.IsLockable && command.IsLockedByDefault != lockContext.LockedCommands.Contains(command.Alias)); }
/// <summary> /// Gets if the specified module is locked. /// </summary> /// <param name="module">The module to check.</param> /// <param name="lockContext">The lockable context to work with.</param> /// <returns>True if the module is locked.</returns> public static bool IsModuleLocked(this ModuleDetails module, IDbLockableContext lockContext) { if (lockContext == null) { return(module.IsLockedByDefault); } return(module.IsLockable && module.IsLockedByDefault != lockContext.LockedModules.Contains(module.Name)); }
/// <summary> /// Gets if the specified command or its module is locked. /// </summary> /// <param name="locking">The locking service to work with.</param> /// <param name="context">The command context to look for.</param> /// <param name="command">The command to check.</param> /// <returns>True if the command or its module is locked.</returns> public static async Task <bool> IsLockedAsync(this IContextingService locking, ICommandContext context, CommandDetails command) { IDbLockableContext lockContext = await locking.FindDbLockableContextAsync(context).ConfigureAwait(false); if (lockContext == null) { return(command.IsLockedByDefault || command.Module.IsLockedByDefault); } return(command.IsLocked(lockContext)); }
private IEnumerable <string> FormatLockedCommands(IDbLockableContext lockContext, bool moduleLocked, IEnumerable <CommandDetails> commands) { foreach (CommandDetails command in commands) { bool commandLocked = command.IsCommandLocked(lockContext); if (moduleLocked || commandLocked) { yield return($"{FormatCommandLocked(commandLocked)}{command.Alias}"); } } }
private string FormatLockedCommandList(IDbLockableContext lockContext, bool moduleLocked, IEnumerable <CommandDetails> commands) { return(string.Join(" **|** ", FormatLockedCommands(lockContext, moduleLocked, commands))); }
private string FormatModuleTitle(IDbLockableContext lockContext, ModuleDetails module) { return($"{configParser.EmbedPrefix}{FormatLocked(lockContext, module)}**{module.Name} Module**"); }
/// <summary> /// Formats the title for a command embed. /// </summary> private string FormatCommandTitle(string prefix, IDbLockableContext lockContext, CommandDetails cmd) { return($"{configParser.EmbedPrefix}{FormatLocked(lockContext, cmd)}**{prefix}{cmd.Alias}**"); }
/// <summary> /// Formats a module to show the locked or not locked symbol when it is locked. /// </summary> private string FormatModuleLocked(IDbLockableContext lockContext, ModuleDetails module) { return(module.IsModuleLocked(lockContext) ? Locked : NotLocked); }
/// <summary> /// Formats a command to show the locked or not locked symbol when it is locked. /// </summary> private string FormatCommandLocked(IDbLockableContext lockContext, CommandDetails command) { return(command.IsCommandLocked(lockContext) ? Locked : NotLocked); }
/// <summary> /// Formats a command to show the locked symbol when it or its module is locked. /// </summary> private string FormatLocked(IDbLockableContext lockContext, CommandDetails command) { return(command.IsLocked(lockContext) ? Locked : string.Empty); }
/// <summary> /// Gets if the specified module is locked. /// </summary> /// <param name="locking">The locking service to work with.</param> /// <param name="context">The command context to look for.</param> /// <param name="module">The module to check.</param> /// <returns>True if the module is locked.</returns> public static async Task <bool> IsModuleLockedAsync(this IContextingService locking, ICommandContext context, ModuleDetails module) { IDbLockableContext lockContext = await locking.FindDbLockableContextAsync(context).ConfigureAwait(false); return(module.IsModuleLocked(lockContext)); }