-
Notifications
You must be signed in to change notification settings - Fork 5
/
bots.go
88 lines (78 loc) · 1.89 KB
/
bots.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
package bots
import (
"fmt"
"github.com/andatoshiki/toshiki-e5subot/config"
"github.com/andatoshiki/toshiki-e5subot/db"
"github.com/andatoshiki/toshiki-e5subot/logger"
"go.uber.org/zap"
"golang.org/x/net/proxy"
tb "gopkg.in/tucnak/telebot.v2"
"net/http"
"time"
)
var bot *tb.Bot
const (
logo = `
______ __ _ __ _ ________
/_ __/__ ___ / / (_) /__ (_) / __/ __/
/ / / _ \(_-</ _ \/ / '_// / / _//__ \
/_/ \___/___/_//_/_/_/\_\/_/ /___/____/
@andatoshiki | 安田俊樹 | www.toshiki.top
@chenskiro | chenskiro | www.chenskiro.com
❤ 私はいつもChenskiroを愛します~
`
)
func Start() {
var err error
fmt.Print(logo)
config.Init()
logger.Init()
db.Init()
InitTask()
poller := &tb.LongPoller{Timeout: 15 * time.Second}
midPoller := tb.NewMiddlewarePoller(poller, func(upd *tb.Update) bool {
if upd.Message == nil {
return true
}
if !upd.Message.Private() {
return false
}
return true
})
setting := tb.Settings{
Token: config.BotToken,
Poller: midPoller,
}
if config.Socks5 != "" {
dialer, err := proxy.SOCKS5("tcp", config.Socks5, nil, proxy.Direct)
if err != nil {
zap.S().Fatalw("failed to get dialer",
"error", err, "proxy", config.Socks5)
}
transport := &http.Transport{}
transport.Dial = dialer.Dial
setting.Client = &http.Client{Transport: transport}
}
bot, err = tb.NewBot(setting)
if err != nil {
zap.S().Fatalw("failed to create bot", "error", err)
}
fmt.Printf("Bot: %d %s\n", bot.Me.ID, bot.Me.Username)
makeHandlers()
fmt.Println("Bot Start")
fmt.Println("------------")
bot.Start()
}
func makeHandlers() {
// 所有用户
bot.Handle("/start", bStart)
bot.Handle("/my", bMy)
bot.Handle("/bind", bBind)
bot.Handle("/unbind", bUnBind)
bot.Handle("/export", bExport)
bot.Handle("/help", bHelp)
bot.Handle(tb.OnText, bOnText)
// 管理员
bot.Handle("/task", bTask)
bot.Handle("/log", bLog)
}