-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (84 loc) · 2.35 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
package main
import (
"database/sql"
"encoding/json"
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"net/http"
"os"
"time"
//tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
_ "github.com/mattn/go-sqlite3"
"liis_sklad_bot/entity"
"liis_sklad_bot/helpers"
)
func main() {
//СОЗДАНИЕ БД
os.Create("./Stocks_Users.db")
database, _ := sql.Open("sqlite3", "./Stocks_Users.db")
statement, err := database.Prepare("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, is_banned BOOLEAN)")
if err != nil {
fmt.Println(err)
}
statement.Exec()
if err != nil {
fmt.Println(err)
}
var BotSets entity.BotSettings
//ИЗВЛЕКАЕМ ИЗ ФАЙЛА С НАСТРОЙКАМИ ПОЛЯ
bs, err := helpers.GetSettings("settings.json")
if err != nil {
fmt.Println("open file error: " + err.Error())
return
}
if err := json.Unmarshal(bs, &BotSets); err != nil {
fmt.Println("setts")
fmt.Println(err)
return
}
bot, err := tgbotapi.NewBotAPI(BotSets.Bot_token)
if err != nil {
log.Panic(err)
}
Stocks := []entity.Stock{}
// ОБНОВЛЕНИЕ АССОРТИМЕНТА
go func() {
for {
resp, _ := http.Get(fmt.Sprintf("https://tools.aimylogic.com/api/googlesheet2json?sheet=%v&id=%v", BotSets.Google_sheet_stock_list, BotSets.Google_sheet_stock_url))
Stocks = []entity.Stock{}
err = json.NewDecoder(resp.Body).Decode(&Stocks)
if err != nil {
fmt.Println(resp.Body)
fmt.Println(err, " body, err")
}
resp.Body.Close()
for i, position := range Stocks {
if position.Quantity == "" || position.Quantity == " " {
Stocks[i].Quantity = "?"
}
if position.Number == "" || position.Number == " " {
Stocks[i].Number = "?"
}
if position.Units == "" || position.Units == " " {
Stocks[i].Units = "?"
}
}
time.Sleep(2 * time.Hour) //hour
}
}()
//НАСТРОЙКА СЛУШАТЕЛЯ
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
//ВЫПОЛНЕНИЕ КОМАНД ПОЛЬЗОВАТЕЛЯ
for update := range updates {
if update.Message != nil { // If we got a message
helpers.ExecuteUserCommand(update, database, BotSets, bot, Stocks)
} // else {
// if update.CallbackQuery != nil {
// helpers.ExecuteCallbackCommand(update, database, BotSets, bot, statement)
// }
//}
}
}