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