Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
441 commits
Select commit Hold shift + click to select a range
cfdae9e
Migrate to TikTok node/share/video api
ailinykh Aug 25, 2021
d985d51
Get rid of opengraph parser
ailinykh Aug 25, 2021
e7f7ae1
log error right in place
ailinykh Aug 25, 2021
548af7a
Retreive youtube thumbnails from ffmpeg converting
ailinykh Aug 25, 2021
3618de3
Add ability to check that user is member of the chat
ailinykh Aug 25, 2021
167fedc
Add test for checking winner left the chat
ailinykh Aug 26, 2021
4498432
Move Player and Round infrastructure models into one file
ailinykh Aug 26, 2021
ce988fe
Add UpdatePlayer method to IGameStorage protocol
ailinykh Aug 27, 2021
b10d1d7
Add ability to update player info using /pidoreg command
ailinykh Aug 27, 2021
5f61341
Do not use Username as primary key
ailinykh Aug 27, 2021
df6aa88
go get -u; go mod tidy
ailinykh Aug 27, 2021
0c98977
Do not call makeMessage before error check
ailinykh Aug 27, 2021
140bdb9
Fix IsUserMemberOfChat telebot implementation
ailinykh Aug 28, 2021
f808d97
Add ability to set header for any http reuest
ailinykh Sep 1, 2021
6745f84
Add .mp4 suffix to upload media strategy file if not present
ailinykh Sep 1, 2021
fc197db
TikTok flow updated for HTML parsing
ailinykh Sep 1, 2021
e0f9d24
Use separate http client for TikTok flow
ailinykh Sep 1, 2021
7a01d7b
Add custom CookieJar implementation which stores all the cookies in j…
ailinykh Sep 1, 2021
5496c65
TikTok flow handles 404 server response
ailinykh Sep 1, 2021
0d2a18d
A little code refactoring
ailinykh Sep 1, 2021
95ba2ce
TikTok flow code refactoring
ailinykh Sep 1, 2021
52d470c
Rename l (localizer) to t (translate)
ailinykh Sep 1, 2021
f3969f8
Add logger as a dependency to faggot game
ailinykh Sep 1, 2021
29b6174
Update player info in case of first, last or username mismatch
ailinykh Sep 1, 2021
ef160cb
More logs for game
ailinykh Sep 1, 2021
b27ab94
Use DisplayName() everywhere instead of Username
ailinykh Sep 2, 2021
6a83029
Fix mistake with using Errorf instead of Infof
ailinykh Sep 2, 2021
bf5b295
Move TelebotAdapter creation into makeIBot factory
ailinykh Sep 4, 2021
b09b51f
Create IRand protocol
ailinykh Sep 9, 2021
2724e56
Create math/rand implementation of IRand protocol
ailinykh Sep 9, 2021
10b126f
Use Rand protocol as game dependency
ailinykh Sep 9, 2021
d56ef99
Change loglevel of ffprobe invocation to panic
ailinykh Sep 14, 2021
960e015
Respect youtube age restriction policy
ailinykh Sep 29, 2021
6eae1a0
Change youtube message removing strategy (#23)
ailinykh Oct 16, 2021
ae4a830
Tests for image flow (#24)
ailinykh Oct 18, 2021
8bed6a8
Link flow initial tests added (#25)
ailinykh Oct 21, 2021
de5100d
Rename some files in test helpers (#26)
ailinykh Oct 21, 2021
9458825
Add logger to twitter_parser
ailinykh Nov 11, 2021
f31118d
Update ffmpeg version in Dockerfile
ailinykh Nov 24, 2021
1904187
The `stats` command should display only top 10 winners
ailinykh Nov 24, 2021
dcee0c7
TikTok: move response struct closer to unmarshal
ailinykh Dec 14, 2021
96e91dd
Print source and destination files codec as well
ailinykh Dec 14, 2021
3340d1a
More informative message on video proccessing step
ailinykh Dec 15, 2021
f18ebd6
Fix accidentally removing message
ailinykh Jan 2, 2022
efed0d0
return error in cacse of adge resrtriction
ailinykh Jan 2, 2022
f14fdb4
fix incorrect total player count
ailinykh Jan 5, 2022
82304ff
Move tiktok api call into a separate file
ailinykh Jan 5, 2022
d7d8cd4
Update tiktok api debug line
ailinykh Jan 5, 2022
3403de3
Make ITikTokAPI Get method return TikTokResponce instead of TikTokHTM…
ailinykh Jan 5, 2022
1482e5a
Rename ttf to flow
ailinykh Jan 5, 2022
1f68c8c
Rename TikTokAPI to TikTokWebAPI
ailinykh Jan 5, 2022
6c75baf
Add core.Rand dependency to TikTokWebAPI
ailinykh Jan 5, 2022
6a6873f
Extract random digits generation into a separate function
ailinykh Jan 5, 2022
07e467a
Rename tf to just in twitter_flow.go
ailinykh Jan 6, 2022
49abd28
Refactor tiktok web api to ore.IMediaFactory
ailinykh Jan 7, 2022
72c03b1
Create domain specific http client for tiktok
ailinykh Jan 7, 2022
9fbe09c
Rename tiktok web api to tik tok html api
ailinykh Jan 7, 2022
8757628
Add tiktok json api as alternative to tiktok html api
ailinykh Jan 7, 2022
5ae317e
attempt to fix build
ailinykh Jan 7, 2022
10176dd
Add tiktok media factory composing two APIs
ailinykh Jan 8, 2022
96d3303
Add tiktok api as separate file to extract all the network related st…
ailinykh Jan 8, 2022
bf9c58b
Change tiktok api item info signature
ailinykh Jan 8, 2022
9fa3f2b
Migrate to tiktok_api struct in tiktok media factory
ailinykh Jan 8, 2022
d633143
Add an ITikTokAPI interface
ailinykh Jan 8, 2022
a1a9345
Implement ITikTokAPI interface as TikTokJsonAPI
ailinykh Jan 8, 2022
fbe5f00
Implement ITikTokAPI interface as TikTokHTMLAPI
ailinykh Jan 8, 2022
7080e1a
Change implementation TikTokAPI with abstract interface ITikTokAPI
ailinykh Jan 8, 2022
d3bed0f
Add twitter api debug information
ailinykh Jan 15, 2022
5c800e2
Use QuotedStatus media with current tweet description and author
ailinykh Jan 15, 2022
a6cffc7
Add rabbitmq with core.task and default implementation
ailinykh Jan 16, 2022
d74d08b
Update build.yml
ailinykh Jan 16, 2022
788cea3
Add new workflow in docker compose files
ailinykh Jan 16, 2022
02d1f83
Add twitter screenshot logic for tweets without media
ailinykh Jan 16, 2022
9f287e0
Respect caption when creating tb.Video from FileID
ailinykh Jan 31, 2022
1b45689
Add `ReplyTo` field to core.Message
ailinykh Jan 31, 2022
04cd78f
Extend `core.Message` with `Video` field
ailinykh Jan 31, 2022
a13db0d
Add rabbitmq connection close handler
ailinykh Feb 10, 2022
aa23587
Add `rand_string_runes.go` to helpers
ailinykh Feb 12, 2022
677240f
Migrate move helpers.go file from api to helpers package
ailinykh Feb 12, 2022
0800a31
Add initial settings struct and `ISettingsStorage` protocol
ailinykh Feb 13, 2022
5247efd
Add `SettingsStorage` as one of `ISettingsStorage` implementation
ailinykh Feb 13, 2022
f8c0ce9
Rename variables in link flow
ailinykh Feb 13, 2022
7ddf23d
Move delete source message logic from link flow to remove_source_deco…
ailinykh Feb 13, 2022
7e12170
Temporary turn off `removeLinkSourceDecorator` to fix issue
ailinykh Feb 13, 2022
b22a232
Fix for `linkFlow` not implemented error handling
ailinykh Feb 13, 2022
486a5f0
Rename variables in `youtube_flow.go`
ailinykh Feb 13, 2022
f7aa509
Add `ISendVideoStrategy` protocol
ailinykh Feb 13, 2022
dd8689a
Add `SendVideoStrategy` struct as an implementation of `ISendVideoStr…
ailinykh Feb 13, 2022
0b248df
Add `SendVideoStrategySplitDecorator` for spliting video into parts
ailinykh Feb 13, 2022
ba3dac2
Use `ISendVideoStrategy` in youtube flow
ailinykh Feb 13, 2022
36bb613
Replace `errors.New` with `fmt.Errorf`
ailinykh Feb 13, 2022
a8c8d76
Obtain settings right before it needed
ailinykh Feb 13, 2022
df8056a
Use `RemoveSourceDecorator` in youtube flow
ailinykh Feb 13, 2022
6010656
Change twitter flow remove original message logic
ailinykh Feb 13, 2022
b8ff9c2
get rid of one redundant test since remove logic was moved to decorator
ailinykh Feb 14, 2022
eec9e63
rename to in image_flow.go
ailinykh Feb 15, 2021
a5430d7
rename variables in image_flow.go
ailinykh Feb 15, 2021
807a685
rename variables in tiktok_flow.go
ailinykh Feb 15, 2021
e214df3
rename variables in twitter_flow.go
ailinykh Feb 15, 2021
f7d7abd
rename variables in twitter_parser.go
ailinykh Feb 16, 2021
5815f60
rename method to in ITweetHandler protocol
ailinykh Feb 16, 2021
12c3dad
rename variables in twitter_timeout.go
ailinykh Feb 18, 2021
9c0c918
rename variables in video_flow.go
ailinykh Feb 20, 2022
b93aad8
Reestablish rabbitmq connection on close
ailinykh Mar 9, 2022
f5672a9
inline keyboard implementation added
ailinykh Mar 13, 2022
8cb1ece
Add Edit method to IBot interface
ailinykh Mar 13, 2022
86b37d8
Add ability to edit message text and buttons at the same time
ailinykh Mar 13, 2022
0dc031d
Replace `AllButtons` method with `GetButtonIds` to be able to localiz…
ailinykh Mar 13, 2022
69d525a
Added instagram reels processing
ailinykh Mar 15, 2022
7bea9c3
Add remove source decorator for instagram reels flow
ailinykh Mar 15, 2022
5179926
Remove redundant log message
ailinykh Mar 15, 2022
f37286a
Fix incorrect settings storage data saved
ailinykh Mar 16, 2022
92ae359
Extend default settings with payload array of strings
ailinykh Mar 16, 2022
df112ae
Move LocalizerMock into a separate file
ailinykh Mar 16, 2022
0252247
Make ChatID primary key
ailinykh Mar 16, 2022
35a4271
Add fake settings storage for test cases
ailinykh Mar 16, 2022
24acef9
Welcome message and `/start` command added with ability to save payload
ailinykh Mar 17, 2022
c21d452
Extend command with settings upadate
ailinykh Mar 18, 2022
6a362cc
Ugrade handler from command to text handler
ailinykh Mar 18, 2022
0082976
Avoid multiple settings records on bot launch
ailinykh Mar 19, 2022
e1fae2d
More logs in `/start` command handler
ailinykh Mar 19, 2022
84fb5e0
Add `IUserStorage` interface to persist user info
ailinykh Mar 20, 2022
ce0c84c
Add `UserStorage` gorm implemetration
ailinykh Mar 20, 2022
59f2c89
Add `FakeUserStorage` for test cases
ailinykh Mar 20, 2022
3578366
Add user cache to `/start` command
ailinykh Mar 20, 2022
d618e00
Create custom `UserID` type as alias to `int`
ailinykh Mar 20, 2022
cefb395
Add `gorm:"autoUpdateTime"` to settings struct
ailinykh Mar 20, 2022
0e69261
typo fixed
ailinykh Mar 20, 2022
01daa14
Add `OutlineAPI` struct for outline server communication
ailinykh Mar 21, 2022
42f4673
Add `OutlineStorage` for storing keys in the database
ailinykh Mar 21, 2022
5242dc6
Add `OutlineVpnFacade` for composing outline storage and outline api
ailinykh Mar 21, 2022
abc9a33
Add `VpnKey` struct and `IVpnAPI` for key management
ailinykh Mar 21, 2022
cac98f0
Add `VpnLocalizer` for the whole vpn key management process localization
ailinykh Mar 21, 2022
cef3a5e
Add `OutlineVpnFlow` as interface between bot and vpn key manager
ailinykh Mar 21, 2022
531a212
Ignore "not implemented" error reports
ailinykh Mar 21, 2022
47d7685
Add `Chat` struct for chat info representation
ailinykh Mar 22, 2022
b4dc495
Replace `Message.ChatID` field with `Chat` struct
ailinykh Mar 22, 2022
e5b165a
Add `IChatStorage` interface for chat data persisting
ailinykh Mar 22, 2022
6dd9c29
Add `ChatStorage` sqlite implementation of `IChatStorage`
ailinykh Mar 22, 2022
c307f4c
Add `FakeChatStorage` implementation of `IChatStorage` for testing
ailinykh Mar 22, 2022
5886e5f
Return "record not found" error in test_helpers
ailinykh Mar 22, 2022
5209241
Make `Users` accessible in `FakeUserStorage`
ailinykh Mar 22, 2022
8f8f302
Extend `IChatStorage` interface with `UpdateSettings` method
ailinykh Mar 22, 2022
8ee4150
Make `Chats` variable accessible from outside in test_helpers
ailinykh Mar 22, 2022
4d1f43d
Test `StartFlow` async creating user and chat data
ailinykh Mar 22, 2022
ebdb47d
Remove `ISettingsStorage` from `StartFlow`
ailinykh Mar 22, 2022
baa2942
More traces in `UserStorage` create user method
ailinykh Mar 22, 2022
efff742
Fix update settings method logic in `ChatStorage`
ailinykh Mar 22, 2022
9c6b78a
Remove settingsCache from `StartFlow` since it deprecated
ailinykh Mar 22, 2022
ae796c9
Refactor `start_flow` methods to more plain signatures
ailinykh Mar 24, 2022
05e993c
Refactor `Makefile` and move executable file to `bin` directory
ailinykh Mar 24, 2022
b4b9ad3
Upgrade `go` version up to 1.17
ailinykh Mar 24, 2022
96a5bfa
Rollback Dockerfile `/bin/` path
ailinykh Mar 24, 2022
95371dd
Update build.yml
ailinykh Mar 24, 2022
23e5177
revert build.yaml
ailinykh Mar 24, 2022
58fdf9b
Merge branch 'master' of https://github.com/ailinykh/pullanusbot
ailinykh Mar 24, 2022
528a848
Upgrade all `go.mod` depeendencies
ailinykh Mar 24, 2022
2d1073d
Change User ID from `int` to `int64`
ailinykh Mar 24, 2022
d5c2f25
Upgrade `telebot` to version 3
ailinykh Mar 25, 2022
c2e864c
Remove deprecacted `ISettingsStorage` protocol
ailinykh Mar 25, 2022
c2ffe48
Add `InMemoryUserStorage` for chace user data
ailinykh Mar 26, 2022
9c0edf7
Add `UserStorageDecorator` to fallback between different user storages
ailinykh Mar 26, 2022
395d4ec
Combine inmemory and database user storage in composition root
ailinykh Mar 26, 2022
84c604e
Remove redundant users cache from `StartFlow`
ailinykh Mar 26, 2022
094d220
Add database user `CreatedAt` and `UpdatedAt` fields
ailinykh Mar 26, 2022
4976ad0
Increase performance in `telebot` core message and bot factory
ailinykh Mar 26, 2022
4865639
Add `InMemoryChatStorage` for chat info cache
ailinykh Mar 26, 2022
17c54ba
Fix `InMemoryUserStorage` create user method return error
ailinykh Mar 26, 2022
4de32eb
Update `UserStorageDecorator` to work with cache and database storage
ailinykh Mar 26, 2022
1ef8ae1
Add `ChatStorageDecorator` to combine cache and database chat logic
ailinykh Mar 26, 2022
79ddeb5
Remove redundant code from `StartFlow`
ailinykh Mar 26, 2022
acbe6e5
Increase performance by using in memory chat cache in telebot
ailinykh Mar 26, 2022
53af892
Add initial chat and user creation logic into `bootstrap_flow` and ma…
ailinykh Mar 27, 2022
39ec5d1
Remove redundant logic from `start_flow`
ailinykh Mar 27, 2022
dfacf5b
Extend `chat_storage_decorator` with logger
ailinykh Mar 27, 2022
e4fc901
Remove obsolete settings storage
ailinykh Mar 28, 2022
5e97fc5
Add core `command` entity
ailinykh Mar 29, 2022
ff3d985
Extend core `IBot` with `GetCommands` and `SetCommands` methods
ailinykh Mar 30, 2022
4300270
Extend `ICommandService` methods woth `IBot` interface
ailinykh Mar 30, 2022
887fa24
Add `CommandService` into usecases
ailinykh Mar 30, 2022
f420d8a
Enable `/proxy` command depending on `/proxy` invocation
ailinykh Mar 30, 2022
d4a1ed7
Extend `start_flow` with `/help` command and commandService
ailinykh Mar 30, 2022
efad7a5
Remove mutex out of global scope
ailinykh Mar 30, 2022
d4ef90f
Add `chatStorage` and `commandService` to the `GameFlow`
ailinykh Mar 30, 2022
f6db8e0
Enable `GameFlow` commands depending on chat settings
ailinykh Mar 30, 2022
02cb8f5
Respect chat settings in game tests
ailinykh Mar 30, 2022
39c1c67
Fix instagram reel regexp
ailinykh Apr 9, 2022
3ff5c01
Fix for `MEDIA_CAPTION_TOO_LONG` telegram error
ailinykh Apr 9, 2022
ae3bb99
add makeCaption func to telebot factory
ailinykh Apr 9, 2022
4b053cc
Extract instagram reel id using regexp
ailinykh Apr 9, 2022
baa6616
Add reel clips metadata to `IgReelItem`
ailinykh Apr 9, 2022
6e069a0
Save instagram json into file for debug reasons
ailinykh Apr 9, 2022
f1cda16
Append music to instagram reel caption if any
ailinykh Apr 9, 2022
96d127d
Extend reels flow with UploadVideoStrategy
ailinykh Apr 23, 2022
a076b3e
Rename `reels_flow` to more generic `instagram_flow`
ailinykh Apr 23, 2022
62b3071
Rename TikTok to TikTokV1
ailinykh Oct 15, 2022
a7ef413
TikTok HTML API v2
ailinykh Oct 15, 2022
2d5265a
Fix IVideoHandler function name
ailinykh Oct 19, 2022
f65cbf3
Fix i do not care flow
ailinykh Oct 19, 2022
267d2c4
More logs for video uploading
ailinykh Oct 19, 2022
5141462
cleanup the garbage in IVideoSplitter
ailinykh Oct 19, 2022
5140654
Add download video factory for
ailinykh Oct 19, 2022
5edb497
Add Instargam reel structs
ailinykh Oct 19, 2022
4602994
go mod verify
ailinykh Oct 19, 2022
3a5a33f
Add json cookie jar
ailinykh Oct 19, 2022
1cc1bbb
Fix CreateUploadMediaStrategy return value type
ailinykh Oct 19, 2022
dea352a
Fix instagram reel and tv flows
ailinykh Oct 19, 2022
d2c77fa
Move logging into file downloader
ailinykh Oct 24, 2022
bef1df5
Add size to core.Media struct
ailinykh Oct 24, 2022
c7b953c
Add file size limit to upload media strategy
ailinykh Oct 24, 2022
b790f63
Rename UploadMediaStrategy to UploadMediaStrategyDecorator
ailinykh Oct 24, 2022
1888b7e
Rename UploadMediaStrategyDecorator to UploadMediaDecorator
ailinykh Oct 24, 2022
220bc47
Fallback to splitting in case of file size limit
ailinykh Oct 24, 2022
19a7e62
More logs in TelebotAdapter SendVideo func
ailinykh Oct 25, 2022
f4126f7
Fix logger closing file descriptor issue
ailinykh Oct 25, 2022
6ae6acf
Format telebot initialization signature
ailinykh Oct 25, 2022
65a3b51
Add SendMultipartVideo to send video via http
ailinykh Oct 25, 2022
c8ffb92
Add `multipart` as fallback for large video uploads
ailinykh Oct 25, 2022
83fb325
Support for youtube shorts
ailinykh Oct 26, 2022
151afdd
add telegram-bot-api to development docker-compose file
ailinykh Oct 26, 2022
a3d097b
Add timestamp to multipart uploader
ailinykh Oct 26, 2022
ec89ca5
Add ChatID type alias
ailinykh Oct 27, 2022
5533cd8
Add ISettingsProvider protocol
ailinykh Oct 27, 2022
93720a7
Add settings storage as a default `ISettingsProvider` implementation
ailinykh Oct 27, 2022
b815ab8
Replace `IChatStorage` with `ISettingsProvider` in game
ailinykh Oct 27, 2022
af86818
Replace `IChatStorage` with `ISettingsProvider` in start flow
ailinykh Oct 27, 2022
3fd03c6
Remove `core.Settinge` and replace it with ISettingsProvider
ailinykh Oct 27, 2022
8efd46d
Replace int64 with ChatID in `core` package
ailinykh Oct 29, 2022
de30371
Use `core.SettingKey` instead of `string`
ailinykh Oct 29, 2022
685d35f
Add `IBoolSettingProvider` interface which represent a boolean setting
ailinykh Oct 30, 2022
349183d
Add default `BoolSettingProvider` implementation
ailinykh Oct 30, 2022
d17acc3
Replace `ISettingsProvider` with `IBoolSettingProvider` in remove sou…
ailinykh Oct 30, 2022
94bbeee
Add `User` to `ButtonPressed` func to be able to identify who pressed…
ailinykh Oct 30, 2022
03c21e7
Remove TikTok `Referrer` header
ailinykh Jan 5, 2023
af13cd2
passthrough tiktok api error
ailinykh Feb 8, 2023
16b11f4
add more logs fro instagram html
ailinykh Feb 8, 2023
5576cbe
Add payload to `Button`
ailinykh Mar 18, 2023
a59f55d
Fix for `i do not care` flow
ailinykh Mar 18, 2023
db2d224
Log incoming video with chatid
ailinykh Mar 19, 2023
0d60de8
Replace `youtube-dl` with `yt-dlp`
ailinykh Mar 19, 2023
140c59d
update twitter tokens
ailinykh May 28, 2023
eb2532f
Attempt to fix twitter parsing error
ailinykh Jul 12, 2023
2a361a7
Replace `TikTok` api with `yt-dlp` api
ailinykh Jul 13, 2023
9ff60c0
More logs for `telebot` and `youtube_api`
ailinykh Jul 14, 2023
fc4de57
Log `yt-dlp` output in case of unmarshaling error
ailinykh Jul 14, 2023
cd49cee
add `--quiet --no-warnings --dump-json` params to `yt-dlp` invocation
ailinykh Jul 14, 2023
d77cd8c
Add multiple language support for `ILocalizer` interface
ailinykh Jul 14, 2023
b7cbcdb
Replace `youtube_api` with `ytdlp_api`
ailinykh Jul 17, 2023
027e34f
prevent from removing messages
ailinykh Jul 17, 2023
0b8e8e6
Use original `m4a_dash` audio format in case if 140 not found
ailinykh Jul 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .docker/dev/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: "2"
services:
bot:
build: ../..
container_name: pullanusbot
environment:
BOT_TOKEN: 12345678:XXXXXXXXxxxxxxxxXXXXXXXXxxxxxxxxXXX
ADMIN_CHAT_ID: 1488
volumes:
- ./.directory/pullanusbot-data:/usr/local/share/pullanusbot-data
restart: always

telegram-bot-api:
image: aiogram/telegram-bot-api:latest
environment:
TELEGRAM_API_ID: 1488
TELEGRAM_API_HASH: XXXXXXXXxxxxxxxxXXXXXXXXxxxxxxxxXXX
TELEGRAM_VERBOSITY: 1
volumes:
- ./.directory/telegram-bot-api-data:/var/lib/telegram-bot-api
ports:
- "8081:8081"
restart: always

# Create service with RabbitMQ.
message-broker:
image: rabbitmq:3-management-alpine
container_name: message-broker
ports:
- 5672:5672 # for sender and consumer connections
- 15672:15672 # for serve RabbitMQ GUI
volumes:
- ./.directory/rabbitmq-data/data/:/var/lib/rabbitmq
- ./.directory/rabbitmq-data/log/:/var/log/rabbitmq
restart: always
networks:
- dev-network

networks:
# Create a new Docker network.
dev-network:
driver: bridge
12 changes: 12 additions & 0 deletions .docker/prod/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '2'
services:
bot:
image: ailinykh/pullanusbot
container_name: pullanusbot
environment:
BOT_TOKEN: 12345678:XXXXXXXXxxxxxxxxXXXXXXXXxxxxxxxxXXX
ADMIN_CHAT_ID: 1488
AMQP_URL: amqp://guest:guest@localhost:5672/
volumes:
- ./pullanusbot-data:/usr/local/share/pullanusbot-data
restart: always
13 changes: 13 additions & 0 deletions .docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[supervisord]
nodaemon=true
loglevel=debug

[program:telegram-bot-api]
command=telegram-bot-api --api-id=%(ENV_API_ID)s --api-hash=%(ENV_API_HASH)s --local

[program:pullanusbot]
command=pullanusbot

[program:sshd]
command=/usr/sbin/sshd -D
autorestart=true
3 changes: 3 additions & 0 deletions .docker/telegram-bot-api
Git LFS file not shown
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data
bin
63 changes: 63 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: build
on:
push:
branches:
- master

jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:

- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Print go version
run: go version

- name: Check out code into the Go module directory
uses: actions/checkout@v1

# - name: Git LFS setup
# run: git lfs pull

- name: Build
run: make build

- name: Test
run: make test

- name: Coverage
run: bash <(curl -s https://codecov.io/bash)


- name: Generate build number
uses: einaregilsson/build-number@v2
with:
token: ${{secrets.github_token}}

- name: Setup tag
run: echo "::set-env name=TAG::0.6.$BUILD_NUMBER"

- name: Build docker container
run: |
docker build -t ${{ github.repository }}:$TAG -t ${{ github.repository }}:latest .
echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
docker push --all-tags ${{ github.repository }}
env:
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
DOCKER_PWD: ${{ secrets.DOCKER_PWD }}

- name: Deploy app
run: |
echo "$SSH_IDENTITY_KEY" > identity
chmod 600 identity
ssh -i identity -o StrictHostKeyChecking=no root@proxy.ailinykh.com "/bin/bash ./docker/pullanusbot/deploy_app.sh $TAG"
env:
SSH_IDENTITY_KEY: ${{ secrets.SSH_IDENTITY_KEY }}

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*.dll
*.so
*.dylib
*.db
coverage.txt
.env
bin

# Test binary, built with `go test -c`
*.test
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:stretch as builder
WORKDIR /go/src/github.com/ailinykh/pullanusbot
# cache dependencies first
COPY go.mod go.sum ./
RUN go mod download
# now build
ADD . .
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags '-extldflags "-static"'

FROM jrottenberg/ffmpeg:5.1-alpine313
RUN apk update && apk add tzdata python3 --no-cache && \
wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp && \
chmod a+rx /usr/local/bin/yt-dlp && \
ln -s /usr/bin/python3 /usr/bin/python
COPY --from=builder /go/src/github.com/ailinykh/pullanusbot/pullanusbot /usr/local/bin/pullanusbot
WORKDIR /usr/local/share
VOLUME [ "/usr/local/share/pullanusbot-data" ]
ENTRYPOINT pullanusbot
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 indes <wl@live.it>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-include .env

.PHONY: all serve kill run test build clean restart

APP ?= bin/pullanusbot
PID = $(APP).pid
GO_FILES = $(wildcard *.go)

all: serve

before:
@echo "🛠 rebuilding an app..."

serve: run
@fswatch -x -o --event Created --event Updated --event Renamed -r -e '.*' -i '\.go$$' . | xargs -n1 -I{} make restart || make kill

$(APP): $(GO_FILES)
@go build $? -o $@

kill:
@kill `cat $(PID)` || true

run: build
@$(APP) & echo $$! > $(PID)

test:
GO_ENV=testing go test ./... -v -coverprofile=coverage.txt -race -covermode=atomic

build: $(GO_FILES)
@go build -o $(APP) .

clean:
rm -f $(APP)

restart: kill before build run
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# pullanusbot

[![Build Status](https://github.com/ailinykh/pullanusbot/workflows/build/badge.svg)](https://github.com/ailinykh/pullanusbot/actions?query=workflow%3Abuild)
[![Go Report Card](https://goreportcard.com/badge/github.com/ailinykh/pullanusbot)](https://goreportcard.com/report/github.com/ailinykh/pullanusbot)
![GitHub](https://img.shields.io/github/license/ailinykh/pullanusbot.svg)

This bot helps your telegram chat to consume content in more native way

Let's say somebody sends a link to the webm video:

![bot-webm-video](https://user-images.githubusercontent.com/939390/95298451-c7757100-0884-11eb-9140-4c6474959720.gif)

Or a video file as a document:

![bot-video-convert](https://user-images.githubusercontent.com/939390/95298623-07d4ef00-0885-11eb-92e4-b3c2015f7ecc.gif)

It's even support links to twitter videos

![bot-twitter-video](https://user-images.githubusercontent.com/939390/95298730-3783f700-0885-11eb-9650-b0c04e40aa2f.gif)

... and images!

![bot-twitter-images](https://user-images.githubusercontent.com/939390/95298790-4cf92100-0885-11eb-8bb2-8adbc91f5b23.gif)

## how to run

Setup environment

```shell
brew install go ffmpeg youtube-dl
```
clone repo

```shell
git clone https://github.com/ailinykh/pullanusbot.git
cd pullanusbot
```

install go dependencies
```shell
go mod download
```
obtain bot token from [@BotFather](https://t.me/BotFather) and your telegram ID via `/info` command from [@pullanusbot](https://t.me/pullanusbot)

```shell
echo "export BOT_TOKEN:=12345678:XXXXXXXXxxxxxxxxXXXXXXXXxxxxxxxxXXX" > .env
```

and run!

```shell
make
```
12 changes: 0 additions & 12 deletions Readme.MD

This file was deleted.

81 changes: 81 additions & 0 deletions api/http_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package api

import (
"fmt"
"io/ioutil"
"net/http"

"github.com/ailinykh/pullanusbot/v2/core"
)

func CreateHttpClient() *HttpClient {
return &HttpClient{map[string]string{"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}}
}

type HttpClient struct {
headers map[string]string
}

func (c *HttpClient) GetRedirectLocation(url core.URL) (core.URL, error) {
client := http.DefaultClient
req, _ := http.NewRequest("HEAD", url, nil)

for k, v := range c.headers {
req.Header.Set(k, v)
}

res, err := client.Do(req)
if err != nil {
return "", err
}

return res.Request.URL.String(), nil
}

// GetContentType is a core.IHttpClient interface implementation
func (c *HttpClient) GetContentType(url core.URL) (string, error) {
client := http.DefaultClient
req, _ := http.NewRequest("HEAD", url, nil)

for k, v := range c.headers {
req.Header.Set(k, v)
}

res, err := client.Do(req)
if err != nil {
return "", err
}

if header, ok := res.Header["Content-Type"]; ok {
return header[0], nil
}
return "", fmt.Errorf("content-type not found")
}

// GetContent is a core.IHttpClient interface implementation
func (c *HttpClient) GetContent(url core.URL) (string, error) {
client := http.DefaultClient
req, _ := http.NewRequest("GET", url, nil)

for k, v := range c.headers {
req.Header.Set(k, v)
}

res, err := client.Do(req)
if err != nil {
return "", err
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", err
}

return string(body), nil
}

// SetHeader remembers all passed values and applies it to every request
func (c *HttpClient) SetHeader(key string, value string) {
c.headers[key] = value
}
Loading