Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AmarnathCJD/gogram
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Jan 21, 2024
2 parents f909da5 + 2e8e0ae commit e3d8fcd
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion internal/aes_ige/aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func encryptMessageWithTempKeys(msg []byte, nonceSecond, nonceServer *big.Int) (

// https://tlgrm.ru/docs/mtproto/auth_key#server-otvecaet-dvuma-sposobami
// generateTempKeys генерирует временные ключи для шифрования в процессе обемна ключами.
func generateTempKeys(nonceSecond, nonceServer *big.Int) (key []byte, iv []byte, err error) {
func generateTempKeys(nonceSecond, nonceServer *big.Int) (key, iv []byte, err error) {
if nonceSecond == nil {
return nil, nil, errors.New("nonceSecond is nil")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/mtproto/messages/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Unencrypted struct {
MsgID int64
}

func (msg *Unencrypted) Serialize(client MessageInformator) ([]byte, error) {
func (msg *Unencrypted) Serialize(_ MessageInformator) ([]byte, error) {
buf := bytes.NewBuffer(nil)
e := tl.NewEncoder(buf)
// authKeyHash, always 0 if unencrypted
Expand Down
2 changes: 1 addition & 1 deletion internal/mtproto/objects/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (*GzipPacked) CRC() uint32 {
return CrcGzipPacked
}

func (*GzipPacked) MarshalTL(e *tl.Encoder) error {
func (*GzipPacked) MarshalTL(_ *tl.Encoder) error {
panic("not implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/transport/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func DialProxy(s *url.URL, network, addr string) (net.Conn, error) {
return conn, nil
}

func DialSocks5(s *url.URL, network, addr string) (net.Conn, error) {
func DialSocks5(s *url.URL, _, addr string) (net.Conn, error) {
conn, err := net.Dial("tcp", s.Hostname()+":"+s.Port())
if err != nil {
return nil, err
Expand Down Expand Up @@ -167,7 +167,7 @@ func DialSocks5(s *url.URL, network, addr string) (net.Conn, error) {
return conn, nil
}

func DialSocks4(s *url.URL, network, addr string) (net.Conn, error) {
func DialSocks4(s *url.URL, _, addr string) (net.Conn, error) {
conn, err := net.Dial("tcp", s.Hostname()+":"+s.Port())
if err != nil {
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions internal/utils/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (box *Box) GetFlags() uint32 {
}

// CheckFlag checks the flag status
func (box *Box) CheckFlag(flag uint32) bool {
func (box *Box) CheckFlag(_ uint32) bool {
return true
}

Expand All @@ -56,11 +56,11 @@ func (box *Box) SetFlags(uint32) {
}

// AddFlag adds the flag
func (box *Box) AddFlag(flag uint32) {
func (box *Box) AddFlag(_ uint32) {
}

// RemoveFlag removes the flag
func (box *Box) RemoveFlag(flag uint32) {
func (box *Box) RemoveFlag(_ uint32) {
}

// GetVersion returns the box version
Expand Down Expand Up @@ -197,7 +197,7 @@ type IAnyType interface {

type BoxPath []BoxType

func (lhs BoxPath) compareWith(rhs BoxPath) (forwardMatch bool, match bool) {
func (lhs BoxPath) compareWith(rhs BoxPath) (forwardMatch, match bool) {
if len(lhs) > len(rhs) {
return false, false
}
Expand Down Expand Up @@ -270,7 +270,7 @@ type Mvhd struct {
NextTrackID uint32 `mp4:"14,size=32"`
}

func (*Mvhd) AddFlag(flag uint32) {}
func (*Mvhd) AddFlag(_ uint32) {}

// GetType returns the BoxType
func (*Mvhd) GetType() BoxType {
Expand Down Expand Up @@ -423,7 +423,7 @@ func ExtractBoxes(r io.ReadSeeker, parent *BoxInfo, paths []BoxPath) ([]*BoxInfo
func BoxTypeMoov() BoxType { return StrToBoxType("moov") }
func BoxTypeMvhd() BoxType { return StrToBoxType("mvhd") }

func matchPath(paths []BoxPath, path BoxPath) (forwardMatch bool, match bool) {
func matchPath(paths []BoxPath, path BoxPath) (forwardMatch, match bool) {
for i := range paths {
fm, m := path.compareWith(paths[i])
forwardMatch = forwardMatch || fm
Expand Down Expand Up @@ -1003,7 +1003,7 @@ func buildFieldsAny(t reflect.Type) []*field {
}
}

func buildField(fieldName string, tag string) *field {
func buildField(fieldName, tag string) *field {
f := &field{
name: fieldName,
}
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func (*Meta) GetType() BoxType {
return BoxTypeMeta()
}

func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker, size uint64, ctx Context) (n uint64, override bool, err error) {
func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker, _ uint64, _ Context) (n uint64, override bool, err error) {
// for Apple Quick Time
buf := make([]byte, 4)
if _, err := io.ReadFull(r, buf); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions telegram/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ type PasswordOptions struct {

// 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) {
func (c *Client) Edit2FA(currPwd, newPwd string, opts ...*PasswordOptions) (bool, error) {
if currPwd == "" && newPwd == "" {
return false, errors.New("current password and new password both cannot be empty")
}
Expand Down Expand Up @@ -560,7 +560,7 @@ func passwordHash2(password, salt1, salt2 []byte) []byte {
return saltingHashing(pbkdf2sha512(passwordHash1(password, salt1, salt2), salt1, 100000), salt2)
}

func pbkdf2sha512(hash1 []byte, salt1 []byte, i int) []byte {
func pbkdf2sha512(hash1, salt1 []byte, i int) []byte {
return AlgoKey(hash1, salt1, i, 64, sha512.New)
}

Expand Down
8 changes: 4 additions & 4 deletions telegram/buttons.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func (Button) Force(placeHolder string) *ReplyKeyboardForceReply {
return &ReplyKeyboardForceReply{Placeholder: placeHolder}
}

func (Button) Auth(Text string, URL string, ForwardText string, ButtonID int32) *KeyboardButtonURLAuth {
func (Button) Auth(Text, URL, ForwardText string, ButtonID int32) *KeyboardButtonURLAuth {
return &KeyboardButtonURLAuth{Text: Text, URL: URL, FwdText: ForwardText, ButtonID: ButtonID}
}

func (Button) URL(Text string, URL string) *KeyboardButtonURL {
func (Button) URL(Text, URL string) *KeyboardButtonURL {
return &KeyboardButtonURL{Text: Text, URL: URL}
}

func (Button) Data(Text string, Data string) *KeyboardButtonCallback {
func (Button) Data(Text, Data string) *KeyboardButtonCallback {
return &KeyboardButtonCallback{Text: Text, Data: []byte(Data)}
}

Expand Down Expand Up @@ -54,7 +54,7 @@ func (Button) SwitchInline(Text string, SamePeer bool, Query string) *KeyboardBu
return &KeyboardButtonSwitchInline{Text: Text, SamePeer: SamePeer, Query: Query}
}

func (Button) WebView(Text string, URL string) *KeyboardButtonSimpleWebView {
func (Button) WebView(Text, URL string) *KeyboardButtonSimpleWebView {
return &KeyboardButtonSimpleWebView{Text: Text, URL: URL}
}

Expand Down
8 changes: 4 additions & 4 deletions telegram/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Participant struct {
// Params:
// - chatID: The ID of the chat
// - userID: The ID of the user
func (c *Client) GetChatMember(chatID interface{}, userID interface{}) (*Participant, error) {
func (c *Client) GetChatMember(chatID, userID interface{}) (*Participant, error) {
channel, err := c.GetSendablePeer(chatID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -283,7 +283,7 @@ type AdminOptions struct {

// Edit Admin rights of a user in a chat,
// returns true if successfull
func (c *Client) EditAdmin(PeerID interface{}, UserID interface{}, Opts ...*AdminOptions) (bool, error) {
func (c *Client) EditAdmin(PeerID, UserID interface{}, Opts ...*AdminOptions) (bool, error) {
opts := getVariadic(Opts, &AdminOptions{IsAdmin: true, Rights: &ChatAdminRights{}, Rank: "Admin"}).(*AdminOptions)
peer, err := c.GetSendablePeer(PeerID)
if err != nil {
Expand Down Expand Up @@ -332,7 +332,7 @@ type BannedOptions struct {

// Edit Restricted rights of a user in a chat,
// returns true if successfull
func (c *Client) EditBanned(PeerID interface{}, UserID interface{}, opts ...*BannedOptions) (bool, error) {
func (c *Client) EditBanned(PeerID, UserID interface{}, opts ...*BannedOptions) (bool, error) {
o := getVariadic(opts, &BannedOptions{Ban: true, Rights: &ChatBannedRights{}}).(*BannedOptions)
if o.Rights == nil {
o.Rights = &ChatBannedRights{}
Expand Down Expand Up @@ -381,7 +381,7 @@ func (c *Client) EditBanned(PeerID interface{}, UserID interface{}, opts ...*Ban
return true, nil
}

func (c *Client) KickParticipant(PeerID interface{}, UserID interface{}) (bool, error) {
func (c *Client) KickParticipant(PeerID, UserID interface{}) (bool, error) {
peer, err := c.GetSendablePeer(PeerID)
if err != nil {
return false, err
Expand Down
4 changes: 2 additions & 2 deletions telegram/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"golang.org/x/net/html"
)

func (c *Client) FormatMessage(message string, mode string) ([]MessageEntity, string) {
func (c *Client) FormatMessage(message, mode string) ([]MessageEntity, string) {
return parseEntities(message, mode)
}

// parseEntities parses the message and returns a list of MessageEntities and the cleaned text string
func parseEntities(message string, mode string) ([]MessageEntity, string) {
func parseEntities(message, mode string) ([]MessageEntity, string) {
if strings.EqualFold(mode, HTML) {
return parseHTML(message)
} else if strings.EqualFold(mode, MarkDown) {
Expand Down
6 changes: 3 additions & 3 deletions telegram/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ func GetHostIp(dcID int) string {
panic("Invalid Data Center ID")
}

func getStr(a string, b string) string {
func getStr(a, b string) string {
if a == "" {
return b
}
return a
}

func getInt(a int, b int) int {
func getInt(a, b int) int {
if a == 0 {
return b
}
Expand Down Expand Up @@ -543,7 +543,7 @@ func ExtractVideoThumb(path string, duration int64) (string, error) {
}

// TODO: implement this
func GetAudioMetadata(path string) (performer string, title string, duration int32) {
func GetAudioMetadata(path string) (performer, title string, duration int32) {
dur := GetVideoDuration(path)
metadata := make(map[string]string)
cmd := exec.Command("ffprobe", "-v", "error", "-show_entries", "format_tags=artist,title", "-of", "default=noprint_wrappers=1:nokey=1", path)
Expand Down
2 changes: 1 addition & 1 deletion telegram/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func GenerateRandomString(n int) string {

// TODO: IMPLEMENT SenderChat Correctly.

func UploadProgressBar(m *NewMessage, total int32, now int32) {
func UploadProgressBar(m *NewMessage, total, now int32) {
var (
progressfillemojirectangleempty = "◾️"
progressfillemojirectanglefull = "◻️"
Expand Down
12 changes: 6 additions & 6 deletions telegram/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type SendOptions struct {
// Note: If the message parameter is a NewMessage or a pointer to a NewMessage, the function will extract the message text and entities from it.
// If the message parameter is a media object, the function will send the media as a separate message and return a pointer to a NewMessage object containing information about the sent media.
// If the message parameter is a string, the function will parse it for entities and send it as a text message.
func (c *Client) SendMessage(peerID interface{}, message interface{}, opts ...*SendOptions) (*NewMessage, error) {
func (c *Client) SendMessage(peerID, message interface{}, opts ...*SendOptions) (*NewMessage, error) {
opt := getVariadic(opts, &SendOptions{}).(*SendOptions)
opt.ParseMode = getStr(opt.ParseMode, c.ParseMode())
var (
Expand Down Expand Up @@ -310,7 +310,7 @@ type MediaMetadata struct {
// - If the caption in opts is a pointer to a NewMessage, its entities will be used instead.
// - If the entites field in opts is not nil, it will override any entities parsed from the caption.
// - If send_as in opts is not nil, the message will be sent from the specified peer, otherwise it will be sent from the sender peer.
func (c *Client) SendMedia(peerID interface{}, Media interface{}, opts ...*MediaOptions) (*NewMessage, error) {
func (c *Client) SendMedia(peerID, Media interface{}, opts ...*MediaOptions) (*NewMessage, error) {
opt := getVariadic(opts, &MediaOptions{}).(*MediaOptions)
opt.ParseMode = getStr(opt.ParseMode, c.ParseMode())

Expand Down Expand Up @@ -401,7 +401,7 @@ func (c *Client) sendMedia(Peer InputPeer, Media InputMedia, Caption string, ent
// - If the caption in opts is a pointer to a NewMessage, its entities will be used instead.
// - If the entites field in opts is not nil, it will override any entities parsed from the caption.
// - If send_as in opts is not nil, the messages will be sent from the specified peer, otherwise they will be sent from the sender peer.
func (c *Client) SendAlbum(peerID interface{}, Album interface{}, opts ...*MediaOptions) ([]*NewMessage, error) {
func (c *Client) SendAlbum(peerID, Album interface{}, opts ...*MediaOptions) ([]*NewMessage, error) {
opt := getVariadic(opts, &MediaOptions{}).(*MediaOptions)
opt.ParseMode = getStr(opt.ParseMode, c.ParseMode())
var (
Expand Down Expand Up @@ -540,7 +540,7 @@ func (a *ActionResult) Cancel() bool {

// 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) {
func (c *Client) SendAction(PeerID, Action interface{}, topMsgID ...int32) (*ActionResult, error) {
peerChat, err := c.GetSendablePeer(PeerID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -587,7 +587,7 @@ type ForwardOptions struct {

// Forward forwards a message.
// This method is a wrapper for messages.forwardMessages.
func (c *Client) Forward(peerID interface{}, fromPeerID interface{}, msgIDs []int32, opts ...*ForwardOptions) ([]NewMessage, error) {
func (c *Client) Forward(peerID, fromPeerID interface{}, msgIDs []int32, opts ...*ForwardOptions) ([]NewMessage, error) {
opt := getVariadic(opts, &ForwardOptions{}).(*ForwardOptions)
toPeer, err := c.GetSendablePeer(peerID)
if err != nil {
Expand Down Expand Up @@ -964,7 +964,7 @@ func convertOption(s *SendOptions) *MediaOptions {
}
}

func getVariadic(v interface{}, def interface{}) interface{} {
func getVariadic(v, def interface{}) interface{} {
if v == nil {
return def
}
Expand Down
2 changes: 1 addition & 1 deletion telegram/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ UpdateTypeSwitching:
return true
}

func (c *Client) GetDifference(Pts int32, Limit int32) (Message, error) {
func (c *Client) GetDifference(Pts, Limit int32) (Message, error) {
c.Logger.Debug("updates.getDifference: [pts: ", Pts, " limit: ", Limit, "]")

updates, err := c.UpdatesGetDifference(&UpdatesGetDifferenceParams{
Expand Down
2 changes: 1 addition & 1 deletion telegram/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func IsPhone(phone string) bool {
return phoneRe.MatchString(phone)
}

func getValue(val interface{}, def interface{}) interface{} {
func getValue(val, def interface{}) interface{} {
switch v := val.(type) {
case string:
if v == "" {
Expand Down

0 comments on commit e3d8fcd

Please sign in to comment.