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.