Hi,
I'm in the middle of creating my chat mod for the forums and have come across an issue. One of the commands I will be implementing on there looks as follows: /ban username banlength message_to_user , the user then clicks their send button and the script reads in "/ban" using the following code:
msg = request.form("strMessageInput")
' If the user enters the ban emote then do the ban stuff
If left(lcase(msg), 4) = "/ban" then
' If the user is not an administrator then show them an error
If NOT blnAdmin then
'''' Error stuff goes in here '''''
Else
' This is the main bit where I want to disect the message
End If
' Put the rest of the checks in below
ElseIf left(lcase(msg), 5) = "/kick" then
End If
|
What I want to do from here is create 3 variables 1 to hold the user name of the user to ban and the next to hold the ban length and the final one to hold the message to the user.
What I would like is to ask the question to see if anyone can come up with an easier way to do it than I currently have it planned, as below.
' Take the emote out of the string
msg = replace(lcase(msg), "/ban", "")
' Trim the string to get rid of all spaces at either end if any exist
msg = trim(msg)
' Convert the remaining bit of the message into an array
msgArray = split(msg, " ")
' The first part we need to take out is the username to check
banUsername = msgArray(0)
' Get the length of the ban we are wishing to give the user
banLength = cInt(msgArray(1))
' Get the message to send the user when they are being kicked from the chat
banMsg = msgArray(2)
|
The only problems I have is that from within the 4 part string, 2 of these will be optional - the ban length and the message to the user. So when I run this code and I just enter /ban bootcom the script will spit it out because it is quite clearly no longer an array as there are no spaces to trim. How would I be able to get around this and would anyone have any better suggestions on how to make this work?