mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2014
Posts: 65
E
Exuviax Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Mar 2014
Posts: 65
Alright, this is pretty complicated. I am trying to get my bot to add commands in a certain format to an HTML file, which so far, is working! But, now I need him to be able to remove the line from the HTML file.

So far I have tired doing "write -dl(start of sentence) command.file" but it won't delete the line because their is more information then I can provide.

So here is the full script.

Code:

on *:TEXT:!cadd *:#:{
  set %name #
  if ($nick isop $chan) {
    var %command_file = C:\Users\Randy\Documents\ExubotWebsite\ $+ $right(#,-1) $+ \commands.txt
    var %website_file = C:\Users\Randy\Documents\ExubotWebsite\ $+ $right(#,-1) $+ \commands.html
    var %cmd = $mid($1,2)
    var %k = $+($network,-,$chan)

    if ($ini(%command_file,%k,$2) >= 1) {
      var %inusecadd = $rand(1,3)
      if (%inusecadd == 1) { msg # /me $nick > Command already in use.   }
      if (%inusecadd == 2) { msg # /me $nick --> Command already in use.  }
      if (%inusecadd == 3) { msg # /me $nick -> Command already in use.  } 
    }

    else {
      if (! isin $2) {
        var %incorrect $2
        var %correct $remove(%incorrect, $chr(33))
        var %wrongcadd = $rand(1,3)
        if (%wrongcadd == 1) { msg # /me $nick > Incorrect usage: Don't include "!" while setting the command " $+ $2 $+ " instead use " $+ %correct $+ " }
        if (%wrongcadd == 2) { msg # /me $nick --> Incorrect usage: Don't include "!" while setting the command " $+ $2 $+ " instead use " $+ %correct $+ " }
        if (%wrongcadd == 3) { msg # /me $nick -> Incorrect usage: Don't include "!" while setting the command " $+ $2 $+ " instead use " $+ %correct $+ " }       
      } 
      else {
        writeini %command_file %k $2 $3-
        write %website_file <tr> <td class="text-left"> ! $+ $2 </td> <td class="text-left"> $3- </td> </tr>
        var %cadd = $rand(1,3)
        if (%cadd == 1) { msg # /me $nick > The Command ! $+ $2 has been added to $right(#,-1) $+ 's command list: http://exudev.ca/ $+ $right(#,-1) $+ /commands.txt }
        if (%cadd == 2) { msg # /me $nick --> The Command ! $+ $2 has been added to $right(#,-1) $+ 's command list: http://exudev.ca/ $+ $right(#,-1) $+ /commands.txt  }
        if (%cadd == 3) { msg # /me $nick -> The Command ! $+ $2 has been added to $right(#,-1) $+ 's command list: http://exudev.ca/ $+ $right(#,-1) $+ /commands.txt  } 
      }
    }
  }

}
on *:TEXT:!cdel *:#:{
  var %cmd = $mid($2,2)
  if ($nick isop $chan) { 

    var %command_file = C:\Users\Randy\Documents\ExubotWebsite\ $+ $right(#,-1) $+ \commands.txt
    var %website_file = C:\Users\Randy\Documents\ExubotWebsite\ $+ $right(#,-1) $+ \commands.html
    var %k = $+($network,-,$chan)

    var %t = $readini(%command_file,n,%k,%cmd)

    if ($ini(%command_file,%k,$2) >= 1) {
      remini %command_file %k $2
      var %cdel = $rand(1,3)
      if (%cdel == 1) { msg # /me $nick > The command ! $+ $2 has been found in $right(#,-1) $+ 's command list and has been deleted. %t  }
      if (%cdel == 2) { msg # /me $nick --> The command ! $+ $2 has been found in $right(#,-1) $+ 's command list and has been deleted. %t }
      if (%cdel == 3) { msg # /me $nick -> The command ! $+ $2 has been found in $right(#,-1) $+ 's command list and has been deleted. %t } 
    } 
    else { 
      var %cdell = $rand(1,3)
      if (%cdell == 1) { msg # /me $nick > Sorry, command ! $+ $2 could not be found.  }
      if (%cdell == 2) { msg # /me $nick --> Sorry, command ! $+ $2 could not be found.  }
      if (%cdell == 3) { msg # /me $nick -> Sorry, command ! $+ $2 could not be found.  } 
    }
  }
}

on *:TEXT:!commands:#:{
  if ($read(C:\Users\Randy\Documents\ExubotWebsite\ $+ $right(#,-1) $+ \commands.txt)) {
    var %clist = $rand(1,3)
    if (%clist == 1) { msg # /me $nick > Command list: http://exudev.ca/ $+ $right(#,-1) $+ /commands.txt   }
    if (%clist == 2) { msg # /me $nick --> Command list: http://exudev.ca/ $+ $right(#,-1) $+ /commands.txt  }
    if (%clist == 3) { msg # /me $nick -> Command list: http://exudev.ca/ $+ $right(#,-1) $+ /commands.txt.  } 
  }
  else {
    var %cnone = $rand(1,3)
    if (%cnone == 1) { msg # /me $nick > No commands found. Use !cadd [command] [message] to add new commands (No Brackets) }
    if (%cnone == 2) { msg # /me $nick --> No commands found. Use !cadd [command] [message] to add new commands (No Brackets)  }
    if (%cnone == 3) { msg # /me $nick -> No commands found. Use !cadd [command] [message] to add new commands (No Brackets)  }
  }
}



on $*:TEXT:m/\!.*/iS:#:{
  var %command_file = C:\Users\Randy\Documents\ExubotWebsite\ $+ $right(#,-1) $+ \commands.txt
  var %cmd = $mid($1,2)

  if ($me == $nick) {
    halt 
  }

  var %k = $+($network,-,$chan)
  var %t = $readini(%command_file,n,%k,%cmd)

  if ($len(%t)) { 
    var %command = $rand(1,3)
    if (%command == 1) { msg # /me > %t  }
    if (%command == 2) { msg # /me --> %t  }
    if (%command == 3) { msg # /me -> %t  } 
  }
}



So as you can see, when you add a command into the bot it writes it in two spots. Commands.txt and Commands.html (For the site) it writes it in like this



Which is awesome, because the site is reading it fine. Now come the trouble of removing one of those lines when the user type !cdel COMMMAND

I am not sure how I can get it to specify the exact line I want, as it is variable, and the user doesn't type in what the command says, with !cadd I have the user type in "Command" and "message" which is how it is set, but when removing the script has to find it just by "Command" which is what I am having issues with..

Thank you in advance


I do things with stuff that makes other things do stuff.
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
You could make a token variable that could keep track of the order of the commands.
Code:
set $addtok(%commandtokenname, $2, 32)

then find the token number
Code:
set %linenumbertobeerased $findtoken(%commandtokenname, $2, 32)

you would then delete the token and the line
Code:
set $deltok(%commandtokenname, %linenumbertobeerased, 32)
write -dl %linenumbertobeerased Commands.html

you could also use a while loop to iterate over the document for the line containing the text
Code:
var %c $2
var %l $lines(Commands.html)
var %i 1
while (%i < %l) {
tokenize 32 $read(Commands.html, n, %i)
if (%c == $4) { write -dl %i Commands.html }
inc %i
}



Last edited by Belhifet; 14/12/14 11:16 PM.
Joined: Jul 2006
Posts: 4,180
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
Originally Posted By: /help /write
The -s# switch scans a file for the line beginning with the specified text and performs the operation on that line.

/write -dstest c:\info.txt

This will scan file info.txt for a line beginning with the word "test" and if found, deletes it.
You need /write -ds, not -dl, something like
Code:
/write -ds"<tr> <td class="text-left"> ! $+ $2"


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Mar 2014
Posts: 65
E
Exuviax Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Mar 2014
Posts: 65
The only problem with this would be the bot being used in multiple channels.. smirk


I do things with stuff that makes other things do stuff.
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Your original question failed to mention that :< Just add the channel to whatever variable you'd like to use.

Last edited by Belhifet; 15/12/14 01:35 AM.
Joined: Mar 2014
Posts: 65
E
Exuviax Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Mar 2014
Posts: 65
I would love to use your code, and I thank you for posting it. But, unfortunately I just don't know mIRC enough to understand how to implement your code.


I do things with stuff that makes other things do stuff.

Link Copied to Clipboard