Skip to content

Commit

Permalink
Fix commandstats, add removemessagecount which can remove by user, ch…
Browse files Browse the repository at this point in the history
…annel, for the guild, per channel and user. Completely map out db and waste time thinking nativeaot would be a good idea, would not have worked anyway.
  • Loading branch information
SylveonDeko committed Oct 24, 2024
1 parent e655736 commit 137fb3d
Show file tree
Hide file tree
Showing 13 changed files with 1,005 additions and 545 deletions.
2 changes: 0 additions & 2 deletions src/Mewdeko/Database/Extensions/GuildConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ public static IQueryable<GuildConfig> IncludeEverything(this DbSet<GuildConfig>
{
return config
.AsQueryable()
.Include(gc => gc.LogSetting)
.ThenInclude(gc => gc.IgnoredChannels)
.Include(gc => gc.Permissions)
.Include(gc => gc.CommandCooldowns)
.Include(gc => gc.GuildRepeaters)
Expand Down
1,071 changes: 817 additions & 254 deletions src/Mewdeko/Database/MewdekoContext.cs

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/Mewdeko/Database/Models/GuildConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,6 @@ public class GuildConfig : DbEntity
/// </summary>
public string? ChannelByeMessageText { get; set; } = "%user% has left!";

/// <summary>
/// Gets or sets the log settings for the guild.
/// </summary>
public LogSetting LogSetting { get; set; } = new();

/// <summary>
/// Gets or sets a value indicating whether to restrict self-assigned roles to be exclusive.
Expand Down
234 changes: 0 additions & 234 deletions src/Mewdeko/Database/Models/LogSetting.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,6 @@ public LogCommandService(DbContextProvider dbProvider, IDataCache cache, Discord
public async Task OnReadyAsync()
{
await using var dbContext = await dbProvider.GetContextAsync();
var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = await dbContext.GuildConfigs
.AsQueryable()
.Include(gc => gc.LogSetting)
.ThenInclude(ls => ls.IgnoredChannels)
.Where(x => guildIds.Contains(x.GuildId))
.ToListAsyncEF();

// Store the log settings in a concurrent dictionary for fast access
GuildLogSettings = dbContext.LoggingV2
.ToDictionary(g => g.GuildId, g => g)
Expand Down
36 changes: 13 additions & 23 deletions src/Mewdeko/Modules/OwnerOnly/OwnerOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,46 +338,36 @@ async Task<PageBuilder> PageFactory(int page)
[Aliases]
public async Task CommandStats()
{
await using var dbContext = await dbProvider.GetContextAsync();
await using var context1 = await dbProvider.GetContextAsync();
await using var context2 = await dbProvider.GetContextAsync();
await using var context3 = await dbProvider.GetContextAsync();
await using var context4 = await dbProvider.GetContextAsync();

var commandStatsTable = dbContext.CommandStats;
var topCommandTask = commandStatsTable
var topCommandTask = context1.CommandStats
.Where(x => !x.Trigger)
.GroupBy(q => q.NameOrId)
.Select(g => new
{
g.Key, Count = g.Count()
})
.Select(g => new { g.Key, Count = g.Count() })
.OrderByDescending(gc => gc.Count)
.FirstOrDefaultAsyncLinqToDB();

var topModuleTask = commandStatsTable
var topModuleTask = context2.CommandStats
.Where(x => !x.Trigger)
.GroupBy(q => q.Module)
.Select(g => new
{
g.Key, Count = g.Count()
})
.Select(g => new { g.Key, Count = g.Count() })
.OrderByDescending(gc => gc.Count)
.FirstOrDefaultAsyncLinqToDB();

var topGuildTask = commandStatsTable
var topGuildTask = context3.CommandStats
.Where(x => !x.Trigger)
.GroupBy(q => q.GuildId)
.Select(g => new
{
g.Key, Count = g.Count()
})
.Select(g => new { g.Key, Count = g.Count() })
.OrderByDescending(gc => gc.Count)
.FirstOrDefaultAsyncLinqToDB();

var topUserTask = commandStatsTable
var topUserTask = context4.CommandStats
.Where(x => !x.Trigger)
.GroupBy(q => q.UserId)
.Select(g => new
{
g.Key, Count = g.Count()
})
.Select(g => new { g.Key, Count = g.Count() })
.OrderByDescending(gc => gc.Count)
.FirstOrDefaultAsyncLinqToDB();

Expand All @@ -396,7 +386,7 @@ public async Task CommandStats()
.AddField("Top Command", $"{topCommand.Key} was used {topCommand.Count} times!")
.AddField("Top Module", $"{topModule.Key} was used {topModule.Count} times!")
.AddField("Top User", $"{user} has used commands {topUser.Count} times!")
.AddField("Top Guild", $"{guild} has used commands {topGuild.Count} times!");
.AddField("Top Guild", $"{guild?.Name ?? "Unknown"} has used commands {topGuild.Count} times!");

await ctx.Channel.SendMessageAsync(embed: eb.Build());
}
Expand Down
Loading

0 comments on commit 137fb3d

Please sign in to comment.