feat: add retry button

This commit is contained in:
Yiyang Kang 2023-03-08 16:20:11 +08:00
parent 672cd8b575
commit daa0c86d09
Signed by: kkyy
GPG Key ID: 80FD317ECAF06CC3
1 changed files with 8 additions and 1 deletions

View File

@ -19,8 +19,11 @@ var (
translateBtnEn = translateMenu.Data("English", "btn_tr_en", "English") translateBtnEn = translateMenu.Data("English", "btn_tr_en", "English")
translateBtnJa = translateMenu.Data("日本語", "btn_tr_ja", "Japanese") translateBtnJa = translateMenu.Data("日本語", "btn_tr_ja", "Japanese")
translateBtnRetry = translateMenu.Data("Try again", "btn_tr_retry")
translateBtns = []*tele.Btn{ translateBtns = []*tele.Btn{
&translateBtnZhTw, &translateBtnZhCn, &translateBtnEn, &translateBtnJa, &translateBtnZhTw, &translateBtnZhCn, &translateBtnEn, &translateBtnJa,
&translateBtnRetry,
} }
translateCmdRe = regexp.MustCompile(`^\s*\/tr(anslate)?(@\S*)?\s*`) translateCmdRe = regexp.MustCompile(`^\s*\/tr(anslate)?(@\S*)?\s*`)
@ -103,7 +106,11 @@ func handleTranslateBtn(c tele.Context) error {
} }
respText := resp.Choices[0].Message.Content respText := resp.Choices[0].Message.Content
_, err = c.Bot().Reply(origMsg, respText, tele.Silent) retryBtn := translateBtnRetry
retryBtn.Data = targetLang
respMenu := &tele.ReplyMarkup{}
respMenu.Inline(respMenu.Row(retryBtn))
_, err = c.Bot().Reply(origMsg, respText, tele.Silent, respMenu)
// delete the temporary message // delete the temporary message
if err := c.Delete(); err != nil { if err := c.Delete(); err != nil {