Init
This commit is contained in:
parent
264c97183e
commit
3faede7b1c
74 changed files with 6228 additions and 1 deletions
65
bot/handlers/url.go
Normal file
65
bot/handlers/url.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"govd/bot/core"
|
||||
"govd/database"
|
||||
extractors "govd/ext"
|
||||
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters/message"
|
||||
)
|
||||
|
||||
func URLHandler(bot *gotgbot.Bot, ctx *ext.Context) error {
|
||||
messageURL := getMessageURL(ctx.EffectiveMessage)
|
||||
if messageURL == "" {
|
||||
return nil
|
||||
}
|
||||
dlCtx, err := extractors.CtxByURL(messageURL)
|
||||
if err != nil {
|
||||
core.HandleErrorMessage(
|
||||
bot, ctx, err)
|
||||
return nil
|
||||
}
|
||||
if dlCtx == nil || dlCtx.Extractor == nil {
|
||||
return nil
|
||||
}
|
||||
userID := ctx.EffectiveMessage.From.Id
|
||||
if ctx.EffectiveMessage.Chat.Type != "private" {
|
||||
settings, err := database.GetGroupSettings(ctx.EffectiveMessage.Chat.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dlCtx.GroupSettings = settings
|
||||
}
|
||||
if userID != 1087968824 {
|
||||
// groupAnonymousBot
|
||||
_, err = database.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = core.HandleDownloadRequest(bot, ctx, dlCtx)
|
||||
if err != nil {
|
||||
core.HandleErrorMessage(
|
||||
bot, ctx, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func URLFilter(msg *gotgbot.Message) bool {
|
||||
return message.Text(msg) && !message.Command(msg) && containsURL(msg)
|
||||
}
|
||||
|
||||
func containsURL(msg *gotgbot.Message) bool {
|
||||
return message.Entity("url")(msg)
|
||||
}
|
||||
|
||||
func getMessageURL(msg *gotgbot.Message) string {
|
||||
for _, entity := range msg.Entities {
|
||||
if entity.Type == "url" {
|
||||
return msg.Text[entity.Offset : entity.Offset+entity.Length]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue