Mirc script, sockread - mirc

I'm trying to make a script which will take data from a webpage and post it on irc.
I've managed to do it, but im not able to make it repeat its job multiple times.
This is what i tried:
alias mib {
var %i = 0
%bitka = $1
while (%i <= 4) {
$myb(%bitka)
inc %i 1
}
}
Alias "myb" works, it gets the data and posts it.
I tried to make it repeat what alias "myb" does 5 times, but it does it only once. Idealy i want it to keep posting that data until i turn it off, but i wanted to go with baby steps. Not successfuly though.
Help is appreciated. Thanks.

Value-returning functions in mIRC are called identifiers, they are prefixed with the $ sigil. A non-value returning function is called a command and their syntax is a bit different to that of identifiers. If alias "myb" is not supposed to return anything, as understood by your code, it should be changed to command syntax. If your alias returns something, as your code is, it will be executed by mIRC as if it was a command, which can result in undesired behavior.
alias mib {
var %i = 0
while (%i < 5) {
myb $1-
inc %i
}
}

No recursion at mIRC.
Try using Signals.

/timer 1 4 $myb(%bitka)
This does repeat it 4 times with 1 second delay in between.
I gues this is what you want. You can also check my website for another sockread script.

Related

Nightbot command - !uptime combined with a different command, is it possible?

I don't know if I'm posting to the right place or what but I was wondering if someone could help me with a Nightbot command I want to make.
I have the !uptime command and I have a !rage command which only retrieves one value. Now I'd like to combine the two into a command that would retrieve 5 or 6 different values (stages of rage in this situation) depending on what value !uptime would retrieve. So basically if I have been streaming for an hour !rage would say minimum but if for 5 hours it would say critical or something.
How is this possible? Someone pls help
Go to https://nightbot.tv/commands/custom and simply add these two commands
command : message : alias
!hour : $(eval var index = $(1); const options=["min","avg","max","babyRage"]; options[index] )
!rage : $(urlfetch https://beta.decapi.me/twitch/uptime/itsashawe) : !hour
NOTE: Remember to use your channel name instead of mine (itsashawe). Make sure you add !hour as alias in the !rage command.
P.S.
I've used an api to make it simpler. The rage command calls the hour command which gets the hours, minutes and seconds. The rage command uses $(1) i.e. the first argument i.e. the hour and uses it as an index to get values from options which you can change according to your use.

Using the Begin-process-end for Powershell. What are the benefits?

i'm currently trying to do a small script to retrieve data from a server using REST endpoint. As it's the first time i work with powershell, i'm a bit disappointed by the 'lack' of structure and 'typing' in it.
Then i structured my code like this with comments :
# declare ------------------------------------------------------------------------------------------
// All the var i'll need in my process
# do -----------------------------------------------------------------------------------------------
// Ask for user to enter URL and credentials
// Check if credentials are correct
// Connect to the server
// Retrieves the data in a list (JSON formatted) --> List REST EndPoint
// Foreach document in my list
// retrieve the document's details --> single file REST EndPoint
// download the file into local directory
// End Foreach
# display results ----------------------------------------------------------------------------------
// display :
// Downloaded files
// Non-Downloaded files
During review, my colleague told me "Oh ! What you need is the 'begin-process-end' " and then just leave.
I then read somethings about this here but for what i see, the structure is the same as i did with my comments but i don't see the point where it's "What i need" as a functionalities.
Since i'm a real beginner, i maybe miss the point. Could you explain it to me ?
(btw, thx to the kind person who'll edit my ugly english mistakes)
Think of these blocks as a pre-processor (the begin block), actual processor (the process block), and a post-processor(the end block) to a function.
You don't need to define any of these blocks (although Begin and End block will always need a Process block), and can write code just fine without them, but the idea behind them is to divide the function into three separate areas of code. The following function should make it a little clearer:
function addition_by_one {
# Arguments to a powershell functions are defined inside the param block.
Param (
[int]$number
)
# In the below begin block, the variable $a was initialized to 1.
Begin {
$a = 1
}
# The Process block does the main work. In this case, $a is added to the argument supplied to the function.
Process {
$sum = $number + $a
}
# Finally, the End block will execute after the process block completes.
End {
"Sum is $sum"
}
}
# Call the function with any integer argument.
addition_by_one -number 3
Being/process/end is really for pipelines. You can't process from the pipe without a process block.
1..5 | & { process {$_ * 2} }
2
4
6
8
10

How to find out KDB Query Execution Time

I would like to find out how much time a query took for getting executed. I plan to log this for audit and support purposes.
I have found this in the documentation:
q)\t log til 100000 / milliseconds for log of first 100000 numbers
3
But the above method actually evaluates the query again and tells us the time. It doesn't return the results of the query. So if I use this it will actually be like running every query twice, once for getting the results and once for knowing the execution time.
Is there any other method someone is aware of?
You could also capture the time before/after the query runs to figure out the execution time.
Execute on one line:
q)start:.z.p;result:log til 100000;exectime:.z.p-start
q)exectime
0D00:00:00.297268000
q)result
-0w 0 0.6931472 1.098612 1.386294 ...
This method will give you nano-second precision but can easily be adapted to return the same as \t.
q)res:system"t a:{st:.z.p;log til 10000000;.z.p-st}[]"
q)`long$`time$a /convert to Ms
297
q)res
297
You can use a "system t" call (the equivalent of \t) to store the result and the time in one go.
b:system"t a:log til 100000"
It's not very general or functional though so it mightn't suit your needs to have the commands inside a string.
Expanding on Connor's idea, you can wrap this in a function that will return the value and print the time taken to stdout:
time:{ t0:.z.t; r:eval x; 0N!.z.t-t0; :r }
And then send the parse tree of your function as the argument:
q)a:time (log;til 100000)
00:00:00.003
q)a
-0w 0 0.6931472 1.098612 1.386294 1.609438 1.791759 1.94591 2.079442 2.197225..

How to save variable after closing mIRC?

I'm new to do this language and i'm trying to code my own bot. I alredy got the basics and manage to use variables and aliases, however i was looking forward to do a mini-game in my chat in which you could have your own pet, name it and level it up.
I could do all this, however my problem resides in that at the end of the day, i would close the program and all the pets would go away, and that kind of destroys the purpose of it.
I was wondering if there was any way in i could save these variables and reload them each time i open the program, maybe save them on a .txt?
Any suggestion are greatly appreciated.
I agree with one of the comments that it's best to go with .ini files for this problem.
An example of the syntax, taken from the url linked above:
writeini reminder.ini birthday jenna 2/28/1983
writeini reminder.ini birthday Mike 10/10/1990
This produces the following file:
[birthday]
jenna = 2/28/1983
Mike = 10/10/1990
And is to be read like this:
echo -a Mike: $readini(reminder.ini, n, birthday, mike)
echo -a Jenna: $readini(reminder.ini, n, birthday, jenna)
If you want more flexibility to define your own data format, you can also revert to plain text files. The basic /write and $read functions have some pretty neat functionality: see the docs
Something like this should work for writing:
; search if the pet is already saved
$read(pets.txt,ns,%petname)
if ($readn == 0) {
; append to end of file
write pets.txt %petname %age %mood
}
else {
; replace line
write -l $readn pets.txt %petname %age %mood
}
To retrieve specific pets:
var %pet_info = $read(pets.txt, ns, %petname)
; Split the found line on space (ASCII-code 32)
tokenize 32 %pet_info
var %age = $2
var %mood = $3
This returns the line that starts with the petname you're looking for.

How can I get the extension entered by user in a Perl AGI script?

I'm new to Asterisk AGI programming. Im trying to create a simple IVR, using asterisk-perl, where a user can enter any extension from 1 to 4. Here is my code so far:
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
for($i = 0 ; $i < 2 ; $i++)
{
$AGI->exec('Playback','welcome');
$AGI->exec('WaitExten','5|m');
}
Now, I want to know the extension the user entered and take some action accordingly. How to get the extension entered by the user?
Thank You.
I believe you want to use get_data, allowing you to play a file and then wait a given time for a given number of digits e.g.:
$AGI->get_data('demo-welcome', 15000, 5);
See here
Well since the WaitExten command changes the user to a new extension, I suppose you can read the special variable ${EXTEN} after calling WaitExten. I'm not familiar with Asterisk::Perl though, I've only used FastAGI from Java, so I don't know the exact command, but there must be some command to read a variable's value.