Skip to content

Commit

Permalink
- add flag to enable/disable send photos by number feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Romancha committed Feb 15, 2024
1 parent d0a860f commit 487c933
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

## Introduction

The Photo Moments Telegram Bot delivers serendipitous snapshots from your personal collection straight to Telegram, enabling you to fondly reminisce about cherished memories.
The Photo Moments Telegram Bot delivers serendipitous snapshots from your personal collection straight to Telegram,
enabling you to fondly reminisce about cherished memories.

<img src="images/example_photo.jpg" width="400px">
<img src="images/example_photo_info.jpg" width="400px">
Expand Down Expand Up @@ -62,14 +63,15 @@ library [libvips](https://www.libvips.org/).
## Configuration
| Param | Description |
|-------------------------|------------------------------------------------------------------------------------------------------------|
| FM_TG_BOT_TOKEN | Telegram bot token, take from [@BotFather](https://t.me/BotFather) |
| FM_CHAT_ID | Chat ID where the bot will send messages. [@userinfobot](https://t.me/userinfobot) Can help to get chat id |
| FM_ALLOWED_USERS_ID | Telegram user IDs that can use the bot. You can specify multiple id with separator ``;`` |
| FM_PHOTO_PATH | Path to the photo library folder |
| FM_PHOTO_COUNT | The number of photos that the bot will send according to the schedule. Default ``5``, maximum ``10`` |
| FM_SEND_PHOTO_CRON_SPEC | [Cron](https://en.wikipedia.org/wiki/Cron) to send random photos. Default ``0 10 * * *`` |
| Param | Description |
|--------------------------|------------------------------------------------------------------------------------------------------------|
| FM_TG_BOT_TOKEN | Telegram bot token, take from [@BotFather](https://t.me/BotFather) |
| FM_CHAT_ID | Chat ID where the bot will send messages. [@userinfobot](https://t.me/userinfobot) Can help to get chat id |
| FM_ALLOWED_USERS_ID | Telegram user IDs that can use the bot. You can specify multiple id with separator ``;`` |
| FM_PHOTO_PATH | Path to the photo library folder |
| FM_PHOTO_COUNT | The number of photos that the bot will send according to the schedule. Default ``5``, maximum ``10`` |
| FM_SEND_PHOTOS_BY_NUMBER | Send photos by number. Default ``true`` |
| FM_SEND_PHOTO_CRON_SPEC | [Cron](https://en.wikipedia.org/wiki/Cron) to send random photos. Default ``0 10 * * *`` |
## Commands
Expand Down
38 changes: 24 additions & 14 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ var keyBotToken = "FM_TG_BOT_TOKEN"
var keyPhotoCount = "FM_PHOTO_COUNT"
var keyPhotoPath = "FM_PHOTO_PATH"
var keyCronSpec = "FM_SEND_PHOTO_CRON_SPEC"
var keySendPhotosByNumber = "FM_SEND_PHOTOS_BY_NUMBER"
var keyDebug = "FM_DEBUG"

type Config struct {
chatId int64
allowedUserIds []int64
botToken string
photoCount int
photoPath string
cronSpec string
debug bool
chatId int64
allowedUserIds []int64
botToken string
photoCount int
photoPath string
cronSpec string
sendPhotosByNumber bool
debug bool
}

// TODO: rewrite configs with go-flags
func getConfig() Config {

chatIdEnv := os.Getenv(keyChatId)
Expand Down Expand Up @@ -66,19 +69,26 @@ func getConfig() Config {
cronSpec = overrideCronSpec
}

sendPhotosByNumber := false
overrideSendPhotosByNumber, err := strconv.ParseBool(os.Getenv(keySendPhotosByNumber))
if err == nil {
sendPhotosByNumber = overrideSendPhotosByNumber
}

debug := false
debugEnv, err := strconv.ParseBool(os.Getenv(keyDebug))
if err == nil {
debug = debugEnv
}

return Config{
chatId: int64(chatId),
allowedUserIds: allowedUserIds,
botToken: os.Getenv(keyBotToken),
photoCount: parsedCount,
photoPath: photoLibPath,
cronSpec: cronSpec,
debug: debug,
chatId: int64(chatId),
allowedUserIds: allowedUserIds,
botToken: os.Getenv(keyBotToken),
photoCount: parsedCount,
photoPath: photoLibPath,
cronSpec: cronSpec,
sendPhotosByNumber: sendPhotosByNumber,
debug: debug,
}
}
17 changes: 9 additions & 8 deletions lang/ru/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ volumes:
## Конфигурация
| Параметр | Описание |
|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| FM_TG_BOT_TOKEN | Токен телеграм бота, полученный у [@BotFather](https://t.me/BotFather) |
| FM_CHAT_ID | Идентификатор чата, куда бот будет слать уведомления. Можно воспользоваться [@userinfobot](https://t.me/userinfobot) для получения id |
| FM_ALLOWED_USERS_ID | Идентификаторы пользователей телеграм, которые могут пользоваться ботом. Можно указать несколько id с разделителем ``;`` |
| FM_PHOTO_PATH | Путь до папки с библиотекой фотографий |
| FM_PHOTO_COUNT | количество фотографий, которое будет отправлено ботом по расписанию. По умолчанию ``5``, максимум ``10`` |
| FM_SEND_PHOTO_CRON_SPEC | Расписание [Cron](https://en.wikipedia.org/wiki/Cron) для отправки случайных фотографий. По умолчанию ``0 10 * * *`` |
| Параметр | Описание |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| FM_TG_BOT_TOKEN | Токен телеграм бота, полученный у [@BotFather](https://t.me/BotFather) |
| FM_CHAT_ID | Идентификатор чата, куда бот будет слать уведомления. Можно воспользоваться [@userinfobot](https://t.me/userinfobot) для получения id |
| FM_ALLOWED_USERS_ID | Идентификаторы пользователей телеграм, которые могут пользоваться ботом. Можно указать несколько id с разделителем ``;`` |
| FM_PHOTO_PATH | Путь до папки с библиотекой фотографий |
| FM_PHOTO_COUNT | количество фотографий, которое будет отправлено ботом по расписанию. По умолчанию ``5``, максимум ``10`` |
| FM_SEND_PHOTOS_BY_NUMBER | Отправка фотографий по числу. По умолчанию ``true`` |
| FM_SEND_PHOTO_CRON_SPEC | Расписание [Cron](https://en.wikipedia.org/wiki/Cron) для отправки случайных фотографий. По умолчанию ``0 10 * * *`` |
## Команды
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ func main() {
}

// If user send a number, send that many random photos
userPhotoCount, parseUserCountErr := strconv.Atoi(update.Message.Text)
if parseUserCountErr == nil {
sendRandomPhoto(userPhotoCount, &update, bot)
if cfg.sendPhotosByNumber {
userPhotoCount, parseUserCountErr := strconv.Atoi(update.Message.Text)
if parseUserCountErr == nil {
sendRandomPhoto(userPhotoCount, &update, bot)
}
}
}
}
Expand Down

0 comments on commit 487c933

Please sign in to comment.