feat: add channel cmds
This commit is contained in:
@@ -71,56 +71,55 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
}
|
||||
|
||||
mediaClass, ok := msg.GetMedia()
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch mediaClass.(type) {
|
||||
case *tg.MessageMediaDocument:
|
||||
if docClass, ok := mediaClass.(*tg.MessageMediaDocument).GetDocument(); ok {
|
||||
// logger.Warn("document",
|
||||
// zap.Int64("channel", channel.ID),
|
||||
// zap.Int("msg_id", msg.ID),
|
||||
// zap.String("file_name", docClass.String()),
|
||||
// )
|
||||
if ok {
|
||||
switch mediaClass.(type) {
|
||||
case *tg.MessageMediaDocument:
|
||||
if docClass, ok := mediaClass.(*tg.MessageMediaDocument).GetDocument(); ok && cfg.ExportMedia {
|
||||
// logger.Warn("document",
|
||||
// zap.Int64("channel", channel.ID),
|
||||
// zap.Int("msg_id", msg.ID),
|
||||
// zap.String("file_name", docClass.String()),
|
||||
// )
|
||||
|
||||
doc := docClass.(*tg.Document)
|
||||
doc := docClass.(*tg.Document)
|
||||
|
||||
if doc.GetSize() > int64(t.Config.GetMaxSize()) {
|
||||
logger.Warn(
|
||||
"document size too large",
|
||||
if doc.GetSize() > int64(t.Config.GetMaxSize()) {
|
||||
logger.Warn(
|
||||
"document size too large",
|
||||
zap.Int64("channel", channel.ID),
|
||||
zap.Int64("size", doc.GetSize()),
|
||||
zap.String("SizeHuman", humanize.Bytes(uint64(doc.GetSize()))),
|
||||
zap.String("Limit", t.Config.MaxSize),
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
data, err := t.saveDocument(ctx, cfg, doc)
|
||||
if err != nil {
|
||||
logger.Error("save document failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
channelMessage.WithDocument(doc.GetID(), data)
|
||||
}
|
||||
case *tg.MessageMediaWebPage:
|
||||
if page, ok := mediaClass.(*tg.MessageMediaWebPage).GetWebpage().(*tg.WebPage); ok {
|
||||
channelMessage.WithWebPage(page.GetID(), page.Title, page.URL)
|
||||
} else {
|
||||
logger.Warn("web_page",
|
||||
zap.Int64("channel", channel.ID),
|
||||
zap.Int64("size", doc.GetSize()),
|
||||
zap.String("SizeHuman", humanize.Bytes(uint64(doc.GetSize()))),
|
||||
zap.String("Limit", t.Config.MaxSize),
|
||||
zap.Int64("msg_id", page.GetID()),
|
||||
zap.String("url", mediaClass.(*tg.MessageMediaWebPage).GetWebpage().String()),
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
data, err := t.saveDocument(ctx, cfg, doc)
|
||||
if err != nil {
|
||||
logger.Error("save document failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
case *tg.MessageMediaPhoto:
|
||||
if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok && cfg.ExportMedia {
|
||||
photo := photoClass.(*tg.Photo)
|
||||
if err := t.savePhoto(ctx, cfg, photo); err != nil {
|
||||
logger.Error("save photo failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
channelMessage.WithPhoto(photo.GetID(), "jpg")
|
||||
}
|
||||
channelMessage.WithDocument(doc.GetID(), data)
|
||||
}
|
||||
case *tg.MessageMediaWebPage:
|
||||
if page, ok := mediaClass.(*tg.MessageMediaWebPage).GetWebpage().(*tg.WebPage); ok {
|
||||
channelMessage.WithWebPage(page.GetID(), page.Title, page.URL)
|
||||
} else {
|
||||
logger.Warn("web_page",
|
||||
zap.Int64("channel", channel.ID),
|
||||
zap.Int64("msg_id", page.GetID()),
|
||||
zap.String("url", mediaClass.(*tg.MessageMediaWebPage).GetWebpage().String()),
|
||||
)
|
||||
}
|
||||
case *tg.MessageMediaPhoto:
|
||||
if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok {
|
||||
photo := photoClass.(*tg.Photo)
|
||||
if err := t.savePhoto(ctx, cfg, photo); err != nil {
|
||||
logger.Error("save photo failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
channelMessage.WithPhoto(photo.GetID(), "jpg")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user