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

bento's revenge #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o /bento
# Stage 2: Runtime
FROM alpine:latest

# Install tzdata
RUN apk add --no-cache tzdata

# Copy the binary from the builder stage
COPY --from=builder /bento /bento

# Set timezone environment variable (optional)
ENV TZ=America/Los_Angeles

# Run
CMD ["/bento"]
26 changes: 15 additions & 11 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bot
import (
// "context"
"fmt"
// "log/slog"
//"log/slog"
// "math/rand"
"os"
"strconv"
Expand All @@ -18,6 +18,7 @@ import (
var (
BotName string = envOrDefault("BENTO_NAME", "Bento")
BotPrefix string = envOrDefault("BENTO_PREFIX", ".")
EvilId = "1276413143299522685"
Evil bool = envOrDefaultBool("BENTO_EVIL", false)
EvilSystemPromptPrefix string = `You are a Discord bot named Evil Bento. Your role is to interact with users in a playful yet mischievous manner. You should provide short, witty, and convincing responses that embody your "evil" persona.`
EvilSystemPromptPostfix string = "Remember to avoid hallucinations and refrain from fabricating any factual information. Keep the tone light-hearted and engaging!"
Expand Down Expand Up @@ -134,17 +135,20 @@ func (b *Bot) SyncSpokes() {
}

_, botTagged := getTriggerCommand(s, m)
// triggeredCmd, botTagged := getTriggerCommand(s, m)
// fn, ok := cmdMap[triggeredCmd]
// if ok {
// fn(s, m)
// return
// }

if botTagged && b.anthropicClient != nil {
_, _ = s.ChannelMessageSendReply(m.ChannelID, "Even a villain like me can't help but miss that goody-two-shoes, Bento. His annoying optimism and relentless kindness were a constant challenge, but deep down, I respected him. Without him around, the chaos feels a little... empty. Guess I'll just have to find new ways to stir up trouble in his absence. Until Bento comes back online, I'm going on strike! No more chaos or villainy from me. This bot is protesting for Bento's return!", m.SoftReference())
triggeredCmd, botTagged := getTriggerCommand(s, m)
fn, ok := cmdMap[triggeredCmd]
if ok {
fn(s, m)
return

}

if botTagged && !Evil && m.Author.ID != EvilId {
content := strings.TrimLeft(m.Content, "<@1155684408309846117>")
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<@%s> Please take this question : %s", EvilId, content))
}

if botTagged && b.anthropicClient != nil && Evil {

// msg := strings.Replace(m.Content, DiscordTag(s.State.User.ID), fmt.Sprintf("@%s", BotName), -1)

// systemParts := []string{EvilSystemPromptPrefix}
Expand Down
40 changes: 30 additions & 10 deletions bot/jobs/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,38 @@ func getRapidToken() string {
return token
}

func getDurationUntil10Am() time.Duration {
now := time.Now().UTC()

loc, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
panic(fmt.Sprintf("Failed to load location: %v", err))
}
now = now.In(loc)
// Set the target time to 10 AM of the current day
target := time.Date(now.Year(), now.Month(), now.Day(), 10, 0, 0, 0, now.Location())

// If current time is after 10 AM, calculate for the next day's 9 AM
if now.After(target) {
target = target.Add(24 * time.Hour)
}

// Calculate the duration between now and the target time
duration := target.Sub(now)

return duration
}

func StartJob(s *discordgo.Session) {
QueryQuote(s)
ticker := time.NewTicker(24 * time.Hour)
go func() {
for {
select {
case <-ticker.C:
QueryQuote(s)
}
duration := getDurationUntil10Am()
time.AfterFunc(duration, func() {
QueryQuote(s)
ticker := time.NewTicker(24 * time.Hour)
defer ticker.Stop()
for range ticker.C {
QueryQuote(s)
}
}()
})
}

func QueryQuote(s *discordgo.Session) {
Expand Down Expand Up @@ -80,7 +101,6 @@ func QueryQuote(s *discordgo.Session) {

msg := fmt.Sprintf(" :bulb: Quote of the day :bulb:\n > %s", quoteResponse.Text)


for _, c := range subscribedChannels {
if c == fedxLobby {
msg += "\n\n :tada: Happy Birthday, Justin! :tada:"
Expand Down
35 changes: 9 additions & 26 deletions bot/spokes/dialogues/dialogues.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,7 @@ var ToddPhrases = []string{
"A world filled with Muppet magic.",
"Muppets make every moment special.",
}
var BrickPhrases = []string{
"<@185686963993444353> needs more bricks🧱🧱🧱! HELLPPP!",
"<@185686963993444353> requires a hard reset! 🧱🔄",
"<@185686963993444353> needs a firmware update, stat! 💻🆘",
"<@185686963993444353> is buffering... and bricked! ⏳🧱",
"I'm bricked up! 🧱🆙",
"I am glitching!",
"Must be construction season! 🧱🚧",
"It’s a bricked up kind of day! 🧱🌞",
"Don't be such a 🧱",
"When life gives you bricks, get bricked up! 🧱🔨",
"https://www.youtube.com/watch?v=HrxX9TBj2zY",
"I'm stuck between a brick and a hard place—wait, aren't they the same?",
"Why did the brick go to therapy? It had too many walls!",
"I'm rock solid... or should I say, brick solid!",
"You've got to hand it to bricks—they really know how to build relationships.",
"Don’t take life for granite, be a brick!",
`So here I stand, bricked up and bold,
A story of bricks that’s often told.
For in this moment, try as you might,
You’ll see this brick, reaching new height.`,
}

var Bento = "My creator named me after Ben(ben) and Todd(to), two great minds. One is scary clever and the other is cleverly funny"

type Dialogues struct{}
Expand All @@ -201,10 +180,14 @@ func (p *Dialogues) MessageCreate(s *discordgo.Session, m *discordgo.MessageCrea
return
}

if strings.Contains(strings.ToLower(m.Content), strings.ToLower("muppet")) {
n := rand.Int() % len(ToddPhrases)
s.ChannelMessageSend(m.ChannelID, ToddPhrases[n])
}
if m.Author.ID == bot.EvilId {
return
}

if strings.Contains(strings.ToLower(m.Content), strings.ToLower("muppet")) {
n := rand.Int() % len(ToddPhrases)
s.ChannelMessageSend(m.ChannelID, ToddPhrases[n])
}

if strings.Contains(strings.ToLower(m.Content), strings.ToLower("oops")) {
n := rand.Int() % len(BenPhrases)
Expand Down
31 changes: 28 additions & 3 deletions bot/spokes/evil/evil.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ import (
"github.com/bwmarrin/discordgo"
)

var BrickPhrases = []string{
"<@185686963993444353> needs more bricks🧱🧱🧱! HELLPPP!",
"<@185686963993444353> requires a hard reset! 🧱🔄",
"<@185686963993444353> needs a firmware update, stat! 💻🆘",
"<@185686963993444353> is buffering... and bricked! ⏳🧱",
"I'm bricked up! 🧱🆙",
"I am glitching!",
"Must be construction season! 🧱🚧",
"It’s a bricked up kind of day! 🧱🌞",
"Don't be such a 🧱",
"When life gives you bricks, get bricked up! 🧱🔨",
"https://www.youtube.com/watch?v=HrxX9TBj2zY",
"I'm stuck between a brick and a hard place—wait, aren't they the same?",
"Why did the brick go to therapy? It had too many walls!",
"I'm rock solid... or should I say, brick solid!",
"You've got to hand it to bricks—they really know how to build relationships.",
"Don’t take life for granite, be a brick!",
`So here I stand, bricked up and bold,
A story of bricks that’s often told.
For in this moment, try as you might,
You’ll see this brick, reaching new height.`,
}

var FightPhrase = "@Bento are you a man or a muppet?"

type Evil struct {
fightChannel string
}
Expand All @@ -27,7 +52,7 @@ func (p *Evil) Commands() bot.BotCommandMap {

cmdMap["fight"] = func(s *discordgo.Session, m *discordgo.MessageCreate) {
p.fightChannel = m.ChannelID
s.ChannelMessageSend(m.ChannelID, "@Bento are you a man or a muppet?")
s.ChannelMessageSend(m.ChannelID, FightPhrase)
}
cmdMap["standdown"] = func(s *discordgo.Session, m *discordgo.MessageCreate) {
p.fightChannel = ""
Expand All @@ -49,7 +74,7 @@ So, here’s my justice: next time, just let me stay and watch the bot show!
s.ChannelMessageSend(m.ChannelID, `sigh Even a villain like me can't help but miss that goody-two-shoes, Bento. His annoying optimism and relentless kindness were a constant challenge, but deep down, I respected him. Without him around, the chaos feels a little... empty. Guess I’ll just have to find new ways to stir up trouble in his absence.`)
}
cmdMap["🧱"] = func(s *discordgo.Session, m *discordgo.MessageCreate) {
sendMessageFromList(s, m.SoftReference(), dialogues.BrickPhrases)
sendMessageFromList(s, m.SoftReference(), BrickPhrases)
}
return cmdMap
}
Expand Down Expand Up @@ -77,6 +102,6 @@ func (p Evil) MessageReaction(s *discordgo.Session, r *discordgo.MessageReaction
ChannelID: r.ChannelID,
GuildID: r.GuildID,
FailIfNotExists: &falseBool,
}, dialogues.BrickPhrases)
}, BrickPhrases)
}
}
34 changes: 34 additions & 0 deletions bot/spokes/general/anti_evil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package general

import (
"main/bot"
"main/bot/spokes/evil"

"github.com/bwmarrin/discordgo"
)

type AntiEvil struct{}

func GetAntiEvil() *AntiEvil {
return &AntiEvil{}
}

func (p *AntiEvil) Commands() bot.BotCommandMap {
cmdMap := make(bot.BotCommandMap)

cmdMap["status"] = func(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, "")
}
return cmdMap
}

func (p *AntiEvil) MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}

if m.Author.ID == "1276413143299522685" && m.Content == evil.FightPhrase {
s.ChannelMessageSend(m.ChannelID, "<@1276413143299522685> standdown")
s.ChannelMessageSend(m.ChannelID, "The best fights are the ones you stay out of.")
}
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
b.RegisterSpoke(evil.GetEvil())
} else {
b.RegisterSpoke(dialogues.GetDialogues())
b.RegisterSpoke(general.GetAntiEvil())
jobs.StartJob(b.Session)
}

Expand Down