Get Started - Learn How To Make Your Bot!
List of all currently Free Items
Added on version 23.1.0b5
moderate_room(self, user_id: str, action: Literal["kick", "ban", "unban", "mute"], action_length: int | None = None,) -> None:
Takes action against a user in the room.
Here’s an example on how to kick an user using a “kick <@user>” command on chat:
async def on_chat(self, user: User, message: str) -> None:
if message.startswith("kick"):
if user.username == "ItsVini":
pass
else:
await self.highrise.chat("You do not have permission to use this command.")
return
#separete message into parts
parts = message.split()
#check if message is valid "kick @username"
if len(parts) != 2:
await self.highrise.chat("Invalid kick command format.")
return
#checks if there's a @ in the message
if "@" not in parts[1]:
username = parts[1]
else:
username = parts[1][1:]
#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
#kick user
try:
await self.highrise.moderate_room(user_id, "kick")
except Exception as e:
await self.highrise.chat(f"{e}")
return
#send message to chat
await self.highrise.chat(f"{username} has been kicked from the room.")
Let's break down the code step-by-step to understand its functionality:
async def on_chat(self, user: User, message: str) -> None:
This is the definition of an asynchronous function named on_chat
. It takes three arguments:
self
: The reference to the instance of the class (assuming this function is inside a class).user
: An object representing the user who sent the message, probably containing user information like their username.message
: A string representing the content of the user's message in the chat.if user.username == "ItsVini":
This checks if the user who sent the message has the username "ItsVini." If so, the code proceeds without performing the kick action. This probably means that the user "ItsVini" is exempt from being kicked.if len(parts) != 2:
This checks if the split message has exactly two parts. If not, the code sends a message to the chat indicating an "Invalid kick command format," and the function returns.username
. Otherwise, it removes the "@" symbol and assigns the modified second part as the username
.username
. It does a case-insensitive comparison by converting both the room_user's username and the given username
to lowercase.user_id
, indicating that the user has been found.user_id
variable is not present, it means the specified user was not found in the chat room. The code sends a message to the chat saying "User not found, please specify a valid user and coordinate," and the function returns.await self.highrise.moderate_room(user_id, "kick")
statement. This function likely sends a moderation command to remove the specified user from the chat room.username
has been kicked from the room.Overall, this code is designed to allow users with the username "ItsVini" to use the "kick" command to remove other users from the chat room. Other users attempting to use the "kick" command will receive a message indicating they don't have permission. The function requires the "kick" command to be in the format "kick @username," where username
is the username of the user to be kicked. If the specified user is found in the chat room, they will be kicked, and a confirmation message will be sent to the chat.