Skip to content

Commit

Permalink
Support to change message's icon emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhiroki committed Aug 31, 2018
1 parent f695b22 commit 34a436f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func main() {
Name: "username, u",
Usage: "Stream messages as given bot user. Defaults to auth user",
},
cli.StringFlag{
Name: "iconemoji, i",
Usage: "Stream messages as given bot icon emoji. Defaults to auth user's icon",
},
}

app.Action = func(c *cli.Context) {
Expand All @@ -150,6 +154,7 @@ func main() {

noop = c.Bool("noop")
username := c.String("username")
iconEmoji := c.String("iconemoji")
fileName := c.String("filename")
fileType := c.String("filetype")
fileComment := c.String("comment")
Expand All @@ -160,7 +165,7 @@ func main() {
}

InitAPI(token)
slackcat := newSlackcat(username, channel)
slackcat := newSlackcat(username, iconEmoji, channel)

if c.Bool("list") {
fmt.Println("channels:")
Expand Down
7 changes: 6 additions & 1 deletion slackcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type Slackcat struct {
queue *StreamQ
shutdown chan os.Signal
username string
iconEmoji string
channelID string
channelName string
}

func newSlackcat(username, channelname string) *Slackcat {
func newSlackcat(username, iconEmoji, channelname string) *Slackcat {
sc := &Slackcat{
queue: newStreamQ(),
shutdown: make(chan os.Signal, 1),
username: username,
iconEmoji: iconEmoji,
channelName: channelname,
}

Expand Down Expand Up @@ -98,6 +100,9 @@ func (sc *Slackcat) postMsg(msglines []string) {
msgOpts.AsUser = false
msgOpts.Username = sc.username
}
if sc.iconEmoji != "" {
msgOpts.IconEmoji = sc.iconEmoji
}

err := api.ChatPostMessage(sc.channelID, msg, msgOpts)
failOnError(err)
Expand Down

0 comments on commit 34a436f

Please sign in to comment.