mIRC Homepage
Posted By: eduard0 Getting topic and saving it to %var - 24/07/06 08:47 PM
I'd like to get channel's topic, remove the first word / a specified part of text / some first letters of it and save it to %var after that. How do I do that?
Posted By: OrionsBelt Re: Getting topic and saving it to %var - 24/07/06 09:14 PM
Well doing all of it, is a bit difficult, would require 3 seperate scripts / commands in my opinion.

Anyway, to get the channels topic, and save it in a variable, you could use something like this
Code:
alias Get-Topic {
  set %channel-topic $chan($active).topic
  echo -s Topic is %channel-topic
}


Usage:
/Get-Topic
In the channel where you want to get the topic from.
Currently it will return the topic in the status window, just to visualise it, you could take that part out as well.

To remove the first word, some letter or some part, read up on:
$gettok
$left
$mid
$len

Or specify what you actually want with the topic.

Good luck.
Posted By: eduard0 Re: Getting topic and saving it to %var - 25/07/06 09:01 AM
I'm working on a script that would change a specified channel's topic every 0:00am so that the topic first looks like this (for example): "TTG:91 other text" and after the idea is to replace the TTG:91 with TTG:90 next day and TTG:89 the following day.

I think it's easier to deal with the topic in multiple parts, so that one %var contains the number that will be reduced by 1 every 0:00 and the other topic would be saved in it's own %var.
Posted By: DaveC Re: Getting topic and saving it to %var - 25/07/06 11:32 AM
Code:
;
;usage $new.topic.string(<channel>,<?|-|+|N>)
;
alias new.topic.string {
  if ($chan($1) == $1) {
    if (TTG:* * iswm $chan($1).topic) {
      var %num = $mid($gettok($chan($1).topic),1,32),5)
      if ($2 == ?) { return %num }
      if ($2 == -) { dec %num }
      if ($2 == +) { inc %num }
      if ($2 isnum) { var %num = $2 }
      return $+(TTG:,%num $gettok($chan($1).topic),2-,32))
    }
  }
}

* untested *

This does not set the topic but returns with a new topic string that you can set or do what ever you want with, that or it returns with the NUMBER from the topic
examples below... assume topic of #channelname is "TTG:90 blah blah blah" (the topic must start with TTG: then have one or more words to it.)

//echo -a $new.topic.string(#channelname,?)
90
//echo -a $new.topic.string(#channelname,-)
TTG:89 blah blah blah
//echo -a $new.topic.string(#channelname,+)
TTG:91 blah blah blah
//echo -a $new.topic.string(#channelname,88)
TTG:88 blah blah blah
© mIRC Discussion Forums