From 7ce679d241732676d4068841cd2f56807f8debac Mon Sep 17 00:00:00 2001 From: Andrei Kurilov <18027129+akurilov@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:11:04 +0200 Subject: [PATCH] chore: rename subscriptions to queries in UI --- main.go | 4 ++-- service/chats/error.go | 2 +- service/chats/reader.go | 14 +++++--------- service/messages/format.go | 2 +- service/subscriptions/condition.go | 2 +- service/subscriptions/create.go | 14 +++++++------- service/subscriptions/description.go | 2 +- service/subscriptions/extend.go | 10 +++++----- service/subscriptions/list.go | 4 ++-- service/subscriptions/start.go | 8 ++++---- service/subscriptions/stop.go | 4 ++-- service/usage/limits.go | 6 +++--- 12 files changed, 34 insertions(+), 38 deletions(-) diff --git a/main.go b/main.go index 1df8964..59c49f5 100644 --- a/main.go +++ b/main.go @@ -249,7 +249,7 @@ func main() { }, { Text: "app", - Description: "Manage Subscriptions and Publishing in Application", + Description: "Manage Queries and Publishing in Application", }, { Text: "pub", @@ -257,7 +257,7 @@ func main() { }, { Text: "sub", - Description: "Subscribe for Keywords", + Description: "Query for Keywords", }, { Text: "donate", diff --git a/service/chats/error.go b/service/chats/error.go index ff0bd1a..61f875a 100644 --- a/service/chats/error.go +++ b/service/chats/error.go @@ -3,5 +3,5 @@ package chats import "errors" var ErrAlreadyExists = errors.New("chat already exists") -var ErrNotFound = errors.New("chat or subscription not found") +var ErrNotFound = errors.New("chat or query not found") var ErrInternal = errors.New("internal failure") diff --git a/service/chats/reader.go b/service/chats/reader.go index c345f17..fa8c46b 100644 --- a/service/chats/reader.go +++ b/service/chats/reader.go @@ -35,13 +35,9 @@ const msgFmtReadOnceFailed = "unexpected failure: %s\ndon't worry, retrying in % const backOffInit = 1 * time.Second const backOffFactor = 3 const backOffMax = 24 * time.Hour -const msgExpired = "⚠ The subscription has been expired." -const msgExpiresSoon = "⏳ The subscription expires in %s." -const msgFmtExtendSteps = ` Please consider the following steps to extend it: -1. Go to your private chat with @AwakariBot. -2. Tap the "Subscriptions" reply keyboard button. -3. Select the subscription "%s". -4. Tap the "▲ Extend" button.` +const msgExpired = "⚠ The query has been expired." +const msgExpiresSoon = "⏳ The query expires in %s." +const msgFmtExtendSteps = " Please extend it." const resumeBatchSize = 16 const minIntervalLimit = 1 * time.Second const day = 24 * time.Hour @@ -195,7 +191,7 @@ func (r *reader) runOnce() (err error) { case errors.Is(err, api.ErrApiDisabled): fallthrough case errors.Is(err, clientAwkApiReader.ErrNotFound): - _ = r.tgCtx.Send(fmt.Sprintf("failed to read by subscription: %s, cause: %s, stopping", err, r.subId)) + _ = r.tgCtx.Send(fmt.Sprintf("failed to read by query: %s, cause: %s, stopping", err, r.subId)) _ = r.chatStor.UnlinkSubscription(ctx, r.subId) r.stop = true err = nil @@ -254,7 +250,7 @@ func (r *reader) deliverEventsRead( } } case codes.NotFound: - _ = r.tgCtx.Send(fmt.Sprintf("subscription %s doesn't exist, stopping", r.subId)) + _ = r.tgCtx.Send(fmt.Sprintf("query %s doesn't exist, stopping", r.subId)) _ = r.chatStor.UnlinkSubscription(ctx, r.subId) r.stop = true err = nil diff --git a/service/messages/format.go b/service/messages/format.go index 7a75e09..c99f1f1 100644 --- a/service/messages/format.go +++ b/service/messages/format.go @@ -115,7 +115,7 @@ func (f Format) convert(evt *pb.CloudEvent, subDescr string, mode FormatMode, tr if txt == "" && attrNameFound { txt = fmt.Sprintf("%s\n\n", attrName.GetCeString()) } - txt += fmt.Sprintf("Subscription: %s\n\nsource: %s\n", subDescr, evt.Source) + txt += fmt.Sprintf("Query: %s\n\nsource: %s\n", subDescr, evt.Source) var attrsTxt string if attrs { attrsTxt = f.convertExtraAttrs(evt, mode, trunc) diff --git a/service/subscriptions/condition.go b/service/subscriptions/condition.go index 5056672..70554d1 100644 --- a/service/subscriptions/condition.go +++ b/service/subscriptions/condition.go @@ -51,7 +51,7 @@ func (ch ConditionHandler) Update(tgCtx telebot.Context, args ...string) (err er err = ch.ClientAwk.UpdateSubscription(groupIdCtx, userId, subId, sd) } if err == nil { - _ = tgCtx.Send("Subscription updated.") + _ = tgCtx.Send("Query updated.") } return } diff --git a/service/subscriptions/create.go b/service/subscriptions/create.go index 97e9696..3a064bd 100644 --- a/service/subscriptions/create.go +++ b/service/subscriptions/create.go @@ -27,13 +27,13 @@ const maxTextCondTermsLength = 256 const expiresDefaultDuration = time.Hour * 24 * usage.ExpiresDefaultDays // ~ month const ReqSubCreate = "sub_create" -const msgSubCreate = "Creating a basic subscription with a single text matching condition. " + +const msgSubCreate = "Creating a simple text query. " + "Reply a name followed by keywords to the next message. Example:\n" + "
Wishlist1 tesla iphone
" const msgSubCreated = "If you want to read it in another chat, unlink it first using the
/start
command." -var errCreateSubNotEnoughArgs = errors.New("not enough arguments to create a text subscription") -var errInvalidCondition = errors.New("invalid subscription condition") +var errCreateSubNotEnoughArgs = errors.New("not enough arguments to create a text query") +var errInvalidCondition = errors.New("invalid query condition") var errLimitReached = errors.New("limit reached") var whiteSpaceRegex = regexp.MustCompile(`\p{Zs}+`) @@ -80,12 +80,12 @@ func CreateBasicReplyHandlerFunc( if err == nil { err = requestDeliveryInterval(tgCtx, subId) } else { - err = fmt.Errorf("failed to create the subscription:\n%w", err) + err = fmt.Errorf("failed to create the query:\n%w", err) } if err == nil { err = tgCtx.Send(msgSubCreated, telebot.ModeHTML) } else { - err = fmt.Errorf("failed to link the created subscription to this chat:\n%w", err) + err = fmt.Errorf("failed to link the created query to this chat:\n%w", err) } return } @@ -136,7 +136,7 @@ func decodeNumOp(src subscriptions.Operation) (dst condition.NumOp) { func validateSubscriptionData(sd subscription.Data) (err error) { if sd.Description == "" { - err = errors.New("invalid subscription:\nempty description") + err = errors.New("invalid query:\nempty description") } if err == nil { err = validateCondition(sd.Condition) @@ -151,7 +151,7 @@ func validateCondition(cond condition.Condition) (err error) { countChildren := len(children) if tc.GetLogic() == condition.GroupLogicOr && countChildren > limitGroupOrCondChildrenCount { err = fmt.Errorf( - "%w:\nchildren condition count for the group condition with \"Or\" logic is %d, limit is %d,\nconsider to use an additional subscription instead", + "%w:\nchildren condition count for the group condition with \"Or\" logic is %d, limit is %d,\nconsider to use an additional query instead", errInvalidCondition, countChildren, limitGroupOrCondChildrenCount, diff --git a/service/subscriptions/description.go b/service/subscriptions/description.go index ddae0a3..f2ae70e 100644 --- a/service/subscriptions/description.go +++ b/service/subscriptions/description.go @@ -51,7 +51,7 @@ func DescriptionReplyHandlerFunc(clientAwk api.Client, groupId string) service.A } if err == nil { // force reply removes the keyboard, hence don't forget to restore it - err = tgCtx.Send(fmt.Sprintf("Subscription description changed to \"%s\"", descr)) + err = tgCtx.Send(fmt.Sprintf("Query description changed to \"%s\"", descr)) } return } diff --git a/service/subscriptions/extend.go b/service/subscriptions/extend.go index 56d0bb9..64503d5 100644 --- a/service/subscriptions/extend.go +++ b/service/subscriptions/extend.go @@ -29,7 +29,7 @@ const CmdExtend = "extend" const ReqSubExtend = "sub_extend" const daysMin = 10 const daysMax = 365 -const msgFmtRunOnceFailed = "failed to extend subscription, id: %s, user id: %s, cause: %s, retrying in: %s" +const msgFmtRunOnceFailed = "failed to extend the query, id: %s, user id: %s, cause: %s, retrying in: %s" type ExtendHandler struct { CfgPayment config.PaymentConfig @@ -90,8 +90,8 @@ func (eh ExtendHandler) HandleExtensionReply(tgCtx telebot.Context, args ...stri price := int(float64(countDays) * eh.CfgPayment.Price.Subscription.Extension * eh.CfgPayment.Currency.SubFactor) invoice := telebot.Invoice{ Start: uuid.NewString(), - Title: "Subscription Extension", - Description: fmt.Sprintf("Subscription %s: extend by %d days", subId, countDays), + Title: "Query Extension", + Description: fmt.Sprintf("Query %s: extend by %d days", subId, countDays), Payload: string(orderData), Currency: eh.CfgPayment.Currency.Code, Prices: []telebot.Price{ @@ -146,12 +146,12 @@ func (eh ExtendHandler) ExtendPaid(tgCtx telebot.Context, args ...string) (err e err = backoff.RetryNotify(e.runOnce, b, func(err error, d time.Duration) { eh.Log.Warn(fmt.Sprintf(msgFmtRunOnceFailed, op.SubId, userId, err, d)) if d > 1*time.Second { - _ = tgCtx.Send("Extending the subscription, please wait...") + _ = tgCtx.Send("Extending the query, please wait...") } }) } if err == nil { - err = tgCtx.Send(fmt.Sprintf("Subscription has been successfully extended by %d days", op.DaysAdd)) + err = tgCtx.Send(fmt.Sprintf("Query has been successfully extended by %d days", op.DaysAdd)) } return } diff --git a/service/subscriptions/list.go b/service/subscriptions/list.go index f5bfea3..b53ec7c 100644 --- a/service/subscriptions/list.go +++ b/service/subscriptions/list.go @@ -21,7 +21,7 @@ func ListOnGroupStartHandlerFunc(clientAwk api.Client, chatStor chats.Storage, g m, err = listButtons(groupIdCtx, userId, clientAwk, chatStor, tgCtx.Chat().ID, CmdStart, "") if err == nil { err = tgCtx.Send( - "Own subscriptions list. "+ + "Own queries list. "+ "Use the app to manage. "+ "Select one or more to read in this chat:", m, telebot.ModeHTML, @@ -42,7 +42,7 @@ func PageNext(clientAwk api.Client, chatStor chats.Storage, groupId string) serv var m *telebot.ReplyMarkup m, err = listButtons(groupIdCtx, userId, clientAwk, chatStor, tgCtx.Chat().ID, args[0], cursor) if err == nil { - err = tgCtx.Send("Own subscriptions list page:", m, telebot.ModeHTML) + err = tgCtx.Send("Own queries list page:", m, telebot.ModeHTML) } return } diff --git a/service/subscriptions/start.go b/service/subscriptions/start.go index c342705..7abadbe 100644 --- a/service/subscriptions/start.go +++ b/service/subscriptions/start.go @@ -16,9 +16,9 @@ import ( ) const CmdStart = "sub_start" -const msgFmtChatLinked = "Linked the subscription \"%s\" to this chat. " + +const msgFmtChatLinked = "Linked the query \"%s\" to this chat. " + "New matching messages will appear here with a minimum interval of %s. " + - "Use the app to manage own subscriptions." + "Use the app to manage own queries." var deliveryIntervalRows = [][]string{ { @@ -75,7 +75,7 @@ func requestDeliveryInterval(tgCtx telebot.Context, subId string) (err error) { rows = append(rows, row) } m.Inline(rows...) - err = tgCtx.Send("Choose the minimum interval for the message delivery for this subscription:", m) + err = tgCtx.Send("Choose the minimum interval for the message delivery for this query:", m) return } @@ -102,7 +102,7 @@ func start( err = chatStor.LinkSubscription(context.TODO(), chat) switch { case errors.Is(err, chats.ErrAlreadyExists): - err = errors.New("the chat is already linked to a subscription, try to use another group chat") + err = errors.New("the chat is already linked to a query, try to use another group chat") } } var subData subscription.Data diff --git a/service/subscriptions/stop.go b/service/subscriptions/stop.go index 52fb025..d045e90 100644 --- a/service/subscriptions/stop.go +++ b/service/subscriptions/stop.go @@ -16,9 +16,9 @@ func Stop(chatStor chats.Storage) service.ArgHandlerFunc { err = chatStor.UnlinkSubscription(context.Background(), subId) if err == nil { if chats.StopChatReader(subId) { - _ = tgCtx.Send("Unlinked the subscription from this chat") + _ = tgCtx.Send("Unlinked the query from this chat") } else { - _ = tgCtx.Send(fmt.Sprintf("Unlinked the subscription from this chat. Note: don't delete this group for the next %s. Some new messages may appear here.", chats.ReaderTtl)) + _ = tgCtx.Send(fmt.Sprintf("Unlinked the query from this chat. Note: don't delete this group for the next %s. Some new messages may appear here.", chats.ReaderTtl)) } } return diff --git a/service/usage/limits.go b/service/usage/limits.go index 5eb36f6..8f5947d 100644 --- a/service/usage/limits.go +++ b/service/usage/limits.go @@ -57,7 +57,7 @@ func (lh LimitsHandler) RequestExtension(tgCtx telebot.Context, args ...string) //case usage.SubjectSubscriptions: // err = tgCtx.Send( // fmt.Sprintf( - // "The limit extension price is %s %.2f per day per subscription starting from 2nd. "+ + // "The limit extension price is %s %.2f per day per query starting from 2nd. "+ // "Reply with the count of days to add:", // lh.CfgPayment.Currency.Code, // lh.CfgPayment.Price.Subscription.CountLimit, @@ -220,7 +220,7 @@ func formatUsageSubject(subj usage.Subject) (s string) { case usage.SubjectPublishEvents: s = "Message Daily Publications" case usage.SubjectSubscriptions: - s = "Subscriptions Count" + s = "Queries Count" default: s = "undefined" } @@ -249,7 +249,7 @@ func (lh LimitsHandler) RequestIncrease(tgCtx telebot.Context, args ...string) ( err = tgCtx.Send( fmt.Sprintf( // TODO: uncomment the code below only when payments are in use - //"The price is %s %.2f per day per additional subscription. "+ + //"The price is %s %.2f per day per additional query. "+ "Reply the count to add to the current limit:", // TODO: uncomment the code below only when payments are in use //lh.CfgPayment.Currency.Code,