mirror of
https://github.com/woodchen-ink/Q58Bot.git
synced 2025-07-18 13:52:07 +08:00
fix bugs
This commit is contained in:
parent
d0af4542f7
commit
800a60c659
@ -7,7 +7,7 @@ import (
|
|||||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterCommands(bot *tgbotapi.BotAPI, adminID int64) error {
|
func RegisterCommands(bot *tgbotapi.BotAPI) error {
|
||||||
commands := []tgbotapi.BotCommand{
|
commands := []tgbotapi.BotCommand{
|
||||||
{Command: "add", Description: "添加新的关键词"},
|
{Command: "add", Description: "添加新的关键词"},
|
||||||
{Command: "delete", Description: "删除现有的关键词"},
|
{Command: "delete", Description: "删除现有的关键词"},
|
||||||
@ -18,10 +18,11 @@ func RegisterCommands(bot *tgbotapi.BotAPI, adminID int64) error {
|
|||||||
{Command: "listwhite", Description: "列出白名单域名"},
|
{Command: "listwhite", Description: "列出白名单域名"},
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := tgbotapi.NewBotCommandScopeChatAdministrators(adminID)
|
|
||||||
|
|
||||||
config := tgbotapi.NewSetMyCommands(commands...)
|
config := tgbotapi.NewSetMyCommands(commands...)
|
||||||
config.Scope = &scope // 注意这里使用 &scope 来获取指针
|
|
||||||
|
// 不设置 Scope,这将使命令对所有用户可见
|
||||||
|
// config.Scope = nil
|
||||||
|
|
||||||
config.LanguageCode = "" // 空字符串表示默认语言
|
config.LanguageCode = "" // 空字符串表示默认语言
|
||||||
|
|
||||||
_, err := bot.Request(config)
|
_, err := bot.Request(config)
|
||||||
|
@ -26,7 +26,12 @@ func init() {
|
|||||||
var err error
|
var err error
|
||||||
botToken = os.Getenv("BOT_TOKEN")
|
botToken = os.Getenv("BOT_TOKEN")
|
||||||
chatID = mustParseInt64(os.Getenv("CHAT_ID"))
|
chatID = mustParseInt64(os.Getenv("CHAT_ID"))
|
||||||
symbols = strings.Split(os.Getenv("SYMBOLS"), ",")
|
|
||||||
|
symbolsRaw := strings.Split(os.Getenv("SYMBOLS"), ",")
|
||||||
|
symbols = make([]string, len(symbolsRaw))
|
||||||
|
for i, s := range symbolsRaw {
|
||||||
|
symbols[i] = strings.ReplaceAll(s, "/", "")
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化 singaporeTZ
|
// 初始化 singaporeTZ
|
||||||
singaporeTZ = time.FixedZone("Asia/Singapore", 8*60*60) // UTC+8
|
singaporeTZ = time.FixedZone("Asia/Singapore", 8*60*60) // UTC+8
|
||||||
|
@ -106,7 +106,25 @@ func messageHandler(bot *tgbotapi.BotAPI, update tgbotapi.Update, linkFilter *co
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if update.Message.Chat.Type != "private" || update.Message.From.ID != adminID {
|
// 检查是否是管理员发送的私聊消息
|
||||||
|
if update.Message.Chat.Type == "private" && update.Message.From.ID == adminID {
|
||||||
|
command := update.Message.Command()
|
||||||
|
args := update.Message.CommandArguments()
|
||||||
|
|
||||||
|
switch command {
|
||||||
|
case "add", "delete", "list", "deletecontaining":
|
||||||
|
linkFilter.HandleKeywordCommand(bot, update.Message, command, args)
|
||||||
|
case "addwhite", "delwhite", "listwhite":
|
||||||
|
linkFilter.HandleWhitelistCommand(bot, update.Message, command, args)
|
||||||
|
default:
|
||||||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "未知命令")
|
||||||
|
bot.Send(msg)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理非管理员消息或群组消息
|
||||||
|
if update.Message.Chat.Type != "private" {
|
||||||
if rateLimiter.Allow() {
|
if rateLimiter.Allow() {
|
||||||
processMessage(bot, update.Message, linkFilter)
|
processMessage(bot, update.Message, linkFilter)
|
||||||
}
|
}
|
||||||
@ -145,7 +163,7 @@ func StartBot() error {
|
|||||||
|
|
||||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||||
|
|
||||||
err = core.RegisterCommands(bot, 0)
|
err = core.RegisterCommands(bot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error registering commands: %w", err)
|
return fmt.Errorf("error registering commands: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user