Browse Source

Add commands for managing guild bridging

guilds status will list the guild names, their ids, and whether or not the
guild is bridged.

guilds bridge <guildID> will bridge the guild with the given ID. If you add the
--entire flag, it will create a portal for each channel on the guild.

guilds unbridge <guildID> will stop bridging the guild with the given ID and
remove all portals for that guild.

Refs #8
Gary Kramlich 3 years ago
parent
commit
7ec86340c3
1 changed files with 43 additions and 4 deletions
  1. 43 4
      bridge/commands.go

+ 43 - 4
bridge/commands.go

@@ -53,7 +53,7 @@ type commands struct {
 	Reconnect  reconnectCmd  `kong:"cmd,help='Reconnect to Discord'"`
 	Version    versionCmd    `kong:"cmd,help='Displays the version of the bridge.'"`
 
-	Guilds guildsCmd `kong:"cmd,help='Guild bridging management.',hidden='1'"`
+	Guilds guildsCmd `kong:"cmd,help='Guild bridging management.'"`
 
 	LoginMatrix  loginMatrixCmd  `kong:"cmd,help='Replace the puppet for your Discord account with your real Matrix account.'"`
 	LogoutMatrix logoutMatrixCmd `kong:"cmd,help='Switch the puppet for your Discord account back to the default one.'"`
@@ -304,7 +304,9 @@ func (m *pingMatrixCmd) Run(g *globals) error {
 // Guilds Commands
 ///////////////////////////////////////////////////////////////////////////////
 type guildsCmd struct {
-	Status guildStatusCmd `kong:"cmd,help='Show the bridge status for the guilds you are in'"`
+	Status   guildStatusCmd   `kong:"cmd,help='Show the bridge status for the guilds you are in'"`
+	Bridge   guildBridgeCmd   `kong:"cmd,help='Bridge a guild'"`
+	Unbridge guildUnbridgeCmd `kong:"cmd,help="Unbridge a guild'"`
 }
 
 type guildStatusCmd struct{}
@@ -313,9 +315,46 @@ func (c *guildStatusCmd) Run(g *globals) error {
 	g.user.guildsLock.Lock()
 	defer g.user.guildsLock.Unlock()
 
-	for _, guild := range g.user.guilds {
-		fmt.Fprintf(g.context.Stdout, "%s %s %t\n", guild.GuildName, guild.GuildID, guild.Bridge)
+	if len(g.user.guilds) == 0 {
+		fmt.Fprintf(g.context.Stdout, "you haven't joined any guilds.")
+	} else {
+		for _, guild := range g.user.guilds {
+			status := "not bridged"
+			if guild.Bridge {
+				status = "bridged"
+			}
+			fmt.Fprintf(g.context.Stdout, "%s %s %s\n", guild.GuildName, guild.GuildID, status)
+		}
+	}
+
+	return nil
+}
+
+type guildBridgeCmd struct {
+	GuildID string `kong:"arg,help='the id of the guild to unbridge'"`
+	Entire  bool   `kong:"flag,help='whether or not to bridge all channels'"`
+}
+
+func (c *guildBridgeCmd) Run(g *globals) error {
+	if err := g.user.bridgeGuild(c.GuildID, c.Entire); err != nil {
+		return err
 	}
 
+	fmt.Fprintf(g.context.Stdout, "Successfully bridged guild %s", c.GuildID)
+
+	return nil
+}
+
+type guildUnbridgeCmd struct {
+	GuildID string `kong:"arg,help='the id of the guild to unbridge'"`
+}
+
+func (c *guildUnbridgeCmd) Run(g *globals) error {
+	if err := g.user.unbridgeGuild(c.GuildID); err != nil {
+		return err
+	}
+
+	fmt.Fprintf(g.context.Stdout, "Successfully unbridged guild %s", c.GuildID)
+
 	return nil
 }