private bool HasPermissionOnCmd(IApplicationCommand cmd) { var permissionValidator = new PermissionAttributeValidator(cmd); var hasPermission = permissionValidator.HasPermissionOnInstance(); return(hasPermission); }
private string GetModuleName(IApplicationCommand cmd) { string moduleName = string.Format("{0}|{1}|{2}|{3}", Application.ProductName, CmdType, cmd.GetType().Assembly.GetName().Name, cmd.GetType().Name); return(moduleName); }
private async Task PublishAsync(IApplicationCommand command, ApplicationCommandReplySchemes replyScheme, CancellationToken token = default) { command.ReplyScheme = replyScheme; command.Topic = _options.Topic; await _messagePublisher.PublishAsync(command, token).ConfigureAwait(false); }
public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null) { Preconditions.NotNull(command, nameof(command)); Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false); }
public static IDomainCommand FillFrom(this IDomainCommand domainCommand, IApplicationCommand applicationCommand) { domainCommand.ApplicationCommandId = applicationCommand.Id; domainCommand.ApplicationCommandType = applicationCommand.GetType().FullName; domainCommand.ApplicationCommandReplyScheme = applicationCommand.ReplyScheme; return(domainCommand); }
protected async Task DisableCommandRunTaskAndEnableCommandAsync(IApplicationCommand command) { await DisableCommandAsync(command.GetType()); await command.ExecuteAsync(this); await EnableCommandAsync(command.GetType()); }
public ApplicationCommandResult <TPayload> ExecuteCommand <TPayload>(IApplicationCommand command, ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled) { return(ExecuteCommandAsync <TPayload>(command, replyScheme) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
public async Task PublishAsync(IApplicationCommand command, CancellationToken token = default) { PreConditions.NotNull(command, nameof(command)); command.Topic = _options.Topic; command.ReplyScheme = ApplicationCommandReplySchemes.None; await _messagePublisher.PublishAsync(command, token); }
public void Publish(IApplicationCommand command) { PreConditions.NotNull(command, nameof(command)); command.Topic = _options.Topic; command.ReplyScheme = ApplicationCommandReplySchemes.None; _messagePublisher.Publish(command); }
public static Task DeleteAsync(this IApplicationCommand command, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { var client = command.GetRestClient(); return(command.GuildId != null ? client.DeleteGuildApplicationCommandAsync(command.ApplicationId, command.GuildId.Value, command.Id, options, cancellationToken) : client.DeleteGlobalApplicationCommandAsync(command.ApplicationId, command.Id, options, cancellationToken)); }
public static Task <IApplicationCommand> ModifyAsync(this IApplicationCommand command, Action <ModifyApplicationCommandActionProperties> action, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { var client = command.GetRestClient(); return(command.GuildId != null ? client.ModifyGuildApplicationCommandAsync(command.ApplicationId, command.GuildId.Value, command.Id, action, options, cancellationToken) : client.ModifyGlobalApplicationCommandAsync(command.ApplicationId, command.Id, action, options, cancellationToken)); }
public void AddCommand(IApplicationCommand command, bool defaultEnabled) { Commands.Add(command); var commandType = command.GetType(); lock (EnableRequests) { EnableRequests[commandType] = 0; } lock (DisableRequests) { DisableRequests[commandType] = 0; } DefaultEnabled[commandType] = defaultEnabled; }
internal void Construct(IApplicationCommand command, ApplicationCommandArguments arguments, Func <Task <bool> > preCondition) { _command = command; _preCondition = preCondition; _arguments = arguments; title.Text = command.Title; subtitle.Text = command.Subtitle; button.SetTitle(command.Label, UIControlState.Normal); subtitle.SizeToFit(); button.SetBackgroundImage(Theme.CommandButton, UIControlState.Normal); }
public MainWindowViewModel(IRegionManager regionManager, IApplicationCommand applicationCommand, TmsClient nepse, IDialogService dialog, MeroshareClient meroshareClient, IConfiguration config) { _regionManager = regionManager; _client = nepse; _dialog = dialog; _meroshareClient = meroshareClient; _config = config; ApplicationCommand = applicationCommand; applicationCommand.ShowMessage = ShowMessage; _client.PromptCredentials = GetTmsCredentials; _meroshareClient.PromptCredential = GetMeroShareCredentials; }
public async Task <ApplicationCommandResult> ExecuteCommandAsync( IApplicationCommand command, ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled, CancellationToken token = default) { PreConditions.NotNull(command, nameof(command)); await PublishAsync(command, replyScheme, token); var promise = new ApplicationCommandExecutionPromise(command); _commandResultListener.AddExecutingPromise(promise); return(await promise.Future.ConfigureAwait(false)); }
private void Execute(IApplicationCommand cmd, bool log, bool audit) { if (audit && cmd.Audit) { AuditCommand(cmd); } if (HasPermissionOnCmd(cmd)) { cmd.Execute(); } else { ShowNoPermissionMessage(); } }
private static TArg GetApplicationCommandProperties<TArg>(IApplicationCommand command) where TArg : ApplicationCommandProperties { bool isBaseClass = typeof(TArg) == typeof(ApplicationCommandProperties); switch (true) { case true when (typeof(TArg) == typeof(SlashCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.Slash: return new SlashCommandProperties() as TArg; case true when (typeof(TArg) == typeof(MessageCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.Message: return new MessageCommandProperties() as TArg; case true when (typeof(TArg) == typeof(UserCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.User: return new UserCommandProperties() as TArg; default: throw new InvalidOperationException($"Cannot modify application command of type {command.Type} with the parameter type {typeof(TArg).FullName}"); } }
public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong?guildId, IApplicationCommand command, RequestOptions options = null) { return(guildId.HasValue ? DeleteGuildCommandAsync(client, guildId.Value, command, options) : DeleteGlobalCommandAsync(client, command, options)); }
public static async Task <ApplicationCommand> ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, ApplicationCommandProperties arg, RequestOptions options = null) { var model = new ModifyApplicationCommandParams { Name = arg.Name, DefaultPermission = arg.IsDefaultPermission.IsSpecified ? arg.IsDefaultPermission.Value : Optional <bool> .Unspecified }; if (arg is SlashCommandProperties slashProps) { Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); model.Description = slashProps.Description.Value; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } return(await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false)); }
public static Task <ApplicationCommand> ModifyGuildCommandAsync <TArg>(BaseDiscordClient client, IApplicationCommand command, ulong guildId, Action <TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties { var arg = GetApplicationCommandProperties <TArg>(command); func(arg); return(ModifyGuildCommandAsync(client, command, guildId, arg, options)); }
public static async Task <ApplicationCommand> ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, ApplicationCommandProperties args, RequestOptions options = null) { if (args.Name.IsSpecified) { Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name)); } var model = new ModifyApplicationCommandParams { Name = args.Name, DefaultPermission = args.IsDefaultPermission.IsSpecified ? args.IsDefaultPermission.Value : Optional <bool> .Unspecified }; if (args is SlashCommandProperties slashProps) { if (slashProps.Description.IsSpecified) { Preconditions.AtMost(slashProps.Description.Value.Length, 100, nameof(slashProps.Description)); Preconditions.AtLeast(slashProps.Description.Value.Length, 1, nameof(slashProps.Description)); } if (slashProps.Options.IsSpecified) { if (slashProps.Options.Value.Count > 10) { throw new ArgumentException("Option count must be 10 or less"); } } model.Description = slashProps.Description; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } return(await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false)); }
public void SetApplicationCommand(IApplicationCommand command) { _applicationCommand = command; }
public ApplicationCommandExecutionPromise(IApplicationCommand command) { ApplicationCommand = command; _completionSource = new TaskCompletionSource <ApplicationCommandResult>(); }
public TmsLiveMarketPageViewModel(IApplicationCommand appCommand, TmsClient client) : base(appCommand) { _client = client; }
public ActiveAwareBindableBase(IApplicationCommand appCommand) { AppCommand = appCommand; AppCommand.RefreshCommand.RegisterCommand(RefreshCommand); }
public ApplicationCommandResult <TResult> ExecuteCommand <TResult>( IApplicationCommand command, ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled) => _executor.ExecuteCommand <TResult>(command, replyScheme);
public async Task <ApplicationCommandResult <TPayload> > ExecuteCommandAsync <TPayload>(IApplicationCommand command, CancellationToken token = default) { return(await ExecuteCommandAsync <TPayload>(command, ApplicationCommandReplySchemes.OnDomainCommandHandled, token) .ConfigureAwait(false)); }
public CommandBinding(IApplicationCommand command) { _command = command; }
public MeroShareAsbaApplicationReportPageViewModel(IApplicationCommand appCommand, MeroshareClient client, IDialogService dialog) : base(appCommand) { _client = client; _dialog = dialog; }
public async Task <ApplicationCommandResult <TResult> > ExecuteCommandAsync <TResult>( IApplicationCommand command, ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled, CancellationToken token = default) => await _executor.ExecuteCommandAsync <TResult>(command, replyScheme, token);