#pragma warning disable CA1822 // "Mark members as static" - will not make static to encourage better structure
using Discord.Net;
using RegexBot.Common;
using RegexBot.Data;
namespace RegexBot;
partial class RegexbotClient {
///
/// Appends a note to the moderation log regarding the given user, containing the given message.
///
///
/// Unlike warnings, notes are private and intended for moderators only. Users are never notified and may
/// never be aware of notes associated with them. Otherwise, they function as any other entry in the log.
///
/// The guild which the target user is associated.
/// The snowflake ID of the target user.
///
/// The the entity which issued this log item.
/// If it was a user, this value preferably is in the format.
///
/// The message to add to this entry.
///
/// The resulting from the creation of this note.
///
public ModLogEntry AddUserNote(SocketGuild guild, ulong targetUser, string source, string? message) {
var entry = new ModLogEntry() {
GuildId = (long)guild.Id,
UserId = (long)targetUser,
LogType = ModLogType.Note,
IssuedBy = source,
Message = message
};
using (var db = new BotDatabaseContext()) {
db.Add(entry);
db.SaveChanges();
}
// TODO notify
return entry;
}
///
/// Warns a user, adding an entry to the moderation log and also attempting to notify the user.
///
/// The guild which the target user is associated.
/// The snowflake ID of the target user.
///
/// The the entity which issued this log item.
/// If it was a user, this value preferably is in the format.
///
/// The message to add to this entry.
///
/// A tuple containing the resulting and .
///
public async Task<(ModLogEntry, LogAppendResult)> AddUserWarnAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
var entry = new ModLogEntry() {
GuildId = (long)guild.Id,
UserId = (long)targetUser,
LogType = ModLogType.Warn,
IssuedBy = source,
Message = message
};
using (var db = new BotDatabaseContext()) {
db.Add(entry);
await db.SaveChangesAsync();
}
// TODO notify
// Attempt warning message
var userSearch = _svcEntityCache.QueryUserCache(targetUser.ToString());
var userDisp = userSearch != null
? $" user **{userSearch.Username}#{userSearch.Discriminator}**"
: $" user with ID **{targetUser}**";
var targetGuildUser = guild.GetUser(targetUser);
if (targetGuildUser == null) return (entry, new LogAppendResult(
new HttpException(System.Net.HttpStatusCode.NotFound, null), entry.LogId, userDisp));
var sendStatus = await _svcCommonFunctions.SendUserWarningAsync(targetGuildUser, message);
return (entry, new LogAppendResult(sendStatus, entry.LogId, userDisp));
}
}