Skip to content

Custom commands panic the Twitch and Discord bots (nil CreatedAt after the gRPC move) #717

Open

Description

@emircan-sahin

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:

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

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}:

"{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

  1. Add a custom command with !acmd hello world.
  2. Run !hello.
  3. panic: runtime error: invalid memory address or nil pointer dereference in helper.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions