Author Topic: onTEXT notices  (Read 4890 times)

LilScab

  • Newbie
  • *
  • Posts: 10
onTEXT notices
« on: May 03, 2008, 10:24:52 PM »
working on a basic ontext notice script, but what i need to add, but don't know how, is the ability for someone in my chatroom to trigger the notice to another person.

this is what is currently does, it will send the notice to the person who uses the command
Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
     if instr(Message,"!news") then
       SendCommand "/notice " & NickName & " 4" & NickName & "12, read this! [link to news article] ",ServerNumber
     end if
End Sub

what i would like to add is something like "!news [nickname]" as the trigger where [nickname] is who the notice will be sent to.

HackBenjamin

  • Newbie
  • *
  • Posts: 35
Re: onTEXT notices
« Reply #1 on: May 04, 2008, 01:49:55 PM »
working on a basic ontext notice script, but what i need to add, but don't know how, is the ability for someone in my chatroom to trigger the notice to another person.

this is what is currently does, it will send the notice to the person who uses the command
Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
     if instr(Message,"!news") then
       SendCommand "/notice " & NickName & " 4" & NickName & "12, read this! [link to news article] ",ServerNumber
     end if
End Sub

what i would like to add is something like "!news [nickname]" as the trigger where [nickname] is who the notice will be sent to.

Code: [Select]
sub ontext(message,channel,nickname,host,servernumber)
if lcase(left(message,6)) = "!news " and if len(message) > 6 then
 username = mid(message,7)
  SendCommand "/notice " & username & " " & username & " read this & [link]",servernumber
end if
end sub
 

You gotta split up the !news from the target
 lcase converts the message to lowercase, so that it triggers on any case
  left(message,6) takes all the text from the beginning of the message to the 6th character
   len(message) > 6 checks if the message is longer than 6 characters
    mid(message,7) takes everything after the 7th character and uses that as the username

  I hope I hepled you a little

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: onTEXT notices
« Reply #2 on: May 04, 2008, 02:31:59 PM »
You might wanna add this part to HackBenjamin's code:

Code: [Select]
If InStr(Username," ") then Username = Left(Username,InStr(Username," ")-1)

this prevents the script from being abused, in case someone has a script that can be triggered with notices
"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: onTEXT notices
« Reply #3 on: May 04, 2008, 08:48:58 PM »
Thanks for the assistance, it is much appreciated.

LilScab

  • Newbie
  • *
  • Posts: 10
Re: onTEXT notices
« Reply #4 on: May 04, 2008, 09:11:13 PM »
back again quickly, i am obviously missing something, because as is, i am getting a syntax error in line #3, and i can't see what it is.

Code: [Select]
sub ontext(message,channel,nickname,host,servernumber)
If InStr(Username," ") then Username = Left(Username,InStr(Username," ")-1)
if lcase(left(message,6)) = "!news " and if len(message) > 6 then
 username = mid(message,7)
  SendCommand "/notice " & username & " " & username & " read this! [link] ",servernumber
end if
end sub

as before, any help is much appreciated.

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: onTEXT notices
« Reply #5 on: May 04, 2008, 10:23:54 PM »
You got it backwards.
When you are checking for Username at first, it has no value, because you have not assigned it a value.

Code: [Select]
Sub Ontext(message,channel,nickname,host,servernumber)
If lcase(left(message,6)) = "!news " and len(message) > 6 then
  Username = mid(message,7)
  If InStr(Username," ") then Username = Left(Username,InStr(Username," ")-1)
  SendCommand "/notice " & username & " read this! [link]",Servernumber
End if
End Sub
The IceChat God

LilScab

  • Newbie
  • *
  • Posts: 10
Re: onTEXT notices
« Reply #6 on: May 08, 2008, 03:41:48 AM »
Thanks for the help again.

I switched the lines around but still got a syntax error, so i copied the code from your post snerf, and everything was fixed, dunno what the problem was, but you are GOD !!!!   :-D

Amis

  • Newbie
  • *
  • Posts: 17
Re: onTEXT notices
« Reply #7 on: May 16, 2008, 12:43:35 AM »
the problem is:

if lcase(left(message,6)) = "!news " and if len(message) > 6 then

The red part is not needed