Skip to content

Commit

Permalink
refactor(action): deprecate limit_to_rooms, add output_to_rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r committed Jul 21, 2021
1 parent cd72f30 commit 72d2ff7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions core/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,23 @@ func handleMessage(action models.Action, outputMsgs chan<- models.Message, msg *
}

msg.Output = output

// bridge for deprecation of LimitToRooms on action
if len(action.LimitToRooms) > 0 && len(action.OutputToRooms) == 0 {
bot.Log.Warn().Msgf("'limit_to_rooms' on actions is deprecated and will be removed in the next version - update action '%s' to use `output_to_rooms' instead", action.Name)
action.OutputToRooms = action.LimitToRooms[:]
}

// Send to desired room(s)
if direct && len(action.LimitToRooms) > 0 { // direct=true and limit_to_rooms is specified
if direct && len(action.OutputToRooms) > 0 { // direct=true and limit_to_rooms is specified
bot.Log.Debug().Msgf("'direct_message_only' is set - 'limit_to_rooms' field on the '%s' action will be ignored", action.Name)
} else if !direct && len(action.LimitToRooms) > 0 { // direct=false and limit_to_rooms is specified
msg.OutputToRooms = utils.GetRoomIDs(action.LimitToRooms, bot)
} else if !direct && len(action.OutputToRooms) > 0 { // direct=false and limit_to_rooms is specified
msg.OutputToRooms = utils.GetRoomIDs(action.OutputToRooms, bot)

if len(msg.OutputToRooms) == 0 {
return errors.New("the rooms defined in 'limit_to_rooms' do not exist")
}
} else if !direct && len(action.LimitToRooms) == 0 { // direct=false and no limit_to_rooms is specified
} else if !direct && len(action.OutputToRooms) == 0 { // direct=false and no limit_to_rooms is specified
msg.OutputToRooms = []string{msg.ChannelID}
}
// Else: direct=true and no limit_to_rooms is specified
Expand Down
3 changes: 2 additions & 1 deletion models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type Action struct {
Auth []Auth `mapstructure:"auth"`
ExposeJSONFields map[string]string `mapstructure:"expose_json_fields"`
Response string `mapstructure:"response"`
LimitToRooms []string `mapstructure:"limit_to_rooms"`
LimitToRooms []string `mapstructure:"limit_to_rooms"` // deprecated
OutputToRooms []string `mapstructure:"output_to_rooms"`
Message string `mapstructure:"message"`
Reaction string `mapstructure:"update_reaction" binding:"omitempty"`
}
Expand Down

0 comments on commit 72d2ff7

Please sign in to comment.