Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Oct 17, 2022
1 parent 15631a7 commit 9c39f7a
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 221 deletions.
2 changes: 1 addition & 1 deletion mtproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (m *MTProto) ReconnectToNewDC(dc int) (*MTProto, error) {
sender, _ := NewMTProto(cfg)
sender.serverRequestHandlers = m.serverRequestHandlers
m.stopRoutines()
m.Logger.Info("User Migrated to DC: ", dc)
m.Logger.Info(fmt.Sprintf("User Migrated to DC: %d", dc))
err := sender.CreateConnection(true)
if err != nil {
return nil, fmt.Errorf("creating connection: %w", err)
Expand Down
22 changes: 20 additions & 2 deletions telegram/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ func (c *Client) SendCode(phoneNumber string) (hash string, err error) {
return resp.PhoneCodeHash, nil
}

type LoginOptions struct {
Password string `json:"password,omitempty"`
Code string `json:"code,omitempty"`
CodeHash string `json:"code_hash,omitempty"`
CodeCallback func() string `json:"-"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
}

// Authorize client with phone number, code and phone code hash,
// If phone code hash is empty, it will be requested from telegram server
func (c *Client) Login(phoneNumber string, options ...*LoginOptions) (bool, error) {
Expand Down Expand Up @@ -92,11 +101,11 @@ func (c *Client) Login(phoneNumber string, options ...*LoginOptions) (bool, erro
break
}
if matchError(err, "The phone code entered was invalid") {
fmt.Println("The phone code entered was invalid, please try again")
fmt.Println("The phone code entered was invalid, please try again!")
continue
} else if matchError(err, "Two-steps verification is enabled") {
var passwordInput string
fmt.Println("Two-step verification is enabled")
fmt.Println("Two-steps verification is enabled")
for {
fmt.Printf("Enter password: ")
fmt.Scanln(&passwordInput)
Expand Down Expand Up @@ -143,6 +152,7 @@ func (c *Client) Login(phoneNumber string, options ...*LoginOptions) (bool, erro
AuthResultSwitch:
switch auth := Auth.(type) {
case *AuthAuthorizationSignUpRequired:
fmt.Println("Signing up...")
var firstName, lastName string
if opts.FirstName == "" {
fmt.Printf("Enter first name: ")
Expand Down Expand Up @@ -195,6 +205,14 @@ func (c *Client) AcceptTOS() (bool, error) {
}
}

type PasswordOptions struct {
Hint string `json:"hint,omitempty"`
Email string `json:"email,omitempty"`
EmailCodeCallback func() string `json:"email_code_callback,omitempty"`
}

// Edit2FA changes the 2FA password of the current user,
// if 2fa is already enabled, should provide the current password.
func (c *Client) Edit2FA(currPwd string, newPwd string, opts ...*PasswordOptions) (bool, error) {
if currPwd == "" && newPwd == "" {
return false, errors.New("current password and new password both cannot be empty")
Expand Down
2 changes: 1 addition & 1 deletion telegram/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "regexp"

const (
ApiVersion = 147
Version = "v1.0.1a"
Version = "v1.0.2"

DefaultDC = 4

Expand Down
16 changes: 16 additions & 0 deletions telegram/inlinequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ func (b *InlineBuilder) Results() []InputBotInlineResult {
return b.InlineResults
}

type ArticleOptions struct {
ID string `json:"id,omitempty"`
ExcludeMedia bool `json:"exclude_media,omitempty"`
Thumb InputWebDocument `json:"thumb,omitempty"`
Content InputWebDocument `json:"content,omitempty"`
LinkPreview bool `json:"link_preview,omitempty"`
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
Entities []MessageEntity `json:"entities,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
Caption string `json:"caption,omitempty"`
Venue *InputBotInlineMessageMediaVenue `json:"venue,omitempty"`
Location *InputBotInlineMessageMediaGeo `json:"location,omitempty"`
Contact *InputBotInlineMessageMediaContact `json:"contact,omitempty"`
Invoice *InputBotInlineMessageMediaInvoice `json:"invoice,omitempty"`
}

func (b *InlineBuilder) Article(title, description, text string, options ...*ArticleOptions) InputBotInlineResult {
var opts ArticleOptions
if len(options) > 0 {
Expand Down
20 changes: 19 additions & 1 deletion telegram/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@ func (c *Client) SendDice(peerID interface{}, emoji string) (*NewMessage, error)
return c.SendMedia(peerID, &InputMediaDice{Emoticon: emoji})
}

type ActionResult struct {
Peer InputPeer `json:"peer,omitempty"`
Client *Client `json:"client,omitempty"`
}

// Cancel the pointed Action,
// Returns true if the action was cancelled
func (a *ActionResult) Cancel() bool {
if a.Peer == nil || a.Client == nil {
return false // Avoid nil pointer dereference
}
b, err := a.Client.MessagesSetTyping(a.Peer, 0, &SendMessageCancelAction{})
if err != nil {
return false
}
return b
}

// SendAction sends a chat action.
// This method is a wrapper for messages.setTyping.
func (c *Client) SendAction(PeerID interface{}, Action interface{}, topMsgID ...int32) (*ActionResult, error) {
Expand Down Expand Up @@ -460,7 +478,7 @@ func (c *Client) SendReadAck(PeerID interface{}, MaxID ...int32) (*MessagesAffec
if err != nil {
return nil, err
}
maxID := getVariadic(MaxID, 0).(int32)
maxID := getVariadic(MaxID, int32(0)).(int32)
return c.MessagesReadHistory(peerChat, maxID)
}

Expand Down
197 changes: 0 additions & 197 deletions telegram/types.go

This file was deleted.

Loading

0 comments on commit 9c39f7a

Please sign in to comment.