-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from CSUSTers/dev
command /mc back again
- Loading branch information
Showing
16 changed files
with
177 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,43 @@ | ||
package base | ||
|
||
import ( | ||
"csust-got/config" | ||
"csust-got/log" | ||
"csust-got/prom" | ||
"csust-got/util" | ||
|
||
"fmt" | ||
"go.uber.org/zap" | ||
. "gopkg.in/tucnak/telebot.v2" | ||
) | ||
|
||
// MC we not use message count anymore | ||
func MC(m *Message) { | ||
util.SendReply(m.Chat, "再mc自杀", m) | ||
if !config.BotConfig.PromConfig.Enabled { | ||
util.SendReply(m.Chat, "再mc自杀", m) | ||
return | ||
} | ||
msgR := util.SendMessage(m.Chat, "稍等。。。") | ||
data, err := prom.QueryMessageCount(m.Chat.Title) | ||
if err != nil { | ||
log.Error("MC error", zap.Error(err)) | ||
util.EditMessage(msgR, "再mc自杀!!!") | ||
return | ||
} | ||
if len(data) == 0 { | ||
util.EditMessage(msgR, "再mc自杀!") | ||
return | ||
} | ||
text := "本群大水怪名单(数据有半分钟延迟):\n" | ||
// rankCN := []string{"零", "一", "二", "三", "四", "wu", "六", "七", "八", "九", "十"} | ||
text += fmt.Sprintf("第一名:'%v'!他的一生,是龙王的一生,他把有限的生命贡献在了无限的发送 message 上,24h内数量高达 %v 条!群友因为他感受到这个群还有活人,我们把最热烈 fake_ban 送给他,让他在新的一天里享受快乐的退休时光吧!\n", | ||
data[0].Name, data[0].Value) | ||
if len(data) > 1 { | ||
text += fmt.Sprintf("第二名:'%v'!他用上洪荒之力,在24h内水了 %v 条消息,这个数字证明了它他的决心,虽然没能夺冠,让我们仍旧把掌声送给他!\n", | ||
data[1].Name, data[1].Value) | ||
} | ||
if len(data) > 2 { | ||
text += fmt.Sprintf("第三名:'%v'!这位朋友很努力,在24h内水了 %v 条消息!很棒,再接再厉!\n", | ||
data[2].Name, data[2].Value) | ||
} | ||
util.EditMessage(msgR, text) | ||
} | ||
|
||
// message type | ||
// const ( | ||
// MESSAGE = "message" | ||
// STICKER = "sticker" | ||
// TOTAL = "total" | ||
// ) | ||
|
||
// MC is handler for command `mc`. | ||
// func MC() module.Module { | ||
// handler := func(ctx context.Context, update tgbotapi.Update, bot *tgbotapi.BotAPI) { | ||
// text := "啊等等,刚才数到多少来着,完了,忘记了QAQ..." | ||
// defer func() { | ||
// msg := tgbotapi.NewMessage(update.Message.Chat.ID, text) | ||
// util.SendMessage(bot, msg) | ||
// }() | ||
// resSticker, err := ctx.GlobalClient().ZRevRangeWithScores(ctx.WrapKey(STICKER), 0, 3).Result() | ||
// if err != nil { | ||
// log.Error("Get Sticker count in redis ZRevRangeWithScores failed", zap.Error(err)) | ||
// return | ||
// } | ||
// err = ctx.GlobalClient().ZUnionStore(ctx.WrapKey(TOTAL), &redis.ZStore{ | ||
// Keys: []string{ctx.WrapKey(STICKER), ctx.WrapKey(MESSAGE)}, | ||
// Weights: nil, | ||
// Aggregate: "", | ||
// }).Err() | ||
// if err != nil { | ||
// log.Error("Redis ZUnionStore failed", zap.Error(err)) | ||
// return | ||
// } | ||
// resTotal, err := ctx.GlobalClient().ZRevRangeWithScores(ctx.WrapKey(TOTAL), 0, 3).Result() | ||
// if err != nil { | ||
// log.Error("Get total message count in redis ZRevRangeWithScores failed", zap.Error(err)) | ||
// return | ||
// } | ||
// text = wrapText(bot, update.Message.Chat.ID, resSticker, resTotal) | ||
// } | ||
// return module.Stateful(handler) | ||
// } | ||
|
||
// MessageCount is used to count message. | ||
// func MessageCount() module.Module { | ||
// handler := func(ctx context.Context, update tgbotapi.Update, bot *tgbotapi.BotAPI) { | ||
// message := update.Message | ||
// // We won't count commands | ||
// if message.IsCommand() { | ||
// return | ||
// } | ||
// userID := message.From.ID | ||
// ctx.GlobalClient().ZIncr(ctx.WrapKey(getMessageType(message)), IncrKey(userID)) | ||
// } | ||
// return module.Stateful(handler) | ||
// } | ||
|
||
// func wrapText(bot *tgbotapi.BotAPI, chatID int64, resSticker, resTotal []redis.Z) string { | ||
// if len(resTotal) == 0 { | ||
// return "从我记事起。。。。没人嗦过话呢" | ||
// } | ||
// text := "本群大水怪名单:\n" | ||
// userID, _ := strconv.Atoi(resTotal[0].Member.(string)) | ||
// user := util.GetChatMember(bot, chatID, userID).User | ||
// text += fmt.Sprintf("第一名:'%v'!他的一生,是龙王的一生,他把有限的生命贡献在了无限的发送 message 上,累计数量高达 %v 条!群友因为他感受到这个群还有活人,我们把最热烈 fake_ban 送给他,让他在新的一天里享受快乐的退休时光吧!\n", | ||
// user.FirstName+user.LastName, int(resTotal[0].Score)) | ||
// if len(resTotal) > 1 { | ||
// userID, _ := strconv.Atoi(resTotal[1].Member.(string)) | ||
// user := util.GetChatMember(bot, chatID, userID).User | ||
// text += fmt.Sprintf("第二名:'%v'!他用上洪荒之力,水了 %v 条消息,这个数字证明了它他的决心,虽然没能夺冠,让我们仍旧把掌声送给他!\n", | ||
// user.FirstName+user.LastName, int(resTotal[1].Score)) | ||
// } | ||
// if len(resTotal) > 2 { | ||
// userID, _ := strconv.Atoi(resTotal[2].Member.(string)) | ||
// user := util.GetChatMember(bot, chatID, userID).User | ||
// text += fmt.Sprintf("第三名:'%v'!这位朋友很努力,累计水了 %v 条消息!很棒,再接再厉!\n", | ||
// user.FirstName+user.LastName, int(resTotal[2].Score)) | ||
// } | ||
// return text | ||
// } | ||
|
||
// // We count Stickers and other Messages separately. | ||
// func getMessageType(message *tgbotapi.Message) string { | ||
// if message.Sticker != nil { | ||
// return STICKER | ||
// } | ||
// return MESSAGE | ||
// } | ||
// | ||
// // IncrKey return a ZSET config to increase message count | ||
// func IncrKey(userID int) *redis.Z { | ||
// return &redis.Z{ | ||
// Score: 1, | ||
// Member: strconv.Itoa(userID), | ||
// } | ||
// } | ||
// | ||
// // DecrKey return a ZSET config to decrease message count | ||
// func DecrKey(userID int) *redis.Z { | ||
// return &redis.Z{ | ||
// Score: -1, | ||
// Member: strconv.Itoa(userID), | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type promConfig struct { | ||
Enabled bool | ||
Address string | ||
MessageQuery string | ||
} | ||
|
||
func (c *promConfig) readConfig() { | ||
c.Enabled = viper.GetBool("prometheus.enabled") | ||
c.Address = viper.GetString("prometheus.address") | ||
c.MessageQuery = viper.GetString("prometheus.message_query") | ||
} | ||
|
||
func (c *promConfig) checkConfig() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.