module
0.0.0-20241214100749-064836411b35
Repository: https://github.com/prdsrm/std.git
Documentation: pkg.go.dev
# README
std: simpler td
MTPROTO helper library and tools, tailored for bot & channel automation, groups or channel monitoring, managing sessions and scraping.
Features
- Session helpers for gotd
- allows converting a Telethon SQLite Session, or TDATA session, to a Telethon string session
- export all of your sessions to Telethon string session
- Examples: simply generate a telethon string session for your account, with manual login, or an existing SQLite / TDATA session Or, use the postgres back-end to connect to an account, and manage your sessions.
- Bot automation helpers
- Structured object in order to automate official bot.
- Examples: scrape data from SpyDefi Bot, check out the code.
- Group and channel monitoring / scraping
- Custom object tailored for parsing message from channels.
- Examples: monitor newly listed tokens on DexScreener, check out the code.
- Common helpers for gotd
- Create shareable folders(https://t.me/addlist/random), export chats in them, join them.
- Scrape similar channels, export them into a Maltego file
- Join channel, add views, reactions, create channels and groups, promote & demote members, add members to your channel, easily.
- Automate posting in your channel.
- Export all members from a channel you own.
Installation
Run the following in your Go project:
go get github.com/prdsrm/std
Usage
Scrape similar channels example, (here, we get the channels similar to Pavel Durov personal channel):
package main
import (
"context"
"fmt"
"log"
examples "github.com/gotd/td/examples"
"github.com/gotd/td/telegram"
"github.com/gotd/td/telegram/auth"
"github.com/gotd/td/tg"
"github.com/prdsrm/std/channels"
"github.com/prdsrm/std/session"
)
func run(ctx context.Context, client *telegram.Client, dispatcher tg.UpdateDispatcher, options telegram.Options) error {
channels, err := channels.GetSimilarChannels(ctx, client, "durov")
if err != nil {
return err
}
for _, channel := range channels {
fmt.Println("Channel: ", channel.ID, channel.Username)
}
return nil
}
func main() {
authOpt := auth.SendCodeOptions{}
flow := auth.NewFlow(examples.Terminal{}, authOpt)
err := session.Connect(run, session.Windows(), 2040, "b18441a1ff607e10a989891a5462e627", "", "", flow)
if err != nil {
log.Fatalln("can't connect: ", err)
}
}
You can run this example, just create a main.go
file, and install the library with go get
, then run go run
.
Bot automation example, extracting KOLs data from https://t.me/spydefi_bot:
package main
import (
"context"
"fmt"
"log"
"os"
"regexp"
"strconv"
"github.com/gotd/td/telegram"
"github.com/gotd/td/tg"
"github.com/prdsrm/std/bot"
"github.com/prdsrm/std/messages"
"github.com/prdsrm/std/session"
"github.com/prdsrm/std/utils"
)
var expr = `(?m)Statsfor\@([a-zA-Z0-9_]{4,32}):Consistency:([0-9.]{1,3})%NumberofAlphaCalls:([0-9]+)BestCall:([a-zA-Z0-9.]+)(\(x[0-9.]+\))LastCall:([a-zA-Z0-9]+)(\(x[0-9.]+\))AverageCallMarketcap:\$([0-9.]+)(K|M|B)AverageXPerCall:x([0-9.]+)TotalCallsTracked:(\d+)NumberofAchievementCalls:calls:(\d+)calls:(\d+)TotalAchievements:(\d+)AchievementCallsrefertocallsthathavegonex2\+asperourparameters`
var re = regexp.MustCompile(expr)
func saveSpydefiChannelData(ctx messages.MonitoringContext) error {
cleanedMessage := utils.RemoveSpacesAndNewlines(ctx.GetMessage().Message)
for _, match := range re.FindAllStringSubmatch(cleanedMessage, -1) {
username := match[1]
averageCallMC := match[8]
numberMC, err := strconv.ParseFloat(averageCallMC, 2)
if err != nil {
return err
}
mc := int(numberMC)
averageCallMCUnit := match[9]
var numberAverageCallMC int
if averageCallMCUnit == "M" {
numberAverageCallMC = mc * 1_000_000
}
if averageCallMCUnit == "K" {
numberAverageCallMC = mc * 1_000
} else {
numberAverageCallMC = mc * 1_000_000_000
}
averageCallX := match[10]
numberAverageCallX, _ := strconv.ParseFloat(averageCallX, 2)
// NOTE: starting from here, you could start saving the result in a database or something similar.
fmt.Println("Data: ", username, numberAverageCallMC, numberAverageCallX)
return messages.EndConversation
}
if cleanedMessage == "ThisKOLChannelwasnotfoundinournetworkMakesureyouhaveenteredtheusernamecorrectly!Youcanalsousethe/trackme<@username>featuretosubmitanychannelstobetracked." {
fmt.Println("This channel does not exist, in the spydefi database.")
return messages.EndConversation
}
return nil
}
func listen(ctx context.Context, client *telegram.Client, dispatcher tg.UpdateDispatcher, options telegram.Options) error {
fmt.Println("Successfully connected to the bot")
automation, err := bot.NewAutomation(ctx, client, dispatcher, "spydefi_bot", true)
if err != nil {
return err
}
fmt.Println("Sending start message with params")
// NOTE: channel is completely random.
err = automation.SendStartMessageWithParams("tggemarcheologisttelegram-1001942713434")
if err != nil {
return err
}
automation.Handle(re, saveSpydefiChannelData)
err = automation.Listen()
if err != nil {
return err
}
return nil
}
func main() {
phone := os.Getenv("PHONE_NUMBER")
password := os.Getenv("PASSWORD")
sessionString := os.Getenv("SESSION_STRING")
flow := session.GetNewDefaultAuthConversator(phone, password)
err := session.Connect(listen, session.Windows(), 2040, "b18441a1ff607e10a989891a5462e627", sessionString, "", flow)
if err != nil {
log.Fatalln("can't connect: ", err)
}
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
BSD-3-Clause license, because FreeBSD is great
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author