Skip to content

Commit

Permalink
Add /about command
Browse files Browse the repository at this point in the history
  • Loading branch information
jm8 committed Oct 25, 2024
1 parent fabb803 commit d8657b4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
65 changes: 61 additions & 4 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"database/sql"
"fmt"
"log"
"net/url"

"github.com/bwmarrin/discordgo"
)
Expand All @@ -25,9 +27,16 @@ var (
// Commands/options without description will fail the registration
// of the command.
{
Name: "about",

Description: "Lookup information about a discord user",
Name: "about",
Description: "Lookup information about a discord user who has linked their OSU account",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "user",
Description: "User",
Required: true,
},
},
},
}

Expand All @@ -36,10 +45,58 @@ var (
if !requireAdmin(b, i) {
return
}
options := i.ApplicationCommandData().Options
user := options[0].UserValue(nil)

row := b.Db.QueryRow(`SELECT name_num, display_name, last_login, student, alum, employee, faculty FROM users WHERE discord_id = ?`, user.ID)
var (
nameNum string
displayName string
lastLogin int
student bool
alum bool
employee bool
faculty bool
)
err := row.Scan(&nameNum, &displayName, &lastLogin, &student, &alum, &employee, &faculty)
if err != nil {
b.Session.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{

Check failure on line 63 in discord.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `b.Session.InteractionRespond` is not checked (errcheck)
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "User has not linked their OSU account",
},
})
return
}
content := fmt.Sprintf("**[%s (%s)](<https://www.osu.edu/search/?query=%s>)**\nLast login: <t:%d:f>\n",
displayName,
nameNum,
url.QueryEscape(nameNum),
lastLogin,
)

sep := ""
if student {
content += sep + "Student"
sep = ", "
}
if alum {
content += sep + "Alum"
sep = ", "
}
if employee {
content += sep + "Employee"
sep = ", "
}
if faculty {
content += sep + "Faculty"
sep = ", "

Check failure on line 93 in discord.go

View workflow job for this annotation

GitHub Actions / Lint

ineffectual assignment to sep (ineffassign)
}

b.Session.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{

Check failure on line 96 in discord.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `b.Session.InteractionRespond` is not checked (errcheck)
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "This command has not been finished",
Content: content,
},
})
},
Expand Down
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,6 @@ func main() {

db, err := sql.Open("sqlite", "./auth.db")

bot := &DiscordBot{
Token: os.Getenv("DISCORD_BOT_TOKEN"),
GuildId: os.Getenv("DISCORD_GUILD_ID"),
AdminRoleId: os.Getenv("DISCORD_ADMIN_ROLE_ID"),
StudentRoleId: os.Getenv("DISCORD_STUDENT_ROLE_ID"),
ClientId: os.Getenv("DISCORD_CLIENT_ID"),
ClientSecret: os.Getenv("DISCORD_CLIENT_SECRET"),
Db: db,
}
bot.Connect()

if err != nil {
log.Fatalln("Failed to load the database:", err)
}
Expand All @@ -246,6 +235,17 @@ func main() {
}
}

bot := &DiscordBot{
Token: os.Getenv("DISCORD_BOT_TOKEN"),
GuildId: os.Getenv("DISCORD_GUILD_ID"),
AdminRoleId: os.Getenv("DISCORD_ADMIN_ROLE_ID"),
StudentRoleId: os.Getenv("DISCORD_STUDENT_ROLE_ID"),
ClientId: os.Getenv("DISCORD_CLIENT_ID"),
ClientSecret: os.Getenv("DISCORD_CLIENT_SECRET"),
Db: db,
}
bot.Connect()

authEnvironment := os.Getenv("ENV")
var authProvider AuthProvider
var rootURL *url.URL
Expand Down

0 comments on commit d8657b4

Please sign in to comment.