telegram

package
v1.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultConfigPath = "telegram-config.json"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse added in v1.0.14

type APIResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
	Error   string `json:"error,omitempty"`
}

APIResponse represents the response from the verification API

type AlchemyRequest

type AlchemyRequest struct {
	JSONRPC string        `json:"jsonrpc"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
	ID      int           `json:"id"`
}

AlchemyRequest represents a JSON-RPC request to Alchemy

type AlchemyResponse

type AlchemyResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      int         `json:"id"`
	Result  interface{} `json:"result,omitempty"`
	Error   *struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

AlchemyResponse represents a JSON-RPC response from Alchemy

type BlockchainData

type BlockchainData struct {
	Votes   *big.Int
	Rewards *big.Int
	Wins    *big.Int
	Balance *big.Int
}

BlockchainData represents the blockchain data for a user

type Node added in v1.0.14

type Node struct {
	PeerID  string    `json:"peer_id"`
	EOA     string    `json:"eoa"`
	AddedAt time.Time `json:"added_at"`
}

Node represents a node in the verification status response

func (*Node) UnmarshalJSON added in v1.0.14

func (n *Node) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaling for Node to handle the time format

type PeerPreviousData added in v1.0.17

type PeerPreviousData struct {
	Votes   string `json:"votes"`
	Rewards string `json:"rewards"`
	Wins    string `json:"wins"`
}

PeerPreviousData stores previous values for a single peer Used for per-peer delta tracking Add more fields as needed (e.g., Rank, Wins)

type PreviousData

type PreviousData struct {
	Votes     *big.Int                    `json:"votes"`   // total
	Rewards   *big.Int                    `json:"rewards"` // total
	Wins      *big.Int                    `json:"wins"`    // total
	Peers     map[string]PeerPreviousData `json:"peers"`   // per-peer
	LastCheck time.Time                   `json:"last_check"`
}

PreviousData stores the previous blockchain data for comparison Now supports both total and per-peer tracking The Peers map key is the peer ID

type Rank added in v1.0.14

type Rank struct {
	PeerID       string    `json:"peerId"`
	Rank         int       `json:"rank"`
	TotalWins    int       `json:"totalWins"`
	TotalRewards int       `json:"totalRewards"`
	LastSeen     time.Time `json:"lastSeen"`
}

Rank represents rank data for a peer

func (*Rank) UnmarshalJSON added in v1.0.14

func (r *Rank) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaling for Rank to handle the time format

type Stats added in v1.0.14

type Stats struct {
	TotalNodes  int `json:"totalNodes"`
	RankedNodes int `json:"rankedNodes"`
}

Stats represents user statistics

type TelegramConfig

type TelegramConfig struct {
	BotToken    string `json:"bot_token"`
	ChatID      string `json:"chat_id"`
	WelcomeSent bool   `json:"welcome_sent"`
	APIURL      string `json:"api_url"`
}

TelegramConfig stores the info needed to send messages to Telegram

type TelegramService

type TelegramService struct {
	ConfigPath        string
	ForceConfigUpdate bool
	Config            *TelegramConfig
	UserEOAAddress    string
	EOAAddress        string // For non-interactive mode
	BotToken          string // For non-interactive mode
	ChatID            string // For non-interactive mode
	PeerIDs           []string
	PreviousData      *PreviousData
	StopChan          chan bool
	// contains filtered or unexported fields
}

TelegramService represents the telegram monitoring service

func NewTelegramService

func NewTelegramService(configPath string, forceUpdate bool, eoaAddress string, botToken string, chatID string) *TelegramService

NewTelegramService creates a new telegram service instance

func (*TelegramService) CheckVerificationStatus added in v1.0.14

func (t *TelegramService) CheckVerificationStatus(telegramID int64) (*VerificationStatus, error)

CheckVerificationStatus checks if a user has been verified in Discord

func (*TelegramService) EnsureTelegramConfig added in v1.0.14

func (t *TelegramService) EnsureTelegramConfig() error

EnsureTelegramConfig loads or prompts for config

func (*TelegramService) GetBlockchainData

func (t *TelegramService) GetBlockchainData(userAddress string) (*BlockchainData, error)

GetBlockchainData queries all blockchain data for a user using Alchemy API

func (*TelegramService) GetBlockchainDataForPeerID added in v1.0.9

func (t *TelegramService) GetBlockchainDataForPeerID(peerID string, previousData *PreviousData) (*BlockchainData, error)

GetBlockchainDataForPeerID gets blockchain data for a specific peer ID If API calls fail, it preserves the previous values to prevent negative changes

func (*TelegramService) GetPeerIDs added in v1.0.14

func (t *TelegramService) GetPeerIDs(eoaAddress string) ([]string, error)

GetPeerIDs fetches the peer IDs associated with the given EOA address

func (*TelegramService) GetUserRankData added in v1.0.14

func (t *TelegramService) GetUserRankData(telegramID int64) (*UserRankData, error)

GetUserRankData gets rank data for verified users' peer IDs

func (*TelegramService) IssueVerificationCode added in v1.0.14

func (t *TelegramService) IssueVerificationCode(telegramID string) (*VerificationCode, error)

IssueVerificationCode sends a verification code to the API

func (*TelegramService) Run

func (t *TelegramService) Run() error

Run starts the telegram monitoring service

type TelegramUpdate added in v1.0.14

type TelegramUpdate struct {
	UpdateID int64 `json:"update_id"`
	Message  struct {
		MessageID int64 `json:"message_id"`
		From      struct {
			ID        int64  `json:"id"`
			FirstName string `json:"first_name"`
			LastName  string `json:"last_name"`
			Username  string `json:"username"`
		} `json:"from"`
		Chat struct {
			ID    int64  `json:"id"`
			Type  string `json:"type"`
			Title string `json:"title"`
		} `json:"chat"`
		Date     int64  `json:"date"`
		Text     string `json:"text"`
		Entities []struct {
			Type   string `json:"type"`
			Offset int    `json:"offset"`
			Length int    `json:"length"`
		} `json:"entities"`
	} `json:"message"`
}

TelegramUpdate represents an incoming Telegram update

type TelegramUpdatesResponse added in v1.0.14

type TelegramUpdatesResponse struct {
	OK     bool             `json:"ok"`
	Result []TelegramUpdate `json:"result"`
}

TelegramUpdatesResponse represents the response from getUpdates

type UserRankData added in v1.0.14

type UserRankData struct {
	TelegramID int64     `json:"telegramId"`
	DiscordID  int64     `json:"discordId"`
	VerifiedAt time.Time `json:"verifiedAt"`
	Ranks      []Rank    `json:"ranks"`
	Stats      Stats     `json:"stats"`
}

UserRankData represents the user rank data response from the API

func (*UserRankData) UnmarshalJSON added in v1.0.14

func (u *UserRankData) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaling for UserRankData to handle the time format

type VerificationCode added in v1.0.14

type VerificationCode struct {
	Code       string    `json:"code"`
	TelegramID string    `json:"telegram_id"`
	PeerID     string    `json:"peer_id"`
	EOA        string    `json:"eoa"`
	ExpiresAt  time.Time `json:"expires_at"`
}

VerificationCode represents a verification code for Discord linking

type VerificationStatus added in v1.0.14

type VerificationStatus struct {
	TelegramID int64     `json:"telegramId"`
	IsVerified bool      `json:"isVerified"`
	DiscordID  int64     `json:"discordId"`
	VerifiedAt time.Time `json:"verifiedAt"`
	Nodes      []Node    `json:"nodes"`
}

VerificationStatus represents the verification status response from the API

func (*VerificationStatus) UnmarshalJSON added in v1.0.14

func (v *VerificationStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaling for VerificationStatus to handle the time format

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL