mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
Fix status command, remove parameter in status command
This commit is contained in:
parent
b666b43000
commit
67f05b6f3d
@ -10,55 +10,36 @@ namespace JetKarmaBot.Commands
|
||||
{
|
||||
class StatusCommand : IChatCommand
|
||||
{
|
||||
public IReadOnlyCollection<string> Names => new[] { "status" };
|
||||
public IReadOnlyCollection<string> Names => ["status"];
|
||||
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
var asker = ctx.EventArgs.Message.From;
|
||||
var awardTypeName = ctx.Command.Parameters.FirstOrDefault();
|
||||
bool isPrivate = ctx.EventArgs.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private;
|
||||
|
||||
string response;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(awardTypeName))
|
||||
{
|
||||
// var awards = db.Awards.Where(x => x.ToId == asker.Id)
|
||||
// .GroupBy(x => x.AwardTypeId)
|
||||
// .Select(x => new { AwardTypeId = x.Key, Amount = x.Sum(y => y.Amount) });
|
||||
if (!db.Awards.Any(x => x.ToId == asker.Id && (x.ChatId == ctx.EventArgs.Message.Chat.Id || isPrivate)))
|
||||
var awards = db.Awards.Where(x => x.ToId == asker.Id);
|
||||
if (!isPrivate)
|
||||
awards = awards.Where(x => x.ChatId == ctx.EventArgs.Message.Chat.Id);
|
||||
|
||||
if (!awards.Any())
|
||||
response = currentLocale["jetkarmabot.status.havenothing"];
|
||||
else
|
||||
{
|
||||
var awardsQuery = from award in db.Awards
|
||||
where award.ToId == asker.Id && (award.ChatId == ctx.EventArgs.Message.Chat.Id || isPrivate)
|
||||
group award by award.AwardTypeId into g
|
||||
join awardType in db.AwardTypes
|
||||
on g.Key equals awardType.AwardTypeId
|
||||
select new { AwardTypeId = g.Key, AwardTypeSymbol = awardType.Symbol, Amount = g.Sum(x => x.Amount) };
|
||||
var awardsByType = await awardsQuery.ToListAsync();
|
||||
response = currentLocale["jetkarmabot.status.listalltext"] + "\n"
|
||||
+ string.Join("\n",
|
||||
awardsByType.Select(a => $" - {a.AwardTypeSymbol} {a.Amount}")
|
||||
);
|
||||
var aq = db.AwardTypes.GroupJoin(
|
||||
awards,
|
||||
at => at.AwardTypeId,
|
||||
aw => aw.AwardTypeId,
|
||||
(at, aws) => new {at.Symbol, Amount = aws.Sum(aw => aw.Amount) });
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var awardTypeIdQuery = from awt in db.AwardTypes
|
||||
where awt.CommandName == awardTypeName
|
||||
select awt.AwardTypeId;
|
||||
var awardTypeId = await awardTypeIdQuery.FirstAsync();
|
||||
var awardType = await db.AwardTypes.FindAsync(awardTypeId);
|
||||
var awardsByType = await aq.ToListAsync();
|
||||
|
||||
response = string.Format(currentLocale["jetkarmabot.status.listspecifictext"],
|
||||
await db.Awards.Where(
|
||||
x => x.AwardTypeId == awardTypeId
|
||||
&& x.ToId == asker.Id
|
||||
&& (x.ChatId == ctx.EventArgs.Message.Chat.Id || isPrivate))
|
||||
.SumAsync(x => x.Amount), awardType.Symbol);
|
||||
response =
|
||||
currentLocale["jetkarmabot.status.listalltext"] + "\n"
|
||||
+ string.Join("\n", awardsByType.Select(a => $" - {a.Symbol} {a.Amount}"));
|
||||
}
|
||||
|
||||
await ctx.SendMessage(response);
|
||||
@ -70,14 +51,6 @@ namespace JetKarmaBot.Commands
|
||||
public string Description => "Shows the amount of awards that you have";
|
||||
public string DescriptionID => "jetkarmabot.status.help";
|
||||
|
||||
public IReadOnlyCollection<ChatCommandArgument> Arguments => new ChatCommandArgument[] {
|
||||
new ChatCommandArgument(){
|
||||
Name="awardtype",
|
||||
Required=false,
|
||||
Type=ChatCommandArgumentType.String,
|
||||
Description="The awardtype to show. If empty shows everything.",
|
||||
DescriptionID= "jetkarmabot.status.awardtypehelp"
|
||||
}
|
||||
};
|
||||
public IReadOnlyCollection<ChatCommandArgument> Arguments => [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
"jetkarmabot.status.listspecifictext": "У вас зараз {0}{1}.",
|
||||
"jetkarmabot.status.havenothing": "У вас пакуль нічога няма.",
|
||||
"jetkarmabot.status.help": "Паказвае справаздачу па ўзнагародах.",
|
||||
"jetkarmabot.status.awardtypehelp": "Тып ўзнагароды, па якой падасца справаздачу. Калі пуста, то падасца зводны справаздачу.",
|
||||
"jetkarmabot.changelocale.justchanged": "Так дакладна.",
|
||||
"jetkarmabot.changelocale.getlocale": "Я зараз кажу па-беларускай.",
|
||||
"jetkarmabot.changelocale.listalltext": "Я ведаю:",
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
"jetkarmabot.status.listspecifictext": "You are at {0}{1} now.",
|
||||
"jetkarmabot.status.havenothing": "You don't have anything yet.",
|
||||
"jetkarmabot.status.help": "Shows the amount of awards that you have",
|
||||
"jetkarmabot.status.awardtypehelp": "The awardtype to show. If empty shows everything.",
|
||||
"jetkarmabot.changelocale.justchanged": "Roger that.",
|
||||
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English.",
|
||||
"jetkarmabot.changelocale.listalltext": "I know:",
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
"jetkarmabot.status.listspecifictext": "У вас сейчас {0}{1}.",
|
||||
"jetkarmabot.status.havenothing": "У вас пока ничего нет.",
|
||||
"jetkarmabot.status.help": "Показывает отчет по наградам.",
|
||||
"jetkarmabot.status.awardtypehelp": "Тип награды, по которой покажется отчет. Если пусто, то покажется сводный отчет.",
|
||||
"jetkarmabot.changelocale.justchanged": "Так точно.",
|
||||
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски.",
|
||||
"jetkarmabot.changelocale.listalltext": "Я знаю:",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user