commented out old functions
This commit is contained in:
parent
cb57f2e0ce
commit
3af1726c1d
|
|
@ -16,11 +16,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
minLength int = 3
|
// minLength int = 3
|
||||||
repoType string = "repo_type"
|
// repoType string = "repo_type"
|
||||||
projectRepo string = "project_repo"
|
// projectRepo string = "project_repo"
|
||||||
buildRepo string = "build_repo"
|
// buildRepo string = "build_repo"
|
||||||
nameOption string = "name"
|
// nameOption string = "name"
|
||||||
tagsPreset = [3]discordgo.ForumTag{
|
tagsPreset = [3]discordgo.ForumTag{
|
||||||
{
|
{
|
||||||
Name: "В работе",
|
Name: "В работе",
|
||||||
|
|
@ -38,88 +38,89 @@ var (
|
||||||
EmojiName: "🚧",
|
EmojiName: "🚧",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
commands = []discordgo.ApplicationCommand{
|
|
||||||
{
|
// commands = []discordgo.ApplicationCommand{
|
||||||
Name: "ping",
|
// {
|
||||||
Description: "pongs in a reply",
|
// Name: "ping",
|
||||||
},
|
// Description: "pongs in a reply",
|
||||||
{
|
// },
|
||||||
Name: "coda_ticket",
|
// {
|
||||||
Description: "Creates ticket in Coda.io w/ provided info",
|
// Name: "coda_ticket",
|
||||||
},
|
// Description: "Creates ticket in Coda.io w/ provided info",
|
||||||
{
|
// },
|
||||||
Name: "init_project",
|
// {
|
||||||
Description: "Connect project with Coda ID",
|
// Name: "init_project",
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
// Description: "Connect project with Coda ID",
|
||||||
{
|
// Options: []*discordgo.ApplicationCommandOption{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
// {
|
||||||
Name: "key",
|
// Type: discordgo.ApplicationCommandOptionString,
|
||||||
Description: "Project's key from Coda.io",
|
// Name: "key",
|
||||||
Required: true,
|
// Description: "Project's key from Coda.io",
|
||||||
MinLength: &minLength,
|
// Required: true,
|
||||||
},
|
// MinLength: &minLength,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// },
|
||||||
Name: "project",
|
// {
|
||||||
Description: "Create new development ticket",
|
// Name: "project",
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
// Description: "Create new development ticket",
|
||||||
{
|
// Options: []*discordgo.ApplicationCommandOption{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
// {
|
||||||
Name: "project_name",
|
// Type: discordgo.ApplicationCommandOptionString,
|
||||||
Description: "Temporary project name",
|
// Name: "project_name",
|
||||||
Required: true,
|
// Description: "Temporary project name",
|
||||||
MinLength: &minLength,
|
// Required: true,
|
||||||
},
|
// MinLength: &minLength,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// },
|
||||||
Name: "info",
|
// {
|
||||||
Description: "Get project's info",
|
// Name: "info",
|
||||||
},
|
// Description: "Get project's info",
|
||||||
{
|
// },
|
||||||
Name: "repo",
|
// {
|
||||||
Description: "Creates repository of selected type. Name used for projects channels only",
|
// Name: "repo",
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
// Description: "Creates repository of selected type. Name used for projects channels only",
|
||||||
{
|
// Options: []*discordgo.ApplicationCommandOption{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
// {
|
||||||
Name: repoType,
|
// Type: discordgo.ApplicationCommandOptionString,
|
||||||
Description: "The type of repo",
|
// Name: repoType,
|
||||||
Required: true,
|
// Description: "The type of repo",
|
||||||
Choices: []*discordgo.ApplicationCommandOptionChoice{
|
// Required: true,
|
||||||
{
|
// Choices: []*discordgo.ApplicationCommandOptionChoice{
|
||||||
Name: "Unity project repo",
|
// {
|
||||||
Value: projectRepo,
|
// Name: "Unity project repo",
|
||||||
},
|
// Value: projectRepo,
|
||||||
{
|
// },
|
||||||
Name: "XCode build repo",
|
// {
|
||||||
Value: buildRepo,
|
// Name: "XCode build repo",
|
||||||
},
|
// Value: buildRepo,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// },
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
// {
|
||||||
Name: nameOption,
|
// Type: discordgo.ApplicationCommandOptionString,
|
||||||
Description: "Type the repository's name",
|
// Name: nameOption,
|
||||||
Required: false,
|
// Description: "Type the repository's name",
|
||||||
MinLength: &minLength,
|
// Required: false,
|
||||||
},
|
// MinLength: &minLength,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// },
|
||||||
Name: "folder",
|
// {
|
||||||
Description: "Command for cloud folder creation",
|
// Name: "folder",
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
// Description: "Command for cloud folder creation",
|
||||||
{
|
// Options: []*discordgo.ApplicationCommandOption{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
// {
|
||||||
Name: nameOption,
|
// Type: discordgo.ApplicationCommandOptionString,
|
||||||
Description: "Type the folder's name",
|
// Name: nameOption,
|
||||||
Required: false,
|
// Description: "Type the folder's name",
|
||||||
MinLength: &minLength,
|
// Required: false,
|
||||||
},
|
// MinLength: &minLength,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}
|
// },
|
||||||
|
// }
|
||||||
)
|
)
|
||||||
|
|
||||||
func initBotWith(token string) *discordgo.Session {
|
func initBotWith(token string) *discordgo.Session {
|
||||||
|
|
@ -195,36 +196,43 @@ func updateForum(conf *domain.Config, s *discordgo.Session) ([]discordgo.ForumTa
|
||||||
return dchan.AvailableTags, nil
|
return dchan.AvailableTags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandRegistration(s *discordgo.Session, commands []discordgo.ApplicationCommand) []*discordgo.ApplicationCommand {
|
// commandRegistration
|
||||||
oldCommands, err := s.ApplicationCommands(s.State.User.ID, s.State.Application.GuildID)
|
// unused, cause method was deprecated;
|
||||||
if err != nil {
|
// func commandRegistration(s *discordgo.Session, commands []discordgo.ApplicationCommand) []*discordgo.ApplicationCommand {
|
||||||
log.Panicf("Cannot get old commands: %v", err)
|
// oldCommands, err := s.ApplicationCommands(s.State.User.ID, s.State.Application.GuildID)
|
||||||
}
|
// if err != nil {
|
||||||
|
// log.Panicf("Cannot get old commands: %v", err)
|
||||||
|
// }
|
||||||
|
|
||||||
var removedCommands []string
|
// var removedCommands []string
|
||||||
for _, cmd := range oldCommands {
|
// for _, cmd := range oldCommands {
|
||||||
err := s.ApplicationCommandDelete(s.State.User.ID, s.State.Application.GuildID, cmd.ID)
|
// err := s.ApplicationCommandDelete(s.State.User.ID, s.State.Application.GuildID, cmd.ID)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Printf("commands removed: %v", removedCommands)
|
// log.Printf("commands removed: %v", removedCommands)
|
||||||
log.Panicf("removing old comands failed with %s command, err: %v", cmd.Name, err)
|
// log.Panicf("removing old comands failed with %s command, err: %v", cmd.Name, err)
|
||||||
}
|
// }
|
||||||
removedCommands = append(removedCommands, cmd.Name)
|
// removedCommands = append(removedCommands, cmd.Name)
|
||||||
}
|
// }
|
||||||
log.Printf("commands removed: %v", removedCommands)
|
// log.Printf("commands removed: %v", removedCommands)
|
||||||
|
|
||||||
log.Println("Adding commands...")
|
// log.Println("Adding commands...")
|
||||||
var cmds []*discordgo.ApplicationCommand
|
// var cmds []*discordgo.ApplicationCommand
|
||||||
for _, cmd := range commands {
|
// for _, cmd := range commands {
|
||||||
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, "", &cmd)
|
// cmd, err := s.ApplicationCommandCreate(s.State.User.ID, "", &cmd)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Panicf("Cannot create '%v' command: %v", cmd.Name, err)
|
// log.Panicf("Cannot create '%v' command: %v", cmd.Name, err)
|
||||||
}
|
// }
|
||||||
cmds = append(cmds, cmd)
|
// cmds = append(cmds, cmd)
|
||||||
log.Println(cmd.Name + " command added")
|
// log.Println(cmd.Name + " command added")
|
||||||
}
|
// }
|
||||||
return cmds
|
// return cmds
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// Run - метод
|
||||||
|
//
|
||||||
|
// 1. Инициализирует бота Discord, создаёт некоторое подобие роутера
|
||||||
|
// 2. Объявляет доступные роутинги
|
||||||
|
// 3. Объявляет доступные для роутов хэндлеры
|
||||||
func Run(conf *domain.Config, opts DiscordOptions) error {
|
func Run(conf *domain.Config, opts DiscordOptions) error {
|
||||||
|
|
||||||
// bot init
|
// bot init
|
||||||
|
|
@ -239,19 +247,21 @@ func Run(conf *domain.Config, opts DiscordOptions) error {
|
||||||
|
|
||||||
r := discord_router.NewApp(s)
|
r := discord_router.NewApp(s)
|
||||||
|
|
||||||
var commonMw = []discord_router.Middleware{
|
// Depretated
|
||||||
h.WithInitialResponse,
|
// var commonMw = []discord_router.Middleware{
|
||||||
h.RejectPM,
|
// h.WithInitialResponse,
|
||||||
}
|
// h.RejectPM,
|
||||||
|
// }
|
||||||
|
|
||||||
r.Use(commonMw...).
|
// Depretated
|
||||||
Route("ping", h.Ping).
|
// r.Use(commonMw...).
|
||||||
Route("project", h.CreateProject).
|
// Route("ping", h.Ping).
|
||||||
Route("info", h.ProjectInfo).
|
// Route("project", h.CreateProject).
|
||||||
Route("repo", h.CreateGit).
|
// Route("info", h.ProjectInfo).
|
||||||
Route("folder", h.CreateFolder).
|
// Route("repo", h.CreateGit).
|
||||||
Route("init_project", h.InitChannelAsProject).
|
// Route("folder", h.CreateFolder).
|
||||||
Route("coda_ticket", h.CreateCoda)
|
// Route("init_project", h.InitChannelAsProject).
|
||||||
|
// Route("coda_ticket", h.CreateCoda)
|
||||||
|
|
||||||
// and components
|
// and components
|
||||||
r.
|
r.
|
||||||
|
|
@ -280,7 +290,7 @@ func Run(conf *domain.Config, opts DiscordOptions) error {
|
||||||
h.SetAvailableTags(tags)
|
h.SetAvailableTags(tags)
|
||||||
|
|
||||||
// commands registration
|
// commands registration
|
||||||
cmds := commandRegistration(s, commands)
|
// cmds := commandRegistration(s, commands)
|
||||||
|
|
||||||
// gracefull shutdown
|
// gracefull shutdown
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
@ -289,12 +299,12 @@ func Run(conf *domain.Config, opts DiscordOptions) error {
|
||||||
<-stop
|
<-stop
|
||||||
log.Println("Graceful shutdown")
|
log.Println("Graceful shutdown")
|
||||||
|
|
||||||
log.Println("Removing commands...")
|
// log.Println("Removing commands...")
|
||||||
for _, h := range cmds {
|
// for _, h := range cmds {
|
||||||
err := s.ApplicationCommandDelete(s.State.User.ID, "", h.ID)
|
// err := s.ApplicationCommandDelete(s.State.User.ID, "", h.ID)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Panicf("Cannot delete '%v' command: %v", h.Name, err)
|
// log.Panicf("Cannot delete '%v' command: %v", h.Name, err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,10 +119,9 @@ func (h *Handler) Ping(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPosts
|
// ListenPosts
|
||||||
/*
|
//
|
||||||
..listens to new posts in specific channel
|
// ..listens to new posts in specific channel
|
||||||
to act them like a task
|
// to act them like a task
|
||||||
*/
|
|
||||||
func (h *Handler) ListenPosts(s *discordgo.Session, th *discordgo.ThreadCreate) {
|
func (h *Handler) ListenPosts(s *discordgo.Session, th *discordgo.ThreadCreate) {
|
||||||
|
|
||||||
// Check if thread starter is not a bot, and thread started at the tasks channel;
|
// Check if thread starter is not a bot, and thread started at the tasks channel;
|
||||||
|
|
@ -133,6 +132,12 @@ func (h *Handler) ListenPosts(s *discordgo.Session, th *discordgo.ThreadCreate)
|
||||||
// Get all messages from the channel:
|
// Get all messages from the channel:
|
||||||
msgs, _ := s.ChannelMessages(th.ID, 1, "", "", "")
|
msgs, _ := s.ChannelMessages(th.ID, 1, "", "", "")
|
||||||
|
|
||||||
|
if len(msgs) == 0 {
|
||||||
|
log.Println("msgs are empty")
|
||||||
|
s.ChannelMessageSend(th.ID, "чет пошло не так, пингани @naudachu плиз")
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
// Take the first one:
|
// Take the first one:
|
||||||
msg, _ := s.ChannelMessage(th.ID, msgs[0].ID)
|
msg, _ := s.ChannelMessage(th.ID, msgs[0].ID)
|
||||||
|
|
||||||
|
|
@ -313,10 +318,9 @@ func (h *Handler) HandleTaskButtons(s *discordgo.Session, i *discordgo.Interacti
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateFolder
|
// CreateFolder
|
||||||
/*
|
//
|
||||||
- creates project's cloud folder;
|
// - creates project's cloud folder;
|
||||||
- writed folder link to db;
|
// - writed folder link to db;
|
||||||
*/
|
|
||||||
func (h *Handler) CreateFolder(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (h *Handler) CreateFolder(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
const (
|
const (
|
||||||
nameOption string = "folder_name"
|
nameOption string = "folder_name"
|
||||||
|
|
@ -347,14 +351,14 @@ func (h *Handler) CreateFolder(s *discordgo.Session, i *discordgo.InteractionCre
|
||||||
// Creating request:
|
// Creating request:
|
||||||
var req controller.FolderRequest
|
var req controller.FolderRequest
|
||||||
name, insertedValueNotNil := optionMap[nameOption]
|
name, insertedValueNotNil := optionMap[nameOption]
|
||||||
dchan, err := s.Channel(i.ChannelID)
|
currentChannel, err := s.Channel(i.ChannelID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error while identifying channel: %v", err)
|
log.Printf("error while identifying channel: %v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if dchan.ParentID == h.conf.IsProjectChannel {
|
if currentChannel.ParentID == h.conf.IsProjectChannel {
|
||||||
req.ChannelID = dchan.ID
|
req.ChannelID = currentChannel.ID
|
||||||
if insertedValueNotNil {
|
if insertedValueNotNil {
|
||||||
req.InsertedName = name.StringValue()
|
req.InsertedName = name.StringValue()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ import (
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Get - *not used*
|
||||||
|
//
|
||||||
|
// Достаёт запись из таблицы config
|
||||||
|
// config - ключ приложений и номер последнего созданного приложения (// todo или следующего?)
|
||||||
func (wc *WorkflowController) Get(ctx context.Context) (*domain.ApplicationConfig, error) {
|
func (wc *WorkflowController) Get(ctx context.Context) (*domain.ApplicationConfig, error) {
|
||||||
c, err := wc.q.GetConfig(ctx)
|
c, err := wc.q.GetConfig(ctx)
|
||||||
return &domain.ApplicationConfig{
|
return &domain.ApplicationConfig{
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// WriteTaskToDB
|
// WriteTaskToDB
|
||||||
/*
|
//
|
||||||
Makes an SQL query to create new tasks row from domain.Task entity
|
// Makes an SQL query to create new tasks row from domain.Task entity
|
||||||
- Creator field: telegram nickname or Discord's Mention();
|
// - Creator field: telegram nickname or Discord's Mention();
|
||||||
- Creator link (tg ID) in telegram case;
|
// - Creator link (tg ID) in telegram case;
|
||||||
- Description from telegram/discord message bodies;
|
// - Description from telegram/discord message bodies;
|
||||||
*/
|
|
||||||
func (wc *WorkflowController) WriteTaskToDB(t *domain.Task) (*domain.Task, error) {
|
func (wc *WorkflowController) WriteTaskToDB(t *domain.Task) (*domain.Task, error) {
|
||||||
dbtask, err := wc.q.InsertTask(context.TODO(), db.InsertTaskParams{
|
dbtask, err := wc.q.InsertTask(context.TODO(), db.InsertTaskParams{
|
||||||
Creator: pgtype.Text{String: t.Creator, Valid: true},
|
Creator: pgtype.Text{String: t.Creator, Valid: true},
|
||||||
|
|
|
||||||
|
|
@ -76,21 +76,6 @@ func (c *Coda) CreateApp(task domain.CodaApplication) (string, error) {
|
||||||
return "", fmt.Errorf("unexpected coda response: %s", whResponse.ReqID)
|
return "", fmt.Errorf("unexpected coda response: %s", whResponse.ReqID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// arr := strings.Split(whResponse.ReqID, sep)
|
|
||||||
// if arr[0] == "mutate" {
|
|
||||||
// mutate = arr[1]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// mutateResponse, err := c.R().
|
|
||||||
// SetContentType("application/json").
|
|
||||||
// SetBearerAuthToken(c.Config.Develop).
|
|
||||||
// Get(fmt.Sprintf("/mutationStatus/%s", mutate))
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// return "", fmt.Errorf("unable to get coda mutate result: %s", mutate)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _ = mutateResponse
|
|
||||||
return whResponse.ReqID, nil
|
return whResponse.ReqID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Подготовка контейнера проекта:
|
Подготовка контейнера проекта:
|
||||||
1. Поменять в коде файл окружения на '.env'
|
1. Поменять в коде файл окружения на '.env'
|
||||||
2. Собрать контейнер: `docker build -t naudachu/pimp-containerized:latest --pull .`
|
2. Собрать контейнер: `docker build -t naudachu/pimp-containerized:latest --pull .`
|
||||||
3. Затолкать контейнер в docker hub: `docker push naudachu/pimp-containerized:latest`
|
3. Затолкать контейнер в docker hub: `docker push naudachu/pimp-containerized:latest` (надо залогинится мб `docker login -u naudachu --password-stdin`)
|
||||||
|
|
||||||
# Запуск контейнера на сервере:
|
# Запуск контейнера на сервере:
|
||||||
1. Вытягиваем новый образ: `scp ./compose.yaml root@serverhost:~/compose.yaml`
|
1. Вытягиваем новый образ: `scp ./compose.yaml root@serverhost:~/compose.yaml`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue