Skip to content

Commit

Permalink
Merge pull request #9 from pkdindustries/alexschlessinger/issue8
Browse files Browse the repository at this point in the history
toggle for addressing mode #8
  • Loading branch information
alexschlessinger authored Apr 11, 2023
2 parents 1042191 + f6ba6d2 commit 86ec63a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
root.PersistentFlags().BoolP("list", "l", false, "list configured personalities")
root.PersistentFlags().StringP("directory", "d", "./personalities", "personalities configuration directory")
root.PersistentFlags().BoolP("verbose", "v", false, "enable verbose logging of sessions and configuration")

root.PersistentFlags().BoolP("addressed", "a", true, "require bot be addressed by nick for response")
vip.BindPFlags(root.PersistentFlags())

vip.SetEnvPrefix("SOULSHACK")
Expand Down
14 changes: 12 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
Server string
Port int
SSL bool
Addressed bool
}

type ChatContext struct {
Expand All @@ -33,8 +34,8 @@ type ChatContext struct {
Config *Config
Client *girc.Client
Event *girc.Event
Args []string
Session *ChatSession
Args []string
}

func PersonalityFromViper(v *vip.Viper) *Personality {
Expand All @@ -57,6 +58,7 @@ func IrcFromViper(v *vip.Viper) *Config {
Server: v.GetString("server"),
Port: v.GetInt("port"),
SSL: v.GetBool("ssl"),
Addressed: v.GetBool("addressed"),
}
}

Expand Down Expand Up @@ -89,7 +91,15 @@ func (c *ChatContext) Reply(message string) *ChatContext {
}

func (c *ChatContext) Valid() bool {
return (c.IsAddressed() || c.IsPrivate()) && len(c.Args) > 0
// check if the message is addressed to the bot or if being addressed is not required
addressed := c.IsAddressed() || !c.Config.Addressed
hasArguments := len(c.Args) > 0

// valid if:
// - the message is either addressed to the bot or being addressed is not required
// - or the message is private
// - and at least one argument
return (addressed || c.IsPrivate()) && hasArguments
}

func (c *ChatContext) IsPrivate() bool {
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func sendMessage(ctx *ChatContext, message string) {
ctx.Reply(message)
}

var configParams = map[string]string{"prompt": "", "model": "", "nick": "", "greeting": "", "goodbye": "", "directory": "", "session": ""}
var configParams = map[string]string{"prompt": "", "model": "", "nick": "", "greeting": "", "goodbye": "", "directory": "", "session": "", "addressed": ""}

func handleSet(ctx *ChatContext) {

Expand Down

0 comments on commit 86ec63a

Please sign in to comment.