Using with Python

Python Example

The script includes BasedLang meta programming comments that provide additional context and define models for potential integration with a Large Language Model (LLM).

import telnetlib
import re
HOST = ""
PORT = 23
# Connect to the telnet server
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
# !based0.1:
# let userSelectionModel = "text-davinci-003"
# context userSelectionContext = "Select a user from the chat to interact with."
def select_user():
    # Fetch the list of users from the chat
    tn.write(b"LIST USERS\n")
    users_list = tn.read_until(b"END OF LIST", TIMEOUT).decode('ascii')
    # Extract usernames using regex
    usernames = re.findall(r'Username: (\w+)', users_list)
    # Display the list of users and ask for selection
    print("Select a user to interact with:")
    for i, user in enumerate(usernames):
        print(f"{i + 1}. {user}")
    # Get the user's choice
    selected_index = int(input("Enter the number of the user: ")) - 1
    selected_user = usernames[selected_index]
    # !based0.1:
    # print "User selected: " selected_user
    return selected_user
# Call the function to select a user
selected_user = select_user()
# Now you can interact with the selected user
# For example, send a message to the selected user
message = f"Hello, {selected_user}! How are you today?"
tn.write(f"MESSAGE {selected_user} {message}\n".encode('ascii'))
# Close the connection