mIRC Home    About    Download    Register    News    Help

Print Thread
Recognize name of Alias calling another Alias? #266509 20/12/19 02:03 AM
Joined: Jan 2017
Posts: 57
KubosKube Offline OP
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
Sorry for the confusing thread title. Ran out of space.

I need an alias to recognize either the name of the alias calling it, or the filepath of the alias calling it.

For example:
Code
alias customA { 
   customB test-text
}

alias customB {
   echo -a $nameOfCallingAlias wants to say $1-
}


Running alias customA would result in an echo of "customA wants to say test-text"
Optionally, I could use $isalias(customA).fname to get customA's filepath. So in essence, as an alternative, I could use "$isalias($nameOfCallingAlias).fname".

What I need to know is... can I do that? Is there a non-fictional identifier to replace my mythological $nameOfCallingAlias ?

Re: Recognize name of Alias calling another Alias? [Re: KubosKube] #266510 20/12/19 03:46 AM
Joined: Apr 2010
Posts: 946
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 946
There is not a way to get the caller's name.

May I ask what you are trying to do specifically?


I am SReject
My Stuff
Re: Recognize name of Alias calling another Alias? [Re: KubosKube] #266513 20/12/19 09:35 AM
Joined: Jan 2004
Posts: 1,407
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,407
This is something that's been requested several times over the years, you can search the forum for threads mentioning $caller $calias caller calias etc. There is a similar identifier $caller but this only returns the general type of 'thing' that called the identifier. So, $caller tells you whether something is in a /timer or the editbox or an event etc. It can tell you the $caller identifier was called from within a custom command or custom identifier, but not the name of it You can see more details in https://en.wikichip.org/wiki/mirc/identifiers/$caller

The only way I can think of which currently sort-works is something that's not universal, because it works only if the caller alias creates something the called-alias can see, then must clean up after itself. And, if you don't know which alias called customB, you'd have to go everywhere customB is mentioned and add the extra tracking info.

You can either pass an optional parameter, or create a %global_variable or a hashtable item or a &binary_variable, where all except the 1st requires the caller-alias delete the item so there aren't any later false positives.

Code
alias customA { 
   customB test-text customA
   noop $customB(test-test,customA)
}

alias customB {
   echo -a $2 wants to say $1-
}

alias customA { 
   hadd -m callertable caller customA
   customB test-text
   noop $customB(test-test)
   hdel callertable caller
}

alias customB {
   echo -a $hget(callertable,caller) wants to say $1-
}

alias customA { 
   bset -t &caller customA
   customB test-text
   noop $customB(test-test)
   bunset &caller
}

alias customB {
   echo -a $bvar(&caller,1-).text wants to say $1-
}

alias customA { 
   set %callername customA
   customB test-text
   noop $customB(test-test)
   unset %callername
}

alias customB {
   echo -a %callername wants to say $1-
}


If customB can be called by somthing besides an alias where you defined the answer, you can have conditional logic checking if the answer exists.

if ($2 != $null) do this | else do that
if ($bvar(&caller,0)) do this | else do that
if ($hget(callertable,caller) != $null) do this | else do that
if (%callername != $null) do this | else do that

Re: Recognize name of Alias calling another Alias? [Re: FroggieDaFrog] #266519 20/12/19 06:46 PM
Joined: Jan 2017
Posts: 57
KubosKube Offline OP
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
I'm compartmentalizing my file storage, so I can make and share scripts that are easy to install/uninstall, and each script will keep track of it's data in it's own file. The file system should look a little like this:
Code
$mircdir
   Scripts
      KubosKubot-Scripts
         core.KubosKubot
            core.KubosKubot.mrc
            core.config.KubosKubot.ini
         plugin.Example
            plugin.Example.mrc
            plugin.config.Example.ini


What I want is to make an alias inside core.KubosKubot.mrc that can read and write to ini files dependent on where the alias trying to write is at. For example,

Code
core.KubosKubot.mrc
alias kubot.ReadIni {
   set %temp $isalias($callingAlias).fname
   return $readini($mircdir\scripts\KubosKubot-Scripts\ $+ $remove(%temp, .mrc) $+ \ $+ $replace(%temp, .mrc, .ini), Section, Item)


I'm not at my PC, I'm on my lunch at work, so I can't check to see if I used $remove and $replace correctly.

Re: Recognize name of Alias calling another Alias? [Re: KubosKube] #266522 21/12/19 02:22 AM
Joined: Jan 2017
Posts: 57
KubosKube Offline OP
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
In fact, I could get by if the calling alias, rather than being recognized by the called alias, rather can recognize its own name. For example,

Code
In the remote "alias_customA.mrc"
alias customA {
   customB $myOwnFileName
}

and in the remote "alias_customB.mrc"
alias customB {
   echo -a $1-
}


The difference here rather than what I asked at first is that the alias can tell the called alias through text what it's own name is, and running alias customA will echo "alias_customA.mrc"

And so it goes on. I will keep looking around, and thank you guys for your help.

Re: Recognize name of Alias calling another Alias? [Re: KubosKube] #266526 22/12/19 05:15 AM
Joined: Jan 2017
Posts: 57
KubosKube Offline OP
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
Alright, for anyone who has made it even this far, let me explain what I've done and why I did it.

Lemme paste some code right here right quick...

Code
;#### System .Ini Handlers ####
alias kubot.sys.readini { ;Reads from files in KubosKubot's folders
  ; Use as an identifier: $kubot.sys.readini($$1=AliasName, $$2=.FileSuffix, $$3=Section, $$4=Item, $5=OverrideFilename)
  kubot.debug -
  kubot.debug kubot.sys.readini is WORKING...
  if (!$5) {
    kubot.debug Default method inputs: $1 $2 $3 $4

    set %filename $replace($isalias($1).fname, .mrc, $2)
    kubot.debug Attempting to replace .mrc with $2 : %filename
  }
  else {
    kubot.debug Alternate method inputs: $1 $2 $3 $4 $5

    set %filename $replace($isalias($1).fname,$nopath($isalias($1).fname), $5 $+ $2)
    kubot.debug Attemping to replace $nopath($isalias($1).fname) with $5 $+ $2 $+ : %filename
  }
  set %result $readini(%filename, $3, $4)
  kubot.debug Returning $chr(91) $+ $3 $+ $chr(93) $+ : $+ $4 = %result
  kubot.debug kubot.sys.readini is FINISHED!
  kubot.debug -
  return %result
}

alias kubot.sys.writeini { ;Writes to files in KubosKubot's folders
  ; Use as a command: /kubot.sys.writeini $$1=AliasName $$2=.FileSuffix $$3=Section $$4=Item $$5=Data $6=OverrideFilename
  kubot.debug -
  kubot.debug kubot.sys.writeini is WORKING...
  if (!$6) {
    kubot.debug Default method inputs: $1 $2 $3 $4 $5

    set %filename $replace($isalias($1).fname, .mrc, $2)
    kubot.debug Attempting to replace .mrc with $2 : %filename

  }
  else {
    kubot.debug Alternate method inputs: $1 $2 $3 $4 $5 $6

    set %filename $replace($isalias($1).fname,$nopath($isalias($1).fname), $6 $+ $2)
    kubot.debug Attemping to replace $nopath($isalias($1).fname) with $6 $+ $2 $+ : %filename
  }
  kubot.debug Writing $chr(91) $+ $3 $+ $chr(93) $+ : $+ $4 = $5 to $nopath(%filename)
  kubot.debug kubot.sys.writeini is FINISHED!
  kubot.debug -
  writeini %filename $3 $4 $5
}


My original dilemma was that I could not access the name of the alias making the call, but my original purpose was to get the filename of the alias making the call. This script does that, so that's alright.

Something worth noting is that "alias kubot.debug" is simply an echo script. It echoes into my chat window. Surprise?

Anyways, with kubot.sys.readini, you can see in the comment that there are four mandatory parameters and a fifth optional one. The first parameter is the name of the alias who called kubot.sys.readini. It is inputted manually.

Roughly the same story with kubot.sys.writeini, except it has five mandatory parameters and a sixth optional one.

The optional parameter allows the script to read/write two different files.

Code
alias test {
   kubot.sys.writeini test .cfg sample value data custom
}


Runing alias test would result in a file named Custom.cfg in the same folder as test.mrc, and it's contents would be "[sample], value=data"