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

Aannouncement settings #20

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ discord.command:
msg.button.delete: Schließen
msg.error.not_author: Das ist die Nachricht von %s. Du kannst das nicht verwenden!

announcement:
base: ankündigungen
base.description: Admin Commands für Ankündigungen
display: Ankündigungen

birthday:
base: geburtstag
base.description: Verschiedene Einstellungen für den Geburtstagsbot
Expand Down
5 changes: 5 additions & 0 deletions data/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ discord.command:
msg.teams.title: Teams
msg.teams.team: Team %d

announcement:
base: announcement
base.description: Admin commands for announcements
display: Announcements

secretsanta:
base: Secret Santa
display: Secret Santa
Expand Down
15 changes: 15 additions & 0 deletions modules/announcement/announcementbase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package announcement

import (
"github.com/bwmarrin/discordgo"
"github.com/cake4everyone/cake4everybot/logger"
"github.com/cake4everyone/cake4everybot/util"
)

var log = logger.New("Announcement")

type announcementBase struct {
util.InteractionUtil
member *discordgo.Member
user *discordgo.User
}
51 changes: 51 additions & 0 deletions modules/announcement/chatCommand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package announcement

import (
"github.com/bwmarrin/discordgo"
"github.com/cake4everyone/cake4everybot/data/lang"
"github.com/cake4everyone/cake4everybot/util"
)

// The Chat (slash) command of the announcement package.
type Chat struct {
announcementBase
ID string
}

const (
// Prefix for translation key, i.e.:
// key := tp+"base" // => announcement
tp = "discord.command.announcement."
)

// AppCmd (ApplicationCommand) returns the definition of the chat command
func (cmd Chat) AppCmd() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Name: lang.GetDefault(tp + "base"),
NameLocalizations: util.TranslateLocalization(tp + "base"),
Description: lang.GetDefault(tp + "base.description"),
DescriptionLocalizations: util.TranslateLocalization(tp + "base.description"),
}
}

// Handle handles the functionality of a command
func (cmd Chat) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) {
cmd.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i}
cmd.member = i.Member
cmd.user = i.User
if i.Member != nil {
cmd.user = i.Member.User
} else if i.User != nil {
cmd.member = &discordgo.Member{User: i.User}
}
}

// SetID sets the registered command ID for internal uses after uploading to discord
func (cmd *Chat) SetID(id string) {
cmd.ID = id
}

// GetID gets the registered command ID
func (cmd Chat) GetID() string {
return cmd.ID
}
43 changes: 43 additions & 0 deletions modules/announcement/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package announcement

import (
"strings"

"github.com/bwmarrin/discordgo"
"github.com/cake4everyone/cake4everybot/util"
)

// The Component of the announcement package.
type Component struct {
announcementBase
data discordgo.MessageComponentInteractionData
}

// Handle handles the functionality of a component.
func (c Component) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) {
c.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i}
c.member = i.Member
c.user = i.User
if i.Member != nil {
c.user = i.Member.User
} else if i.User != nil {
c.member = &discordgo.Member{User: i.User}
}
//lint:ignore SA4005 currently not used but will be when implementing the component // TODO: remove when implementing the component
c.data = i.MessageComponentData()

ids := strings.Split(c.data.CustomID, ".")
// pop the first level identifier
util.ShiftL(ids)

switch util.ShiftL(ids) {
default:
log.Printf("Unknown component interaction ID: %s", c.data.CustomID)
}

}

// ID returns the custom ID of the modal to identify the module
func (c Component) ID() string {
return "announcement"
}
Loading