-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser.go
47 lines (37 loc) · 1.01 KB
/
user.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
41
42
43
44
45
46
47
package main
import tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
type User struct {
ChatID int64
Host string
Port int
User string
Pass string
Bot *tgbotapi.BotAPI
State State // What interface user is using
}
// int = User.ID
var users = map[int]*User{}
func NewUser(bot *tgbotapi.BotAPI, update tgbotapi.Update) *User {
u := &User{Bot: bot, ChatID: GetChatID(update), Port: 22}
users[GetUserID(update)] = u
return u
}
func (u *User) Println(line string) (tgbotapi.Message, error) {
m := tgbotapi.NewMessage(u.ChatID, line)
m.DisableWebPagePreview = true
return u.Bot.Send(m)
}
func (u *User) Send(msg tgbotapi.MessageConfig) (tgbotapi.Message, error) {
return u.Bot.Send(msg)
}
func (u *User) HideKeyboard(text string) (tgbotapi.Message, error) {
m := tgbotapi.NewMessage(u.ChatID, text)
m.ReplyMarkup = tgbotapi.NewHideKeyboard(true)
return u.Send(m)
}
func (u *User) IsReady() bool {
if u.Host != "" && u.Port != 0 && u.User != "" && u.Pass != "" {
return true
}
return false
}