Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (bot *HelpBot) initCommands() {
"next": bot.nextRequestCommand,
"clear": bot.clearCommand,
"unregister": bot.unregisterCommand,
"whois": bot.whoIsCommand,
"cancel": bot.assistantCancelCommand,
}
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -535,6 +537,30 @@ 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, "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(
"@%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.")
Expand Down