-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebhookをBotに置き換え #553
Open
DO885
wants to merge
10
commits into
traPtitech:main
Choose a base branch
from
DO885:feat/bot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WebhookをBotに置き換え #553
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ea10302
✨ implement bot
DO885 18cce41
✨ post by bot
DO885 945b428
✏️ rename webhook to bot
DO885 5414bd9
✨ implement post struct
DO885 2814672
✨ implement stamps updated handler
DO885 d3f2da1
✨ v13 migration
DO885 0cdce1c
✨ implement PostRepository
DO885 af8b511
✨ add status stamps to bot post
DO885 8125083
✨ ignore old stamp
DO885 0c3b48c
🧹 replaced webhook to bot
DO885 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ debug | |
|
||
# for development | ||
_development/* | ||
.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
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
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 |
---|---|---|
|
@@ -30,4 +30,5 @@ type Repository interface { | |
RoomRepository | ||
TagRepository | ||
UserRepository | ||
PostRepository | ||
} |
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,18 @@ | ||
package domain | ||
|
||
import "github.com/gofrs/uuid" | ||
|
||
type Post struct { | ||
MessageID uuid.UUID | ||
EventID uuid.UUID | ||
} | ||
|
||
type WritePostParams struct { | ||
MessageID uuid.UUID | ||
EventID uuid.UUID | ||
} | ||
|
||
type PostRepository interface { | ||
CreatePost(params WritePostParams) (*Post, error) | ||
GetPost(MessageID uuid.UUID) (*Post, error) | ||
} |
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
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
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,51 @@ | ||
package bot | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
"github.com/traPtitech/knoQ/domain" | ||
"github.com/traPtitech/knoQ/infra/db" | ||
traqwsbot "github.com/traPtitech/traq-ws-bot" | ||
"github.com/traPtitech/traq-ws-bot/payload" | ||
) | ||
|
||
var Bot *traqwsbot.Bot | ||
|
||
const ( | ||
AttendanceStampID = "93d376c3-80c9-4bb2-909b-2bbe2fbf9e93" | ||
AbsentStampID = "544c04db-9cc3-4c0e-935d-571d4cf103a2" | ||
PendingStampID = "bc9a3814-f185-4b3d-ac1f-3c8f12ad7b52" | ||
) | ||
|
||
func BotMessageStampsUpdatedHandler(p *payload.BotMessageStampsUpdated, gormRepo db.GormRepository) { | ||
post, err := gormRepo.GetPost(uuid.FromStringOrNil(p.MessageID)) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
for _, stamp := range p.Stamps { | ||
if time.Now().After(stamp.UpdatedAt.Add(3 * time.Second)) { | ||
// 3秒以上経過したスタンプは無視 | ||
continue | ||
} | ||
var scheduleStatus domain.ScheduleStatus | ||
switch stamp.StampID { | ||
case AttendanceStampID: | ||
// 出席 | ||
scheduleStatus = domain.Attendance | ||
case AbsentStampID: | ||
// 欠席 | ||
scheduleStatus = domain.Absent | ||
case PendingStampID: | ||
// 未定 | ||
scheduleStatus = domain.Pending | ||
default: | ||
continue | ||
} | ||
err := gormRepo.UpsertEventSchedule(post.EventID, uuid.FromStringOrNil(stamp.UserID), scheduleStatus) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,36 @@ | ||
package db | ||
|
||
import ( | ||
"github.com/gofrs/uuid" | ||
"github.com/traPtitech/knoQ/domain" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type WritePostParams struct { | ||
domain.WritePostParams | ||
} | ||
|
||
func (repo *GormRepository) CreatePost(params WritePostParams) (*Post, error) { | ||
p, err := createPost(repo.db, params) | ||
return p, defaultErrorHandling(err) | ||
} | ||
|
||
func (repo *GormRepository) GetPost(MessageID uuid.UUID) (*Post, error) { | ||
post, err := getPost(repo.db, MessageID) | ||
return post, defaultErrorHandling(err) | ||
} | ||
|
||
func createPost(db *gorm.DB, params WritePostParams) (*Post, error) { | ||
post := ConvWritePostParamsToPost(params) | ||
err := db.Create(&post).Error | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &post, nil | ||
} | ||
|
||
func getPost(db *gorm.DB, messageID uuid.UUID) (*Post, error) { | ||
post := Post{} | ||
err := db.Take(&post, messageID).Error | ||
return &post, err | ||
} |
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
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 |
---|---|---|
|
@@ -19,5 +19,6 @@ func Migrations() []*gormigrate.Migration { | |
v10(), | ||
v11(), | ||
v12(), | ||
v13(), | ||
} | ||
} |
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,25 @@ | ||
package migration | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"github.com/gofrs/uuid" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type v13Post struct { | ||
MessageID uuid.UUID `gorm:"type:char(36); primaryKey"` | ||
EventID uuid.UUID `gorm:"type:char(36); not null"` | ||
} | ||
|
||
func (*v13Post) TableName() string { | ||
return "posts" | ||
} | ||
|
||
func v13() *gormigrate.Migration { | ||
return &gormigrate.Migration{ | ||
ID: "13", | ||
Migrate: func(db *gorm.DB) error { | ||
return db.Migrator().CreateTable(&v13Post{}) | ||
}, | ||
} | ||
} |
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,28 @@ | ||
package repository | ||
|
||
import ( | ||
"github.com/gofrs/uuid" | ||
"github.com/traPtitech/knoQ/domain" | ||
"github.com/traPtitech/knoQ/infra/db" | ||
) | ||
|
||
func (repo *Repository) CreatePost(params domain.WritePostParams) (*domain.Post, error) { | ||
p := db.WritePostParams{ | ||
WritePostParams: params, | ||
} | ||
post, err := repo.GormRepo.CreatePost(p) | ||
if err != nil { | ||
return nil, defaultErrorHandling(err) | ||
} | ||
domainPost := db.ConvPostTodomainPost(*post) | ||
return &domainPost, nil | ||
} | ||
|
||
func (repo *Repository) GetPost(MessageID uuid.UUID) (*domain.Post, error) { | ||
post, err := repo.GormRepo.GetPost(MessageID) | ||
if err != nil { | ||
return nil, defaultErrorHandling(err) | ||
} | ||
domainPost := db.ConvPostTodomainPost(*post) | ||
return &domainPost, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventにtraQのmessageを紐づけるなら新しくテーブルを作らなくてもeventsテーブルにカラムを追加するのでもいいかもしれないです