🚧 Added 'messages' and 'commands' functions for filtering 'Message' updates
Added support of general commands and messages with stickers
This commit is contained in:
parent
d2fcbf8a59
commit
ad8b0853ab
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
"github.com/toby3d/go-telegram" // My Telegram bindings
|
||||
)
|
||||
|
||||
func commands(msg *telegram.Message) error {
|
||||
log.Ln("[commands] Check command message")
|
||||
switch strings.ToLower(msg.Command()) {
|
||||
case "start":
|
||||
log.Ln("[commands] Received a /start command")
|
||||
// TODO: Reply by greetings message and add user to DB
|
||||
return nil
|
||||
case "help":
|
||||
log.Ln("[commands] Received a /help command")
|
||||
// TODO: Reply by help instructions
|
||||
return nil
|
||||
case "addsticker":
|
||||
log.Ln("[commands] Received a /addsticker command")
|
||||
// TODO: Change current state to "addSticker" for adding sticker
|
||||
return nil
|
||||
case "delsticker":
|
||||
log.Ln("[commands] Received a /delsticker command")
|
||||
// TODO: Change current state to "delSticker" for deleting sticker
|
||||
return nil
|
||||
case "cancel":
|
||||
log.Ln("[commands] Received a /cancel command")
|
||||
// TODO: Change current state to default for aborting /addSticker or
|
||||
// /delSticker commands
|
||||
return nil
|
||||
default:
|
||||
return nil // Do nothing because unsupported command
|
||||
}
|
||||
}
|
6
main.go
6
main.go
|
@ -32,9 +32,13 @@ func main() {
|
|||
case update.Message != nil:
|
||||
log.Ln("[main] Get Message update")
|
||||
// TODO: Added support of commands, grab and save sticker in DB
|
||||
err = messages(update.Message)
|
||||
errCheck(err)
|
||||
default:
|
||||
log.Ln("[main] Get unsupported update")
|
||||
continue // Ignore any other updates
|
||||
// Ignore any other updates
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
"github.com/toby3d/go-telegram" // My Telegram bindings
|
||||
)
|
||||
|
||||
// message function check Message update on commands, sended stickers or other
|
||||
// user stuff
|
||||
func messages(msg *telegram.Message) error {
|
||||
if msg.From.ID == bot.Self.ID ||
|
||||
msg.ForwardFrom.ID == bot.Self.ID {
|
||||
log.Ln("[messages] Received a message from myself, ignore this update")
|
||||
return nil
|
||||
}
|
||||
|
||||
if msg.IsCommand() {
|
||||
log.Ln("[message] Received a command message")
|
||||
return commands(msg)
|
||||
}
|
||||
|
||||
if msg.Sticker != nil {
|
||||
// TODO: Upload new or delete exist sticker in pack
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil // Do nothing because unsupported actions
|
||||
}
|
Loading…
Reference in New Issue