public WebhookOptionsBuilder(IServiceCollection services) { WebhookOptions = new WebhookOptions(); Services = services; services.AddMemoryCache(); services.AddSingleton <ICacheSignal, CacheSignal>(); }
public async Task SendMessageAsync(WebhookOptions options) { if (!(_client.GetChannel(options.Webhook.TextChannel) is SocketTextChannel channel)) { return; } var client = WebhookClient(options.Webhook.WebhookId, options.Webhook.WebhookToken); await WebhookFallbackAsync(client, channel, options); }
public async Task SendMessageAsync(WebhookOptions Options) { if (!(SocketClient.GetChannel(Options.Webhook.TextChannel) is SocketTextChannel Channel)) { return; } var Client = WebhookClient(Options.Webhook.WebhookId, Options.Webhook.WebhookToken); await WebhookFallbackAsync(Client, Channel, Options); }
public static ElsaOptionsBuilder AddWebhooks( this ElsaOptionsBuilder elsaOptions, Action <WebhookOptions>?configure = default) { var services = elsaOptions.Services; // Configure Webhooks. var options = new WebhookOptions(); configure?.Invoke(options); // Services. services .AddScoped <IActivityTypeProvider, WebhookActivityTypeProvider>() .AddScoped(options.WebhookDefinitionStoreFactory); services.Decorate <IWebhookDefinitionStore, InitializingWebhookDefinitionStore>(); return(elsaOptions); }
public async Task <WebhookWrapper> UpdateWebhookAsync(SocketTextChannel channel, WebhookWrapper old, WebhookOptions options) { var hook = !(_client.GetChannel(old.TextChannel) is SocketTextChannel getChannel) ? await GetWebhookAsync(channel.Guild, new WebhookOptions { Webhook = old }) : await GetWebhookAsync(getChannel, new WebhookOptions { Webhook = old }); if (channel.Id == old.TextChannel && hook != null) { return(old); } if (hook != null) { await hook.DeleteAsync(); } var New = await channel.CreateWebhookAsync(options.Name, AvatarStream()); return(new WebhookWrapper { TextChannel = channel.Id, WebhookId = New.Id, WebhookToken = New.Token }); }
public Task WebhookFallbackAsync(DiscordWebhookClient client, ITextChannel channel, WebhookOptions options) { if (client == null && channel != null) { PrettyConsole.Log(LogSeverity.Error, "WebhookFallback", $"Falling back to Channel: {channel.Name}"); return(channel.SendMessageAsync(options.Message, embed: options.Embed)); } return(client.SendMessageAsync(options.Message, embeds: options.Embed == null ? null : new List <Embed> { options.Embed })); }
public async Task <RestWebhook> GetWebhookAsync(SocketTextChannel channel, WebhookOptions options) { return((await channel?.GetWebhooksAsync())?.FirstOrDefault(x => x?.Name == options.Name || x?.Id == options.Webhook.WebhookId)); }
public async Task <RestWebhook> GetWebhookAsync(SocketGuild guild, WebhookOptions options) { return((await guild?.GetWebhooksAsync())?.FirstOrDefault(x => x?.Name == options.Name || x?.Id == options.Webhook.WebhookId)); }
public Task WebhookFallbackAsync(DiscordWebhookClient Client, ITextChannel Channel, WebhookOptions Options) { if (Client == null && Channel != null) { LogService.Write(Enums.LogSource.DSD, $"Falling back to Channel: {Channel.Name}", System.Drawing.Color.Yellow); return(Channel.SendMessageAsync(Options.Message, embed: Options.Embed)); } return(Client.SendMessageAsync(Options.Message, embeds: Options.Embed == null ? null : new List <Embed>() { Options.Embed })); }
public async Task <RestWebhook> GetWebhookAsync(SocketTextChannel Channel, WebhookOptions Options) => (await Channel?.GetWebhooksAsync())?.FirstOrDefault(x => x?.Name == Options.Name || x?.Id == Options.Webhook.WebhookId);
public async Task <RestWebhook> GetWebhookAsync(SocketGuild Guild, WebhookOptions Options) => (await Guild?.GetWebhooksAsync())?.FirstOrDefault(x => x?.Name == Options.Name || x?.Id == Options.Webhook.WebhookId);
public async Task <WebhookWrapper> UpdateWebhookAsync(SocketTextChannel Channel, WebhookWrapper Old, WebhookOptions Options) { var Hook = !(SocketClient.GetChannel(Old.TextChannel) is SocketTextChannel GetChannel) ? await GetWebhookAsync(Channel.Guild, new WebhookOptions { Webhook = Old }) : await GetWebhookAsync(GetChannel, new WebhookOptions { Webhook = Old }); if (Channel.Id == Old.TextChannel && Hook != null) { return(Old); } else if (Hook != null) { await Hook.DeleteAsync(); } var New = await Channel.CreateWebhookAsync(Options.Name, AvatarStream()); return(new WebhookWrapper { TextChannel = Channel.Id, WebhookId = New.Id, WebhookToken = New.Token }); }