Author Topic: Request: URL script  (Read 16235 times)

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Request: URL script
« Reply #15 on: February 15, 2008, 12:00:18 AM »
I think I found a pretty easy way to add flood protection

Code: [Select]
Dim MessageCount
MessageCount = 0

Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
If Channel = "#specificchannel" then
  If Left(Message,8) = "!whatis " then
    If Len(Message) > 8 then
      word = Mid(Message,9)
      definition = GetInifile("definitions.ini","definitions",word,"")
      If MessageCount < 4 then
        If Len(definition) > 0 then
          SendCommand "/msg " & Channel & " " & word & ": " & definition,ServerNumber
          MessageCount = MessageCount + 1
        Else
          SendCommand "/msg " & Channel & " word: " & word & ", not found in database",ServerNumber
          MessageCount = MessageCount + 1
        End If
      ElseIf MessageCount = 4 then
       SendCommand "/timer $randtimer 1 60"
       MessageCounter = 0
      End If
    End If
  End If
End If
End Sub

Once again, I haven't tested it but I hope it works
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Request: URL script
« Reply #16 on: February 15, 2008, 12:29:51 AM »
Code: [Select]
Dim MessageCount
MessageCount = 0

Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
If Channel = "#specificchannel" then
  If Left(Message,8) = "!whatis " then
    If Len(Message) > 8 then
      word = Mid(Message,9)
      definition = GetInifile("definitions.ini","definitions",word,"")
      If MessageCount < 4 then
        If Len(definition) > 0 then
          SendCommand "/msg " & Channel & " " & word & ": " & definition,ServerNumber
          MessageCount = MessageCount + 1
        Else
          SendCommand "/msg " & Channel & " word: " & word & ", not found in database",ServerNumber
          MessageCount = MessageCount + 1
        End If
      ElseIf MessageCount = 4 then
       SendCommand "/timer $randtimer 1 60 /! ResetCounter"
      End If
    End If
  End If
End If
End Sub

Sub ResetCounter()
MessageCounter = 0
End Sub

Ok, so apparently the code I posted earlier won't work, so I made a new one, and this one should work.

this code will let the script send 4 messages, but after every 4th message it will wait 60 before it accepts another request. It might not be exactly what you want, but actual flood protection would get pretty complicated
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Request: URL script
« Reply #17 on: February 15, 2008, 02:11:07 AM »
@Morio: I noticed a problem. I asked my friend to flood whith the !whatis command, and after 4 messages it stopped sending anything, not only after 60 seconds but at all.

And this is exactly what i want ^_^ Just a blockade for the script for not being abused

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Request: URL script
« Reply #18 on: February 15, 2008, 03:44:32 AM »
aa, there's a typo in the script.

In the ResetCounter sub it should be:
MessageCount = 0
not:
Messagecounter = 0

the problem with this kind of flood protection is that it doesn't matter how far apart the 4 messages are, after every 4th message it will wait 60 seconds before responding to the command again.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Request: URL script
« Reply #19 on: February 15, 2008, 04:34:53 AM »
Thanks a lot, now it works exactly like it should. I have lots of ideas for scripts, but don't know anything about scripting..
Anyways here is the full script if anyone would want to use it without going through the whole topic:

First, open the scripts editor (CTRL+S) and add an alias:

Code: [Select]
/define:/! Define $1 | $2 | $3-
Then go to the scripts tab, start a new file and paste the code:

Code: [Select]
Sub Define(action,word,definition)
If action = "add" then WriteInifile "definitions.ini","definitions",word,definition
If action = "remove" then WriteInifile "definitions.ini","definitions",word,""
If action = "repair" then WriteInifile "definitions.ini","definitions",word,definition
End Sub

Dim MessageCount
MessageCount = 0

Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
If Channel = "#your_channel" then
  If Left(Message,8) = "!whatis " then
    If Len(Message) > 8 then
      word = Mid(Message,9)
      definition = GetInifile("definitions.ini","definitions",word,"")
      If MessageCount < 4 then
        If Len(definition) > 0 then
          SendCommand "/msg " & Channel & " " & word & ": " & definition,ServerNumber
          MessageCount = MessageCount + 1
        Else
          SendCommand "/msg " & Channel & " word: " & word & ", not found in database",ServerNumber
          MessageCount = MessageCount + 1
        End If
      ElseIf MessageCount = 4 then
       SendCommand "/timer $randtimer 1 60 /! ResetCounter"
      End If
    End If
  End If
End If
End Sub

Sub ResetCounter()
MessageCount = 0
End Sub

Change the "#your_channel" in
Code: [Select]
If Channel = "#your_channel" then to the name of your channel

save it as a IceChat 5 file

to add definitions use: /define add WORD DEFINITION
to delete definitions use: /define delete WORD DEFINITION
to change definitions use: /define repair WORD DEFINITION

to trigger the script, users of your channel must use the: !whatis WORD
the trigger won't work for yourself

the script has a simple build-in flood protection, 4 msgs in 60 seconds

LilScab

  • Newbie
  • *
  • Posts: 10
Re: Request: URL script
« Reply #20 on: March 01, 2008, 07:09:47 PM »
What is the chance of adding the ability for channel op/admin to add definitions?

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Request: URL script
« Reply #21 on: March 02, 2008, 04:10:50 AM »
You could add something like this to the ONTEXT sub
Code: [Select]
'check if the person is an op
If IsOp(Nickname,Channel,ServerNumber) then
  'check that the message starts with the right command
  If Left(Message,5) = "!add " and Len(Message) > 5
    'get the text after the '!add' command
    TotalWords = Trim(Mid(Message,6))
    If InStr(TotalWords," ") > 0 then
      'get the word
      Word = Left(TotalWords,InStr(TotalWords," ")-1)

      'get the definition
      Definition = Mid(TotalWords,InStr(TotalWords," ")+1)

      'write to the file
      WriteInifile "definitions.ini","definitions",Word,Definition
    End If
  End If
End If

The code for removing a word is pretty similar, you should be able to figure it out from the script
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

LilScab

  • Newbie
  • *
  • Posts: 10
Re: Request: URL script
« Reply #22 on: March 02, 2008, 11:29:36 PM »
thanks for the info, i'll adjust it to my needs later when i get the time.

This adjustment is much appreciated.