Skip to content

Commit

Permalink
support attachment type option
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenserCai committed Aug 27, 2023
1 parent a20ec29 commit e39c5bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion dbot/slash_handler/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Date: 2023-08-17 09:52:25
* @version:
* @LastEditors: SpenserCai
* @LastEditTime: 2023-08-27 16:19:12
* @LastEditTime: 2023-08-27 19:30:05
* @Description: file content
*/
package slash_handler
Expand Down Expand Up @@ -33,6 +33,10 @@ func (shdl SlashHandler) GetCommandStr(i *discordgo.Interaction) string {
cmd += fmt.Sprintf("%v: ```json\n%v```\n", utils.FormatCommand(v.Name), v.Value)
continue
}
if v.Type == discordgo.ApplicationCommandOptionAttachment {
cmd += fmt.Sprintf("%v: %v\n", utils.FormatCommand(v.Name), i.ApplicationCommandData().Resolved.Attachments[v.Value.(string)].URL)
continue
}
cmd += fmt.Sprintf("%v: %v\n", utils.FormatCommand(v.Name), v.Value)
}
return cmd
Expand Down
19 changes: 10 additions & 9 deletions dbot/slash_handler/png_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Date: 2023-08-19 18:27:34
* @version:
* @LastEditors: SpenserCai
* @LastEditTime: 2023-08-22 14:36:40
* @LastEditTime: 2023-08-27 19:30:36
* @Description: file content
*/
package slash_handler
Expand All @@ -27,21 +27,22 @@ func (shdl SlashHandler) PngInfoOptions() *discordgo.ApplicationCommand {
Description: "Get image info",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "image_url",
Description: "The url of the image",
Type: discordgo.ApplicationCommandOptionAttachment,
Name: "image",
Description: "The image",
Required: true,
},
},
}
}

func (shdl SlashHandler) PngInfoSetOptions(dsOpt []*discordgo.ApplicationCommandInteractionDataOption, opt *intersvc.SdapiV1PngInfoRequest) {
func (shdl SlashHandler) PngInfoSetOptions(cmd discordgo.ApplicationCommandInteractionData, opt *intersvc.SdapiV1PngInfoRequest) {

for _, v := range dsOpt {
for _, v := range cmd.Options {
switch v.Name {
case "image_url":
opt.Image = func() *string { v, _ := utils.GetImageBase64(v.StringValue()); return &v }()
case "image":
fileUrl := cmd.Resolved.Attachments[v.Value.(string)].URL
opt.Image = func() *string { v, _ := utils.GetImageBase64(fileUrl); return &v }()
}
}
}
Expand Down Expand Up @@ -73,7 +74,7 @@ func (shdl SlashHandler) PngInfoCommandHandler(s *discordgo.Session, i *discordg
shdl.ReportCommandInfo(s, i)
node := global.ClusterManager.GetNodeAuto()
action := func() (map[string]interface{}, error) {
shdl.PngInfoSetOptions(i.ApplicationCommandData().Options, option)
shdl.PngInfoSetOptions(i.ApplicationCommandData(), option)
shdl.PngInfoAction(s, i, option, node)
return nil, nil
}
Expand Down

0 comments on commit e39c5bd

Please sign in to comment.