mIRC Homepage
Posted By: DJ_Sol mirc error event? - 10/04/11 07:00 PM
Hello,

I don't mean the on error event. Supposedly that only relays an error message from the server. I want access to mirc's internal errors.

Let's say I enter a command that doesn't exist.

/command 1
mIRC says in the status window: COMMAND Unknown command

Is there anyway, besides monitoring my status window, that I can be notified of this in a script?

I was messing around with a text response script where I make mirc remotely perform a dynamic command. (I know how dangerous this can be, thanks.) Just for fun I wanted to let the remote user know if the command failed. I put an :error with messaging at the bottom but it didn't catch the error of the unnknown command.

Code:
  elseif ($1 = .c) $eval($2-,2)
return
:error { echo 4 -s ERROR: $error | msg # $error }


Any ideas? Thanks.
Posted By: starbucks_mafia Re: mirc error event? - 10/04/11 07:13 PM
That message isn't an internal mIRC error. When you execute a command mIRC does the following:
a) Checks for an alias with that name and executes it.
Or if not:
b) Checks for a built-in command with that name and executes it
Or if not:
c) Sends it to the server.

If there's no such command recognised by the server then it will respond with raw 421 (ERR_UNKNOWNCOMMAND), which is what you see in the status window. So in answer to your question you need to use a raw event to catch 421.

If you don't want it to get to the stage where it sends it to the server in the first place then you'd need to perform the checks mentioned above yourself. You can use $isalias() for the first check, unfortunately there's no easy way to check for built-ins so you'd probably have to check against a hardcoded list of existing commands in your script.
Posted By: DJ_Sol Re: mirc error event? - 10/04/11 07:18 PM
Cool man, thanks. smile
Posted By: Masoud Re: mirc error event? - 10/04/11 07:22 PM
If i get your meaning currectly, you can store the channel name and command somewhere and then handle RAW 421 which is for Unknown command... Something like this:

Code:
alias AddCommand {
  if (!$hget(MyCmds)) { hmake MyCmds }
  hadd -m MyCmds $1 $eval($2-,0)
}

on *:Text:*:#:{
  ; Doing some validation for triggers and stuff here...
  AddCommand $chan $eval($2-,0)
  $(,$2-)
}

raw 421:*:{
  if ($hget(MyCmds)) {
    if ($hfind(MyCmds,$+(*,$2,*),1,w).data) {
      msg $gettok($hget(MyCmds,$v1),1,32) It seems $qt($2) is an unknown command!
      hdel MyCmds $v1
    }
  }
}


Hope that helps...
Posted By: Tomao Re: mirc error event? - 10/04/11 07:43 PM
Originally Posted By: starbucks_mafia
unfortunately there's no easy way to check for built-ins so you'd probably have to check against a hardcoded list of existing commands in your script.
It's possible to fetch mIRC's internal errors:
Code:
alias !msg {
  msg # $iif($1,$1-)
  return
  :error
  if (/msg: insufficient parameters isin $error) {
    echo 4 -a * The error $qt($v1) has been caught!
    reseterror
  }
}
/msg <message> will send a message to the channel. Without the message but the /msg command, it'll echo that the error has been caught in red.
Posted By: starbucks_mafia Re: mirc error event? - 10/04/11 07:58 PM
I meant there was no easy way to check if a given string is the name of a built-in command, ie. you cannot know if "/moo" will call an internal command or be sent to the server.
© mIRC Discussion Forums