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

impl change command #104

Merged
merged 1 commit into from
Aug 25, 2024
Merged
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
119 changes: 119 additions & 0 deletions pkg/command/emoji_detail_change_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package command

import (
"MisskeyEmojiBot/pkg/config"
"MisskeyEmojiBot/pkg/handler"
"MisskeyEmojiBot/pkg/repository"
"strconv"

"github.com/bwmarrin/discordgo"
)

type EmojiDetailChangeCommand interface {
}

type emojiDetailChangeCommand struct {
config config.Config
emojiRepository repository.EmojiRepository
discordRepo repository.DiscordRepository
}

func NewEmojiDetailChangeCommand(config config.Config, emojiRepository repository.EmojiRepository, discordRepo repository.DiscordRepository) handler.CommandInterface {
return &emojiDetailChangeCommand{config: config, emojiRepository: emojiRepository, discordRepo: discordRepo}
}

func (c *emojiDetailChangeCommand) GetCommand() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Name: "change_emoji_detail",
Description: "絵文字申請のプロパティを変更します",
Type: discordgo.ChatApplicationCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "property",
Description: "Property to change (name, category, tag, license, other)",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionString,
Name: "value",
Description: "New value for the property",
Required: true,
},
},
}
}

func (c *emojiDetailChangeCommand) Execute(s *discordgo.Session, i *discordgo.InteractionCreate) {
if !c.discordRepo.HasRole(c.config.GuildID, *i.Member.User, c.config.ModeratorID) {
c.discordRepo.ReturnFailedMessage(i, "No permission.")
return
}

channel, _ := s.Channel(i.ChannelID)
emoji, err := c.emojiRepository.GetEmoji(channel.Name)
if err != nil {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "設定に失敗しました。管理者に問い合わせを行ってください。\n",
},
})
}

options := i.ApplicationCommandData().Options
if len(options) < 2 {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "引数が足りません / Not enough arguments.",
},
})
return
}

property := options[0].StringValue()
value := options[1].StringValue()

switch property {
case "name":
emoji.Name = value
case "category":
emoji.Category = value
case "tag":
emoji.Tag = value
case "license":
emoji.License = value
case "other":
emoji.Other = value
default:
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "プロパティが見つかりません / Property not found.",
},
})
return
}

s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "プロパティを変更しました / Changed the property.",
},
})

s.ChannelMessageSend(channel.ID, "# 変更後の絵文字\n")
s.ChannelMessageSend(channel.ID,
"- Name : **"+emoji.Name+"**\n"+
"- Category: **"+emoji.Category+"**\n"+
"- Tag : **"+emoji.Tag+"**\n"+
"- License : **"+emoji.License+"**\n"+
"- Other : **"+emoji.Other+"**\n"+
"- NSFW : **"+strconv.FormatBool(emoji.IsSensitive)+"**\n")

}