How to save variable after closing mIRC? - chat

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.

Related

When using OPT-2.7B or any other natural language model, is there a way to trick it into having a conversation/ give it a pre prompt in the code

Using this code, or a variant of, is there anything that can be added to "trick" opt into conversing as another user in a style more similar to a chatbot. As of now it will either start something more similar to an article or have a conversation with itself for a few lines as seen below.
val = input("Enter your value: ")
input_ids = tokenizer((val), return_tensors='pt').input_ids
output = model.generate(input_ids, min_length=1, max_length=1024, penalty_alpha=0.6, top_k=6)
print("Output:\n" + 100 * '-')
print(tokenizer.decode(output[0], skip_special_tokens=True))
print("" + 100 * '-')
with open("OutputText.txt", "w") as f:
f.write(tokenizer.decode(output[0], skip_special_tokens=True))
Here's an example of the current output:
*User Input:
Hello There.
Model Output:
Hello there. I have an egg that matches your TSV. Would you mind hatching it for me?
Sure, I'll add you now. Let me know when you're online.
Sorry for the late reply. I'm online now for the next few hours. Just send me a trade request whenever you're ready.
No probs, I'm in the middle of a battle at the moment, but I'll get you as soon as I'm done.
Thank you very much for the hatch. Have a nice day :D
*
I've attempted to add a prompt to the start and it hasn't made a difference.

How do I create and array with two heads and LOTS of members

Preface: Please tell me a better way of doing this if you know of any! Even if it changes everything.
I have a powershell script that works with Net-SNMP to store the current value of an OID, change it and then check and store the values. Right now the previous and new values are stored in their own variable. There are about 160 OIDs that I need to change on >1000 nodes in my environment.
For Example for Previous and New values:
$P_vpwrSystemTempCompensation_0 = & '.\SnmpGet.exe' -q -r:"$ip" -v:2c -c:public -o:.1.3.6.1.4.1.13858.2.2.1.0
$N_vpwrSystemTempCompensation_0 = & '.\SnmpGet.exe' -q -r:"$ip" -v:2c -c:public -o:.1.3.6.1.4.1.13858.2.2.1.0
I'm try to figure the best way to store these and output into an CSV. I would like it to be formatted liked this:
Each CSV will be saved with the name and IP of the node I'm hitting.
You can make an object like this in a loop, and that could be exported to csv:
$oid = 'vpwrSystemTempCompensation.0'
$prev = 2
$new = 4647
[pscustomobject]#{OID=$oid; Previous=$prev; New=$new}
OID Previous New
--- -------- ---
vpwrSystemTempCompensation.0 2 5647
By the way, you don't need the call operator to run smnpget, if you don't put it in quotes:
.\SnmpGet.exe -q -r:$ip -v:2c -c:public -o:.1.3.6.1.4.1.13858.2.2.1.0

perl search replace is appending not replacing

I have a perl script in a cron that runs every X minutes. It is suppose to find a string and replace it with a string with more data:
s/remote_phonebook.data.1.name =/remote_phonebook.data.1.name = Users/;
I would expect it to look like this:
before:
remote_phonebook.data.1.name =
after:
remote_phonebook.data.1.name = Users
the first time it runs it works fine. However, each additional time it appends to the end of the line so 3 cron jobs later i see:
remote_phonebook.data.1.name = Users Users Users
How can make it so if "Users" doesn't exist, add it, if it exists, ignore?
If each one of these is a new line you could try:
$s =~ s/remote_phonebook\.data\.1\.name =( Users|$)/remote_phonebook.data.1.name = Users/;
If not, please let me know on the comments.
Provide appropriate trailing context, such as only spaces after the = (which won't then do anything when there is Users after the =):
s/remote_phonebook.data.1.name =\s*$/remote_phonebook.data.1.name = Users/;
or even (as suggested by ThisSuitIsBlackNot):
s/(remote_phonebook.data.1.name =)\s*$/$1 Users/;

Feasibility of extracting arbitrary locations from a given string? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have many spreadsheets with travel information on them amongst other things.
I need to extract start and end locations where the row describes travel, and one or two more things from the row, but what those extra fields are shouldn't be important.
There is no known list of all locations and no fixed pattern of text, all that I can look for is location names.
The field I'm searching in has 0-2 locations, sometimes locations have aliases.
The Problem
If we have this:
00229 | 445 | RTF | Jan | trn_rtn_co | Chicago to Base1
00228 | 445 | RTF | Jan | train | Metroline to home coming from Base1
00228 | 445 | RTF | Jan | train_s | Standard train journey to Friends
I, for instance (though it will vary), will want this:
RTF|Jan|Chicago |Base1
RTF|Jan|Home |Base1
RTF|Jan|NULL |Friends
And then to go though, look up what Base1 and Friends mean for that person (whose unique ID is RTF) and replace them with sensible locations (assuming they only have one set of 'friends'):
RTF|Jan|Chicago |Rockford
RTF|Jan|Home |Rockword
RTF|Jan|NULL |Milwaukee
What I need
I need a way to pick out key words from the final column, such as: Metroline to home coming from Base1.
There are three types of words I'm looking for:
Home LocationsThese are known and limited, I can get these from a list
Home AliasesThese are known and limited, I can get these from a list
Away LocationsThese are unknown but cities/towns/etc in the UK I don't know how to recognize these in the string. This is my main problem
My Ideas
My go to program I thought of was awk, but I don't know if I can reliably search to find where a proper noun (i.e. location) is used for the location names.
Is there a package, library or dictionary of standard locations?
Can I get a program to scour the spreadsheets and 'learn' the names of locations?
This seems like a problem that would have been solved already (i.e. find words in a string of text), but I'm not certain what I'm doing, and I'm only a novice programmer.
Any help on what I can do would be appreciated.
Edit:
Any answer such as "US_Locations_Cities is something you could check against", "Check for strings mentioned in a file in awk using ...", "There is a library for language X that will let a program learn to recognise location names, it's not RegEx, but it might work", or "There is a dictionary of location names here" would be fine.
Ultimately anything that helps me do what I want to do (i.e get the location names!) would be excellent.
Sorry to tell you, but i think this is not 100% programmable.
The best bet would be to define some standard searches:
Chicago to Base1
[WORD] to [WORD]:
where "to" is fixed and you look for exactly one word before and after. the word before then is your source and word after your target
Metroline to home coming from Base1
[WORD] to [WORD] coming from [WORD]:
where "to" and "coming from" is fixed and you look for three words in the appropriate slots.
etc
if you can match a source and target -> ok
if you cannot match something then throw an error for that line and let the user decide or even better implement an appropiate correction and let the program automatically reevaluate that line.
these are non-trivial goals.
consider:
Cities out of us of a
Non english text entries
Abbreviations
for automatic error corrections try to match the found [WORD]'s with a list of us or other cities.
if the city is not found throw an error. if you find that error either include that not found city to your city list or translate a city name in a publicly known (official) name.
The best I can suggest is that, as long as your locations are all US cities, you can use a database of zip codes such as this one.
I don't know how you expect any program to pick up things like Friends or Base1
I have to agree with hacktick that as it stands now, it is not programmable. It seems that the only solution is to invent a language or protocol.
I think an easy implementation follows:
In this language you have two keywords: to and from (you could also possibly allocate at as a keyword synoym for from as well).
These keywords define a portion of string that follows as a "scan area" for
recognizing names
I'm only planning on implementing the simplest scan, but as indicated at the end of the post allows you to do your fallback.
In the implementation you have a "Preferred Name" hash, where you define the names that you want displayed for things that appear there.
{ Base1 => 'Rockford'
, Friends => 'Milwaukee'
, ...
}
You could split your sentences by chunks of text between the keywords, using the following rules:
A. First chunk, if not a keyword is taken as the value of 'from'.
A. On this or any subsequent chunk, if keyword then save the next chunk
after that for that value.
A. Each value is "scanned" for a preferred phrase before being stored
as the value.
my #chunks
= grep {; defined and ( s/^\s+//, s/\s+$//, length ) }
split /\b(from|to)\s+/i, $note
;
my %parts = ( to => '', from => '' );
my $key;
do {
last unless my $chunk = shift #chunks;
if ( $key ) {
$parts{ $key } = $preferred_title{ $chunk } // $chunk;
$key = '';
}
elsif ( exists $parts{ lc $chunk } ) {
$key = lc $chunk;
}
elsif ( !$parts{from} ) {
$parts{from} = $preferred_title{ $chunk } // $chunk;
}
} while ( #chunks );
say join( '|', $note, #parts{ qw<from to> } );
At the very least, collecting these values and printing them out can give you a sieve to decide on further courses of action. This will tell you that 'home coming' is perceived as a 'from' statement, as well as 'Standard train journey'.
You *could fix the 'home coming' by amending the regex thusly:
/\b(?:(?:coming )?(from)|(to))\s+/i
And we could add the following key-value pair to our preferred_title hash:
home => 'Home'
We could simply define 'Standard train journey' => '', or we could create a list of rejection patterns, where we reject a string as a meaningful value if they fit a pattern.
But they allow you to dump out a list of values and refine your scan of data. Another idea is that as it seems that your pretty consistent with your use of capitals (except for 'home') for places. So we could increase our odds of finding the right string by matching the chunk with
/\b(home|\p{Upper}.*)/
Note that this still considers 'Standard train journey' a proper location. So this would still need to be handled by rejection rules.
Here I reiterate that this can be a minimal approach to scanning the data to the point that you can make sense of what it this system takes to be locations and "80/20" it down: that is, hopefully those rules handle 80 percent of the cases, and you can tune the algorithm to handle 80 percent of the remaining 20, and iterate to the point that you simply have to change a handful of entries at worst.
Then, you have a specification that you would need to follow in creating travel notes from then on. You could even scan the notes as they were entered and alert something like
'No destination found in note!'.

How can I map UIDs to user names using Perl library functions?

I'm looking for a way of mapping a uid (unique number representing a system user) to a user name using Perl.
Please don't suggest greping /etc/passwd :)
Edit
As a clarification, I wasn't looking for a solution that involved reading /etc/passwd explicitly. I realize that under the hood any solution would end up doing this, but I was searching for a library function to do it for me.
The standard function getpwuid, just like the same C function, gets user information based on its ID. No uses needed:
my ($name) = getpwuid(1000);
print $name,"\n";
Although it eventually reads /etc/passwd file, using standard interfaces is much more clear for other users to see, let alone it saves you some keystrokes.
Read /etc/passwd and hash the UID to login name.
Edit:
$uid = getpwnam($name);
$name = getpwuid($num);
$name = getpwent();
$gid = getgrnam($name);
$name = getgrgid($num);
$name = getgrent();
As you can see, regardless of which one you pick, the system call reads from /etc/passwd (see this for reference)
Actually I would suggest building a hash based on /etc/passwd :-) This should work well as the user ids are required to be unique.