From 7be95644f93218029893290d0dceb9cc59a79cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sat, 20 Mar 2021 10:27:43 +0100 Subject: [PATCH 1/8] whois command --- command.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/command.go b/command.go index 8ff9421..b447071 100644 --- a/command.go +++ b/command.go @@ -39,6 +39,7 @@ func (bot *HelpBot) initCommands() { "next": bot.nextRequestCommand, "clear": bot.clearCommand, "unregister": bot.unregisterCommand, + "whois": bot.whoIsCommand, "cancel": bot.assistantCancelCommand, } } @@ -74,6 +75,7 @@ var assistant = createTemplate("assistantHelp", `Teaching Assistant commands: {{.Prefix}}next: Removes and returns the first student from the queue. {{.Prefix}}clear: Clears the queue! {{.Prefix}}unregister @mention Unregisters the mentioned user. +{{.Prefix}}whois @mention Returns the real name of the mentioned user {{.Prefix}}cancel Cancels your 'waiting' status. `+"```"+privacy) @@ -535,6 +537,29 @@ func (bot *HelpBot) registerCommand(m *disgord.MessageCreate) { bot.cfg.Prefix)) } +func (bot *HelpBot) whoIsCommand(m *disgord.MessageCreate) { + if len(m.Message.Mentions) < 1 { + replyMsg(bot.client, m, "You must `@mention` a user to get the real name of.") + return + } + user := m.Message.Mentions[0] + var student Student + if !bot.cfg.Autograder { + replyMsg(bot.client, m, "An uknown error occurred") + return + } + err := bot.db.Where("user_id = ?", user.ID).First(&student).Error + if err != nil { + bot.log.Errorln("Failed to retrieve real name from db:", err) + replyMsg(bot.client, m, "An uknown error occurred") + } + + replyMsg(bot.client, m, fmt.Sprintf( + "@%s is %s", + user.Username, student.Name)) + +} + func (bot *HelpBot) unregisterCommand(m *disgord.MessageCreate) { if len(m.Message.Mentions) < 1 { replyMsg(bot.client, m, "You must `@mention` a user to unregister.") From 10c2ea17a72c64163349399bd22aa0f2659a402c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sat, 20 Mar 2021 10:47:46 +0100 Subject: [PATCH 2/8] more descriptive reply --- command.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index b447071..f0605cb 100644 --- a/command.go +++ b/command.go @@ -545,13 +545,14 @@ func (bot *HelpBot) whoIsCommand(m *disgord.MessageCreate) { user := m.Message.Mentions[0] var student Student if !bot.cfg.Autograder { - replyMsg(bot.client, m, "An uknown error occurred") + replyMsg(bot.client, m, "This bot is not linked with Autograder.") return } err := bot.db.Where("user_id = ?", user.ID).First(&student).Error if err != nil { bot.log.Errorln("Failed to retrieve real name from db:", err) replyMsg(bot.client, m, "An uknown error occurred") + return } replyMsg(bot.client, m, fmt.Sprintf( From 7460eed0baeb5d468b742ab8308d97515b7ff346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sun, 21 Mar 2021 11:18:09 +0100 Subject: [PATCH 3/8] fix help alignment --- command.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/command.go b/command.go index f0605cb..a66b815 100644 --- a/command.go +++ b/command.go @@ -69,14 +69,14 @@ You will receive a message when you are next in queue. var assistant = createTemplate("assistantHelp", `Teaching Assistant commands: `+"```"+` -{{.Prefix}}help: Shows this help text -{{.Prefix}}length: Returns the number of students waiting for help. -{{.Prefix}}list : Lists the next students in the queue. -{{.Prefix}}next: Removes and returns the first student from the queue. -{{.Prefix}}clear: Clears the queue! -{{.Prefix}}unregister @mention Unregisters the mentioned user. -{{.Prefix}}whois @mention Returns the real name of the mentioned user -{{.Prefix}}cancel Cancels your 'waiting' status. +{{.Prefix}}help: Shows this help text +{{.Prefix}}length: Returns the number of students waiting for help. +{{.Prefix}}list : Lists the next students in the queue. +{{.Prefix}}next: Removes and returns the first student from the queue. +{{.Prefix}}clear: Clears the queue! +{{.Prefix}}unregister @mention Unregisters the mentioned user. +{{.Prefix}}whois @mention Returns the real name of the mentioned user. +{{.Prefix}}cancel Cancels your 'waiting' status. `+"```"+privacy) func (bot *HelpBot) helpCommand(m *disgord.MessageCreate, helpTmpl *template.Template) error { From 735b1eae0c0fe9358d1f918c85e56ca7fd072771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sun, 21 Mar 2021 11:21:01 +0100 Subject: [PATCH 4/8] Revert "more descriptive reply" This reverts commit 10c2ea17a72c64163349399bd22aa0f2659a402c. --- command.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/command.go b/command.go index a66b815..7186e1a 100644 --- a/command.go +++ b/command.go @@ -545,14 +545,13 @@ func (bot *HelpBot) whoIsCommand(m *disgord.MessageCreate) { user := m.Message.Mentions[0] var student Student if !bot.cfg.Autograder { - replyMsg(bot.client, m, "This bot is not linked with Autograder.") + replyMsg(bot.client, m, "An uknown error occurred") return } err := bot.db.Where("user_id = ?", user.ID).First(&student).Error if err != nil { bot.log.Errorln("Failed to retrieve real name from db:", err) replyMsg(bot.client, m, "An uknown error occurred") - return } replyMsg(bot.client, m, fmt.Sprintf( From 0a0dc0c082b64e2903dbdb7539a189e595595629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sun, 21 Mar 2021 11:25:44 +0100 Subject: [PATCH 5/8] fix help alignment --- command.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/command.go b/command.go index 7186e1a..f817f17 100644 --- a/command.go +++ b/command.go @@ -69,14 +69,14 @@ You will receive a message when you are next in queue. var assistant = createTemplate("assistantHelp", `Teaching Assistant commands: `+"```"+` -{{.Prefix}}help: Shows this help text -{{.Prefix}}length: Returns the number of students waiting for help. -{{.Prefix}}list : Lists the next students in the queue. -{{.Prefix}}next: Removes and returns the first student from the queue. -{{.Prefix}}clear: Clears the queue! -{{.Prefix}}unregister @mention Unregisters the mentioned user. -{{.Prefix}}whois @mention Returns the real name of the mentioned user. -{{.Prefix}}cancel Cancels your 'waiting' status. +{{.Prefix}}help: Shows this help text +{{.Prefix}}length: Returns the number of students waiting for help. +{{.Prefix}}list : Lists the next students in the queue. +{{.Prefix}}next: Removes and returns the first student from the queue. +{{.Prefix}}clear: Clears the queue! +{{.Prefix}}unregister @mention Unregisters the mentioned user. +{{.Prefix}}whois @mention Returns the real name of the mentioned user. +{{.Prefix}}cancel Cancels your 'waiting' status. `+"```"+privacy) func (bot *HelpBot) helpCommand(m *disgord.MessageCreate, helpTmpl *template.Template) error { From e0bd5a5d7e674fa9db4e3742fe8df4570c5002b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sun, 21 Mar 2021 11:29:10 +0100 Subject: [PATCH 6/8] Revert "Revert "more descriptive reply"" This reverts commit 735b1eae0c0fe9358d1f918c85e56ca7fd072771. --- command.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index f817f17..d5d07b1 100644 --- a/command.go +++ b/command.go @@ -545,13 +545,14 @@ func (bot *HelpBot) whoIsCommand(m *disgord.MessageCreate) { user := m.Message.Mentions[0] var student Student if !bot.cfg.Autograder { - replyMsg(bot.client, m, "An uknown error occurred") + replyMsg(bot.client, m, "This bot is not linked with Autograder.") return } err := bot.db.Where("user_id = ?", user.ID).First(&student).Error if err != nil { bot.log.Errorln("Failed to retrieve real name from db:", err) replyMsg(bot.client, m, "An uknown error occurred") + return } replyMsg(bot.client, m, fmt.Sprintf( From d479fae032d76e4498fc431516a66655a25fe084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sun, 21 Mar 2021 11:30:51 +0100 Subject: [PATCH 7/8] fix --- command.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/command.go b/command.go index d5d07b1..0fe7cac 100644 --- a/command.go +++ b/command.go @@ -75,7 +75,11 @@ var assistant = createTemplate("assistantHelp", `Teaching Assistant commands: {{.Prefix}}next: Removes and returns the first student from the queue. {{.Prefix}}clear: Clears the queue! {{.Prefix}}unregister @mention Unregisters the mentioned user. +<<<<<<< HEAD {{.Prefix}}whois @mention Returns the real name of the mentioned user. +======= +{{.Prefix}}whois @mention Returns the real name of the mentioned user +>>>>>>> parent of 7460eed... fix help alignment {{.Prefix}}cancel Cancels your 'waiting' status. `+"```"+privacy) From 4cc212f8f96f0caa8b319af4897aef26af9d0da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Gj=C3=B8lga?= Date: Sun, 21 Mar 2021 11:34:28 +0100 Subject: [PATCH 8/8] clanup --- command.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/command.go b/command.go index 0fe7cac..d5d07b1 100644 --- a/command.go +++ b/command.go @@ -75,11 +75,7 @@ var assistant = createTemplate("assistantHelp", `Teaching Assistant commands: {{.Prefix}}next: Removes and returns the first student from the queue. {{.Prefix}}clear: Clears the queue! {{.Prefix}}unregister @mention Unregisters the mentioned user. -<<<<<<< HEAD {{.Prefix}}whois @mention Returns the real name of the mentioned user. -======= -{{.Prefix}}whois @mention Returns the real name of the mentioned user ->>>>>>> parent of 7460eed... fix help alignment {{.Prefix}}cancel Cancels your 'waiting' status. `+"```"+privacy)