Get Started - Learn How To Make Your Bot!Code SnippetsGet methodsPost methodsWeb APIUseful linksList of all currently Free ItemsList of all currently Free EmotesHighrise Bot SDK Changelog
Added on version 23.1.0b8
move_user_to_room(self, user_id: str, room_id: str) -> None:
This enables your bot to move user to another room, bots operator has to be owner of the second room.
βοΈ Use cases
Hereβs an example on how to move an user using a βmove <@user> <room>β command on chat:
async def on_chat(self, user: User, message: str) -> None: if message.startswith("move"): room_dictionary = {"room_1": "<insert here your room id>", "room_2": "<insert here your room id>",} if user.username != "ItsVini": await self.highrise.chat("You do not have permission to use this command.") return parts = message.split() if len(parts) != 3: await self.highrise.chat("Invalid move command format.") return command, username, room = parts if "@" not in username: username = username else: username = username[1:] if room not in room_dictionary: await self.highrise.chat("Invalid room, please specify a valid room.") return #check if user is in room room_users = (await self.highrise.get_room_users()).content for room_user, pos in room_users: if room_user.username.lower() == username.lower(): user_id = room_user.id break if "user_id" not in locals(): await self.highrise.chat("User not found, please specify a valid user and coordinate") return #move user try: await self.highrise.move_user_to_room(user_id, room_dictionary[room]) except Exception as e: await self.highrise.chat(f"Error: {e}") return
Hereβs an step by step explanation on how this code works:
async def on_chat(self, user: User, message: str) -> None:
:- This is an asynchronous function called
on_chat
. - It takes three parameters:
self
,user
, andmessage
. self
is a reference to the instance of the class this method belongs to.user
is an object representing the user who sent the chat message.message
is a string representing the chat message sent by the user.
if message.startswith("move"):
- The function checks if the chat message starts with the string "move". This indicates that the user wants to move someone to another room.
room_dictionary = {"room_1": "<insert here your room id>", "room_2": "<insert here your room id>",}
- This dictionary contains room names as keys and their corresponding room IDs as values. It seems to be a mapping between room names and their unique identifiers.
if user.username != "ItsVini":
- If the user who sent the message is not named "ItsVini", it means they do not have permission to use the "move" command.
- In that case, the function sends a message to the chat using
self.highrise.chat()
informing the user that they don't have permission and then returns, ending the function.
parts = message.split()
- The function splits the message into individual words and stores them in the list
parts
.
if len(parts) != 3:
- If there are not exactly three words in the message (excluding the "move" command itself), it means the move command format is invalid.
- The function sends a message to the chat informing the user of the invalid format and then returns, ending the function.
command, username, room = parts
- The function unpacks the three words from the
parts
list and assigns them to three variables:command
,username
, androom
.
if "@" not in username:
- The code checks if the
username
provided is not prefixed with "@"; if it is not, it means the username doesn't have the "@" symbol and is stored as it is.
else:
- If the username starts with "@", the code removes the "@" symbol from the username using
username = username[1:]
.
if room not in room_dictionary:
- The code checks if the
room
provided is not a valid room name present in theroom_dictionary
. - If the room is invalid, the function sends a message to the chat asking the user to specify a valid room and then returns, ending the function.
(await self.highrise.get_room_users()).content
- The code calls an asynchronous method
get_room_users()
onself.highrise
to fetch a list of users in the room where this chat event occurred. - The result is awaited using
await
. - The method seems to return some kind of response object, and
content
appears to be the actual list of room users.
for room_user, pos in room_users:
- The code iterates through the list of room users and their corresponding positions (positions are not used in this code snippet).
if room_user.username.lower() == username.lower():
- For each user in the room, the code checks if their username (converted to lowercase) matches the provided
username
(also converted to lowercase). - If there's a match, it means the user with the specified username is found in the room, and their
user_id
is stored in a variable.
if "user_id" not in locals():
- After the loop, if there is no
user_id
variable defined, it means the user with the specifiedusername
was not found in the room. - The function sends a message to the chat asking the user to specify a valid user and coordinate (though there's no coordinate mentioned in the code snippet), and then returns, ending the function.
await self.highrise.move_user_to_room(user_id, room_dictionary[room])
:- The code calls an asynchronous method
move_user_to_room(user_id, room_id)
onself.highrise
. - It seems like this method is used to move the user with the specified
user_id
to the room associated with the providedroom
name in theroom_dictionary
.
except Exception as e:
:- If there is an exception raised during the user movement, the code catches it and sends a message to the chat displaying the error message.