-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
136 lines (118 loc) · 3.66 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Package main provides
package main
import (
"fmt"
"os"
"Maghaze_Bot/utils"
"Maghaze_Bot/utils/password"
// "./utils"
// "./utils/password"
// "github.com/pouya-barzegar/Maghaze_Bot/utils"
// "github.com/pouya-barzegar/Maghaze_Bot/utils/password"
"gopkg.in/telegram-bot-api.v4"
)
// this is the main
func main() {
authorizeAdmin := false
IsDocument := false
tgbot := os.Getenv("TGBOT")
dataDir := os.Getenv("TGBOTDATA")
bot, _ := tgbotapi.NewBotAPI(tgbot)
// bot.Debug = true
u := tgbotapi.NewUpdate(0)
u.Timeout = 30
updates, err := bot.GetUpdatesChan(u)
utils.Check(err)
// this is where everything happens main loop
for update := range updates {
if update.Message == nil {
continue
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
// testing the disable option temp
// msg.DisableNotification = true
// what every Button does
switch update.Message.Text {
case "open":
msg.ReplyMarkup = utils.Keyboard_page1
case "close":
msg.ReplyMarkup = tgbotapi.NewHideKeyboard(true)
// msg.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true)
case "بعدی":
msg.ReplyMarkup = utils.Keyboard_page2
case "قبلی":
msg.ReplyMarkup = utils.Keyboard_page1
case "روتر":
msg.Text = utils.Tealeg_Excel2str("router.xlsx", dataDir)
fmt.Println(msg.Text)
case "سویچ":
msg.Text = utils.Tealeg_Excel2str("switch.xlsx", dataDir)
fmt.Println(msg.Text)
case "تماس با ما":
msg.Text = utils.Tealeg_Excel2str("contact.xlsx", dataDir)
fmt.Println(msg.Text)
case "کارت شبکه":
msg.Text = utils.Tealeg_Excel2str("nic.xlsx", dataDir)
fmt.Println(msg.Text)
case "مودم":
msg.Text = utils.Tealeg_Excel2str("modem.xlsx", dataDir)
fmt.Println(msg.Text)
case "دوربین":
msg.Text = utils.Tealeg_Excel2str("camera.xlsx", dataDir)
fmt.Println(msg.Text)
case "اکسس پوینت":
msg.Text = utils.Tealeg_Excel2str("accesspoint.xlsx", dataDir)
fmt.Println(msg.Text)
case "تجهیزات رادیویی":
msg.Text = utils.Tealeg_Excel2str("radio.xlsx", dataDir)
fmt.Println(msg.Text)
case "سیسکو":
msg.Text = utils.Tealeg_Excel2str("cisco.xlsx", dataDir)
fmt.Println(msg.Text)
case "هاب و KVM":
msg.Text = utils.Tealeg_Excel2str("hub&kvm.xlsx", dataDir)
fmt.Println(msg.Text)
default:
if IsDocument {
fmt.Println("Waiting for a doc file")
msgtime := update.Message.Time()
fmt.Println("Getting the url for the message")
url, err := bot.GetFileDirectURL(update.Message.Document.FileID)
if err != nil {
fmt.Println("Didn't get a doc after all")
continue
}
fmt.Println("Got a doc at time:")
msg.Text = "got a doc at : " + msgtime.Format("Mon Jan 2 15:04:05 MST 2006") + "\n" + url
utils.Url2File(url, dataDir+"/"+update.Message.Document.FileName)
IsDocument = false
}
}
if update.Message.IsCommand() {
switch update.Message.Command() {
case "start":
msg.Text = "به شبکه برتر خوش آمدید!"
fmt.Println("data directory: " + dataDir)
msg.ReplyMarkup = utils.Keyboard_page1
case "login":
tgpass := update.Message.CommandArguments()
fmt.Printf("password entered: = %+v\n", tgpass)
authorizeAdmin = password.Pass_checker(&msg.Text, tgpass)
case "senddoc":
if authorizeAdmin && !IsDocument {
msg.Text = "You can Now send the doc"
fmt.Println("Senddoc command entered")
IsDocument = true
} else {
msg.Text = "You should first try to /login ."
}
case "logout":
authorizeAdmin = false
msg.Text = "you logged out\n switch to normal user"
case "help":
msg.Text = utils.HelpMessage
}
}
bot.Send(msg)
}
}