From 461d07b51041643008ac6d1da78fe783d8f87948 Mon Sep 17 00:00:00 2001 From: Martin Persson Date: Tue, 13 Aug 2019 17:11:49 +0200 Subject: [PATCH] New delete syntax & add ability to create categories --- commands.go | 54 +++++++++++++++++++++++++++++++--------------------- completer.go | 5 +++++ help.go | 6 +++--- languages.go | 5 ++++- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/commands.go b/commands.go index 8409c17..156db35 100644 --- a/commands.go +++ b/commands.go @@ -962,7 +962,7 @@ func commandRaw(session *discordgo.Session, source commandSource, cmd string, ar } case "new": if nargs < 2 { - stdutil.PrintErr("new ", nil) + stdutil.PrintErr("new ", nil) return } switch strings.ToLower(args[0]) { @@ -995,34 +995,44 @@ func commandRaw(session *discordgo.Session, source commandSource, cmd string, ar return } fmt.Println(tl("information.channel") + args[1] + tl("information.created.successfully") + vc.ID + ".") + case "category": + if loc.guild == nil { + stdutil.PrintErr(tl("invalid.guild"), nil) + return + } + c, err := session.GuildChannelCreate(loc.guild.ID, args[1], discordgo.ChannelTypeGuildCategory) + if err != nil { + stdutil.PrintErr(tl("failed.category.create"), err) + return + } + fmt.Println(tl("information.category") + args[1] + tl("information.created.successfully") + c.ID + ".") default: - stdutil.PrintErr("new ", nil) - } - case "channeldelete": - if nargs < 1 { - stdutil.PrintErr("channeldelete ", nil) - return - } - _, err := session.ChannelDelete(args[0]) - if err != nil { - stdutil.PrintErr(tl("failed.channel.delete"), err) - return + stdutil.PrintErr("new ", nil) } - fmt.Println(tl("information.channel") + args[0] + tl("information.deleted.successfully")) - case "guilddelete": - if nargs < 1 { - stdutil.PrintErr("guilddelete ", nil) + case "delete": + if nargs < 2 { + stdutil.PrintErr("delete ", nil) return } - _, err := session.GuildDelete(args[0]) - if err != nil { - stdutil.PrintErr(tl("failed.guild.delete"), err) - return + switch strings.ToLower(args[0]) { + case "channel", "category": + _, err := session.ChannelDelete(args[1]) + if err != nil { + stdutil.PrintErr(tl("failed.channel.delete"), err) + return + } + fmt.Println(tl("information.channel") + args[1] + tl("information.deleted.successfully")) + case "guild": + _, err := session.GuildDelete(args[1]) + if err != nil { + stdutil.PrintErr(tl("failed.guild.delete"), err) + return + } + fmt.Println(tl("information.guild") + args[1] + tl("information.deleted.successfully")) } - fmt.Println(tl("information.channel") + args[0] + tl("information.deleted.successfully")) case "move": if nargs < 2 { - stdutil.PrintErr("move ", nil) + stdutil.PrintErr("move ", nil) return } if loc.guild == nil { diff --git a/completer.go b/completer.go index 4ff84fc..45ee89e 100644 --- a/completer.go +++ b/completer.go @@ -111,6 +111,11 @@ func setCompleter(rl *readline.Instance) { readline.PcItem("vchannel"), readline.PcItem("guild"), ), + readline.PcItem("delete", + readline.PcItem("guild"), + readline.PcItem("channel"), + readline.PcItem("category"), + ), ) } func bookmarkTab(line string) []string { diff --git a/help.go b/help.go index cf2fc0e..f7c21d1 100644 --- a/help.go +++ b/help.go @@ -97,7 +97,7 @@ func printHelp(search string) { help = append(help, "output [yes/no]\tToggle showing 'console.' outputs directly in Discord.") help = append(help, "back\tJump to previous guild and/or channel.") help = append(help, "") - help = append(help, "new \tCreate a new guild or channel") + help = append(help, "new \tCreate a new guild or channel") help = append(help, "bans\tList all bans") help = append(help, "ban \tBan user") help = append(help, "unban \tUnban user") @@ -105,8 +105,8 @@ func printHelp(search string) { help = append(help, "leave\tLeave selected guild!") help = append(help, "ownership \tTransfer ownership.") help = append(help, "") - help = append(help, "channeldelete \tDelete a channel.") - help = append(help, "guilddelete \tDelete a guild.") + // Deleting a category also works when selecting channel, but this is less confusing, I hope. + help = append(help, "delete \tDelete a channel, guild or category.") help = append(help, "") help = append(help, "play \tPlays a song in the selected voice channel") help = append(help, "stop\tStops playing any song.") diff --git a/languages.go b/languages.go index 1e7359b..912286c 100644 --- a/languages.go +++ b/languages.go @@ -129,12 +129,12 @@ failed.channel=Could not query channel failed.guild=Could not query guild failed.guild.edit=Could not edit guild failed.channel.create=Could not create channel +failed.category.create=Could not create category failed.channel.delete=Could not delete channel failed.guild.create=Could not create guild failed.guild.delete=Could not delete guild failed.settings=Could not query user settings failed.timestamp=Couldn't parse timestamp -failed.channel.create=Could not create channel failed.msg.query=Could not get message failed.msg.send=Could not send message failed.msg.edit=Couldn't edit message @@ -198,6 +198,7 @@ information.confirmation=Are you really sure you want to do this? information.aborted=Aborted. information.guild=Guild " information.channel=Channel " +information.category=Category " information.created.successfully=" was created successfully with ID information.deleted.successfully=" was deleted successfully. information.revoked.successfully=Revoked @@ -278,6 +279,7 @@ failed.guild=Kunde inte fråga efter server failed.guild.edit=Kunde inte skapa servern failed.timestamp=Kunde inte tolka tidsstämplar failed.channel.create=Kunde inte skapa kanal +failed.category.create=Kunde inte skapa kategori failed.channel.delete=Kunde inte ta bort kanal failed.guild.create=Kunde inte skapa server failed.guild.delete=Kunde inte ta bort server @@ -341,6 +343,7 @@ information.confirmation=Vill du verkligen göra detta? information.aborted=Avbrutet. information.guild=Servern " information.channel=Kanalen " +information.category=Kategorin " information.created.successfully=" skapades med ID information.deleted.successfully=" togs bort. information.revoked.successfully=Återkallade