Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sticker handler #283

Merged
merged 3 commits into from Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/handlers/telegram/handler.go
Expand Up @@ -30,6 +30,17 @@ func messageHandler(tg *Client, u tgbotapi.Update) {
tg.sendToIrc(formatted)
}

/*
stickerHandler handles the Message.Sticker Telegram Object, which formats the
Telegram message into its base Emoji unicode character.
*/
func stickerHandler(tg *Client, u tgbotapi.Update) {
formatted := tg.Settings.Prefix + u.Message.From.UserName +
tg.Settings.Suffix + u.Message.Sticker.Emoji

tg.sendToIrc(formatted)
}

/*
documentHandler receives a document object from Telegram, and sends
a notification to IRC.
Expand Down
20 changes: 11 additions & 9 deletions internal/handlers/telegram/telegram.go
Expand Up @@ -69,16 +69,18 @@ func (tg *Client) StartBot(errChan chan<- error, sendMessage func(string)) {

// TODO: Move these lines into the updateHandler when available
for update := range updates {
if update.Message == nil {
continue
switch {
case update.Message == nil:
continue
case update.Message.Text != "":
messageHandler(tg, update)
case update.Message.Sticker != nil:
stickerHandler(tg, update)
case update.Message.Document != nil:
documentHandler(tg, update.Message)
default:
continue
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and created a switch statement anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!


if update.Message.Document != nil {
documentHandler(tg, update.Message)
} else {
messageHandler(tg, update)
}

}
errChan <- nil
}