Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
21 kB
1
Indexable
Never
from highrise import BaseBot, CurrencyItem, Item, Position, Reaction, SessionMetadata, User
from typing import Optional, Dict, Union

from highrise import *
from highrise.models import *
import asyncio
from asyncio import Task
import os
import importlib.util
import time
import random
from websockets.exceptions import ConnectionClosed
import re
import socket
user_task_map = {}

usernames = [
    "JimmyBey",
    "YusufSinns",
    "Forzo404",
    "chinarro",
    "izHirry",
    "syndicatexe",
    "TheSanji",
    "Suriyelicarsafi",
    "uzivice",
    "TBO28",
    "ITraxy",
    "B4TUESCOB4R",
    "pengumen",
    "avenger08",
    "M4ST1",
    "Jerey",
    "Batukekocu",
    "ELXAANN",
    "EFUL1M01",
    "iKousei",
    "u.c.a.r.20",
    "1CcRuuaz",
    "MehmetHKT",
    "aroeye",
    "awelll1",
    "Oguzhainzz"
]

dance_emotes = [
    "dance-dontstartnow",
    "dance-russian",
    "dance-macarena",
    "dance-hype",
    "dance-jinglebell",
    "dance-tiktok9",
    "dance-weird",
    "dance-tiktok10",
    "dance-anime",
    "dance-icecream",
    "dance-wrong",
    "dance-employee",
    "dance-touch",
    "dance-pinguin",
    "dance-creepypuppet",
    "dance-shoppingcart",
    "dance-blackpink",
]

timed_free_emotes_list = [
    {'value': 'none','text': 'none', 'time': 0},
    {'value': 'sit-relaxed', 'text': 'relaxed', 'time': 29.889858},
    {'value': 'emote-kissing-bound', 'text': 'Sweet Smooch', 'time': 5},
    {'value': 'idle-loop-sitfloor', 'text': 'Sit', 'time': 22.321055},
    {'value': 'idle-enthusiastic', 'text': 'Enthused', 'time': 15.941537},
    {'value': 'emote-yes', 'text': 'Yes', 'time': 2.565001},
    {'value': 'emote-wave', 'text': 'The Wave', 'time': 2.690873},
    {'value': 'emote-tired', 'text': 'Tired', 'time': 4.61063},
    {'value': "emote-zombierun", 'text': "Zombie Run", 'time': 10 },
    {'value': 'emote-snowball', 'text': 'Snowball Fight!', 'time': 5.230467},
    {'value': 'emote-snowangel', 'text': 'Snow Angel', 'time': 6.218627},
    {'value': 'emote-shy', 'text': 'Shy', 'time': 4.477567},
    {'value': 'emote-sad', 'text': 'Sad', 'time': 5.411073},
    {'value': 'emote-no', 'text': 'No', 'time': 2.703034},
    {'value': 'emote-model', 'text': 'Model', 'time': 6.490173},
    {'value': 'emote-lust', 'text': 'Flirty Wave', 'time': 4.655965},
    {'value': 'emote-laughing', 'text': 'Laugh', 'time': 2.69161},
    {'value': 'emote-kiss', 'text': 'Kiss', 'time': 2.387175},
    {'value': 'emote-hot', 'text': 'Sweating', 'time': 4.353037},
    {'value': 'emote-hello', 'text': 'Hello', 'time': 2.734844},
    {'value': 'emote-greedy', 'text': 'Greedy', 'time': 4.639828},
    {'value': 'emote-curtsy', 'text': 'Curtsy', 'time': 2.425714},
    {'value': 'emote-confused', 'text': 'Confusion', 'time': 8.578827},
    {'value': 'emote-charging', 'text': 'Charging', 'time': 8.025079},
    {'value': 'emote-bow', 'text': 'Bow', 'time': 3.344036},
    {'value': 'emoji-thumbsup', 'text': 'Thumbs Up', 'time': 2.702369},
    {'value': 'emoji-gagging', 'text': 'Tummy Ache', 'time': 5.500202},
    {'value': 'emoji-flex', 'text': 'Flex', 'time': 2.099351},
    {'value': 'emoji-cursing', 'text': 'Cursing Emote', 'time': 2.382069},
    {'value': 'emoji-celebrate', 'text': 'Raise The Roof', 'time': 3.412258},
    {'value': 'emoji-angry', 'text': 'Angry', 'time': 5.760023},
    {'value': 'dance-tiktok8', 'text': 'Savage Dance', 'time': 10.938702},
    {'value': 'dance-tiktok2', 'text': "Don't Start Now", 'time': 10.392353},
    {'value': 'dance-shoppingcart', 'text': "Let's Go Shopping", 'time': 4.316035},
    {'value': 'dance-russian', 'text': 'Russian Dance', 'time': 10.252905},
    {'value': 'dance-pennywise', 'text': "Penny's Dance", 'time': 1.214349},
    {'value': 'dance-macarena', 'text': 'Macarena', 'time': 12.214141},
    {'value': 'dance-blackpink', 'text': 'K-Pop Dance', 'time': 7.150958},
    {'value': 'emote-hyped', 'text': 'Hyped', 'time': 7.492423},
    {'value': 'dance-jinglebell', 'text': 'JingleHop', 'time': 10.958832},
    {'value': 'idle-nervous', 'text': 'Nervous', 'time': 21.714221},
    {'value': 'idle-toilet', 'text': 'Toilet', 'time': 32.174447},
    {'value': 'emote-astronaut', 'text': '#Zero', 'time': 13.791175},
    {'value': 'emote-hearteyes', 'text': 'Heart Eyes', 'time': 4.034386},
    {'value': 'emote-swordfight', 'text': 'Swordfight', 'time': 5.914365},
    {'value': 'emote-timejump', 'text': 'TimeJump', 'time': 4.007305},
    {'value': 'emote-snake', 'text': 'Snake', 'time': 5.262578},
    {'value': 'emote-float', 'text': 'Float', 'time': 8.995302},
    {'value': 'emote-telekinesis', 'text': 'Telekinesis', 'time': 10.492032},
    {'value': 'dance-pinguin', 'text': 'Penguin dance', 'time': 11.58291},
    {'value': 'dance-creepypuppet', 'text': 'Creepy puppet', 'time': 6.416121},
    {'value': 'emote-sleigh', 'text': 'Sleigh', 'time': 11.333165},
    {'value': 'emote-maniac', 'text': 'Maniac', 'time': 4.906886},
    {'value': 'emote-energyball', 'text': 'Energy Ball', 'time': 7.575354},
    {'value': 'idle_singing', 'text': 'Singing', 'time': 10.260182},
    {'value': 'emote-frog', 'text': 'Frog', 'time': 14.55257},
    {'value': 'emote-superpose', 'text': 'Superpose', 'time': 4.530791},
    {'value': 'emote-cute', 'text': 'Cute', 'time': 6.170464},
    {'value': 'dance-tiktok9', 'text': 'TikTok Dance 9', 'time': 11.892918},
    {'value': 'dance-weird', 'text': 'Weird Dance', 'time': 21.556237},
    {'value': 'dance-tiktok10', 'text': 'TikTok Dance 10', 'time': 8.225648},
    {'value': 'emote-pose7', 'text': 'Pose 7', 'time': 4.655283},
    {'value': 'emote-pose8', 'text': 'Pose 8', 'time': 4.808806},
    {'value': 'idle-dance-casual', 'text': 'Casual Dance', 'time': 9.079756},
    {'value': 'emote-pose1', 'text': 'Pose 1', 'time': 2.825795},
    {'value': 'emote-pose3', 'text': 'Pose 3', 'time': 5.10562},
    {'value': 'emote-pose5', 'text': 'Pose 5', 'time': 4.621532},
    {'value': 'emote-cutey', 'text': 'Cutey', 'time': 3.26032},
    {'value': 'emote-punkguitar', 'text': 'Punk Guitar', 'time': 9.365807},
    {'value': 'emote-fashionista', 'text': 'Fashionista', 'time': 5.606485},
    {'value': 'emote-gravity', 'text': 'Gravity', 'time': 8.955966},
    {'value': 'dance-icecream', 'text': 'Ice Cream Dance', 'time': 14.769573},
    {'value': 'dance-wrong', 'text': 'Wrong Dance', 'time': 12.422389},
    {'value': 'idle-uwu', 'text': 'UwU', 'time': 24.761968},
    {'value': 'idle-dance-tiktok4', 'text': 'TikTok Dance 4', 'time': 15.500708},
    {'value': 'dance-pinguin', 'text': 'Penguin dance', 'time': 15.500708},
    {'value': 'dance-russian', 'text': 'Dance Russian', 'time': 10.252905},
    {'value': 'emote-shy2', 'text': 'Advanced Shy', 'time': 4.989278},
    {'value': 'dance-anime', 'text': 'Anime Dance', 'time': 8.46671},
    {'value': 'dance-kawai', 'text': 'Kawaii', 'time': 10.290789},
    {'value': 'idle-wild', 'text': 'Scritchy', 'time': 26.422824},
    {'value': 'emote-iceskating', 'text': 'Ice Skating', 'time': 7.299156},
    {'value': 'emote-pose6', 'text': 'SurpriseBig', 'time': 5.375124},
    {'value': 'emote-celebrationstep', 'text': 'Celebration Step', 'time': 3.353703},
    {'value': 'emote-creepycute', 'text': 'Creepycute', 'time': 7.902453},
    {'value': 'emote-pose10', 'text': 'Pose 10', 'time': 3.989871},
    {'value': 'emote-boxer', 'text': 'Boxer', 'time': 5.555702},
    {'value': 'emote-headblowup', 'text': 'Head Blowup', 'time': 11.667537},
    {'value': 'emote-pose9', 'text': 'Ditzy Pose', 'time': 4.583117},
    {'value': 'emote-teleporting', 'text': 'Teleporting', 'time': 11.7676},
    {"value": "dance-touch", "text": "Touch", "time": 11.7},
    {"value": "idle-guitar", "text": "Air Guitar", "time": 13.229398},
    {"value": "emote-gift", "text": "This Is For You", "time": 5.8},
    {"value": "dance-employee", "text": "Push it", "time": 8},
    {"value": "emote-cutesalute", "text": "Cute Salute", "time": 8},
    {"value": "emote-salute", "text": "Salute", "time": 8},
]

class TaskGroup:
    def __init__(self):
        self.tasks = {}

    async def create_task(self, coro, name):
        task = asyncio.create_task(coro)
        self.tasks[name] = task

    async def cancel_task(self, name):
        if name in self.tasks:
            self.tasks[name].cancel()
            del self.tasks[name]

class Bot(BaseBot):
    def __init__(self):
        self.taskgroup = TaskGroup()
        self.user_follow_tasks_map = {}
    
    async def command_handler(self, user: User, message: str, number: int):
        command = message
                
        functions_folder = "functions"
        # Check if the function exists in the module
        for file_name in os.listdir(functions_folder):
            if file_name.endswith(".py"):
                module_name = file_name[:-3]  # Remove the '.py' extension
                module_path = os.path.join(functions_folder, file_name)
                
                # Load the module
                spec = importlib.util.spec_from_file_location(module_name, module_path)
                module = importlib.util.module_from_spec(spec)
                spec.loader.exec_module(module)
                
                # Check if the function exists in the module
                if hasattr(module, command) and callable(getattr(module, command)):
                    function = getattr(module, command)
                    await function(self, user, number)
        return

    async def on_start(self, session_metadata: SessionMetadata) -> None:
        await self.highrise.chat(f"vip")
        await self.highrise.teleport(user_id="663e07a881544f2ccb7d962b", dest=Position(float(10.5), float(13.25), float(7.5)))  


        
           

    async def send_continuous_random_emotes_in_dance_floor(self):
        emote_duration_mapping = {
            "dance-russian": 3,
            "dance-macarena": 3,
            "dance-jinglebell": 3,
            "dance-tiktok9": 3,
            "dance-weird": 3,
            "dance-tiktok10": 3,
            "dance-anime": 3,
            "dance-icecream": 3,
            "dance-wrong": 3,
            "dance-employee": 3,
            "dance-touch": 3,
            "dance-pinguin": 3,
            "dance-creepypuppet": 3,
            "dance-shoppingcart": 3,
            "dance-blackpink": 3,
        }
        min_x = 3.5
        max_x = 8.5
        min_y = 0.25
        max_y = 0.6  # Since it's a flat plane, the Y-coordinate range remains constant
        min_z = 5.5
        max_z = 10.5

        last_emote_times = {}  # Dictionary to store the last emote time for each user
        user_triggers = {}  # Tracks if a user has been teleported already
        while True:
            try:
                room_users = await self.highrise.get_room_users()
                current_time = time.time()
                for user, position in room_users.content:
                    if isinstance(position, Position):
                        x, y, z = position.x, position.y, position.z
                    else:
                        continue  # Skip non-Position data types
                
                    user_in_region = (min_x <= x <= max_x and min_y <= y <= max_y and min_z <= z <= max_z)
                    if user_in_region:
                        if user_triggers.get(user.id, 0) == 0:
                            # Teleport user slightly and update the trigger to prevent re-teleportation
                            target_position = Position(x + 1, y, z)
                            await self.highrise.teleport(user_id=user.id, dest=target_position)
                            user_triggers[user.id] = 1
                            

                        last_emote_time = last_emote_times.get(user.id, 0)
                        if current_time >= last_emote_time:
                            emote_name = random.choice(list(emote_duration_mapping.keys()))
                            await self.highrise.send_emote(emote_name, user.id)
                            last_emote_times[user.id] = current_time + emote_duration_mapping[emote_name]
                    else:
                        # Reset trigger if user is outside the region
                        if user_triggers.get(user.id, 0) == 1:
                            user_triggers[user.id] = 0
                           
        
            except Exception as e:
                print(f"An error occurred: {str(e)}")

            await asyncio.sleep(2)  # Control the frequency of checks

    async def on_user_join(self, user: User, position: Position | AnchorPosition) -> None:
        """On a user moving in the room."""
        # await self.highrise.chat(f"Nirvanaya hoş geldin 😎 {user.username} ❤️❤️Seni burada görmek güzel😎.")
        await self.highrise.chat(f"OYUN VE VİTRİN ODASINA hoş geldin 😎 {user.username} ❤️❤️Seni burada görmek güzel😎")
        return
    
    async def on_user_leave(self, user: User) -> None:
         await self.highrise.chat(f"{user.username} Hoşçakal yine bekleriz 😎 ")
    async def loop_emote(self: BaseBot, user: User, number_or_name: Union[int, str]) -> None:
        emote_id = ""
        emote_name = ""

        # Use the provided timed_free_emotes_list
        if isinstance(number_or_name, int):
            if 0 <= number_or_name < len(timed_free_emotes_list):
                emote_data = timed_free_emotes_list[number_or_name]
                emote_name = emote_data["text"]
                emote_id = emote_data["value"]
        else:
            for emote_data in timed_free_emotes_list:
                if emote_data["text"].lower() == number_or_name.lower():
                    emote_name = emote_data["text"]
                    emote_id = emote_data["value"]
                    break

        if not emote_id:
            return

        # Check if there is an existing task for the user and cancel it if there is
        if user.username in user_task_map:
            existing_task = user_task_map[user.username]
            existing_task.cancel()



        # Register and start a new task for the user
        user_task_map[user.username] = asyncio.create_task(self.run_emote_loop(user, emote_id, emote_name))
 

    async def run_emote_loop(self, user: User, emote_id: str, emote_name: str):
        user_position = None
        user_in_room = False
        room_users = (await self.highrise.get_room_users()).content
        for room_user, position in room_users:
            if room_user.id == user.id:
                user_position = position
                start_position = position
                user_in_room = True
                break
        if user_position is None:
            await self.highrise.chat("User not found")
            return

        # await self.highrise.chat(f"@{user.username} is looping {emote_name}")

        while start_position == user_position:
            try:
                await self.highrise.send_emote(emote_id, user.id)
            except Exception as e:
                print(f"Error sending emote: {e}")
                return
            emote_duration = next(item["time"] for item in timed_free_emotes_list if item["value"] == emote_id)
            await asyncio.sleep(emote_duration)
    
            # Check if user has moved or left
            room_users = (await self.highrise.get_room_users()).content
            user_in_room = False
            for room_user, position in room_users:
                if room_user.id == user.id:
                    user_position = position
                    user_in_room = True
                    break
            if not user_in_room:
                break

    async def get_user_position(self, message: str):
        # Get the list of room users
        room_users = (await self.highrise.get_room_users()).content
        for room_user, position in room_users:
            if room_user.username.lower() == message.lower():
                try:
                    return {"x": position.x, "y": position.y, "z": position.z}
                except AttributeError:
                    return None
        return None

    async def follow_user(self, user, target_user):
        if target_user is None:
            return
        while True:
            try:
                target_position = await self.get_user_position(target_user)
                if target_position is not None:
                    await self.highrise.teleport(user_id=user.id, dest=Position(target_position['x'] + 1, target_position['y'], target_position['z']))
            except Exception as e:
                print(f"Error in follow_user: {e}")
                return

    async def on_chat(self, user: User, message: str) -> None:
          
        if message.strip().isnumeric():  # Check if the message is a numeric string
            number = int(message.strip())
            if 0 <= number <= len(timed_free_emotes_list):  # Check if the number is within the range of emotes
                await self.loop_emote(user, number)  # Call loop_emote with user and the emote number
            
        elif message.lower() == "stop":
            if user.username in user_task_map:
                existing_task = user_task_map[user.username]
                existing_task.cancel()
                del user_task_map[user.username]
        else:
            # If the message is not a number or "stop", assume it's an emote name
            await self.loop_emote(user, message)  # Call loop_emote with user and the message (emote name)


        
        if message.lower() == "position":
            user_position = await self.get_user_position(user.username)    
            await self.highrise.chat(f"{user_position}")
            
        if message.lower() == "katıl":
            user_position = await self.get_user_position(user.username)
            if user_position is not None:
                await self.highrise.teleport(user_id=user.id, dest=Position(float(7), float(0.25), float(19.5))) 

        if message.lower() == "kelime":
            user_position = await self.get_user_position(user.username)
            if user_position is not None:
                await self.highrise.teleport(user_id=user.id, dest=Position(float(7), float(0.25), float(19.5)))    
        
        if message.lower() == "renk":
            user_position = await self.get_user_position(user.username)
            if user_position is not None:
                await self.highrise.teleport(user_id=user.id, dest=Position(float(7.5), float(0.5), float(12.5)))
            

    

        if message.lower().startswith("take trip"):
            target_user = user.username
            if target_user not in self.user_follow_tasks_map:
                task_name = f"follow_task_{len(self.user_follow_tasks_map)}"
                self.user_follow_tasks_map[target_user] = task_name
                await self.taskgroup.create_task(coro=self.follow_user(user, target_user), name=task_name)
                await self.highrise.chat(f"trip started {target_user}")
        elif message.lower() == "stop":
            if user.username in self.user_follow_tasks_map:
                task_name = self.user_follow_tasks_map[user.username]
                if task_name in self.taskgroup.tasks:
                    task = self.taskgroup.tasks[task_name]
                    try:
                        task.cancel()
                        print(f"Cancelled task for user: {user.username}")
                    except Exception as e:
                        print(f"Error cancelling task for user: {user.username}: {e}")
                    del self.user_follow_tasks_map[user.username]
                    await self.highrise.chat("trip stopped.")
                    
        if message.lower().startswith("tp @".lower()):
            parts = message.split("@")
            if len(parts) > 1 and parts[1].strip():
                target_user = parts[1].strip()
                if user.username not in self.user_follow_tasks_map:
                    target_position = await self.get_user_position(target_user)
                    if target_position is not None:
                        await self.highrise.teleport(user_id=user.id, dest=Position(target_position['x'] + 500, target_position['y']+500, target_position['z']+500))
                        await self.highrise.chat(f"take trip")
            else:
                await self.highrise.chat(" ")
                
# Run the bot
if __name__ == "__main__":
    bot = Bot()
    bot.run()
Leave a Comment