-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
40 lines (33 loc) · 1.24 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"github.com/yanzay/tbot/v2"
)
// Handle the /start command here
func (a *application) startHandler(m *tbot.Message) {
msg := "This is a bot whose sole purpose is to play rock, paper, scissors with you.\nCommands:\n1. Use /play to play.\n2. Use /score to view current scores.\n3. Use /reset to reset scores."
a.client.SendMessage(m.Chat.ID, msg)
}
// Handle the /play command here
func (a *application) playHandler(m *tbot.Message) {
buttons := makeButtons()
a.client.SendMessage(m.Chat.ID, "Pick an option:", tbot.OptInlineKeyboardMarkup(buttons))
}
// Handle the /score command here
func (a *application) scoreHandler(m *tbot.Message) {
msg := fmt.Sprintf("Scores:\nWins: %v\nDraws: %v\nLosses: %v", a.wins, a.draws, a.losses)
a.client.SendMessage(m.Chat.ID, msg)
}
// Handle the /reset command here
func (a *application) resetHandler(m *tbot.Message) {
a.wins, a.draws, a.losses = 0, 0, 0
msg := "Scores have been reset to 0."
a.client.SendMessage(m.Chat.ID, msg)
}
// Handle buttton presses here
func (a *application) callbackHandler(cq *tbot.CallbackQuery) {
humanMove := cq.Data
msg := a.draw(humanMove)
a.client.DeleteMessage(cq.Message.Chat.ID, cq.Message.MessageID)
a.client.SendMessage(cq.Message.Chat.ID, msg)
}