diff --git a/apps/parser/internal/commands/stats/user_me.go b/apps/parser/internal/commands/stats/user_me.go index bdc229955..dcd2bdf35 100644 --- a/apps/parser/internal/commands/stats/user_me.go +++ b/apps/parser/internal/commands/stats/user_me.go @@ -27,8 +27,9 @@ var UserMe = &types.DefaultCommand{ result := &types.CommandsHandlerResult{ Result: []string{ fmt.Sprintf( - "$(%s) used emotes · $(%s) watched · $(%s) messages · $(%s) used points · $(%s) songs requested", + "$(%s) used emotes · $(%s) used commands · $(%s) watched · $(%s) messages · $(%s) used points · $(%s) songs requested", user.Emotes.Name, + user.Commands.Name, user.Watched.Name, user.Messages.Name, user.UsedChannelPoints.Name, diff --git a/apps/parser/internal/variables/user/commands.go b/apps/parser/internal/variables/user/commands.go new file mode 100644 index 000000000..4d140c849 --- /dev/null +++ b/apps/parser/internal/variables/user/commands.go @@ -0,0 +1,40 @@ +package user + +import ( + "context" + "fmt" + + "github.com/samber/lo" + "github.com/satont/twir/apps/parser/internal/types" + model "github.com/satont/twir/libs/gomodels" +) + +var Commands = &types.Variable{ + Name: "user.commands", + Description: lo.ToPtr("User used commands count"), + CommandsOnly: true, + Handler: func( + ctx context.Context, parseCtx *types.VariableParseContext, variableData *types.VariableData, + ) (*types.VariableHandlerResult, error) { + result := &types.VariableHandlerResult{} + + var count int64 + err := parseCtx.Services.Gorm. + WithContext(ctx). + Where(`"channelId" = ? AND "userId" = ?`, parseCtx.Channel.ID, parseCtx.Sender.ID). + Model(&model.ChannelsCommandsUsages{}). + Count(&count). + Error + + if err != nil { + parseCtx.Services.Logger.Sugar().Error(err) + + result.Result = "internal error" + return result, nil + } + + result.Result = fmt.Sprint(count) + + return result, nil + }, +} diff --git a/apps/parser/internal/variables/variables.go b/apps/parser/internal/variables/variables.go index 5e18c61ef..5792d02f9 100644 --- a/apps/parser/internal/variables/variables.go +++ b/apps/parser/internal/variables/variables.go @@ -104,6 +104,7 @@ func New(opts *Opts) *Variables { user.SongsRequestedDuration, user.EmotesTop, user.Watched, + user.Commands, last_donate.Amount, last_donate.Currency, last_donate.UserName,