-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (72 loc) · 1.93 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
"log"
"os"
"strings"
)
func goDotEnvVariable(key string) string {
// load .env file
errLoad := godotenv.Load(".env")
if errLoad != nil {
log.Fatalf("Error loading .env file")
}
return os.Getenv(key)
}
type Users struct {
Users []User `json:"users"`
}
type User struct {
Email string `json:"email"`
Password string `json:"pass"`
ChatID int64 `json:"chat_id"`
}
type Info struct {
Info InfoVal `json:"info"`
}
type InfoVal struct {
Link string `json:"one_time_login_link"`
}
func main() {
bot, err := tgbotapi.NewBotAPI(goDotEnvVariable("TOKEN_TLG"))
if err != nil {
fmt.Println(err)
}
bot.Debug = true
fmt.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
// Loop through each update.
for update := range updates {
// Check if we've gotten a message update.
if update.Message != nil {
// Construct a new message from the given chat ID and containing
// the text that we received.
//msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "great job")
link := return_link(msg.ChatID) // If the message was open, add a copy of our numeric keyboard.
// weekday := int(time.Now().Weekday())
// if time.Now().UTC().Hour() <= 16 && time.Now().UTC().Hour() >= 6 && weekday != 0 && weekday != 6 {
//fmt.Println(time.Now().UTC().Hour())
switch strings.ToUpper(update.Message.Text) {
case "LOGIN":
msg.Text = link
case "/START":
msg.Text = "enter your password"
default:
msg.Text = "nope"
}
// Send the message.
if _, err = bot.Send(msg); err != nil {
fmt.Println(err)
}
// } else {
// msg.Text = "the link is only available during business hours"
// bot.Send(msg)
// }
}
}
}