#This file contains the chars_available and speak functions
# -The "speak" function, which allows Azuria to send a PM, talk on the #gm, or speak in local
#    You input the text you want spoken, which MUST be a string
#    You also input the method. Accepted arguments are "gm" for the #gm, "lc" for local chat, and anything else the program will assume is a username to send a PM to.
# -The "chars_available" function returns how many characters are available for a message, given the method of sending (see above)

from az_error import log_error
from az_time import get_time

def chars_available(method):
    #This variable, maxchars, will store the maximum number of characters that can be sent to the server. Don't know what it is right now,
    #I will check. But basically, depending on the method used, maxchars minus the number of letters used for the command equals the number
    #of characters available.
    maxchars = 0
    if method == "gm":
        command_len = 4 #This is because "#gm " must first be typed, that is 4 characters
    elif method == "lc":
        command_len = 0 #No precursor necessary for local chat
    else:
        command_len = len(method) + 2 #The length of the username plus 2 (one for the "/" and one for the space)
    return maxchars - command_len


def speak(text, method):
    if chars_available(len(text)) - text => 0: #Check to ensure the text does not exceed the limit
        if method == "gm":
            #[*]Send #gm of the text[*]
        elif method == "lc":
            #[*]Send local chat of the text[*]
        else:
            #[*]Send PM to the appropriate recipient of the text[*]
    else:
        if method == "gm":
            method_text = "to the #gm"
        elif method == "lc":
            method_text = "to local chat"
        else:
            method_text = "to " + method + " by PM"
        error = "Sending of message failed. Errory Type: Too Many Characters -- Attemped to send text '" + text + "' " + method_text + "."
        log_error(text, get_time())
