-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,423 additions
and
1,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/go | ||
{ | ||
"name": "Go", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/go:0-1.20", | ||
"features": { | ||
"ghcr.io/devcontainers-contrib/features/vercel-cli:1": {} | ||
}, | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "go version", | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
|
||
"initializeCommand": "git config --global alias.co checkout && git config --global alias.br branch && git config --global alias.ci commit && git config --global alias.st status" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
APP_URL="" | ||
TELE_BOT_TOKEN="" | ||
OPEN_WEATHER_MAP_APP_ID="" | ||
APP_URL="" | ||
TELE_BOT_TOKEN="" | ||
OPEN_WEATHER_MAP_APP_ID="" | ||
UPSTASH_URL="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
name: Vercel Production Deployment | ||
env: | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
Deploy-Production: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install Vercel CLI | ||
run: npm install --global vercel@latest | ||
- name: Pull Vercel Environment Information | ||
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | ||
# - name: Build Project Artifacts | ||
# run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} | ||
# - name: Deploy Project Artifacts to Vercel | ||
# run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} | ||
- name: Deploy to Vercel | ||
run: vercel --prod --token=${{ secrets.VERCEL_TOKEN }} | ||
- name: Send telegram message | ||
uses: appleboy/telegram-action@master | ||
with: | ||
to: ${{ secrets.TELEGRAM_TO }} | ||
token: ${{ secrets.TELEGRAM_TOKEN }} | ||
message: | | ||
name: Vercel Production Deployment | ||
env: | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
Deploy-Production: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install Vercel CLI | ||
run: npm install --global vercel@latest | ||
- name: Pull Vercel Environment Information | ||
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | ||
# - name: Build Project Artifacts | ||
# run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} | ||
# - name: Deploy Project Artifacts to Vercel | ||
# run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} | ||
- name: Deploy to Vercel | ||
run: vercel --prod --token=${{ secrets.VERCEL_TOKEN }} | ||
- name: Send telegram message | ||
uses: appleboy/telegram-action@master | ||
with: | ||
to: ${{ secrets.TELEGRAM_TO }} | ||
token: ${{ secrets.TELEGRAM_TOKEN }} | ||
message: | | ||
Code has been deployed to Vercel successfully 🥰🥰 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.vercel | ||
.vercel | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"cSpell.words": [ | ||
"gonanoid", | ||
"kqxs", | ||
"qrcode", | ||
"rediss", | ||
"shorturl", | ||
"upstash", | ||
"Vercel", | ||
"zeril", | ||
"zerill" | ||
] | ||
{ | ||
"cSpell.words": [ | ||
"gonanoid", | ||
"kqxs", | ||
"qrcode", | ||
"rediss", | ||
"shorturl", | ||
"upstash", | ||
"Vercel", | ||
"zeril", | ||
"zerill" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# Zeril Bot | ||
|
||
[Zeril Bot](https://t.me/zerill_bot) is my practice using Go | ||
|
||
## Lesson Learned | ||
* Go and things in Go | ||
* Vercel Serverless Function | ||
* Telegram Bot API | ||
* Github Action | ||
* RSS | ||
* Redis | ||
* NanoID | ||
# Zeril Bot | ||
|
||
[Zeril Bot](https://t.me/zerill_bot) is my practice using Go | ||
|
||
## Lesson Learned | ||
* Go and things in Go | ||
* Vercel Serverless Function | ||
* Telegram Bot API | ||
* Github Action | ||
* RSS | ||
* Redis | ||
* NanoID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,102 @@ | ||
package hook | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strings" | ||
"zeril-bot/utils/bitcoin" | ||
"zeril-bot/utils/bot" | ||
"zeril-bot/utils/channel" | ||
"zeril-bot/utils/help" | ||
"zeril-bot/utils/kqxs" | ||
"zeril-bot/utils/lunar" | ||
"zeril-bot/utils/qr" | ||
"zeril-bot/utils/quote" | ||
"zeril-bot/utils/random" | ||
"zeril-bot/utils/shortener" | ||
"zeril-bot/utils/structs" | ||
"zeril-bot/utils/weather" | ||
) | ||
|
||
func Handler(w http.ResponseWriter, r *http.Request) { | ||
data := r.Context().Value("data").(structs.HookData) | ||
|
||
channel.GetWg().Add(2) | ||
|
||
if data.CallbackQuery.Data != "" { | ||
resolveCallback(data) | ||
} else { | ||
resolveCommand(data) | ||
} | ||
|
||
channel.GetWg().Wait() | ||
} | ||
|
||
func resolveCommand(data structs.HookData) { | ||
name := data.Message.From.FirstName | ||
chatId := data.Message.Chat.ID | ||
text := data.Message.Text | ||
arr := strings.Fields(text) | ||
|
||
setBotIsTyping(chatId) | ||
|
||
log.Println(fmt.Sprintf("Yêu cầu từ bạn %s: %s", name, text)) | ||
|
||
command := arr[0] | ||
|
||
switch command { | ||
case "/start", "/start@zerill_bot": | ||
help.SendStartMessage(chatId, name) | ||
case "/help", "/help@zerill_bot": | ||
help.SendHelpMessage(chatId) | ||
case "/groupid", "/groupid@zerill_bot": | ||
help.SendGroupId(chatId, string(data.Message.Chat.Type)) | ||
case "/quote", "/quote@zerill_bot": | ||
quote.SendAQuote(chatId) | ||
case "/lunar", "/lunar@zerill_bot": | ||
lunar.SendLunarDateNow(chatId) | ||
case "/weather", "/weather@zerill_bot": | ||
weather.SendForecastOfWeather(chatId, text) | ||
case "/bitcoin", "/bitcoin@zerill_bot": | ||
bitcoin.SendBitcoinPrice(chatId) | ||
case "/qr", "/qr@zerill_bot": | ||
qr.SendQRImage(chatId, text) | ||
case "/random", "/random@zerill_bot": | ||
random.RandomElements(chatId, text) | ||
case "/kqxs", "/kqxs@zerill_bot": | ||
kqxs.Send(chatId, text) | ||
case "/shortener", "/shortener@zerill_bot": | ||
shortener.Generate(chatId, text) | ||
default: | ||
channel.SendMessage(chatId, "Tôi không hiểu câu lệnh của bạn !!!") | ||
} | ||
} | ||
|
||
func resolveCallback(callback structs.HookData) { | ||
name := callback.CallbackQuery.Message.From.FirstName | ||
chatId := callback.CallbackQuery.Message.Chat.ID | ||
text := callback.CallbackQuery.Message.Text | ||
data := callback.CallbackQuery.Data | ||
|
||
setBotIsTyping(chatId) | ||
|
||
log.Println(fmt.Sprintf("Yêu cầu từ bạn %s: %s, callback data: %s", name, text, data)) | ||
|
||
arr := strings.Fields(data) | ||
command := arr[0] | ||
|
||
switch command { | ||
case "/weather": | ||
weather.SendForecastOfWeather(chatId, data) | ||
case "/kqxs": | ||
kqxs.Send(chatId, data) | ||
} | ||
} | ||
|
||
func setBotIsTyping(chatId int) { | ||
go func() { | ||
bot.SetTypingAction(chatId) | ||
channel.GetWg().Done() | ||
}() | ||
} | ||
package hook | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strings" | ||
"zeril-bot/utils/bitcoin" | ||
"zeril-bot/utils/bot" | ||
"zeril-bot/utils/channel" | ||
"zeril-bot/utils/help" | ||
"zeril-bot/utils/kqxs" | ||
"zeril-bot/utils/lunar" | ||
"zeril-bot/utils/qr" | ||
"zeril-bot/utils/quote" | ||
"zeril-bot/utils/random" | ||
"zeril-bot/utils/shortener" | ||
"zeril-bot/utils/structs" | ||
"zeril-bot/utils/weather" | ||
) | ||
|
||
func Handler(w http.ResponseWriter, r *http.Request) { | ||
data := r.Context().Value("data").(structs.HookData) | ||
|
||
channel.GetWg().Add(2) | ||
|
||
if data.CallbackQuery.Data != "" { | ||
resolveCallback(data) | ||
} else { | ||
resolveCommand(data) | ||
} | ||
|
||
channel.GetWg().Wait() | ||
} | ||
|
||
func resolveCommand(data structs.HookData) { | ||
name := data.Message.From.FirstName | ||
chatId := data.Message.Chat.ID | ||
text := data.Message.Text | ||
arr := strings.Fields(text) | ||
|
||
setBotIsTyping(chatId) | ||
|
||
log.Println(fmt.Sprintf("Yêu cầu từ bạn %s: %s", name, text)) | ||
|
||
command := arr[0] | ||
|
||
switch command { | ||
case "/start", "/start@zerill_bot": | ||
help.SendStartMessage(chatId, name) | ||
case "/help", "/help@zerill_bot": | ||
help.SendHelpMessage(chatId) | ||
case "/groupid", "/groupid@zerill_bot": | ||
help.SendGroupId(chatId, string(data.Message.Chat.Type)) | ||
case "/quote", "/quote@zerill_bot": | ||
quote.SendAQuote(chatId) | ||
case "/lunar", "/lunar@zerill_bot": | ||
lunar.SendLunarDateNow(chatId) | ||
case "/weather", "/weather@zerill_bot": | ||
weather.SendForecastOfWeather(chatId, text) | ||
case "/bitcoin", "/bitcoin@zerill_bot": | ||
bitcoin.SendBitcoinPrice(chatId) | ||
case "/qr", "/qr@zerill_bot": | ||
qr.SendQRImage(chatId, text) | ||
case "/random", "/random@zerill_bot": | ||
random.RandomElements(chatId, text) | ||
case "/kqxs", "/kqxs@zerill_bot": | ||
kqxs.Send(chatId, text) | ||
case "/shortener", "/shortener@zerill_bot": | ||
shortener.Generate(chatId, text) | ||
default: | ||
channel.SendMessage(chatId, "Tôi không hiểu câu lệnh của bạn !!!") | ||
} | ||
} | ||
|
||
func resolveCallback(callback structs.HookData) { | ||
name := callback.CallbackQuery.Message.From.FirstName | ||
chatId := callback.CallbackQuery.Message.Chat.ID | ||
text := callback.CallbackQuery.Message.Text | ||
data := callback.CallbackQuery.Data | ||
|
||
setBotIsTyping(chatId) | ||
|
||
log.Println(fmt.Sprintf("Yêu cầu từ bạn %s: %s, callback data: %s", name, text, data)) | ||
|
||
arr := strings.Fields(data) | ||
command := arr[0] | ||
|
||
switch command { | ||
case "/weather": | ||
weather.SendForecastOfWeather(chatId, data) | ||
case "/kqxs": | ||
kqxs.Send(chatId, data) | ||
} | ||
} | ||
|
||
func setBotIsTyping(chatId int) { | ||
go func() { | ||
bot.SetTypingAction(chatId) | ||
channel.GetWg().Done() | ||
}() | ||
} |
Oops, something went wrong.