Skip to content

Commit

Permalink
File per command
Browse files Browse the repository at this point in the history
  • Loading branch information
nint8835 committed Dec 31, 2023
1 parent 2585abf commit c155a4a
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 459 deletions.
25 changes: 25 additions & 0 deletions add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"strings"

"github.com/bwmarrin/discordgo"

"github.com/nint8835/scribe/database"
)

type AddArgs struct {
Text string `description:"Text for the quote to add. To insert a new line, insert \\n."`
Author discordgo.User `description:"Author of the quote."`
Source *string `description:"Link to a source for the quote, if available (such as a Discord message, screenshot, etc.)"`
}

func AddQuoteCommand(_ *discordgo.Session, interaction *discordgo.InteractionCreate, args AddArgs) {
quote := database.Quote{
Text: strings.Replace(args.Text, "\\n", "\n", -1),
Authors: []*database.Author{{ID: args.Author.ID}},
Source: args.Source,
}

addQuote(quote, interaction)
}
38 changes: 38 additions & 0 deletions add_message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"

"github.com/bwmarrin/discordgo"

"github.com/nint8835/scribe/database"
)

func AddQuoteMessageCommand(_ *discordgo.Session, interaction *discordgo.InteractionCreate, message *discordgo.Message) {
if message.Content == "" {
Bot.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Color: (240 << 16) + (85 << 8) + (125),
Title: "Error adding quote.",
Description: "You cannot quote an empty message.",
},
},
Flags: discordgo.MessageFlagsEphemeral,
},
})
return
}

quoteUrl := fmt.Sprintf("https://discord.com/channels/%s/%s/%s", message.GuildID, message.ChannelID, message.ID)

quote := database.Quote{
Text: message.Content,
Authors: []*database.Author{{ID: message.Author.ID}},
Source: &quoteUrl,
}

addQuote(quote, interaction)
}
57 changes: 57 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,63 @@ func Run() error {
return nil
}

func RegisterCommands(parser *switchboard.Switchboard) {
_ = parser.AddCommand(&switchboard.Command{
Name: "add",
Description: "Add a new quote.",
Handler: AddQuoteCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "Quote Message",
Handler: AddQuoteMessageCommand,
GuildID: config.GuildId,
Type: switchboard.MessageCommand,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "get",
Description: "Display an individual quote by ID.",
Handler: GetQuoteCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "random",
Description: "Get a random quote.",
Handler: RandomQuoteCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "list",
Description: "List quotes.",
Handler: ListQuotesCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "remove",
Description: "Remove a quote.",
Handler: RemoveQuoteCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "edit",
Description: "Edit a quote.",
Handler: EditQuoteCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "search",
Description: "Search for quotes.",
Handler: SearchQuotesCommand,
GuildID: config.GuildId,
})
_ = parser.AddCommand(&switchboard.Command{
Name: "db",
Description: "Get a copy of the Scribe database.",
Handler: DbCommand,
GuildID: config.GuildId,
})
}

func main() {
err := Run()
if err != nil {
Expand Down
Loading

0 comments on commit c155a4a

Please sign in to comment.