Difference between revisions of "Making a !request script"

From Scriptwiki
Jump to: navigation, search
(Added pertection against parting all chans)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
I would assume most bot channels use TCLs for this kind of function, but if you really want to use mIRC, here's how to start.
 
I would assume most bot channels use TCLs for this kind of function, but if you really want to use mIRC, here's how to start.
  
  <nowiki>;The on text event of course
+
  ;The on text event of course
on *:text:!request *:#channel: {
+
[[On_text|on *:text]]:!request *:#channel: {
;You will probably want to add some if statements & anti-spam here
+
  ;You will probably want to add some if statements & anti-spam here
;Set the requesters nickname to a variable, for later use
+
  ;Set the requesters nickname to a variable, for later use
;Use gettok to make sure the user isn't requesting #bleh,0 (making your bot part all channels) or #1,#2,#3 (making the bot join multiple channels)
+
  ;Use gettok to make sure the user isn't requesting #bleh,0 (making your bot part all channels) or #1,#2,#3 (making the bot join multiple channels)
set %request. $+ $gettok($2,1,44) $nick
+
  [[set]] %request. $+ [[$gettok]]([[$1-|$2]],1,44) [[$nick]]
join $gettok($2,1,44)
+
  ;Check that we aren't about to "join 0" and part all channels.
}
+
  if ($gettok($2,1,44) != 0) [[join]] [[$v1]]
 
+
}
;Raw 366 is 'End of /NAMES list' (see raws page) and the best trigger for our next part
+
 
+
;Raw 366 is 'End of /NAMES list' (see raws page) and the best trigger for our next part
raw 366:*: {
+
;Lets have it check wheter or not there's a request for the channel, using the variable we set earlier
+
[[Raw_366|raw 366]]:*: {
;..and continue only if that variable exists
+
  ;Lets have it check wheter or not there's a request for the channel, using the variable we set earlier
if (%request. [ $+ [ $2 ] ]) {
+
  ;..and continue only if that variable exists
 
+
  [[If-Then-Else|if]] (%request. [ $+ [ $2 ] ]) {
  ;Here's where you should add all your 'checks'
+
  ;For example, if we want it to deny the request if the channel doesn't have 5 users
+
    ;Here's where you should add all your 'checks'
  if ($nick($2,0) < 5) {
+
    ;For example, if we want it to deny the request if the channel doesn't have 5 users
    ;We will use the variable again, this time to get the requester nickname
+
    if ([[$nick]]($2,0) < 5) {
     msg %request. [ $+ [ $2 ] ] Your request has been denied
+
      ;We will use the variable again, this time to get the requester nickname
 +
      msg %request. [ $+ [ $2 ] ] Your request has been denied
 +
    }
 +
 +
     ;Lets also have it check if the requester is opped on the channel
 +
    elseif (%request. [ $+ [ $2 ] ] !isop $2) {
 +
      msg %request. [ $+ [ $2 ] ] Your request has been denied
 +
    }
 +
 +
    ;If the channel didn't get denied yet, continue with the acception part:
 +
    else {
 +
      [[msg]] %request. [ $+ [ $2 ] ] Your request has been accepted
 +
      ;You should put your bot-add script here, for example:
 +
      msg Mybot addchannel $2
 +
      msg Mybot addowner $2 %request. [ $+ [ $2 ] ]
 +
    }
 +
 +
    ;And unset the variable to keep it clean :)
 +
    [[unset]] %request. $+ $2
 +
    ;Finally, have the bot leave the channel
 +
    [[part]] $2
 
   }
 
   }
 
  ;Lets also have it check if the requester is opped on the channel
 
  elseif (%request. [ $+ [ $2 ] ] !isop $2) {
 
    msg %request. [ $+ [ $2 ] ] Your request has been denied
 
  }
 
 
  ;If the channel didn't get denied yet, continue with the acception part:
 
  else {
 
    msg %request. [ $+ [ $2 ] ] Your request has been accepted
 
    ;You should put your bot-add script here, for example:
 
    msg Mybot addchannel $2
 
    msg Mybot addowner $2 %request. [ $+ [ $2 ] ]
 
  }
 
 
  ;And unset the variable to keep it clean :)
 
  unset %request. $+ $2
 
  ;Finally, have the bot leave the channel
 
  part $2
 
 
  }
 
  }
}
+
 
+
 
+
;-----------------------------------------------------------
;-----------------------------------------------------------
+
;Now, you'll probably want the script to work with supplied botnames, ie: !request #channel botname
;Now, you'll probably want the script to work with supplied botnames, ie: !request #channel botname
+
;which is also quite simple:
;which is also quite simple:
+
 
+
on *:text:!request *:#channel: {
on *:text:!request *:#channel: {
+
  ;We'll make it save the 3rd word (botname) aswell
;We'll make it save the 3rd word (botname) aswell
+
  set %request. $+ $gettok($2,1,44) $nick
set %request. $+ $gettok($2,1,44) $nick
+
  set %requestbot. $+ $gettok($2,1,44) $3
set %requestbot. $+ $gettok($2,1,44) $3
+
  if ($gettok($2,1,44) != 0) join $v1
join $gettok($2,1,44)
+
}
}
+
 
+
;We use the raw 366 again but replace this part:
;We use the raw 366 again but replace this part:
+
msg Mybot addchannel $2
msg Mybot addchannel $2
+
msg Mybot addowner $2 %request. [ $+ [ $2 ] ]
msg Mybot addowner $2 %request. [ $+ [ $2 ] ]
+
;With:
;With:
+
msg %requestbot. [ $+ [ $2 ] ] addchannel $2
msg %requestbot. [ $+ [ $2 ] ] addchannel $2
+
msg %requestbot. [ $+ [ $2 ] ] addowner $2 %request. [ $+ [ $2 ] ]
msg %requestbot. [ $+ [ $2 ] ] addowner $2 %request. [ $+ [ $2 ] ]
+
;You'll obviously need to change those to match the commands of your own bot
;You'll obviously need to change those to match the commands of your own bot
+
 
+
 +
;The rest is up to you
 +
;You will most likely want to add statements that make sure $2 and $3 exist, and $3 is infact a bot and not some random user
 +
;Have fun :)
  
;The rest is up to you
 
;You will most likely want to add statements that make sure $2 and $3 exist, and $3 is infact a bot and not some random user
 
;Have fun :)</nowiki>
 
 
[[Category:Script Archive]]
 
[[Category:Script Archive]]

Latest revision as of 17:22, 3 May 2006

We get a number of people asking about !Request scripts every week I would assume most bot channels use TCLs for this kind of function, but if you really want to use mIRC, here's how to start.

;The on text event of course
on *:text:!request *:#channel: {
  ;You will probably want to add some if statements & anti-spam here
  ;Set the requesters nickname to a variable, for later use
  ;Use gettok to make sure the user isn't requesting #bleh,0 (making your bot part all channels) or #1,#2,#3 (making the bot join multiple channels)
  set %request. $+ $gettok($2,1,44) $nick
  ;Check that we aren't about to "join 0" and part all channels.
  if ($gettok($2,1,44) != 0) join $v1
}

;Raw 366 is 'End of /NAMES list' (see raws page) and the best trigger for our next part

raw 366:*: {
  ;Lets have it check wheter or not there's a request for the channel, using the variable we set earlier
  ;..and continue only if that variable exists
  if (%request. [ $+ [ $2 ] ]) {

    ;Here's where you should add all your 'checks'
    ;For example, if we want it to deny the request if the channel doesn't have 5 users
    if ($nick($2,0) < 5) {
      ;We will use the variable again, this time to get the requester nickname
      msg %request. [ $+ [ $2 ] ] Your request has been denied
    }

    ;Lets also have it check if the requester is opped on the channel
    elseif (%request. [ $+ [ $2 ] ] !isop $2) {
      msg %request. [ $+ [ $2 ] ] Your request has been denied
    }

    ;If the channel didn't get denied yet, continue with the acception part:
    else {
      msg %request. [ $+ [ $2 ] ] Your request has been accepted
      ;You should put your bot-add script here, for example:
      msg Mybot addchannel $2
      msg Mybot addowner $2 %request. [ $+ [ $2 ] ]
    }

    ;And unset the variable to keep it clean :)
    unset %request. $+ $2
    ;Finally, have the bot leave the channel
    part $2
  }
}


;-----------------------------------------------------------
;Now, you'll probably want the script to work with supplied botnames, ie: !request #channel botname
;which is also quite simple:

on *:text:!request *:#channel: {
  ;We'll make it save the 3rd word (botname) aswell
  set %request. $+ $gettok($2,1,44) $nick
  set %requestbot. $+ $gettok($2,1,44) $3
  if ($gettok($2,1,44) != 0) join $v1
}

;We use the raw 366 again but replace this part:
msg Mybot addchannel $2
msg Mybot addowner $2 %request. [ $+ [ $2 ] ]
;With:
msg %requestbot. [ $+ [ $2 ] ] addchannel $2
msg %requestbot. [ $+ [ $2 ] ] addowner $2 %request. [ $+ [ $2 ] ]
;You'll obviously need to change those to match the commands of your own bot


;The rest is up to you
;You will most likely want to add statements that make sure $2 and $3 exist, and $3 is infact a bot and not some random user
;Have fun :)