Compare commits

..

10 Commits

Author SHA1 Message Date
UserA
17e63b59fa Use .env file in docker compose to provide token
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-09-26 11:47:29 +03:00
root
f43969f7c9 Add docker-build caching 2024-08-16 15:14:36 +03:00
akulij
ea4921f3ba Fix typo 2024-08-16 14:58:21 +03:00
akulij
816cd36191 Add channel link button instead of direct link in message 2024-08-16 14:51:42 +03:00
akulij
513fd684e4 Reset user state on /start commandr local commits) 2024-08-13 06:21:45 +03:00
akulij
82c16a4f53 Fix: app crash if no arguments passed to /secret 2024-08-13 06:21:04 +03:00
akulij
aa9f81eaab Do not checkout in CD workflow 2024-08-13 06:14:56 +03:00
akulij
0ec54e3a6e Add basic CD workflow 2024-08-13 06:12:49 +03:00
akulij
0b378236af Fix: answer to callback (to stop buttons blinking) 2024-08-13 04:16:43 +03:00
akulij
a2348a714c Fix: allow to leave a ticket for admins 2024-08-13 03:27:16 +03:00
4 changed files with 53 additions and 4 deletions

19
.gitea/workflows/cd.yaml Normal file
View File

@ -0,0 +1,19 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
- name: Push to server
run: curl http://178.130.41.138:9000/hooks/redeploy-webhook

View File

@ -7,6 +7,7 @@ RUN go mod download
COPY . . COPY . .
RUN go env -w CGO_ENABLED=1 RUN go env -w CGO_ENABLED=1
RUN go build -o app ./cmd/app ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target="/root/.cache/go-build" go build -o app ./cmd/app
WORKDIR /storage WORKDIR /storage
CMD ["/build/app"] CMD ["/build/app"]

View File

@ -122,6 +122,7 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
log.Printf("Args: %s", args) log.Printf("Args: %s", args)
if possibleCommand == "/start" { if possibleCommand == "/start" {
bc.db.Model(&user).Update("state", "start")
kbd := tgbotapi.NewInlineKeyboardMarkup( kbd := tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData(bc.GetBotContent("leave_ticket_button"), "leave_ticket_button"), tgbotapi.NewInlineKeyboardButtonData(bc.GetBotContent("leave_ticket_button"), "leave_ticket_button"),
@ -154,7 +155,8 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
} else if possibleCommand == "/id" && user.IsAdmin() { } else if possibleCommand == "/id" && user.IsAdmin() {
log.Printf("THERe") log.Printf("THERe")
bc.bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, strconv.FormatInt(update.Message.Chat.ID, 10))) bc.bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, strconv.FormatInt(update.Message.Chat.ID, 10)))
} else if possibleCommand == "/secret" && args[0] == bc.cfg.AdminPass { } else if possibleCommand == "/secret" && len(args) > 0 && args[0] == bc.cfg.AdminPass {
bc.db.Model(&user).Update("state", "start")
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask | 0b11) // set real admin ID (0b1) and effective admin toggle (0b10) bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask | 0b11) // set real admin ID (0b1) and effective admin toggle (0b10)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "You are admin now!") msg := tgbotapi.NewMessage(update.Message.Chat.ID, "You are admin now!")
bc.bot.Send(msg) bc.bot.Send(msg)
@ -174,6 +176,7 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Уведомление об отправке тикета", "update:sended_notify")), tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Уведомление об отправке тикета", "update:sended_notify")),
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба оставить тикет", "update:leaveticket_message")), tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба оставить тикет", "update:leaveticket_message")),
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба подписаться на канал", "update:subscribe_message")), tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба подписаться на канал", "update:subscribe_message")),
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Ссылка на канал", "update:channel_link")),
) )
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Выберите пункт для изменения") msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Выберите пункт для изменения")
msg.ReplyMarkup = kbd msg.ReplyMarkup = kbd
@ -184,7 +187,7 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
log.Printf("Set role bitmask (%b) for user: %d", user.RoleBitmask, user.ID) log.Printf("Set role bitmask (%b) for user: %d", user.RoleBitmask, user.ID)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Simulating user experience!") msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Simulating user experience!")
bc.bot.Send(msg) bc.bot.Send(msg)
} else if user.IsEffectiveAdmin() { } else if user.IsEffectiveAdmin() && user.State != "leaveticket" {
if user.State != "start" { if user.State != "start" {
if strings.HasPrefix(user.State, "imgset:") { if strings.HasPrefix(user.State, "imgset:") {
Literal := strings.Split(user.State, ":")[1] Literal := strings.Split(user.State, ":")[1]
@ -282,7 +285,29 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
bc.db.Model(&user).Update("state", "leaveticket") bc.db.Model(&user).Update("state", "leaveticket")
bc.bot.Send(tgbotapi.NewMessage(user.ID, bc.GetBotContent("leaveticket_message"))) bc.bot.Send(tgbotapi.NewMessage(user.ID, bc.GetBotContent("leaveticket_message")))
} else { } else {
bc.bot.Send(tgbotapi.NewMessage(user.ID, bc.GetBotContent("subscribe_message"))) link, err := bc.GetBotContentVerbose("channel_link")
msg := tgbotapi.NewMessage(user.ID, bc.GetBotContent("subscribe_message"))
if err == nil {
kbd := tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonURL("Канал", link)),
)
msg.ReplyMarkup = kbd
}
if err != nil {
log.Printf("NO LINK!!!")
var admins []User
bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins)
for _, admin := range admins {
msg := tgbotapi.NewMessage(admin.ID, "Channel link is not set!!!")
msg.Entities = []tgbotapi.MessageEntity{tgbotapi.MessageEntity{
Type: "code",
Offset: 1,
Length: 2,
}}
bc.bot.Send(msg)
}
}
bc.bot.Send(msg)
} }
} else if user.IsEffectiveAdmin() { } else if user.IsEffectiveAdmin() {
if strings.HasPrefix(update.CallbackQuery.Data, "update:") { if strings.HasPrefix(update.CallbackQuery.Data, "update:") {
@ -311,12 +336,15 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Уведомление об отправке тикета", "update:sended_notify")), tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Уведомление об отправке тикета", "update:sended_notify")),
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба оставить тикет", "update:leaveticket_message")), tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба оставить тикет", "update:leaveticket_message")),
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба подписаться на канал", "update:subscribe_message")), tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Просьба подписаться на канал", "update:subscribe_message")),
tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("Ссылка на канал", "update:channel_link")),
) )
msg := tgbotapi.NewMessage(user.ID, "Выберите пункт для изменения") msg := tgbotapi.NewMessage(user.ID, "Выберите пункт для изменения")
msg.ReplyMarkup = kbd msg.ReplyMarkup = kbd
bc.bot.Send(msg) bc.bot.Send(msg)
} }
} }
canswer := tgbotapi.NewCallback(update.CallbackQuery.ID, "")
bc.bot.Send(canswer)
} else if update.ChannelPost != nil { // TODO } else if update.ChannelPost != nil { // TODO
post := update.ChannelPost post := update.ChannelPost
if post.Text == "setchannelid" { if post.Text == "setchannelid" {

View File

@ -10,5 +10,6 @@ services:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
restart: always restart: always
env_file: ".env"
volumes: volumes:
- ./storage:/storage - ./storage:/storage