This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (62 loc) Β· 1.7 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
package main
import (
"fmt"
"os"
"runtime"
"time"
log "github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/robfig/cron/v3"
)
var token = os.Getenv("TOKEN")
var b, err = tb.NewBot(tb.Settings{
Token: token,
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
})
func main() {
deferInit()
if err != nil {
log.Panicf("Please check your network or TOKEN! %v", err)
}
log.SetOutput(os.Stdout)
log.SetReportCaller(true)
Formatter := &log.TextFormatter{
EnvironmentOverrideColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
return fmt.Sprintf("[%s()]", f.Function), ""
},
}
log.SetFormatter(Formatter)
// toilet KeepMe.Run -f smblock
banner := fmt.Sprintf(`
β β βββ βββ
ββ βββββββββββββββ ββββ ββββ
βββββ ββ ββββ βββ ββββ β ββ β
β ββββββββ β βββββββ βββββ β
%s-%s at %s by %s
`, hash, branch, compileTime, "BennyThink")
fmt.Printf("\n %c[1;32m%s%c[0m\n\n", 0x1B, banner, 0x1B)
c := cron.New()
switch os.Getenv("dev") {
case "true":
scheduler()
_, _ = c.AddFunc("* * * * *", scheduler)
log.SetLevel(log.DebugLevel)
default:
_, _ = c.AddFunc("*/15 * * * *", scheduler)
}
c.Start()
b.Handle("/add", add)
b.Handle(tb.OnText, onText)
b.Handle(tb.OnCallback, onCallback)
b.Handle("/start", start)
b.Handle("/list", list)
b.Handle("/history", history)
b.Handle("/ping", ping)
b.Handle(tb.OnEdited, edited)
log.Infoln("I'm running...")
b.Start()
}