1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-20 00:43:36 +03:00
Octobot/EventResponders.cs
Octol1ttle 201a1ce079
Remora.Discord part 1 out of ∞
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
2023-05-16 00:11:11 +05:00

31 lines
1.1 KiB
C#

using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.Gateway.Responders;
using Remora.Results;
namespace Boyfriend;
public class ReadyResponder : IResponder<IGuildCreate> {
private readonly IDiscordRestChannelAPI _channelApi;
public ReadyResponder(IDiscordRestChannelAPI channelApi) {
_channelApi = channelApi;
}
public async Task<Result> RespondAsync(IGuildCreate gatewayEvent, CancellationToken ct = default) {
if (!gatewayEvent.Guild.IsT0) return Result.FromSuccess(); // is IAvailableGuild
var guild = gatewayEvent.Guild.AsT0;
if (guild.GetConfigBool("SendReadyMessages").IsDefined(out var enabled)
&& enabled
&& guild.GetChannel("PrivateFeedbackChannel").IsDefined(out var channel)) {
Messages.Culture = guild.GetCulture();
var i = Random.Shared.Next(1, 4);
return (Result)await _channelApi.CreateMessageAsync(
channel.ID, string.Format(Messages.Ready, Boyfriend.GetLocalized($"Beep{i}")), ct: ct);
}
return Result.FromSuccess();
}
}