Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging some stuff #7

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmd/client/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func init() {
getCmd,
deleteCmd,
changePassCmd,
runhashCmd,
)

rootCmd.PersistentFlags().IntVarP(&verbosity, "verbosity", "v", 2, "set verbosity (1-4)")
Expand Down
35 changes: 35 additions & 0 deletions cmd/client/runhash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"os"

"github.com/kylrth/disco-bouncer/pkg/encrypt"
"github.com/spf13/cobra"
)

var runhashCmd = &cobra.Command{
Use: "runhash [KEYS...]",
Short: "Compute the MD5 hash of the key exactly as is done on the server",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
err := runhash(args)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
},
}

func runhash(keys []string) error {
for _, key := range keys {
hash, err := encrypt.MD5Hash(key)
if err != nil {
return fmt.Errorf("hash key '%s': %w", key, err)
}

fmt.Println(hash)
}

return nil
}
6 changes: 5 additions & 1 deletion pkg/bouncerbot/bouncerbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ func (b *Bot) handleMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
b.message(m.ChannelID, messageNickPerm)
}

b.l.Info("msg", "admitted new user", "userID", m.Author.ID, "username", m.Author.Username)
b.l.Info(
"msg", "admitted new user", "userID", m.Author.ID, "username", m.Author.Username,
"name", u.Name, "finishYear", u.FinishYear, "isProf", u.Professor, "isTA", u.TA,
"isSL", u.StudentLeadership, "isAB", u.AlumniBoard,
)

// Delete the user now that we've successfully admitted them.
err = b.d.Delete(u.ID)
Expand Down