Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
1e6022df08 | |||
9a020253de | |||
090a1cdc33 | |||
d4b7880715 | |||
7997128fd0 | |||
5ffbac8dd2 | |||
be2cc7ddfa |
13
.drone.yml
13
.drone.yml
@ -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:
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
@ -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),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user