13xforever 92751ba6e9 use file-scoped namespaces to reduce nesting
some formatting might be fucked
2022-06-30 00:59:46 +05:00

23 lines
853 B
C#

using System.Threading.Tasks;
using CompatBot.Database;
using CompatBot.Utils;
using DSharpPlus;
using DSharpPlus.EventArgs;
using Microsoft.EntityFrameworkCore;
namespace CompatBot.EventHandlers;
internal static class Greeter
{
public static async Task OnMemberAdded(DiscordClient _, GuildMemberAddEventArgs args)
{
await using var db = new BotDb();
var explanation = await db.Explanation.FirstOrDefaultAsync(e => e.Keyword == "motd").ConfigureAwait(false);
if (explanation != null)
{
var dm = await args.Member.CreateDmChannelAsync().ConfigureAwait(false);
await dm.SendMessageAsync(explanation.Text, explanation.Attachment, explanation.AttachmentFilename).ConfigureAwait(false);
Config.Log.Info($"Sent motd to {args.Member.GetMentionWithNickname()}");
}
}
}