Remove ulong->long casts
This commit is contained in:
parent
55453cf795
commit
ebe3a403f3
10 changed files with 30 additions and 30 deletions
|
@ -12,22 +12,22 @@ public class CachedGuildMessage {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||||
public long MessageId { get; set; }
|
public ulong MessageId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the message author's snowflake ID.
|
/// Gets the message author's snowflake ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long AuthorId { get; set; }
|
public ulong AuthorId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the associated guild's snowflake ID.
|
/// Gets the associated guild's snowflake ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long GuildId { get; set; }
|
public ulong GuildId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the corresponding channel's snowflake ID.
|
/// Gets the corresponding channel's snowflake ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long ChannelId { get; set; }
|
public ulong ChannelId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the timestamp showing when this message was originally created.
|
/// Gets the timestamp showing when this message was originally created.
|
||||||
|
|
|
@ -9,10 +9,10 @@ public class CachedGuildUser {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the associated guild's snowflake ID.
|
/// Gets the associated guild's snowflake ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long GuildId { get; set; }
|
public ulong GuildId { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="CachedUser.UserId"/>
|
/// <inheritdoc cref="CachedUser.UserId"/>
|
||||||
public long UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="CachedUser.ULastUpdateTime"/>
|
/// <inheritdoc cref="CachedUser.ULastUpdateTime"/>
|
||||||
public DateTimeOffset GULastUpdateTime { get; set; }
|
public DateTimeOffset GULastUpdateTime { get; set; }
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class CachedUser {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||||
public long UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the timestamp showing when this cache entry was last updated.
|
/// Gets the timestamp showing when this cache entry was last updated.
|
||||||
|
|
|
@ -20,12 +20,12 @@ public class ModLogEntry : ISharedEvent {
|
||||||
public DateTimeOffset Timestamp { get; set; }
|
public DateTimeOffset Timestamp { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="CachedGuildUser.GuildId"/>
|
/// <inheritdoc cref="CachedGuildUser.GuildId"/>
|
||||||
public long GuildId { get; set; }
|
public ulong GuildId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ID of the users for which this log entry pertains.
|
/// Gets the ID of the users for which this log entry pertains.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the type of log message this represents.
|
/// Gets the type of log message this represents.
|
||||||
|
|
|
@ -25,7 +25,7 @@ internal partial class ModLogs {
|
||||||
using var db = new BotDatabaseContext();
|
using var db = new BotDatabaseContext();
|
||||||
var cachedMsg = db.GuildMessageCache
|
var cachedMsg = db.GuildMessageCache
|
||||||
.Include(gm => gm.Author)
|
.Include(gm => gm.Author)
|
||||||
.Where(gm => gm.MessageId == (long)argMsg.Id)
|
.Where(gm => gm.MessageId == argMsg.Id)
|
||||||
.SingleOrDefault();
|
.SingleOrDefault();
|
||||||
|
|
||||||
var reportEmbed = new EmbedBuilder()
|
var reportEmbed = new EmbedBuilder()
|
||||||
|
|
|
@ -24,8 +24,8 @@ partial class RegexbotClient {
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<ModLogEntry> AddUserNoteAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
|
public async Task<ModLogEntry> AddUserNoteAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
|
||||||
var entry = new ModLogEntry() {
|
var entry = new ModLogEntry() {
|
||||||
GuildId = (long)guild.Id,
|
GuildId = guild.Id,
|
||||||
UserId = (long)targetUser,
|
UserId = targetUser,
|
||||||
LogType = ModLogType.Note,
|
LogType = ModLogType.Note,
|
||||||
IssuedBy = source,
|
IssuedBy = source,
|
||||||
Message = message
|
Message = message
|
||||||
|
@ -53,8 +53,8 @@ partial class RegexbotClient {
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<(ModLogEntry, LogAppendResult)> AddUserWarnAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
|
public async Task<(ModLogEntry, LogAppendResult)> AddUserWarnAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
|
||||||
var entry = new ModLogEntry() {
|
var entry = new ModLogEntry() {
|
||||||
GuildId = (long)guild.Id,
|
GuildId = guild.Id,
|
||||||
UserId = (long)targetUser,
|
UserId = targetUser,
|
||||||
LogType = ModLogType.Warn,
|
LogType = ModLogType.Warn,
|
||||||
IssuedBy = source,
|
IssuedBy = source,
|
||||||
Message = message
|
Message = message
|
||||||
|
|
|
@ -8,8 +8,8 @@ internal partial class CommonFunctionsService : Service {
|
||||||
// A notification for this entry is then propagated.
|
// A notification for this entry is then propagated.
|
||||||
private void ModLogsProcessRemoval(ulong guildId, ulong targetId, ModLogType remType, string source, string? logReason) {
|
private void ModLogsProcessRemoval(ulong guildId, ulong targetId, ModLogType remType, string source, string? logReason) {
|
||||||
var entry = new ModLogEntry() {
|
var entry = new ModLogEntry() {
|
||||||
GuildId = (long)guildId,
|
GuildId = guildId,
|
||||||
UserId = (long)targetId,
|
UserId = targetId,
|
||||||
LogType = remType,
|
LogType = remType,
|
||||||
IssuedBy = source,
|
IssuedBy = source,
|
||||||
Message = logReason
|
Message = logReason
|
||||||
|
|
|
@ -25,8 +25,8 @@ internal partial class CommonFunctionsService : Service {
|
||||||
return new TimeoutSetResult(ex, false, target);
|
return new TimeoutSetResult(ex, false, target);
|
||||||
}
|
}
|
||||||
var entry = new ModLogEntry() {
|
var entry = new ModLogEntry() {
|
||||||
GuildId = (long)guild.Id,
|
GuildId = guild.Id,
|
||||||
UserId = (long)target.Id,
|
UserId = target.Id,
|
||||||
LogType = ModLogType.Timeout,
|
LogType = ModLogType.Timeout,
|
||||||
IssuedBy = source,
|
IssuedBy = source,
|
||||||
Message = $"Duration: {Math.Floor(duration.TotalMinutes)}min{(reason == null ? "." : " - " + reason)}"
|
Message = $"Duration: {Math.Floor(duration.TotalMinutes)}min{(reason == null ? "." : " - " + reason)}"
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MessageCachingSubservice {
|
||||||
if (arg is SocketSystemMessage) return;
|
if (arg is SocketSystemMessage) return;
|
||||||
|
|
||||||
using var db = new BotDatabaseContext();
|
using var db = new BotDatabaseContext();
|
||||||
CachedGuildMessage? cachedMsg = db.GuildMessageCache.Where(m => m.MessageId == (long)arg.Id).SingleOrDefault();
|
CachedGuildMessage? cachedMsg = db.GuildMessageCache.Where(m => m.MessageId == arg.Id).SingleOrDefault();
|
||||||
|
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
// Alternative for Discord.Net's MessageUpdated handler:
|
// Alternative for Discord.Net's MessageUpdated handler:
|
||||||
|
@ -40,10 +40,10 @@ class MessageCachingSubservice {
|
||||||
|
|
||||||
if (cachedMsg == null) {
|
if (cachedMsg == null) {
|
||||||
cachedMsg = new() {
|
cachedMsg = new() {
|
||||||
MessageId = (long)arg.Id,
|
MessageId = arg.Id,
|
||||||
AuthorId = (long)arg.Author.Id,
|
AuthorId = arg.Author.Id,
|
||||||
GuildId = (long)((SocketGuildUser)arg.Author).Guild.Id,
|
GuildId = ((SocketGuildUser)arg.Author).Guild.Id,
|
||||||
ChannelId = (long)arg.Channel.Id,
|
ChannelId = arg.Channel.Id,
|
||||||
AttachmentNames = arg.Attachments.Select(a => a.Filename).ToList(),
|
AttachmentNames = arg.Attachments.Select(a => a.Filename).ToList(),
|
||||||
Content = arg.Content
|
Content = arg.Content
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,9 +52,9 @@ class UserCachingSubservice {
|
||||||
|
|
||||||
// IMPORTANT: Do NOT forget to save changes in database after calling this!
|
// IMPORTANT: Do NOT forget to save changes in database after calling this!
|
||||||
private static void UpdateUser(SocketUser user, BotDatabaseContext db) {
|
private static void UpdateUser(SocketUser user, BotDatabaseContext db) {
|
||||||
var uinfo = db.UserCache.Where(c => c.UserId == (long)user.Id).SingleOrDefault();
|
var uinfo = db.UserCache.Where(c => c.UserId == user.Id).SingleOrDefault();
|
||||||
if (uinfo == null) {
|
if (uinfo == null) {
|
||||||
uinfo = new() { UserId = (long)user.Id };
|
uinfo = new() { UserId = user.Id };
|
||||||
db.UserCache.Add(uinfo);
|
db.UserCache.Add(uinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ class UserCachingSubservice {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateGuildUser(SocketGuildUser user, BotDatabaseContext db) {
|
private static void UpdateGuildUser(SocketGuildUser user, BotDatabaseContext db) {
|
||||||
var guinfo = db.GuildUserCache.Where(c => c.GuildId == (long)user.Guild.Id && c.UserId == (long)user.Id).SingleOrDefault();
|
var guinfo = db.GuildUserCache.Where(c => c.GuildId == user.Guild.Id && c.UserId == user.Id).SingleOrDefault();
|
||||||
if (guinfo == null) {
|
if (guinfo == null) {
|
||||||
guinfo = new() { GuildId = (long)user.Guild.Id, UserId = (long)user.Id };
|
guinfo = new() { GuildId = user.Guild.Id, UserId = user.Id };
|
||||||
db.GuildUserCache.Add(guinfo);
|
db.GuildUserCache.Add(guinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class UserCachingSubservice {
|
||||||
|
|
||||||
var query = db.UserCache.AsQueryable();
|
var query = db.UserCache.AsQueryable();
|
||||||
if (sID.HasValue)
|
if (sID.HasValue)
|
||||||
query = query.Where(c => c.UserId == (long)sID.Value);
|
query = query.Where(c => c.UserId == sID.Value);
|
||||||
if (nameSearch != null) {
|
if (nameSearch != null) {
|
||||||
query = query.Where(c => c.Username.ToLower() == nameSearch.Value.name.ToLower());
|
query = query.Where(c => c.Username.ToLower() == nameSearch.Value.name.ToLower());
|
||||||
if (nameSearch.Value.disc != null) query = query.Where(c => c.Discriminator == nameSearch.Value.disc);
|
if (nameSearch.Value.disc != null) query = query.Where(c => c.Discriminator == nameSearch.Value.disc);
|
||||||
|
@ -112,9 +112,9 @@ class UserCachingSubservice {
|
||||||
internal CachedGuildUser? DoGuildUserQuery(ulong guildId, string search) {
|
internal CachedGuildUser? DoGuildUserQuery(ulong guildId, string search) {
|
||||||
static CachedGuildUser? innerQuery(ulong guildId, ulong? sID, (string name, string? disc)? nameSearch) {
|
static CachedGuildUser? innerQuery(ulong guildId, ulong? sID, (string name, string? disc)? nameSearch) {
|
||||||
var db = new BotDatabaseContext();
|
var db = new BotDatabaseContext();
|
||||||
var query = db.GuildUserCache.Include(gu => gu.User).Where(c => c.GuildId == (long)guildId);
|
var query = db.GuildUserCache.Include(gu => gu.User).Where(c => c.GuildId == guildId);
|
||||||
if (sID.HasValue)
|
if (sID.HasValue)
|
||||||
query = query.Where(c => c.UserId == (long)sID.Value);
|
query = query.Where(c => c.UserId == sID.Value);
|
||||||
if (nameSearch != null) {
|
if (nameSearch != null) {
|
||||||
query = query.Where(c => (c.Nickname != null && c.Nickname.ToLower() == nameSearch.Value.name.ToLower()) ||
|
query = query.Where(c => (c.Nickname != null && c.Nickname.ToLower() == nameSearch.Value.name.ToLower()) ||
|
||||||
c.User.Username.ToLower() == nameSearch.Value.name.ToLower());
|
c.User.Username.ToLower() == nameSearch.Value.name.ToLower());
|
||||||
|
|
Loading…
Reference in a new issue