Building a Chat Bot with the highrise Library: A Step-by-Step Explanation

GitHub LINK OF ECHO BOT HIGHRISE

ECHO BOT CODE EXPLANATION FOR NEW USERS:

from highrise import BaseBot, CurrencyItem, Item, Position, Reaction, SessionMetadata, User

This line imports various classes from the highrise library that are likely used within the bot.

class Bot(BaseBot):

A new class Bot is defined, which inherits from BaseBot . This implies that Bot is a specialized version of the BaseBot class from the highrise library.

async def on_user_join(self, user: User) β†’ None:
β€œβ€β€œOn a user joining the room.β€β€œβ€
print(f"[JOIN ] {user.username}")

This is a method called on_user_join that is triggered when a user joins the room. It prints a message indicating the event along with the username of the user who joined.

async def on_user_leave(self, user: User) β†’ None:
β€œβ€β€œOn a user leaving the room.β€β€œβ€
print(f"[LEAVE ] {user.username}")

This method is called when a user leaves the room. It takes a User object as a parameter, representing the user who left. The method prints a message indicating the event, including the username of the user who left the room.

async def on_channel(self, sender_id: str, message: str, tags: set[str]) β†’ None:
β€œβ€β€œOn a hidden channel message.β€β€œβ€
pass # This method does nothing (pass) when a hidden channel message is received.

This method is triggered when a message is sent on a hidden channel. It takes the sender_id (ID of the sender), the message content, and a set of tags as parameters. However, in this implementation, it does nothing (pass ). You might extend this method to handle hidden channel messages based on your specific requirements.

async def on_start(self, session_metadata: SessionMetadata) β†’ None:
print(β€œ[START ]”)

This method is called when the bot starts. It takes session_metadata as a parameter, which could contain information about the session. The method simply prints a message indicating the start of the bot.

async def on_chat(self, user: User, message: str) β†’ None:
print(f"[CHAT ] {user.username}: {message}")

This method is triggered when a chat message is received. It takes a User object and the message content as parameters. The method prints a message indicating the chat event, including the username of the user who sent the message and the message content.

async def on_whisper(self, user: User, message: str) β†’ None:
β€œβ€β€œOn a whisper.β€β€œβ€
print(f"[WHISPER] {user.username} {message}")

This method is called when a whisper (a private message) is received. It takes a User object and the message content as parameters. The method prints a message indicating the whisper event, including the username of the user who sent the whisper and the whisper content.

async def on_emote(self, user: User, emote_id: str, receiver: User | None) β†’ None:
β€œβ€β€œOn a received emote.β€β€œβ€
print(f"[EMOTE ] {user.username} {emote_id} {receiver}")

This method is triggered when an emote is received. It takes the sender (User), emote ID, and optionally a receiver (User or None) as parameters. The method prints a message indicating the emote event, including the username of the user who sent the emote, the emote ID, and the receiver’s username if applicable.

async def on_reaction(self, user: User, reaction: Reaction, receiver: User) β†’ None:
β€œβ€β€œCalled when someone reacts in the room.β€β€œβ€
print(f"[REACTION ] {user.username} {reaction} {receiver.username}")

This method is called when someone reacts in the room. It takes the user who reacted (User ), the reaction object, and the receiver (User ) as parameters. The method prints a message indicating the reaction event, including the usernames of the user who reacted, the reaction itself, and the username of the receiver.

async def on_tip(
self, sender: User, receiver: User, tip: CurrencyItem | Item
) β†’ None:
β€œβ€β€œOn a tip received in the room.β€β€œβ€
print(f"[TIP ] {sender.username} {receiver.username} {tip.type} {tip.amount}")

This method is triggered when a tip is received in the room. It takes the sender (User), receiver (User), and the tip (either CurrencyItem or Item) as parameters. The method prints a message indicating the tip event, including the usernames of the sender and receiver, the type of tip, and the tip amount.

async def on_user_move(self, user: User, pos: Position) β†’ None:
β€œβ€β€œOn a user moving in the room.β€β€œβ€
print(f"[MOVE ] {user.username} {pos.x} {pos.y} {pos.z}")

This method is called when a user moves in the room. It takes the user (User ) and the position (Position object) as parameters. The method prints a message indicating the move event, including the username of the user who moved and the coordinates (x, y, z) of their new position.

5 Likes

could anyone prephaps send me a bot script with working capabilities able to chnage floors and all that i would really appricate it