Browse Source

Init

pull/2213/head
Armano den Boef 3 years ago
parent
commit
9892ce7b51
6 changed files with 48 additions and 12 deletions
  1. +1
    -1
      src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs
  2. +1
    -1
      src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs
  3. +1
    -1
      src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs
  4. +1
    -1
      src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs
  5. +2
    -2
      src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs
  6. +42
    -6
      src/Discord.Net.Interactions/InteractionService.cs

+ 1
- 1
src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs View File

@@ -46,7 +46,7 @@ namespace Discord.Interactions

/// <inheritdoc/>
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) =>
CommandService._autocompleteCommandExecutedEvent.InvokeAsync(this, context, result);
CommandService.InvokeResultEventsAsync(this, context, result);

/// <inheritdoc/>
protected override string GetLogString(IInteractionContext context)


+ 1
- 1
src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs View File

@@ -84,7 +84,7 @@ namespace Discord.Interactions
}

protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
=> CommandService._componentCommandExecutedEvent.InvokeAsync(this, context, result);
=> CommandService.InvokeResultEventsAsync(this, context, result);

protected override string GetLogString(IInteractionContext context)
{


+ 1
- 1
src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs View File

@@ -46,6 +46,6 @@ namespace Discord.Interactions

/// <inheritdoc/>
protected override Task InvokeModuleEvent (IInteractionContext context, IResult result)
=> CommandService._contextCommandExecutedEvent.InvokeAsync(this, context, result);
=> CommandService.InvokeResultEventsAsync(this, context, result);
}
}

+ 1
- 1
src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs View File

@@ -85,7 +85,7 @@ namespace Discord.Interactions

/// <inheritdoc/>
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
=> CommandService._modalCommandExecutedEvent.InvokeAsync(this, context, result);
=> CommandService.InvokeResultEventsAsync(this, context, result);

/// <inheritdoc/>
protected override string GetLogString(IInteractionContext context)


+ 2
- 2
src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs View File

@@ -131,8 +131,8 @@ namespace Discord.Interactions
return ParseResult.FromSuccess(readResult.Value);
}

protected override Task InvokeModuleEvent (IInteractionContext context, IResult result)
=> CommandService._slashCommandExecutedEvent.InvokeAsync(this, context, result);
protected override Task InvokeModuleEvent(IInteractionContext context, IResult result)
=> CommandService.InvokeResultEventsAsync(this, context, result);

protected override string GetLogString (IInteractionContext context)
{


+ 42
- 6
src/Discord.Net.Interactions/InteractionService.cs View File

@@ -24,41 +24,47 @@ namespace Discord.Interactions
public event Func<LogMessage, Task> Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } }
internal readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new ();

/// <summary>
/// Occurs when any type of interaction is executed.
/// </summary>
public event Func<ICommandInfo, IInteractionContext, IResult, Task> InteractionExecuted { add { _interactionExecutedEvent.Add(value); } remove { _interactionExecutedEvent.Remove(value); } }
private readonly AsyncEvent<Func<ICommandInfo, IInteractionContext, IResult, Task>> _interactionExecutedEvent = new();

/// <summary>
/// Occurs when a Slash Command is executed.
/// </summary>
public event Func<SlashCommandInfo, IInteractionContext, IResult, Task> SlashCommandExecuted { add { _slashCommandExecutedEvent.Add(value); } remove { _slashCommandExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<SlashCommandInfo, IInteractionContext, IResult, Task>> _slashCommandExecutedEvent = new ();
private readonly AsyncEvent<Func<SlashCommandInfo, IInteractionContext, IResult, Task>> _slashCommandExecutedEvent = new ();

/// <summary>
/// Occurs when a Context Command is executed.
/// </summary>
public event Func<ContextCommandInfo, IInteractionContext, IResult, Task> ContextCommandExecuted { add { _contextCommandExecutedEvent.Add(value); } remove { _contextCommandExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<ContextCommandInfo, IInteractionContext, IResult, Task>> _contextCommandExecutedEvent = new ();
private readonly AsyncEvent<Func<ContextCommandInfo, IInteractionContext, IResult, Task>> _contextCommandExecutedEvent = new ();

/// <summary>
/// Occurs when a Message Component command is executed.
/// </summary>
public event Func<ComponentCommandInfo, IInteractionContext, IResult, Task> ComponentCommandExecuted { add { _componentCommandExecutedEvent.Add(value); } remove { _componentCommandExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<ComponentCommandInfo, IInteractionContext, IResult, Task>> _componentCommandExecutedEvent = new ();
private readonly AsyncEvent<Func<ComponentCommandInfo, IInteractionContext, IResult, Task>> _componentCommandExecutedEvent = new ();

/// <summary>
/// Occurs when a Autocomplete command is executed.
/// </summary>
public event Func<AutocompleteCommandInfo, IInteractionContext, IResult, Task> AutocompleteCommandExecuted { add { _autocompleteCommandExecutedEvent.Add(value); } remove { _autocompleteCommandExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<AutocompleteCommandInfo, IInteractionContext, IResult, Task>> _autocompleteCommandExecutedEvent = new();
private readonly AsyncEvent<Func<AutocompleteCommandInfo, IInteractionContext, IResult, Task>> _autocompleteCommandExecutedEvent = new();

/// <summary>
/// Occurs when a AutocompleteHandler is executed.
/// </summary>
public event Func<IAutocompleteHandler, IInteractionContext, IResult, Task> AutocompleteHandlerExecuted { add { _autocompleteHandlerExecutedEvent.Add(value); } remove { _autocompleteHandlerExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<IAutocompleteHandler, IInteractionContext, IResult, Task>> _autocompleteHandlerExecutedEvent = new();
private readonly AsyncEvent<Func<IAutocompleteHandler, IInteractionContext, IResult, Task>> _autocompleteHandlerExecutedEvent = new();

/// <summary>
/// Occurs when a Modal command is executed.
/// </summary>
public event Func<ModalCommandInfo, IInteractionContext, IResult, Task> ModalCommandExecuted { add { _modalCommandExecutedEvent.Add(value); } remove { _modalCommandExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<ModalCommandInfo, IInteractionContext, IResult, Task>> _modalCommandExecutedEvent = new();
private readonly AsyncEvent<Func<ModalCommandInfo, IInteractionContext, IResult, Task>> _modalCommandExecutedEvent = new();

private readonly ConcurrentDictionary<Type, ModuleInfo> _typedModuleDefs;
private readonly CommandMap<SlashCommandInfo> _slashCommandMap;
@@ -719,6 +725,7 @@ namespace Discord.Interactions
await _cmdLogger.DebugAsync($"Unknown slash command, skipping execution ({string.Join(" ", keywords).ToUpper()})");

await _slashCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false);
return result;
}
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
@@ -736,6 +743,7 @@ namespace Discord.Interactions
await _cmdLogger.DebugAsync($"Unknown context command, skipping execution ({result.Text.ToUpper()})");

await _contextCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false);
return result;
}
return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false);
@@ -750,6 +758,7 @@ namespace Discord.Interactions
await _cmdLogger.DebugAsync($"Unknown custom interaction id, skipping execution ({input.ToUpper()})");

await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false);
return result;
}
return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false);
@@ -779,6 +788,7 @@ namespace Discord.Interactions
await _cmdLogger.DebugAsync($"Unknown command name, skipping autocomplete process ({interaction.Data.CommandName.ToUpper()})");

await _autocompleteCommandExecutedEvent.InvokeAsync(null, context, commandResult).ConfigureAwait(false);
await InvokeResultEventsAsync(null, context, commandResult).ConfigureAwait(false);
return commandResult;
}

@@ -794,11 +804,37 @@ namespace Discord.Interactions
await _cmdLogger.DebugAsync($"Unknown custom interaction id, skipping execution ({input.ToUpper()})");

await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false);
return result;
}
return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false);
}

internal async Task InvokeResultEventsAsync(ICommandInfo info, IInteractionContext context, IResult result)
{
await _interactionExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false);
if (info is not null)
{
switch (info)
{
case SlashCommandInfo slashCmd:
await _slashCommandExecutedEvent.InvokeAsync(slashCmd, context, result).ConfigureAwait(false);
return;
case ContextCommandInfo ctxCmd:
await _contextCommandExecutedEvent.InvokeAsync(ctxCmd, context, result).ConfigureAwait(false);
return;
case ComponentCommandInfo component:
await _componentCommandExecutedEvent.InvokeAsync(component, context, result).ConfigureAwait(false);
return;
case AutocompleteCommandInfo autocomplete:
await _autocompleteCommandExecutedEvent.InvokeAsync(autocomplete, context, result).ConfigureAwait(false);
return;
default:
throw new InvalidOperationException("No event has been designated to this interaction result.");
}
}
}

internal TypeConverter GetTypeConverter(Type type, IServiceProvider services = null)
=> _typeConverterMap.Get(type, services);



Loading…
Cancel
Save