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.Common;
|
|
|
|
using RegexBot.Data;
|
|
|
|
|
|
|
|
namespace RegexBot;
|
|
|
|
partial class RegexbotClient {
|
|
|
|
/// <summary>
|
|
|
|
/// Appends a note to the moderation log regarding the given user, containing the given message.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 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.
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="guild">The guild which the target user is associated.</param>
|
|
|
|
/// <param name="targetUser">The snowflake ID of the target user.</param>
|
|
|
|
/// <param name="source">
|
|
|
|
/// The the entity which issued this log item.
|
|
|
|
/// If it was a user, this value preferably is in the <seealso cref="EntityName"/> format.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="message">The message to add to this entry.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// The resulting <see cref="ModLogEntry"/> from the creation of this note.
|
|
|
|
/// </returns>
|
2022-09-13 21:52:44 +00:00
|
|
|
public async Task<ModLogEntry> AddUserNoteAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
|
2022-08-16 19:37:06 +00:00
|
|
|
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);
|
2022-08-24 03:39:44 +00:00
|
|
|
await db.SaveChangesAsync();
|
2022-08-16 19:37:06 +00:00
|
|
|
}
|
2022-08-24 03:39:44 +00:00
|
|
|
await PushSharedEventAsync(entry);
|
2022-08-16 19:37:06 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Warns a user, adding an entry to the moderation log and also attempting to notify the user.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="guild">The guild which the target user is associated.</param>
|
|
|
|
/// <param name="targetUser">The snowflake ID of the target user.</param>
|
|
|
|
/// <param name="source">
|
|
|
|
/// The the entity which issued this log item.
|
|
|
|
/// If it was a user, this value preferably is in the <seealso cref="EntityName"/> format.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="message">The message to add to this entry.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// A tuple containing the resulting <see cref="ModLogEntry"/> and <see cref="LogAppendResult"/>.
|
|
|
|
/// </returns>
|
|
|
|
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();
|
|
|
|
}
|
2022-08-24 03:39:44 +00:00
|
|
|
await PushSharedEventAsync(entry);
|
2022-08-16 19:37:06 +00:00
|
|
|
|
|
|
|
// Attempt warning message
|
|
|
|
var userSearch = _svcEntityCache.QueryUserCache(targetUser.ToString());
|
|
|
|
var userDisp = userSearch != null
|
2023-11-15 05:09:21 +00:00
|
|
|
? $"**{userSearch.GetDisplayableUsername()}**"
|
2022-09-21 03:39:37 +00:00
|
|
|
: $"user with ID **{targetUser}**";
|
2022-08-16 19:37:06 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|