Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Mar 29, 2024
2 parents 8016445 + 07216db commit c1c7e9b
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 38 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ func main() {
},
{
Text: "app",
Description: "Manage Subscriptions and Publishing in Application",
Description: "Manage Queries and Publishing in Application",
},
{
Text: "pub",
Description: "Publish a basic Message",
},
{
Text: "sub",
Description: "Subscribe for Keywords",
Description: "Query for Keywords",
},
{
Text: "donate",
Expand Down
2 changes: 1 addition & 1 deletion service/chats/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
14 changes: 5 additions & 9 deletions service/chats/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/messages/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion service/subscriptions/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions service/subscriptions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
"<pre>Wishlist1 tesla iphone</pre>"
const msgSubCreated = "If you want to read it in another chat, unlink it first using the <pre>/start</pre> 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}+`)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion service/subscriptions/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions service/subscriptions/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions service/subscriptions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"https://awakari.com/login.html\" target=\"_blank\">app</a> to manage. "+
"Select one or more to read in this chat:",
m, telebot.ModeHTML,
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions service/subscriptions/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"https://awakari.com/login.html\" target=\"blank\">app</a> to manage own subscriptions."
"Use the <a href=\"https://awakari.com/login.html\" target=\"blank\">app</a> to manage own queries."

var deliveryIntervalRows = [][]string{
{
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions service/subscriptions/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions service/usage/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c1c7e9b

Please sign in to comment.