Repository navigation
Description
Describe the bug
Running any custom command (Twitch !foo, Discord /foo) panics and takes the bot process down. Nothing in the handlers recovers panics, and neither go-twitch-irc nor discordgo does either.
The gRPC → model conversion never copies created_at, so BotCommand.CreatedAt is always nil on the bot side:
monorepo/apps/twitch-bot/internal/service/service.go
Lines 153 to 168 in 35a83bd
| func (s *service) GetUserBotCommand(ctx context.Context, commandName string, twitchChannelId string) (*model.BotCommand, error) { | |
| cmd, err := s.botCommandClient.GetUserBotCommand(ctx, platform.TWITCH.String(), commandName, twitchChannelId) | |
| if err != nil { | |
| return nil, err | |
| } | |
| if cmd == nil { | |
| return nil, nil | |
| } | |
| return &model.BotCommand{ | |
| ID: int(cmd.Id), | |
| CommandName: cmd.CommandName, | |
| CommandContent: cmd.CommandContent, | |
| CommandType: int(cmd.CommandType), | |
| Status: int(cmd.Status), | |
| }, nil | |
| } |
(same in
monorepo/apps/discord-bot/internal/service/service.go
Lines 92 to 107 in 35a83bd
| func (s *service) GetUserBotCommand(ctx context.Context, commandName string, discordServerId string) (*model.BotCommand, error) { | |
| cmd, err := s.botCommandClient.GetUserBotCommand(ctx, platform.DISCORD.String(), commandName, discordServerId) | |
| if err != nil { | |
| return nil, err | |
| } | |
| if cmd == nil { | |
| return nil, nil | |
| } | |
| return &model.BotCommand{ | |
| ID: int(cmd.Id), | |
| CommandName: cmd.CommandName, | |
| CommandContent: cmd.CommandContent, | |
| CommandType: int(cmd.CommandType), | |
| Status: int(cmd.Status), | |
| }, nil | |
| } |
FormatCommandContent then formats that date for every command, even when the content has no {cmd.date}:
Lines 59 to 64 in 35a83bd
| "{cmd.date}": cv.CommandCreatedAt.Format(dateTemplate), | |
| "{channel.name}": cv.ChannelName, | |
| // we will keep these old string templates used in commands for a while for backward compatibility. | |
| "{user_name}": username, | |
| "{cmd_date}": cv.CommandCreatedAt.Format(dateTemplate), |
To Reproduce
- Add a custom command with
!acmd hello world. - Run
!hello. panic: runtime error: invalid memory address or nil pointer dereferenceinhelper.FormatCommandContent.
Reproduced with a real gRPC server and client over a fake DB row that has a created_at: after the round trip CreatedAt is <nil> and FormatCommandContent panics.
Expected behavior
The command replies with its content.
Suggested fix
Parse cmd.CreatedAt (RFC3339) in both converters, and only format CommandCreatedAt in helpers.go when it isn't nil.
Activity