Skip to content

Commit

Permalink
💄 Add emoji in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Aug 22, 2021
1 parent 1000761 commit 42a6383
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 36 deletions.
10 changes: 3 additions & 7 deletions bots/bots.go
Expand Up @@ -31,13 +31,10 @@ const (
func BotStart() {
var err error
fmt.Printf("%s\n", logo)
// read config

config.InitConfig()
// Init Logger
logger.InitLogger()
// InitDB
model.InitDB()
// Init Task
InitTask()

Poller := &tb.LongPoller{Timeout: 15 * time.Second}
Expand All @@ -54,9 +51,8 @@ func BotStart() {
Token: config.BotToken,
Poller: spamPoller,
}
// set socks5

if config.Socks5 != "" {
fmt.Println("Proxy: " + config.Socks5)
dialer, err := proxy.SOCKS5("tcp", config.Socks5, nil, proxy.Direct)
if err != nil {
zap.S().Errorw("failed to get dialer",
Expand All @@ -68,7 +64,7 @@ func BotStart() {

botSetting.Client = httpClient
}
// create bot

bot, err = tb.NewBot(botSetting)
if err != nil {
zap.S().Errorw("failed to create bot", "error", err)
Expand Down
7 changes: 3 additions & 4 deletions bots/control.go
Expand Up @@ -22,7 +22,7 @@ func BindUser(m *tb.Message, ClientId, ClientSecret string) error {
if err := cli.GetTokenWithCode(code); err != nil {
return err
}
bot.Send(m.Chat, "Token获取成功!")
bot.Send(m.Chat, "🎉 Token获取成功!")

info, err := cli.GetUserInfo()
if err != nil {
Expand All @@ -38,11 +38,10 @@ func BindUser(m *tb.Message, ClientId, ClientSecret string) error {
Other: "",
}

// MS User Is Exist
if MSAppIsExist(u.TgId, u.ClientId) {
return errors.New("该应用已经绑定过了,无需重复绑定")
return errors.New("该应用已经绑定过了,无需重复绑定")
}
// MS information has gotten

bot.Send(m.Chat,
fmt.Sprintf("ms_id(MD5):%s\nuserPrincipalName:%s\ndisplayName:%s",
u.MsId,
Expand Down
40 changes: 20 additions & 20 deletions bots/handle.go
Expand Up @@ -52,14 +52,14 @@ func bMy(m *tb.Message) {
}

bot.Send(m.Chat,
fmt.Sprintf("选择一个账户查看具体信息\n\n绑定数: %d/%d", GetBindNum(m.Chat.ID), config.BindMaxNum),
fmt.Sprintf("选择一个账户查看具体信息\n\n绑定数: %d/%d", GetBindNum(m.Chat.ID), config.BindMaxNum),
&tb.ReplyMarkup{InlineKeyboard: inlineKeys})
}
func bMyInlineBtn(c *tb.Callback) {
var u *model.Client
model.DB.Where("id = ?", c.Data).First(&u)
bot.Send(c.Message.Chat,
fmt.Sprintf("信息\n别名:%s\nms_id: %s\nclient_id: %s\nclient_secret: %s\n最近更新时间: %s",
fmt.Sprintf("信息\n别名:%s\nms_id: %s\nclient_id: %s\nclient_secret: %s\n最近更新时间: %s",
u.Alias,
u.MsId,
u.ClientId,
Expand All @@ -72,12 +72,12 @@ func bMyInlineBtn(c *tb.Callback) {

func bBind1(m *tb.Message) {
bot.Send(m.Chat,
fmt.Sprintf("应用注册: [点击直达](%s)", model.GetMSRegisterAppUrl()),
fmt.Sprintf("👉 应用注册: [点击直达](%s)", model.GetMSRegisterAppUrl()),
tb.ModeMarkdown,
)

bot.Send(m.Chat,
"请回复 `client_id(空格)client_secret`",
"请回复 `client_id(空格)client_secret`",
&tb.SendOptions{ParseMode: tb.ModeMarkdown,
ReplyMarkup: &tb.ReplyMarkup{ForceReply: true}},
)
Expand All @@ -88,18 +88,18 @@ func bBind1(m *tb.Message) {
func bBind2(m *tb.Message) {
tmp := strings.Split(m.Text, " ")
if len(tmp) != 2 {
bot.Send(m.Chat, "错误的格式")
bot.Send(m.Chat, "错误的格式")
return
}
ClientId := tmp[0]
ClientSecret := tmp[1]
bot.Send(m.Chat,
"授权账户: [点击直达]("+model.GetMSAuthUrl(ClientId)+")",
"👉 授权账户: [点击直达]("+model.GetMSAuthUrl(ClientId)+")",
tb.ModeMarkdown,
)

bot.Send(m.Chat,
"请回复`http://localhost/……(空格)别名`(用于管理)",
"请回复`http://localhost/……(空格)别名`(用于管理)",
&tb.SendOptions{ParseMode: tb.ModeMarkdown,
ReplyMarkup: &tb.ReplyMarkup{ForceReply: true},
},
Expand All @@ -126,7 +126,7 @@ func bUnBind(m *tb.Message) {
}

bot.Send(m.Chat,
fmt.Sprintf("选择一个账户将其解绑\n\n当前绑定数: %d/%d", GetBindNum(m.Chat.ID), config.BindMaxNum),
fmt.Sprintf("选择一个账户将其解绑\n\n当前绑定数: %d/%d", GetBindNum(m.Chat.ID), config.BindMaxNum),
&tb.ReplyMarkup{InlineKeyboard: inlineKeys},
)
}
Expand All @@ -136,10 +136,10 @@ func bUnBindInlineBtn(c *tb.Callback) {
"error", result.Error,
"id", c.Data,
)
bot.Send(c.Message.Chat, "解绑失败!")
bot.Send(c.Message.Chat, "解绑失败!")
return
}
bot.Send(c.Message.Chat, "解绑成功!")
bot.Send(c.Message.Chat, "解绑成功!")
bot.Respond(c)
}
func bExport(m *tb.Message) {
Expand All @@ -154,7 +154,7 @@ func bExport(m *tb.Message) {
var data []*model.Client
model.DB.Where("tg_id = ?", m.Chat.ID).Find(&data)
if len(data) == 0 {
bot.Send(m.Chat, "你还没有绑定过账户嗷~")
bot.Send(m.Chat, "你还没有绑定过账户嗷~")
return
}
for _, u := range data {
Expand All @@ -171,14 +171,14 @@ func bExport(m *tb.Message) {
if err != nil {
zap.S().Errorw("failed to marshal json",
"error", err)
bot.Send(m.Chat, fmt.Sprintf("获取JSON失败!\n\nERROR: %s", err.Error()))
bot.Send(m.Chat, fmt.Sprintf("获取JSON失败!\n\nERROR: %s", err.Error()))
return
}
fileName := fmt.Sprintf("./%d_export_tmp.json", m.Chat.ID)
if err = ioutil.WriteFile(fileName, export, 0644); err != nil {
zap.S().Errorw("failed to write file",
"error", err)
bot.Send(m.Chat, "写入临时文件失败~\n"+err.Error())
bot.Send(m.Chat, "写入临时文件失败~\n"+err.Error())
return
}
exportFile := &tb.Document{
Expand All @@ -202,33 +202,33 @@ func bOnText(m *tb.Message) {
switch UserStatus[m.Chat.ID] {
case USNone:
{
bot.Send(m.Chat, "发送 /help 获取帮助嗷")
bot.Send(m.Chat, "发送 /help 获取帮助嗷")
return
}
case USBind1:
{
if !m.IsReply() {
bot.Send(m.Chat, "请通过回复方式绑定")
bot.Send(m.Chat, "请通过回复方式绑定")
return
}
bBind2(m)
}
case USBind2:
{
if !m.IsReply() {
bot.Send(m.Chat, "请通过回复方式绑定")
bot.Send(m.Chat, "请通过回复方式绑定")
return
}
if GetBindNum(m.Chat.ID) == config.BindMaxNum {
bot.Send(m.Chat, "已经达到最大可绑定数")
bot.Send(m.Chat, "已经达到最大可绑定数")
return
}
bot.Send(m.Chat, "正在绑定中……")
err := BindUser(m, UserClientId[m.Chat.ID], UserClientSecret[m.Chat.ID])
if err != nil {
bot.Send(m.Chat, err.Error())
} else {
bot.Send(m.Chat, "绑定成功!")
bot.Send(m.Chat, "绑定成功!")
}
UserStatus[m.Chat.ID] = USNone
}
Expand All @@ -241,7 +241,7 @@ func bTask(m *tb.Message) {
return
}
}
bot.Send(m.Chat, "只有Bot管理员才有权限执行此操作")
bot.Send(m.Chat, "只有Bot管理员才有权限执行此操作")
}
func bLog(m *tb.Message) {
flag := 0
Expand All @@ -251,7 +251,7 @@ func bLog(m *tb.Message) {
}
}
if flag == 0 {
bot.Send(m.Chat, "只有Bot管理员才有权限执行此操作")
bot.Send(m.Chat, "只有Bot管理员才有权限执行此操作")
return
}
file := config.LogBasePath + "latest.log"
Expand Down
3 changes: 0 additions & 3 deletions bots/sender.go
Expand Up @@ -19,8 +19,6 @@ type Msg struct {
Options []interface{}
}

// 牺牲错误处理和解耦,加快发送速度

func NewSender() *Sender {
return &Sender{}
}
Expand All @@ -36,7 +34,6 @@ func (s *Sender) Init(goroutine int) {
}
}

// Stop until all messages were sent
func (s *Sender) Stop() {
s.wg.Wait()
close(s.done)
Expand Down
2 changes: 0 additions & 2 deletions bots/task.go
Expand Up @@ -57,8 +57,6 @@ func SignTask() {
model.DB.Save(&errClient.Client)
}

// fmt.Println(signErr)
// fmt.Println(errorTimes)
timeSpending := time.Since(start).Seconds()
summarySignTaskForUsers(errClients)
summarySignTaskForAdmins(errClients, timeSpending)
Expand Down

0 comments on commit 42a6383

Please sign in to comment.