diff --git a/logic/service.go b/logic/service.go new file mode 100644 index 0000000..ba6c3cd --- /dev/null +++ b/logic/service.go @@ -0,0 +1,21 @@ +package logic + +import "git.dragon-labs.de/alphyron/group_helper/models" + +type GroupHelperService interface { + CreateGroup(*models.Group) (*models.Group, error) + UpdateGroup(*models.Group) (*models.Group, error) + + GetGroupByID(int64) (*models.Group, error) + GetGroupDatabaseSize(int64) (int, error) + + CreateUser(*models.User) (*models.User, error) + GetUserByID(int64) *models.User + + UserJoinGroup(*models.User, *models.Group) (bool, error) + UserLeaveGroup(*models.User, *models.Group) (bool, error) + IsUserInGroup(*models.User, *models.Group) (bool, error) + + ListGroups() ([]*models.Group, error) + ListUsers() ([]*models.User, error) +} diff --git a/models/group.go b/models/group.go new file mode 100644 index 0000000..09ad143 --- /dev/null +++ b/models/group.go @@ -0,0 +1,35 @@ +package models + +type Group struct { + ID uint `gorm:"primary_key"` + GroupID int64 + Size int + UserJoinMessage string `gorm:"column:msg_user_join;type:text"` + UserVerifiedMessage string `gorm:"column:msg_user_verified;type:text"` + UserLeaveMessage string `gorm:"column:msg_user_leave;type:text"` + UserKickMessage string `gorm:"column:msg_user_kick;type:text"` + ForbidWriting bool `gorm:"column:forbid_writing"` + OnlineCheck int `gorm:"column:kick_cooldown"` +} + +func (group *Group) FillDefaultValues() { + if len(group.UserKickMessage) == 0 { + group.UserKickMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) did not verify!\n They are going to leave us." + } + + if len(group.UserJoinMessage) == 0 { + group.UserJoinMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) joined us. Hello and Welcome! Please verify that you are not a bot." + } + + if len(group.UserLeaveMessage) == 0 { + group.UserLeaveMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) left us." + } + + if len(group.UserVerifiedMessage) == 0 { + group.UserVerifiedMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) is now permitted to stay in the chat!" + } + + if group.OnlineCheck == 0 { + group.OnlineCheck = 5 + } +} diff --git a/models/user.go b/models/user.go new file mode 100644 index 0000000..d517522 --- /dev/null +++ b/models/user.go @@ -0,0 +1,7 @@ +package models + +type User struct { + ID uint `gorm:"primary_key" json:"id"` + UserID int64 `json:"user_id"` + Groups []*Group `json:"groups" gorm:"many2many:GroupUser;"` +}