From 460fa15962d087adc4bf0b6a964d24e30e1201cd Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:58:59 +0000 Subject: [PATCH 1/2] refactor: types of function parameters can be combined If parameters of the same type lie consecutively, mention their type once at the end of the last parameter. --- internal/aes_ige/aes.go | 2 +- internal/utils/media.go | 6 +++--- telegram/auth.go | 4 ++-- telegram/buttons.go | 8 ++++---- telegram/channels.go | 8 ++++---- telegram/formatting.go | 4 ++-- telegram/helpers.go | 6 +++--- telegram/media.go | 2 +- telegram/messages.go | 12 ++++++------ telegram/updates.go | 2 +- telegram/utils.go | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/internal/aes_ige/aes.go b/internal/aes_ige/aes.go index 88d342bd..3a3124d8 100755 --- a/internal/aes_ige/aes.go +++ b/internal/aes_ige/aes.go @@ -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") } diff --git a/internal/utils/media.go b/internal/utils/media.go index 50b32a6e..a64bdc95 100755 --- a/internal/utils/media.go +++ b/internal/utils/media.go @@ -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 } @@ -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 @@ -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, } diff --git a/telegram/auth.go b/telegram/auth.go index f59693ed..4061201b 100755 --- a/telegram/auth.go +++ b/telegram/auth.go @@ -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") } @@ -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) } diff --git a/telegram/buttons.go b/telegram/buttons.go index 2075c302..e60f0b67 100755 --- a/telegram/buttons.go +++ b/telegram/buttons.go @@ -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)} } @@ -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} } diff --git a/telegram/channels.go b/telegram/channels.go index a492f99c..55c7d50c 100755 --- a/telegram/channels.go +++ b/telegram/channels.go @@ -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 @@ -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 { @@ -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{} @@ -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 diff --git a/telegram/formatting.go b/telegram/formatting.go index e67968f0..746f81ca 100755 --- a/telegram/formatting.go +++ b/telegram/formatting.go @@ -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) { diff --git a/telegram/helpers.go b/telegram/helpers.go index 3daedea6..6397babb 100644 --- a/telegram/helpers.go +++ b/telegram/helpers.go @@ -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 } @@ -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) diff --git a/telegram/media.go b/telegram/media.go index 44e9c28f..0c946c5c 100644 --- a/telegram/media.go +++ b/telegram/media.go @@ -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 = "◻️" diff --git a/telegram/messages.go b/telegram/messages.go index f4ec5552..540709be 100644 --- a/telegram/messages.go +++ b/telegram/messages.go @@ -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 ( @@ -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()) @@ -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 ( @@ -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 @@ -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 { @@ -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 } diff --git a/telegram/updates.go b/telegram/updates.go index efbea2ec..05d86189 100644 --- a/telegram/updates.go +++ b/telegram/updates.go @@ -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{ diff --git a/telegram/utils.go b/telegram/utils.go index a8747279..abf3dcdf 100755 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -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 == "" { From c9b868e85fcb0dc7c130e33de6453fd1c7bc6717 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:01:19 +0000 Subject: [PATCH 2/2] refactor: unused parameter should be replaced by underscore Unused parameters in functions or methods should be replaced with `_` (underscore) or removed. --- internal/mtproto/messages/messages.go | 2 +- internal/mtproto/objects/types.go | 2 +- internal/transport/socks.go | 4 ++-- internal/utils/media.go | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/mtproto/messages/messages.go b/internal/mtproto/messages/messages.go index f6781d5d..65be8bfb 100755 --- a/internal/mtproto/messages/messages.go +++ b/internal/mtproto/messages/messages.go @@ -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 diff --git a/internal/mtproto/objects/types.go b/internal/mtproto/objects/types.go index 54065ac5..205dd7f6 100755 --- a/internal/mtproto/objects/types.go +++ b/internal/mtproto/objects/types.go @@ -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") } diff --git a/internal/transport/socks.go b/internal/transport/socks.go index a4e90966..ec9bd418 100755 --- a/internal/transport/socks.go +++ b/internal/transport/socks.go @@ -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 @@ -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 diff --git a/internal/utils/media.go b/internal/utils/media.go index a64bdc95..d8878f5b 100755 --- a/internal/utils/media.go +++ b/internal/utils/media.go @@ -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 } @@ -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 @@ -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 { @@ -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 {