diff --git a/cf.go b/cf.go index 83d60507..9e4620fc 100644 --- a/cf.go +++ b/cf.go @@ -12,7 +12,7 @@ import ( docopt "github.com/docopt/docopt-go" ) -const version = "v0.8.0" +const version = "v0.8.1" func main() { usage := `Codeforces Tool $%version%$ (cf). https://github.com/xalanq/cf-tool diff --git a/client/submit.go b/client/submit.go index 972fca2d..11a73cf1 100644 --- a/client/submit.go +++ b/client/submit.go @@ -1,6 +1,7 @@ package client import ( + "bytes" "errors" "fmt" "io/ioutil" @@ -16,8 +17,8 @@ type SaveSubmission struct { SubmissionID string `json:"submission_id"` } -func findErrorSource(body []byte) ([]byte, error) { - reg := regexp.MustCompile(`"error\sfor__source">(.*?)`) +func findErrorMessage(body []byte) ([]byte, error) { + reg := regexp.MustCompile(`error[a-zA-Z_\-\ ]*">(.*?)`) tmp := reg.FindSubmatch(body) if tmp == nil { return nil, errors.New("Cannot find error") @@ -52,7 +53,7 @@ func (c *Client) SubmitContest(contestID, problemID, langID, source string) (err return } - resp, err = c.client.PostForm(fmt.Sprintf("%v?csrf=%v", URL, csrf), url.Values{ + resp, err = c.client.PostForm(fmt.Sprintf("%v?csrf_token=%v", URL, csrf), url.Values{ "csrf_token": {csrf}, "ftaa": {c.Ftaa}, "bfaa": {c.Bfaa}, @@ -73,9 +74,12 @@ func (c *Client) SubmitContest(contestID, problemID, langID, source string) (err if err != nil { return } - sourceError, err := findErrorSource(body) + errorMessage, err := findErrorMessage(body) if err == nil { - return errors.New(string(sourceError)) + return errors.New(string(errorMessage)) + } + if !bytes.Contains(body, []byte("submitted successfully")) { + return errors.New("Submit failed") } color.Green("Submitted") diff --git a/cmd/cmd.go b/cmd/cmd.go index 98d5b6b2..3b7d1601 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -159,7 +159,7 @@ func getCode(args map[string]interface{}, templates []config.CodeTemplate) (code func getOneCode(args map[string]interface{}, templates []config.CodeTemplate) (name string, index int, err error) { codes := getCode(args, templates) if len(codes) < 1 { - return "", 0, errors.New("Cannot find any supported code\nYou can add some suffixes by `cf config add`") + return "", 0, errors.New("Cannot find any code.\nMaybe you should add a new template by `cf config`") } if len(codes) > 1 { color.Cyan("There are multiple files can be selected.") diff --git a/config/template.go b/config/template.go index 159292ee..90f85574 100644 --- a/config/template.go +++ b/config/template.go @@ -32,7 +32,7 @@ func (c *Config) AddTemplate() (err error) { color.Cyan(`Select a language (e.g. "42"): `) lang := "" for { - lang := util.ScanlineTrim() + lang = util.ScanlineTrim() if val, ok := client.Langs[lang]; ok { color.Green(val) break