|
5 | 5 | "fmt" |
6 | 6 | "slices" |
7 | 7 | "strconv" |
| 8 | + "strings" |
8 | 9 | "sync" |
9 | 10 | "time" |
10 | 11 |
|
|
22 | 23 | GetSubscribersByOffset(ctx context.Context, botID int64, offset int32) (chatIDs []int64, _ error) |
23 | 24 | GetPrayerDay(ctx context.Context, botID int64, date time.Time) (prayerDay *domain.PrayerDay, _ error) |
24 | 25 | SetReminderMessageID(ctx context.Context, botID int64, chatID int64, reminderMessageID int32) error |
| 26 | + DeleteChat(ctx context.Context, botID int64, chatID int64) error |
25 | 27 | } |
26 | 28 |
|
27 | 29 | Handler struct { |
@@ -215,6 +217,17 @@ func (h *Handler) remindUser( |
215 | 217 | ParseMode: models.ParseModeMarkdown, |
216 | 218 | }) |
217 | 219 | if err != nil { |
| 220 | + if strings.HasPrefix(err.Error(), bot.ErrorForbidden.Error()) { |
| 221 | + // bot was blocked or user is deactivated so delete chat |
| 222 | + err = h.db.DeleteChat(ctx, chat.BotID, chat.ChatID) |
| 223 | + if err != nil { |
| 224 | + log.Error("remindUser: delete chat", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID)) |
| 225 | + return fmt.Errorf("remindUser: delete chat: %v", err) |
| 226 | + } |
| 227 | + log.Warn("remindUser: delete chat", log.BotID(chat.BotID), log.ChatID(chat.ChatID)) |
| 228 | + return nil |
| 229 | + } |
| 230 | + |
218 | 231 | log.Error("remindUser: send message", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID)) |
219 | 232 | return fmt.Errorf("remindUser: send message: %v", err) |
220 | 233 | } |
|
0 commit comments