feat: add cmds
This commit is contained in:
@@ -16,10 +16,10 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChannel) error {
|
||||
func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChannel, onlyAddChannel bool) error {
|
||||
inputPeer := &tg.InputPeerChannel{ChannelID: channel.ID, AccessHash: channel.AccessHash}
|
||||
|
||||
limit := 50
|
||||
limit := 20
|
||||
request := &tg.MessagesGetHistoryRequest{
|
||||
Peer: inputPeer,
|
||||
Limit: limit,
|
||||
@@ -32,12 +32,21 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "messages.getHistory")
|
||||
}
|
||||
if len(history.(*tg.MessagesChannelMessages).GetMessages()) == 0 {
|
||||
|
||||
messages := history.(*tg.MessagesChannelMessages).GetMessages()
|
||||
if len(messages) == 0 {
|
||||
if cfg.OffsetID > 0 && request.OffsetID < cfg.OffsetID {
|
||||
cfg.Update(ctx, request.OffsetID)
|
||||
return nil
|
||||
}
|
||||
logger.Info("no new message", zap.Int64("channel", channel.ID))
|
||||
return errorx.ErrNoNewMessage
|
||||
}
|
||||
|
||||
messages := history.(*tg.MessagesChannelMessages).GetMessages()
|
||||
if onlyAddChannel {
|
||||
return cfg.SetOffset(ctx, messages[0].GetID())
|
||||
}
|
||||
|
||||
messages = lo.Reverse(messages)
|
||||
|
||||
for _, item := range messages {
|
||||
|
||||
Reference in New Issue
Block a user