Compare commits

...

7 Commits
fsm ... master

Author SHA1 Message Date
1e6022df08 vote for the task via reply
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-23 15:30:10 +03:00
9a020253de fix secret population
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-23 15:13:10 +03:00
090a1cdc33 fix secret population
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-23 15:10:37 +03:00
d4b7880715 fix autodeploy
Some checks failed
continuous-integration/drone/push Build is failing
2024-05-23 15:07:05 +03:00
7997128fd0 autodeploy
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2024-05-23 15:01:49 +03:00
5ffbac8dd2 fix various bugs
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-23 14:22:44 +03:00
be2cc7ddfa fix broken create
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-23 13:55:05 +03:00
6 changed files with 35 additions and 10 deletions

View File

@ -15,6 +15,19 @@ steps:
from_secret: CI_APP_IMAGE from_secret: CI_APP_IMAGE
tags: tags:
- latest - latest
- name: deploy
image: alpine:latest
environment:
DEPLOYER_AUTH:
from_secret: DEPLOYER_AUTH
DEPLOYER_URL:
from_secret: DEPLOYER_URL
commands:
- apk add --no-cache curl
- curl -H "$DEPLOYER_AUTH" $DEPLOYER_URL
when:
branch:
- master
trigger: trigger:
event: event:

View File

@ -24,7 +24,7 @@ func (c *Chat) ByID(id uint64) (*model.Chat, error) {
func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) { func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) {
var chat model.Chat var chat model.Chat
if err := c.db.Model(model.Chat{TelegramID: id}).First(&chat).Error; err != nil { if err := c.db.Model(&model.Chat{}).Where("telegram_id = ?", id).First(&chat).Error; err != nil {
return nil, util.HandleRecordNotFound(err) return nil, util.HandleRecordNotFound(err)
} }
return &chat, nil return &chat, nil
@ -32,7 +32,7 @@ func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) {
func (c *Chat) ByTelegramIDWithIntegrations(id int64) (*model.Chat, error) { func (c *Chat) ByTelegramIDWithIntegrations(id int64) (*model.Chat, error) {
var chat model.Chat var chat model.Chat
if err := c.db.Model(model.Chat{TelegramID: id}).Preload("Integrations").First(&chat).Error; err != nil { if err := c.db.Model(&model.Chat{}).Where("telegram_id = ?", id).Preload("Integrations").First(&chat).Error; err != nil {
return nil, util.HandleRecordNotFound(err) return nil, util.HandleRecordNotFound(err)
} }
return &chat, nil return &chat, nil
@ -47,6 +47,9 @@ func (c *Chat) ByIDWithIntegrations(id uint64) (*model.Chat, error) {
} }
func (c *Chat) Save(chat *model.Chat) error { func (c *Chat) Save(chat *model.Chat) error {
if chat.ID == 0 {
return c.db.Create(chat).Error
}
return c.db.Model(chat).Save(chat).Error return c.db.Model(chat).Save(chat).Error
} }

View File

@ -16,13 +16,16 @@ func NewIntegration(db *gorm.DB) *Integration {
func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationType) (*model.Integration, error) { func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationType) (*model.Integration, error) {
var integration model.Integration var integration model.Integration
if err := r.db.Model(model.Integration{ChatID: chatID, Type: typ}).First(&integration).Error; err != nil { if err := r.db.Model(&model.Integration{}).Where(`chat_id = ? and "type" = ?`, chatID, typ).First(&integration).Error; err != nil {
return nil, util.HandleRecordNotFound(err) return nil, util.HandleRecordNotFound(err)
} }
return &integration, nil return &integration, nil
} }
func (r *Integration) Save(integration *model.Integration) error { func (r *Integration) Save(integration *model.Integration) error {
if integration.ID == 0 {
return r.db.Create(integration).Error
}
return r.db.Model(integration).Save(integration).Error return r.db.Model(integration).Save(integration).Error
} }

View File

@ -24,7 +24,7 @@ func (u *User) ByID(id uint64) (*model.User, error) {
func (u *User) ByTelegramID(id int64) (*model.User, error) { func (u *User) ByTelegramID(id int64) (*model.User, error) {
var user model.User var user model.User
if err := u.db.Model(model.User{TelegramID: id}).First(&user).Error; err != nil { if err := u.db.Model(&model.User{}).Where("telegram_id = ?", id).First(&user).Error; err != nil {
return nil, util.HandleRecordNotFound(err) return nil, util.HandleRecordNotFound(err)
} }
return &user, nil return &user, nil
@ -32,7 +32,7 @@ func (u *User) ByTelegramID(id int64) (*model.User, error) {
func (u *User) ByTelegramIDs(ids []int64) ([]model.User, error) { func (u *User) ByTelegramIDs(ids []int64) ([]model.User, error) {
var users []model.User var users []model.User
if err := u.db.Model(model.User{}).Where("telegram_id in (?)", ids).Find(&users).Error; err != nil { if err := u.db.Model(&model.User{}).Where("telegram_id in (?)", ids).Find(&users).Error; err != nil {
return nil, util.HandleRecordNotFound(err) return nil, util.HandleRecordNotFound(err)
} }
return users, nil return users, nil
@ -47,5 +47,8 @@ func (u *User) ByIDWithChats(id uint64) (*model.User, error) {
} }
func (u *User) Save(user *model.User) error { func (u *User) Save(user *model.User) error {
if user.ID == 0 {
return u.db.Create(user).Error
}
return u.db.Model(user).Save(user).Error return u.db.Model(user).Save(user).Error
} }

View File

@ -41,18 +41,21 @@ func (h *Poll) Handle(wh telego.Update) error {
return err return err
} }
loc := h.Localizer(user.Language) loc := h.Localizer(user.Language)
_ = loc
if len(wh.Message.Entities) == 0 || if len(wh.Message.Entities) == 0 ||
(len(wh.Message.Entities) > 0 && wh.Message.Entities[0].Type != telego.EntityTypeBotCommand) || (len(wh.Message.Entities) > 0 && wh.Message.Entities[0].Type != telego.EntityTypeBotCommand) ||
(len(wh.Message.Entities) > 0 && wh.Message.Entities[0].Offset != 0) { (len(wh.Message.Entities) > 0 && wh.Message.Entities[0].Offset != 0) {
return nil return nil
} }
taskInfo := strings.TrimSpace(wh.Message.Text[wh.Message.Entities[0].Length:])
if taskInfo == "" && wh.Message.ReplyToMessage != nil {
taskInfo = wh.Message.ReplyToMessage.Text
}
var ( var (
taskID int taskID int
canRedmine bool canRedmine bool
) )
taskInfo := strings.TrimSpace(wh.Message.Text[wh.Message.Entities[0].Length:])
if taskInfo != "" { if taskInfo != "" {
for _, integrationData := range chat.Integrations { for _, integrationData := range chat.Integrations {
id, info := integration.New(integrationData, h.App.Log()).GetTaskInfo(taskInfo) id, info := integration.New(integrationData, h.App.Log()).GetTaskInfo(taskInfo)

View File

@ -44,7 +44,7 @@ func (p Payload) Vote() (val Vote) {
} }
func (p Payload) KeyboardChoice() (val KBChooserData) { func (p Payload) KeyboardChoice() (val KBChooserData) {
if p.Action != PayloadActionVote { if p.Action != PayloadActionChooseKeyboard {
return return
} }
_ = json.Unmarshal(p.Data, &val) _ = json.Unmarshal(p.Data, &val)
@ -65,7 +65,7 @@ type Member struct {
} }
type KBChooserData struct { type KBChooserData struct {
Type uint8 `json:"k"` Type int64 `json:"k"`
} }
type Vote struct { type Vote struct {
@ -83,7 +83,7 @@ func NewKeyboardChooserPayload(userID, chatID int64, kbType uint8) *Payload {
User: userID, User: userID,
Chat: chatID, Chat: chatID,
Data: marshal(KBChooserData{ Data: marshal(KBChooserData{
Type: kbType, Type: int64(kbType),
}), }),
} }
} }