2022-08-24 03:39:44 +00:00
|
|
|
#pragma warning disable CA1822 // "Mark members as static" - members should only be callable by code with access to this instance
|
2022-08-16 19:37:06 +00:00
|
|
|
using Discord.Net;
|
|
|
|
using RegexBot.Data;
|
|
|
|
|
|
|
|
namespace RegexBot.Services.CommonFunctions;
|
|
|
|
internal partial class CommonFunctionsService : Service {
|
|
|
|
|
|
|
|
// things this should do:
|
|
|
|
// set a note
|
|
|
|
// set a warn (like note, but spicy)
|
|
|
|
// -> return with a WarnLogResult? And send it down the chute...
|
|
|
|
|
|
|
|
// Called by EF_Removals, this processes a removal into a log entry.
|
|
|
|
// A notification for this entry is then propagated.
|
|
|
|
private void ModLogsProcessRemoval(ulong guildId, ulong targetId, ModLogType remType, string source, string? logReason) {
|
|
|
|
var entry = new ModLogEntry() {
|
|
|
|
GuildId = (long)guildId,
|
|
|
|
UserId = (long)targetId,
|
|
|
|
LogType = remType,
|
|
|
|
IssuedBy = source,
|
|
|
|
Message = logReason
|
|
|
|
};
|
|
|
|
using (var db = new BotDatabaseContext()) {
|
|
|
|
db.Add(entry);
|
|
|
|
db.SaveChanges();
|
|
|
|
}
|
2022-08-24 03:39:44 +00:00
|
|
|
BotClient.PushSharedEventAsync(entry);
|
2022-08-16 19:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal async Task<HttpException?> SendUserWarningAsync(SocketGuildUser target, string? reason) {
|
2022-09-13 21:52:44 +00:00
|
|
|
const string DMTemplate = "You have been issued a warning in {0}";
|
2022-08-16 19:37:06 +00:00
|
|
|
const string DMTemplateReason = " with the following message:\n{1}";
|
|
|
|
|
|
|
|
var outMessage = string.IsNullOrWhiteSpace(reason)
|
|
|
|
? string.Format(DMTemplate + ".", target.Guild.Name)
|
|
|
|
: string.Format(DMTemplate + DMTemplateReason, target.Guild.Name, reason);
|
|
|
|
try {
|
2022-09-13 21:52:44 +00:00
|
|
|
var dch = await target.CreateDMChannelAsync();
|
2022-08-16 19:37:06 +00:00
|
|
|
await dch.SendMessageAsync(outMessage);
|
|
|
|
} catch (HttpException ex) {
|
|
|
|
return ex;
|
|
|
|
}
|
2022-09-13 21:52:44 +00:00
|
|
|
return null;
|
2022-08-16 19:37:06 +00:00
|
|
|
}
|
|
|
|
}
|