Remove room alias argument and switch to room after creating
This commit is contained in:
		@@ -40,6 +40,7 @@ type MatrixContainer interface {
 | 
				
			|||||||
	MarkRead(roomID, eventID string)
 | 
						MarkRead(roomID, eventID string)
 | 
				
			||||||
	JoinRoom(roomID, server string) (*rooms.Room, error)
 | 
						JoinRoom(roomID, server string) (*rooms.Room, error)
 | 
				
			||||||
	LeaveRoom(roomID string) error
 | 
						LeaveRoom(roomID string) error
 | 
				
			||||||
 | 
						CreateRoom(req *mautrix.ReqCreateRoom) (*rooms.Room, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	GetHistory(room *rooms.Room, limit int) ([]*mautrix.Event, error)
 | 
						GetHistory(room *rooms.Room, limit int) ([]*mautrix.Event, error)
 | 
				
			||||||
	GetEvent(room *rooms.Room, eventID string) (*mautrix.Event, error)
 | 
						GetEvent(room *rooms.Room, eventID string) (*mautrix.Event, error)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -121,7 +121,7 @@ func cmdHelp(cmd *Command) {
 | 
				
			|||||||
/me <message>      - Send an emote message.
 | 
					/me <message>      - Send an emote message.
 | 
				
			||||||
/rainbow <message> - Send a rainbow message (markdown not supported).
 | 
					/rainbow <message> - Send a rainbow message (markdown not supported).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/create <Room Name> <RoomAlias> - Create a room with associated alias. (Alias must not contain spaces.)
 | 
					/create [room name]  - Create a room.
 | 
				
			||||||
/join <room address> - Join a room.
 | 
					/join <room address> - Join a room.
 | 
				
			||||||
/leave               - Leave the current room.
 | 
					/leave               - Leave the current room.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -205,30 +205,16 @@ func cmdKick(cmd *Command) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func cmdCreateRoom(cmd *Command) {
 | 
					func cmdCreateRoom(cmd *Command) {
 | 
				
			||||||
	if len(cmd.Args) < 2 {
 | 
						req := &mautrix.ReqCreateRoom{}
 | 
				
			||||||
		cmd.Reply("Usage: /create <Room Name> <RoomAlias> (Alias must not contain spaces.)")
 | 
						if len(cmd.Args) > 0 {
 | 
				
			||||||
 | 
							req.Name = strings.Join(cmd.Args, " ")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						room, err := cmd.Matrix.CreateRoom(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							cmd.Reply("Failed to create room:", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Get room name as one string from cmd.Args
 | 
						cmd.MainView.SwitchRoom("", room)
 | 
				
			||||||
	roomName := ""
 | 
					 | 
				
			||||||
	for i, v := range cmd.Args {
 | 
					 | 
				
			||||||
		if i == len(cmd.Args)-1 {
 | 
					 | 
				
			||||||
			break
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		roomName += fmt.Sprintf("%s ", v)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	last := len(cmd.Args) - 1 // last arg for room alias
 | 
					 | 
				
			||||||
	// Build the ReqCreateRoom Struct
 | 
					 | 
				
			||||||
	// https://godoc.org/maunium.net/go/mautrix#ReqCreateRoom
 | 
					 | 
				
			||||||
	req := &mautrix.ReqCreateRoom{
 | 
					 | 
				
			||||||
		Name:          strings.TrimSpace(roomName),
 | 
					 | 
				
			||||||
		RoomAliasName: cmd.Args[last],
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	_, err := cmd.Matrix.Client().CreateRoom(req)
 | 
					 | 
				
			||||||
	debug.Print("Create room error:", err)
 | 
					 | 
				
			||||||
	if err == nil {
 | 
					 | 
				
			||||||
		cmd.Reply("The room has been created.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func cmdJoin(cmd *Command) {
 | 
					func cmdJoin(cmd *Command) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user