Author Topic: request for a !warn script  (Read 6796 times)

Jatin

  • Newbie
  • *
  • Posts: 9
request for a !warn script
« on: August 27, 2012, 06:36:08 AM »
hey guys i am using icechat from the day the latest version is released and i am new to it . i dont know much abt scripting but can u make a !warn script i want it to work like as follows
when i write !warn <name> <reason> it should show that [WARNING] <name> hav been warned by <the warning giving person > for the reason :- <reason>
and if a plyer only writes !warn it should show :- plese use  this !warn <name> <reason>

plese make it for me i will very thankfull to u guys ......:)

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: request for a !warn script
« Reply #1 on: August 27, 2012, 06:50:09 AM »
So you want it to show when you write it, or when other people write it as well?
The IceChat God

Jatin

  • Newbie
  • *
  • Posts: 9
Re: request for a !warn script
« Reply #2 on: August 27, 2012, 07:22:09 AM »
can u give me both plese

Jatin

  • Newbie
  • *
  • Posts: 9
Re: request for a !warn script
« Reply #3 on: August 27, 2012, 07:49:56 AM »
 :wink: i want it fast plese snerf

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: request for a !warn script
« Reply #4 on: August 27, 2012, 08:14:57 AM »
If you want it fast, then learn to do this on your own.
People are doing this out of their own free time, and when someone has the time to write it, they will post it.
The IceChat God

Jatin

  • Newbie
  • *
  • Posts: 9
Re: request for a !warn script
« Reply #5 on: August 27, 2012, 08:19:47 AM »
ahh sorry sorry sir but i dont know how to do it can u plese plese do it for me plese

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: request for a !warn script
« Reply #6 on: August 27, 2012, 04:35:11 PM »
If someone wants to write the script for you, they will paste it here.

I do not write scripts.
The IceChat God

gear4

  • Newbie
  • *
  • Posts: 4
Re: request for a !warn script
« Reply #7 on: September 09, 2012, 01:25:27 PM »
I made this for ya:


Quote from: Code
If Left(Message, 5) = "!warn" Then
  Dim segments
  segments = split(Message, " ")

  Select Case True
    Case Mid(ToMessage, 7) = ""
      Sendcommand "/notice " & Nickname & " Error: No nickname specified",ServerNumber
    Case Not InStr(Nicks(Channel,ServerNumber), segments(1))
      Sendcommand "/notice " & Nickname & " Error: Invalid user",ServerNumber
    Case Mid(ToMessage, Len(segments(0) + segments(1)) + 2) = ""
      Sendcommand "/notice " & Nickname & " Error: No warning for user",ServerNumber
    Case Else
      Sendcommand "/msg " & Channel & " [WARNING] " & segments(1) & " has been warned by " & Nickname & " for the reason: " & Mid(Message, Len(segments(0)) + Len(segments(1)) + 2),ServerNumber
  End Select
End If
« Last Edit: September 09, 2012, 01:30:50 PM by gear4 »

gear4

  • Newbie
  • *
  • Posts: 4
Re: request for a !warn script
« Reply #8 on: September 09, 2012, 02:32:40 PM »
Updated:



Quote from: Code
Dim RepeatNumber, KickOps, KickVoice, MaxWarn
Set RepeatNumber = CreateObject("Scripting.Dictionary") ' initializing RepeatNumber
KickOps = False    ' Kick ops (default off)
KickVoice = False  ' Kick voice (default off)
MaxWarns = 3 ' Max warnings

Sub ONTEXT(ToMessage,Channel,Nickname,Host,ServerNumber)
  Message = RemoveCodes(ToMessage)

  If Left(Message, 5) = "!warn" Then
    Dim segments
    segments = split(Message, " ")

    Select Case True
      Case Mid(ToMessage, 7) = "" ' Specified nickname?
        Sendcommand "/notice " & Nickname & " Error: No nickname specified",ServerNumber
      Case Not InStr(Nicks(Channel,ServerNumber), segments(1)) ' Valid nickname?
        Sendcommand "/notice " & Nickname & " Error: Invalid user",ServerNumber
      Case Mid(ToMessage, Len(segments(0) + segments(1)) + 2) = "" ' Specified warning ?
        Sendcommand "/notice " & Nickname & " Error: No warning for user",ServerNumber
      Case Else
        Select Case True
          Case IsOp(NickName,Channel,ServerNumber) and KickOps = False ' Is user op ? Is kick ops on ?
            Exit Sub
          Case IsVoice(NickName,Channel,ServerNumber) and KickVoice = False ' Is user voice ? Is kick voice on ?
            Exit Sub
          Case Not IsOp(GetIdentifier("$me"),Channel,ServerNumber) ' Am I op?
            Exit Sub
          Case Not RepeatNumber.Exists(Nickname & ":" & Channel & ":" & ServerNumber) ' does nick exist in warning amount?
            RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber) = 1
            Sendcommand "/msg " & Channel & " [WARNING] " & segments(1) & " has been warned by " & Nickname & " for the reason: " & Mid(Message, Len(segments(0)) + Len(segments(1)) + 2) & " (" & (MaxWarns - RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber)) & " warnings left)",ServerNumber
          Case MaxWarns - RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber) = 1 ' Is maxwarns hit?
            SendCommand "/msg " & Channel & " &kick " & Nickname & " hit max warnings (" & RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber)  & ")",ServerNumber
            RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber) = 0
          Case Else
            RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber) = RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber) + 1
            Sendcommand "/msg " & Channel & " [WARNING] " & segments(1) & " has been warned by " & Nickname & " for the reason: " & Mid(Message, Len(segments(0)) + Len(segments(1)) + 2) & " (" & (MaxWarns - RepeatNumber.Item(NickName & ":" & Channel & ":" & ServerNumber)) & " warnings left)",ServerNumber
        End Select
    End Select
  End If
End Sub
« Last Edit: September 09, 2012, 02:36:23 PM by gear4 »

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: request for a !warn script
« Reply #9 on: September 11, 2012, 06:59:53 AM »
I haven't tried the script, but there are a few lines that I think might cause errors in some cases.
Code: [Select]
If Left(Message, 5) = "!warn" Then
you might want to change that to
Code: [Select]
If Left(Message, 6) = "!warn " and Len(Message) > 6 Then
That way you can be sure that the message contains a space, and that you will get an array with with at least 2 elements. Otherwise this:
Code: [Select]
Case Mid(ToMessage, 7) = "" ' Specified nickname?and this:
Code: [Select]
Case Not InStr(Nicks(Channel,ServerNumber), segments(1)) ' Valid nickname?might cause errors.

You could also change this:
Code: [Select]
Case Mid(ToMessage, Len(segments(0) + segments(1)) + 2) = "" ' Specified warning ?to
Code: [Select]
Case UBound(segments) < 3 which triggers if the array "segments" has less than 3 elements (that is, if the reason for the warning is missing), and is a bit more elegant than the code you are using.

You could also add this:
Code: [Select]
If UBound(segments) < 3 then Exit Subright after the line where you split the message into an array. That way you only need to check if segments(1) is a valid nickname, since the script will terminate if the message doesn't consist of at least 3 words

"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

gear4

  • Newbie
  • *
  • Posts: 4
Re: request for a !warn script
« Reply #10 on: September 11, 2012, 09:21:26 AM »
I haven't tried the script, but there are a few lines that I think might cause errors in some cases.
Code: [Select]
If Left(Message, 5) = "!warn" Then
you might want to change that to
Code: [Select]
If Left(Message, 6) = "!warn " and Len(Message) > 6 Then
^ No need for "Len(Message) > 6", "Case Mid(ToMessage, 7) = """ checks that for us, and even gives an error

That way you can be sure that the message contains a space, and that you will get an array with with at least 2 elements. Otherwise this:
Code: [Select]
Case Mid(ToMessage, 7) = "" ' Specified nickname?and this:
Code: [Select]
Case Not InStr(Nicks(Channel,ServerNumber), segments(1)) ' Valid nickname?might cause errors.
^ This's why I never used what you wanted me to. Your way won't tell what's wrong - which is plain dumb, incase someone tries to use the script, and sees it's broken.

Code: [Select]
Case Mid(ToMessage, 7) = "" ' Specified nickname?That checks if the nickname was specified, if not, give warning and stop doing anything

Code: [Select]
Case Not InStr(Nicks(Channel,ServerNumber), segments(1)) ' Valid nickname?Only executed once "Case Mid(ToMessage, 7) = """ has been cleared

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: request for a !warn script
« Reply #11 on: September 12, 2012, 12:40:51 PM »
Thank you, I hope many users put it to good use.
The IceChat God

gear4

  • Newbie
  • *
  • Posts: 4
Re: request for a !warn script
« Reply #12 on: September 13, 2012, 03:35:52 AM »
no problem, and with the amount of time I put into this, I hope it's used well too.

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: request for a !warn script
« Reply #13 on: September 13, 2012, 08:40:44 AM »
It might be a good idea to store the warnings to a file instead of a dictionary object, since those reset when you reload your scripts (and when restarting icechat of course). And if you decide to store the warnings to a file, it might be better to use the server name instead of the number, because the number will change depending on the order in which you connect to the servers.

I also noticed one more thing that I would probably change for the script, since it seems to be designed to work on multiple servers.

Code: [Select]
Case Not IsOp(GetIdentifier("$me"),Channel,ServerNumber) ' Am I op?
I haven't written any scripts in a long time, but I think Getidentifier("$me") will get your nickname on the server you happen to have active at the moment, whereas IsOp(GetIdentifier("$me"),Channel,ServerNumber) will try to compare the nickname to the server and channel from which the warning message originated.

So for example if you are on two servers with nicknames "nickname1" and "nickname2" and someone on server 1 gets a warning but you happen to have server 2 open. Then the script will check for "nickname2" on server 1 and channel 1, instead of checking for "nickname1" as you would want it to.

To avoid this I think you can use GetIdentifier("$me",ServerNumber) to get your nickname on a specific server.
"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

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: request for a !warn script
« Reply #14 on: September 13, 2012, 12:05:08 PM »
Well caught Morio.

By the way, for a little nugget of information, MyNickname(ServerNumber) works the same as GetIdentifier("$me", ServerNumber)


I will look into making a similar plugin for IceChat 9.
« Last Edit: September 13, 2012, 12:07:04 PM by Snerf »
The IceChat God