forked from iyear/tdl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package chat | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/gotd/contrib/middleware/floodwait" | ||
"github.com/gotd/contrib/middleware/ratelimit" | ||
"github.com/gotd/td/telegram/query" | ||
"github.com/iyear/tdl/app/internal/tgc" | ||
"github.com/iyear/tdl/pkg/consts" | ||
"github.com/iyear/tdl/pkg/kv" | ||
"github.com/iyear/tdl/pkg/utils" | ||
"golang.org/x/time/rate" | ||
"time" | ||
) | ||
|
||
func List(ctx context.Context, ns, proxy string) error { | ||
kvd, err := kv.New(kv.Options{ | ||
Path: consts.KVPath, | ||
NS: ns, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c := tgc.New(proxy, kvd, false, floodwait.NewSimpleWaiter(), ratelimit.New(rate.Every(time.Millisecond*400), 2)) | ||
|
||
return c.Run(ctx, func(ctx context.Context) error { | ||
|
||
dialogs, err := query.GetDialogs(c.API()).BatchSize(100).Collect(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
blocked, err := utils.Telegram.GetBlockedDialogs(ctx, c.API()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, dialog := range dialogs { | ||
id := utils.Telegram.GetInputPeerID(dialog.Peer) | ||
|
||
if _, ok := blocked[id]; ok { | ||
continue | ||
} | ||
|
||
fmt.Printf("ID: %d, Title: %s, Type: %s\n", id, utils.Telegram.GetPeerName(id, dialog.Entities), utils.Telegram.GetPeerType(id, dialog.Entities)) | ||
} | ||
|
||
return nil | ||
}) | ||
} |
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,15 @@ | ||
package chat | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "chat", | ||
Short: "A set of chat tools", | ||
Example: "", | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(cmdList) | ||
} |
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,25 @@ | ||
package chat | ||
|
||
import ( | ||
"github.com/iyear/tdl/app/chat" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var cmdList = &cobra.Command{ | ||
Use: "ls", | ||
Short: "List your all chats with info", | ||
Example: "", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
proxy, err := cmd.Flags().GetString("proxy") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ns, err := cmd.Flags().GetString("ns") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return chat.List(cmd.Context(), ns, proxy) | ||
}, | ||
} |
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