Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfedcafe committed Mar 28, 2020
1 parent 86209d1 commit d821e6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
}

description := data[2]
code,_ := strconv.Atoi(data[0])
switch description{
code, _ := strconv.Atoi(data[0])
switch description {
case ErrUnauthorized.ʔ():
err = ErrUnauthorized
case ErrToForwardNotFound.ʔ():
Expand Down Expand Up @@ -284,4 +284,4 @@ func (b *Bot) getUpdates(offset int, timeout time.Duration) (upd []Update, err e
}

return updatesReceived.Result, nil
}
}
30 changes: 14 additions & 16 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
)

type ApiError struct {
Code int
Code int
Description string

message string

message string
}

func (err *ApiError) ʔ() string {
Expand All @@ -28,11 +27,11 @@ func badRequest(description ...string) *ApiError {

func (err *ApiError) Error() string {
canonical := err.message
if canonical == ""{
if canonical == "" {
butchered := strings.Split(err.Description, ": ")
if len(butchered) == 2{
if len(butchered) == 2 {
canonical = butchered[1]
}else{
} else {
canonical = err.Description
}
}
Expand All @@ -41,16 +40,16 @@ func (err *ApiError) Error() string {

var (
//RegExp
apiErrorRx = regexp.MustCompile(`{.+"error_code":(\d+),"description":"(.+)"}`)
apiErrorRx = regexp.MustCompile(`{.+"error_code":(\d+),"description":"(.+)"}`)

//bot creation errors
ErrUnauthorized = &ApiError{401,"Unauthorized",""}
ErrUnauthorized = &ApiError{401, "Unauthorized", ""}

// not found etc
ErrToForwardNotFound = badRequest("Bad Request: message to forward not found")
ErrToReplyNotFound = badRequest("Bad Request: reply message not found")
ErrMessageTooLong = badRequest("Bad Request: message is too long")
ErrBlockedByUsr = &ApiError{401,"Forbidden: bot was blocked by the user",""}
ErrBlockedByUsr = &ApiError{401, "Forbidden: bot was blocked by the user", ""}
ErrToDeleteNotFound = badRequest("Bad Request: message to delete not found")
ErrEmptyMessage = badRequest("Bad Request: message must be non-empty")
//checking
Expand All @@ -59,31 +58,30 @@ var (
ErrNotFoundChat = badRequest("Bad Request: chat not found")
ErrMessageNotModified = badRequest("Bad Request: message is not modified")


// Rigts Errors
ErrNoRightsToRestrict = badRequest("Bad Request: not enough rights to restrict/unrestrict chat member")
ErrNoRightsToSendMsg = badRequest("Bad Request: have no rights to send a message")
ErrNoRightsToSendPhoto = badRequest("Bad Request: not enough rights to send photos to the chat")
ErrNoRightsToSendStickers = badRequest("Bad Request: not enough rights to send stickers to the chat")
ErrNoRightsToSendGifs = badRequest("Bad Request: CHAT_SEND_GIFS_FORBIDDEN","sending GIFS is not allowed in this chat")
ErrNoRightsToSendGifs = badRequest("Bad Request: CHAT_SEND_GIFS_FORBIDDEN", "sending GIFS is not allowed in this chat")
ErrNoRightsToDelete = badRequest("Bad Request: message can't be deleted")
ErrKickingChatOwner = badRequest("Bad Request: can't remove chat owner")

// Interacting with group/supergroup after being kicked
ErrInteractKickedG = &ApiError{403,"Forbidden: bot was kicked from the group chat",""}
ErrInteractKickedSprG = &ApiError{403,"Forbidden: bot was kicked from the supergroup chat",""}
ErrInteractKickedG = &ApiError{403, "Forbidden: bot was kicked from the group chat", ""}
ErrInteractKickedSprG = &ApiError{403, "Forbidden: bot was kicked from the supergroup chat", ""}

// file errors etc
ErrWrongTypeOfContent = badRequest("Bad Request: wrong type of the web page content")
ErrCantGetHTTPurlContent = badRequest("Bad Request: failed to get HTTP URL content")
ErrWrongRemoteFileID = badRequest("Bad Request: wrong remote file id specified: can't unserialize it. Wrong last symbol")
ErrFileIdTooShort = badRequest("Bad Request: wrong remote file id specified: Wrong string length")
ErrFileIdTooShort = badRequest("Bad Request: wrong remote file id specified: Wrong string length")
ErrWrongRemoteFileIDsymbol = badRequest("Bad Request: wrong remote file id specified: Wrong character in the string")
ErrWrongFileIdentifier = badRequest("Bad Request: wrong file identifier/HTTP URL specified")
ErrTooLarge = badRequest("Request Entity Too Large")
ErrWrongPadding = badRequest("Bad Request: wrong remote file id specified: Wrong padding in the string") // not my
ErrImageProcess = badRequest("Bad Request: IMAGE_PROCESS_FAILED", "Image process failed")

// sticker errors
ErrWrongStickerpack = badRequest("Bad Request: STICKERSET_INVALID","Stickerset is invalid")
)
ErrWrongStickerpack = badRequest("Bad Request: STICKERSET_INVALID", "Stickerset is invalid")
)

0 comments on commit d821e6b

Please sign in to comment.