Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.env
*.exe
frodo-bot
/frodo-bot
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Then fill in `.env`:
### 2. Run

```bash
go run .
go run ./cmd/frodo-bot
```

### 3. Supported Commands
Expand Down
11 changes: 5 additions & 6 deletions main.go → cmd/frodo-bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os/signal"
"syscall"

"github.com/SimonKimDev/frodo-bot/internal/bot"
"github.com/SimonKimDev/frodo-bot/internal/config"
"github.com/bwmarrin/discordgo"
)

Expand All @@ -17,7 +19,7 @@ func main() {
}

func run() error {
cfg, err := loadConfig()
cfg, err := config.Load()
if err != nil {
return fmt.Errorf("config failed: %w", err)
}
Expand All @@ -27,11 +29,8 @@ func run() error {
return fmt.Errorf("bot failed to init: %w", err)
}

bot := newBot(cfg)
discord.AddHandler(bot.onReady)
discord.AddHandler(bot.onMessage)

discord.Identify.Intents = discordgo.IntentsMessageContent | discordgo.IntentsGuildMessages
b := bot.New(cfg)
b.Register(discord)

// open session
err = discord.Open()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module frodo-bot
module github.com/SimonKimDev/frodo-bot

go 1.26.1

Expand Down
27 changes: 27 additions & 0 deletions internal/bot/bot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package bot

import (
"log"

"github.com/SimonKimDev/frodo-bot/internal/config"
"github.com/bwmarrin/discordgo"
)

type Bot struct {
gifURL string
}

func New(cfg config.Config) *Bot {
return &Bot{gifURL: cfg.GIFURL}
}

func (b *Bot) Register(s *discordgo.Session) {
s.AddHandler(b.onReady)
s.AddHandler(b.onMessage)
s.Identify.Intents = discordgo.IntentsMessageContent | discordgo.IntentsGuildMessages
}

func (b *Bot) onReady(s *discordgo.Session, r *discordgo.Ready) {
user := r.User
log.Printf("logged in as %v", user.Username)
}
20 changes: 6 additions & 14 deletions bot.go → internal/bot/secret.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package main
package bot

import (
"log"
"strings"

"github.com/bwmarrin/discordgo"
)

type Bot struct {
gifURL string
}

func newBot(cfg Config) *Bot {
return &Bot{gifURL: cfg.GIFURL}
}

func (b *Bot) onReady(s *discordgo.Session, r *discordgo.Ready) {
user := r.User
log.Printf("logged in as %v", user.Username)
}

func (b *Bot) onMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot {
return
Expand All @@ -32,3 +20,7 @@ func (b *Bot) onMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
log.Printf("failed to send messages with %v", err)
}
}

func shouldReply(content string) bool {
return strings.Contains(strings.ToLower(content), "secret")
}
4 changes: 2 additions & 2 deletions config.go → internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package config

import (
"errors"
Expand All @@ -13,7 +13,7 @@ type Config struct {
GIFURL string
}

func loadConfig() (Config, error) {
func Load() (Config, error) {
if err := godotenv.Load(); err != nil {
log.Printf(".env file is missing, using environment variable")
}
Expand Down
7 changes: 0 additions & 7 deletions matcher.go

This file was deleted.

Loading