Remove ulong->long casts

This commit is contained in:
Noi 2022-12-03 17:46:26 -08:00
parent 55453cf795
commit ebe3a403f3
10 changed files with 30 additions and 30 deletions

View file

@ -12,22 +12,22 @@ public class CachedGuildMessage {
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public long MessageId { get; set; }
public ulong MessageId { get; set; }
/// <summary>
/// Gets the message author's snowflake ID.
/// </summary>
public long AuthorId { get; set; }
public ulong AuthorId { get; set; }
/// <summary>
/// Gets the associated guild's snowflake ID.
/// </summary>
public long GuildId { get; set; }
public ulong GuildId { get; set; }
/// <summary>
/// Gets the corresponding channel's snowflake ID.
/// </summary>
public long ChannelId { get; set; }
public ulong ChannelId { get; set; }
/// <summary>
/// Gets the timestamp showing when this message was originally created.

View file

@ -9,10 +9,10 @@ public class CachedGuildUser {
/// <summary>
/// Gets the associated guild's snowflake ID.
/// </summary>
public long GuildId { get; set; }
public ulong GuildId { get; set; }
/// <inheritdoc cref="CachedUser.UserId"/>
public long UserId { get; set; }
public ulong UserId { get; set; }
/// <inheritdoc cref="CachedUser.ULastUpdateTime"/>
public DateTimeOffset GULastUpdateTime { get; set; }

View file

@ -12,7 +12,7 @@ public class CachedUser {
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public long UserId { get; set; }
public ulong UserId { get; set; }
/// <summary>
/// Gets the timestamp showing when this cache entry was last updated.

View file

@ -20,12 +20,12 @@ public class ModLogEntry : ISharedEvent {
public DateTimeOffset Timestamp { get; set; }
/// <inheritdoc cref="CachedGuildUser.GuildId"/>
public long GuildId { get; set; }
public ulong GuildId { get; set; }
/// <summary>
/// Gets the ID of the users for which this log entry pertains.
/// </summary>
public long UserId { get; set; }
public ulong UserId { get; set; }
/// <summary>
/// Gets the type of log message this represents.

View file

@ -25,7 +25,7 @@ internal partial class ModLogs {
using var db = new BotDatabaseContext();
var cachedMsg = db.GuildMessageCache
.Include(gm => gm.Author)
.Where(gm => gm.MessageId == (long)argMsg.Id)
.Where(gm => gm.MessageId == argMsg.Id)
.SingleOrDefault();
var reportEmbed = new EmbedBuilder()

View file

@ -24,8 +24,8 @@ partial class RegexbotClient {
/// </returns>
public async Task<ModLogEntry> AddUserNoteAsync(SocketGuild guild, ulong targetUser, string source, string? message) {
var entry = new ModLogEntry() {
GuildId = (long)guild.Id,
UserId = (long)targetUser,
GuildId = guild.Id,
UserId = targetUser,
LogType = ModLogType.Note,
IssuedBy = source,
Message = message
@ -53,8 +53,8 @@ partial class RegexbotClient {
/// </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,
GuildId = guild.Id,
UserId = targetUser,
LogType = ModLogType.Warn,
IssuedBy = source,
Message = message

View file

@ -8,8 +8,8 @@ internal partial class CommonFunctionsService : Service {
// 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,
GuildId = guildId,
UserId = targetId,
LogType = remType,
IssuedBy = source,
Message = logReason

View file

@ -25,8 +25,8 @@ internal partial class CommonFunctionsService : Service {
return new TimeoutSetResult(ex, false, target);
}
var entry = new ModLogEntry() {
GuildId = (long)guild.Id,
UserId = (long)target.Id,
GuildId = guild.Id,
UserId = target.Id,
LogType = ModLogType.Timeout,
IssuedBy = source,
Message = $"Duration: {Math.Floor(duration.TotalMinutes)}min{(reason == null ? "." : " - " + reason)}"

View file

@ -28,7 +28,7 @@ class MessageCachingSubservice {
if (arg is SocketSystemMessage) return;
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) {
// Alternative for Discord.Net's MessageUpdated handler:
@ -40,10 +40,10 @@ class MessageCachingSubservice {
if (cachedMsg == null) {
cachedMsg = new() {
MessageId = (long)arg.Id,
AuthorId = (long)arg.Author.Id,
GuildId = (long)((SocketGuildUser)arg.Author).Guild.Id,
ChannelId = (long)arg.Channel.Id,
MessageId = arg.Id,
AuthorId = arg.Author.Id,
GuildId = ((SocketGuildUser)arg.Author).Guild.Id,
ChannelId = arg.Channel.Id,
AttachmentNames = arg.Attachments.Select(a => a.Filename).ToList(),
Content = arg.Content
};

View file

@ -52,9 +52,9 @@ class UserCachingSubservice {
// IMPORTANT: Do NOT forget to save changes in database after calling this!
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) {
uinfo = new() { UserId = (long)user.Id };
uinfo = new() { UserId = user.Id };
db.UserCache.Add(uinfo);
}
@ -65,9 +65,9 @@ class UserCachingSubservice {
}
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) {
guinfo = new() { GuildId = (long)user.Guild.Id, UserId = (long)user.Id };
guinfo = new() { GuildId = user.Guild.Id, UserId = user.Id };
db.GuildUserCache.Add(guinfo);
}
@ -83,7 +83,7 @@ class UserCachingSubservice {
var query = db.UserCache.AsQueryable();
if (sID.HasValue)
query = query.Where(c => c.UserId == (long)sID.Value);
query = query.Where(c => c.UserId == sID.Value);
if (nameSearch != null) {
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);
@ -112,9 +112,9 @@ class UserCachingSubservice {
internal CachedGuildUser? DoGuildUserQuery(ulong guildId, string search) {
static CachedGuildUser? innerQuery(ulong guildId, ulong? sID, (string name, string? disc)? nameSearch) {
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)
query = query.Where(c => c.UserId == (long)sID.Value);
query = query.Where(c => c.UserId == sID.Value);
if (nameSearch != null) {
query = query.Where(c => (c.Nickname != null && c.Nickname.ToLower() == nameSearch.Value.name.ToLower()) ||
c.User.Username.ToLower() == nameSearch.Value.name.ToLower());