Skip to content

Commit

Permalink
Merge pull request #469 from danluki/feat/usedcommands-me
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont authored Dec 12, 2023
2 parents 3aedf01 + 1e0172b commit e708b65
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/parser/internal/commands/stats/user_me.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions apps/parser/internal/variables/user/commands.go
Original file line number Diff line number Diff line change
@@ -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
},
}
1 change: 1 addition & 0 deletions apps/parser/internal/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e708b65

Please sign in to comment.