mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-12-13 05:35:58 +00:00
another broken query that I can't properly fix myself
This commit is contained in:
parent
a33c69a2bd
commit
4a9fcb2156
@ -46,30 +46,38 @@ namespace CompatBot.Commands
|
|||||||
[Description("List users with warnings, sorted from most warned to least")]
|
[Description("List users with warnings, sorted from most warned to least")]
|
||||||
public async Task Users(CommandContext ctx, [Description("Optional number of items to show. Default is 10")] int number = 10)
|
public async Task Users(CommandContext ctx, [Description("Optional number of items to show. Default is 10")] int number = 10)
|
||||||
{
|
{
|
||||||
var isMod = ctx.User.IsWhitelisted(ctx.Client, ctx.Guild);
|
try
|
||||||
if (number < 1)
|
|
||||||
number = 10;
|
|
||||||
var table = new AsciiTable(
|
|
||||||
new AsciiColumn("Username", maxWidth: 24),
|
|
||||||
new AsciiColumn("User ID", disabled: !ctx.Channel.IsPrivate, alignToRight: true),
|
|
||||||
new AsciiColumn("Count", alignToRight: true),
|
|
||||||
new AsciiColumn("All time", alignToRight: true)
|
|
||||||
);
|
|
||||||
using (var db = new BotDb())
|
|
||||||
{
|
{
|
||||||
var query = from warn in db.Warning
|
var isMod = ctx.User.IsWhitelisted(ctx.Client, ctx.Guild);
|
||||||
group warn by warn.DiscordId
|
if (number < 1)
|
||||||
into userGroup
|
number = 10;
|
||||||
let row = new {discordId = userGroup.Key, count = userGroup.Count(w => !w.Retracted), total = userGroup.Count()}
|
var table = new AsciiTable(
|
||||||
orderby row.count descending
|
new AsciiColumn("Username", maxWidth: 24),
|
||||||
select row;
|
new AsciiColumn("User ID", disabled: !ctx.Channel.IsPrivate, alignToRight: true),
|
||||||
foreach (var row in query.Take(number))
|
new AsciiColumn("Count", alignToRight: true),
|
||||||
|
new AsciiColumn("All time", alignToRight: true)
|
||||||
|
);
|
||||||
|
using (var db = new BotDb())
|
||||||
{
|
{
|
||||||
var username = await ctx.GetUserNameAsync(row.discordId).ConfigureAwait(false);
|
var query = from warn in db.Warning
|
||||||
table.Add(username, row.discordId.ToString(), row.count.ToString(), row.total.ToString());
|
group warn by warn.DiscordId
|
||||||
|
into userGroup
|
||||||
|
let row = new {discordId = userGroup.Key, count = userGroup.Count(w => !w.Retracted), total = userGroup.Count()}
|
||||||
|
orderby row.count descending
|
||||||
|
select row;
|
||||||
|
foreach (var row in query.Take(number))
|
||||||
|
{
|
||||||
|
var username = await ctx.GetUserNameAsync(row.discordId).ConfigureAwait(false);
|
||||||
|
table.Add(username, row.discordId.ToString(), row.count.ToString(), row.total.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
await ctx.SendAutosplitMessageAsync(new StringBuilder("Warning count per user:").Append(table)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Config.Log.Error(e);
|
||||||
|
await ctx.ReactWithAsync(Config.Reactions.Failure, "SQL query for this command is broken at the moment", true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await ctx.SendAutosplitMessageAsync(new StringBuilder("Warning count per user:").Append(table)).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("by"), RequiresBotModRole]
|
[Command("by"), RequiresBotModRole]
|
||||||
|
Loading…
Reference in New Issue
Block a user