Author Topic: Wikilinks, replacing text in messages  (Read 5878 times)

bookofjude

  • Newbie
  • *
  • Posts: 4
Wikilinks, replacing text in messages
« on: March 19, 2006, 06:56:54 PM »
Hi there :-)

The following code takes [[Wiki Links]] (for Wikipedia) and converts them to actual links, then echoes them to the screen. I've never actually used IceChat scripting before--this is my first attempt, and I seem to have broken it, as it only echoes it to the active screen, instead of the channel. What I'm actually looking to do, however, is replace the links in the actual message.

For example:

[10:10] <So and so> [[Test]] blah blah blah

Becomes:

[10:10] <So and so> http://en.wikipedia.org/wiki/Test blah blah blah

Is there any way to actually do this? :D Thanks for help in advance.

Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)             
Dim regEx, CurrentMatch, CurrentMatches, ActualLink, Links, CurrentSearch           
Set regEx = New RegExp             
regEx.Pattern = "\[\[([^\|\]]*)(\|[^\]]*)?\]\]" 
regEx.IgnoreCase = True             
regEx.Global = True             
regEx.MultiLine = True             
Set CurrentMatches = regEx.Execute(Message)             
For Each CurrentSearch in CurrentMatches
     ActualLink = Replace(CurrentSearch,"[[", "")             
     ActualLink = Replace(ActualLink, "]]", "")             
     ActualLink = Replace(ActualLink, "{{", "")             
     ActualLink = Replace(ActualLink, "}}", "")             
     ActualLink = Replace(ActualLink, " ", "_")         
     if ActualLink <> "" Then   
          SendCommand "/echo Wikilink-> http://en.wikipedia.org/wiki/" + ActualLink , ServerNumber             
     End If           
Next           
End Sub

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Wikilinks, replacing text in messages
« Reply #1 on: March 19, 2006, 07:36:19 PM »
Well, if what I am understand is right, all a wiki link is some text within [[ and ]].
Sure, you could use a RexExp, but that seems a bit overkill.

Instead, you just could search for [[ and ]] using Instr, and then get the text between, and replace spaces with underscores.

Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)             
Dim BeginBracket, EndBracket, Link
BeginBracket=Instr(Message,"[[")
EndBracket = Instr(Message,"]]")

If BeginBracket > 0 and BeginBracket < EndBracket then
  Link = Mid(Message,BeginBracket+2, EndBracket-BeginBracket-2)
  Link = Replace(Link," ","_")
  SendCommand "/echo -a http://en.wikipedia.org/wiki/" + Link, ServerNumber 
End if

End Sub
The IceChat God

bookofjude

  • Newbie
  • *
  • Posts: 4
Re: Wikilinks, replacing text in messages
« Reply #2 on: March 19, 2006, 07:41:56 PM »
That's exactly what a wikilink is, but it can also be {{Text}}, so I find the RegExp is a lot easier to use. That part of the script works fine, though. If there isn't a way to actually modify the message onscreen, is there a way to echo it to the window that the message occured in? Becuase if you get several [[Texts]] in different windows, it echoes them all into your current window, and that can be a bit annoying. :-)

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Wikilinks, replacing text in messages
« Reply #3 on: March 19, 2006, 07:55:47 PM »
Look at my example again, I used /echo -a .
The IceChat God

bookofjude

  • Newbie
  • *
  • Posts: 4
Re: Wikilinks, replacing text in messages
« Reply #4 on: March 19, 2006, 08:16:52 PM »
Hm. That still doesn't work. I'll use an example:

Code: [Select]
#channel, in chat tab one, not the current tab

[10:10] <Someone> [[Test]]
[10:11] <Another someone> [[Test]]

#channel2, in chat tab two, also not the current tab

[10:10] <Someone else> [[Blah blah blah]]
[10:11] <Yet another someone> [[Hmmm]]

Private message, in chat tab three, the current tab

[10:10] <Someone else entirely>
Wikilink-> http://en.wikipedia.org/wiki/Test
Wikilink-> http://en.wikipedia.org/wiki/Blah_blah_blah
Wikilink-> http://en.wikipedia.org/wiki/Test
Wikilink-> http://en.wikipedia.org/wiki/Hmmm

That happens with -a, and without -a (which I assume is echo to the active window).

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Wikilinks, replacing text in messages
« Reply #5 on: March 19, 2006, 10:25:50 PM »
Ah, I see what your getting at.
You have to echo to the channel:
Code: [Select]
SendCommand "/echo " + Channel + " blah blah", ServerNumber

This will result in /echo #channel blah blah

And to echo to a specific nickname in a query:
Code: [Select]
SendCommand "/echo =" + NickName + " blah blah", ServerNumber

this results in /echo =Snerf blah blah
The IceChat God

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Wikilinks, replacing text in messages
« Reply #6 on: March 20, 2006, 03:14:59 AM »
If you want the message posted to the channel you should use /msg instead of /echo, like this:
Code: [Select]
SendCommand "/msg " + Channel + " Wikilink-> http://en.wikipedia.org/wiki/ " + ActualLink , ServerNumber
"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

bookofjude

  • Newbie
  • *
  • Posts: 4
Re: Wikilinks, replacing text in messages
« Reply #7 on: March 20, 2006, 09:26:52 PM »
Snerf: Ah, wonderful. That works great, thanks.

Morio: Thanks, too, but I don't want it to send the message to the channel. It's purely a client-side script.