mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
Fix leaderboard command
This commit is contained in:
parent
8fca14e398
commit
d2e8ed4d69
@ -14,11 +14,17 @@ namespace JetKarmaBot.Commands
|
|||||||
|
|
||||||
public async Task<bool> Execute(RequestContext ctx)
|
public async Task<bool> Execute(RequestContext ctx)
|
||||||
{
|
{
|
||||||
var db = ctx.GetFeature<KarmaContext>();
|
bool isPrivate = ctx.EventArgs.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private;
|
||||||
var currentLocale = ctx.GetFeature<Locale>();
|
var currentLocale = ctx.GetFeature<Locale>();
|
||||||
|
if (isPrivate)
|
||||||
|
{
|
||||||
|
await ctx.SendMessage(currentLocale["jetkarmabot.award.errawardself"]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var db = ctx.GetFeature<KarmaContext>();
|
||||||
var asker = ctx.EventArgs.Message.From;
|
var asker = ctx.EventArgs.Message.From;
|
||||||
var awardTypeName = ctx.Command.Parameters.FirstOrDefault();
|
var awardTypeName = ctx.Command.Parameters.FirstOrDefault();
|
||||||
bool isPrivate = ctx.EventArgs.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private;
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(awardTypeName))
|
if (string.IsNullOrWhiteSpace(awardTypeName))
|
||||||
awardTypeName = "star";
|
awardTypeName = "star";
|
||||||
@ -29,16 +35,20 @@ namespace JetKarmaBot.Commands
|
|||||||
var awardTypeId = await awardTypeIdQuery.FirstAsync();
|
var awardTypeId = await awardTypeIdQuery.FirstAsync();
|
||||||
var awardType = await db.AwardTypes.FindAsync(awardTypeId);
|
var awardType = await db.AwardTypes.FindAsync(awardTypeId);
|
||||||
|
|
||||||
await ctx.SendMessage(string.Format(currentLocale["jetkarmabot.leaderboard.specifictext"], awardType.Symbol) + "\n" + string.Join('\n',
|
var topEarners = await db.Awards
|
||||||
await Task.WhenAll((await db.Awards
|
.Where(x => x.ChatId == ctx.EventArgs.Message.Chat.Id && x.AwardTypeId == awardTypeId)
|
||||||
.Where(x => (x.ChatId == ctx.EventArgs.Message.Chat.Id || isPrivate) && x.AwardTypeId == awardTypeId)
|
.GroupBy(x => x.To)
|
||||||
.GroupBy(x => x.ToId)
|
.Select(x => new { User = x.Key, Amount = x.Sum(y => y.Amount) })
|
||||||
.Select(x => new { UserId = x.Key, Amount = x.Sum(y => y.Amount) })
|
|
||||||
.OrderByDescending(x => x.Amount)
|
.OrderByDescending(x => x.Amount)
|
||||||
.Take(5)
|
.Take(5)
|
||||||
.ToListAsync())
|
.ToListAsync();
|
||||||
.Select(async (x, index) => $"{index + 1}. {(await db.Users.FindAsync(x.UserId)).Username} - {x.Amount}"))
|
|
||||||
));
|
var response = string.Format(currentLocale["jetkarmabot.leaderboard.specifictext"], awardType.Symbol) + "\n"
|
||||||
|
+ string.Join('\n', topEarners.Select((x, index)
|
||||||
|
=> $"{index + 1}. {x.User.Username} - {x.Amount}")
|
||||||
|
);
|
||||||
|
|
||||||
|
await ctx.SendMessage(response);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user