Stuck trying to write script to register username with tilte - irc

Working on a bot script to lookup a username on join and see if it's be regiester with a title for the channel I run. Like if my name is Ravenna. I want the bot to check if I've registered the title Mistress with the username Ravenna.
I'm extremely stuck on how to go about this, researching things haven't brought me closer to a solution
so far all I've figured out I want is
on *:JOIN:#channel {
.msg $chan $nick take time to register with me; a pm will be sent to you soon
}
Any help or a source where I can figure out how to write and read files or the snippet code I need would be appericated

I think it's the best to use ini files for this. You should have a look at this: http://en.wikichip.org/wiki/mirc/ini_files and for more on http://en.wikichip.org/wiki/mirc.
For example you have a title called Mistress, your titles.ini file would look like this:
[mistress]
Ravenna=true
[mister]
Denny=true
To read a value you can use: $readini(titles.ini,n,mistress,$nick)
And to check the value you can do:
on *:join:#channel: {
if ($readini(titles.ini,n,mistress,$nick)) {
; code here for mistress
}
elseif ($readini(titles.ini,n,mister,$nick)) {
; code here for mister
}
elseif ($readini(titles.ini,n,TITLE,$nick)) {
; code here for another title
}
else {
; code here when no title
}
}
This way you must manually add a title in your titles.ini file. So if you want to add another title you should add [TITLE] on a new line in your ini file. If you have more questions you can ask here.
If you want to register someone with a title you could make a simple on text event and add a name to the ini file with writeini titles.ini TITLE $nick true

on *:join:#Tristram_Halls: {
if ($readini(titles.ini,n,mistress,$nick)) {
.describe $chan looks up and sees Mistress $nick. "Greetings Mistress."
}
else {
.msg $chan Greetings $nick I have no record of what you are. Please take the time to register that info with me
.msg $chan $nick Please choose from one of the following titles: !Mistress
}
}
on *:text:!Mistress:#:{
/writeini [-n] titles.ini mistress $nick true
}
just testing a short code for mirc title registration. At this point nobody is in the ini file, and I've add the title [mistress] but when anybody joins the channel the bot does this rather than c
Testbot looks up and sees Mistress "Greetings Mistress."

Related

Mirc script to find exact match in customer list

I am using this to find customer name in text file. Names are each on a separate line. I need to find exact name. If searching for Nick specifically it should find Nick only but my code will say found even if only Nickolson is in te list.
On*:text:*!Customer*:#: {
if ($read(system\Customer.txt,$2)) {
.msg $chan $2 Customer found in list! | halt }
else { .msg $chan 4 $2 Customer not found in list. | halt }
}
You have to loop through every matching line and see if the line is an exact match
Something like this
On*:text:*!Custodsddmer*:#: {
var %nick
; loop over all lines that contains nick
while ($read(customer.txt, nw, *nick*, $calc($readn + 1))) {
; check if the line is an exact match
if ($v1 == nick) {
%nick = $v1
; stop the loop because a result is found
break;
}
}
if (%nick == $null) {
.msg $chan 4 $2 Customer not found in list.
}
else{
.msg $chan $2 Customer found in list!
}
You can find more here: https://en.wikichip.org/wiki/mirc/text_files#Iterating_Over_Matches
If you're looking for exact match in a new line separate list, then you can use the 'w' switch without using wildcard '*' character.
From mIRC documentation
$read(filename, [ntswrp], [matchtext], [N])
Scans the file info.txt for a line beginning with the word mirc and
returns the text following the match value. //echo $read(help.txt, w,
*help*)
Because we don't want the wildcard matching, but a exact match, we would use:
$read(customers.txt, w, Nick)
Complete Code:
ON *:TEXT:!Customer *:#: {
var %foundInTheList = $read(system\Customer.txt, w, $2)
if (%foundInTheList) {
.msg # $2 Customer found in list!
}
else {
.msg 4 # $2 Customer not found in list.
}
}
Few remarks on Original code
Halting
halt should only use when you forcibly want to stop any future processing to take place. In most cases, you can avoid it, by writing you code flow in a way it will behave like that without explicitly using halting.
It will also resolve new problems that may arise, in case you will want to add new code, but you will wonder why it isn't executing.. because of the darn now forgotten halt command.
This will also improve you debugging, in the case it will not make you wonder on another flow exit, without you knowing.
Readability
if (..) {
.... }
else { .. }
When considering many lines of codes inside the first { } it will make it hard to notice the else (or elseif) because mIRC remote parser will put on the same identification as the else line also the line above it, which contains the closing } code. You should almost always few extra code in case of readability, especially which it costs new nothing!, as i remember new lines are free of charge.
So be sure the to have the rule of thump of every command in a new line. (that includes the closing bracket)
Matching Text
On*:text:*!Customer*:#: {
The above code has critical problem, and bug.
Critical: Will not work, because on*:text contains no space between on and *:text
Bug: !Customer will match EVERYTHING-BEFORE!customerANDAFTER <NICK>, which is clearly not desired behavior. What you want is :!Customer *: will only match if the first word was !customer and you must enter at least another text, because I've used [SPACE]*.

Is there a way to store message box settings to be used repetitively in Powershell?

I'd like to use the same message box repetitively in a Powershell script, without having to reiterate all the settings each time. I initially thought that I would store it as a variable:
$StandardMessage = [System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
But as I found out this simply stores the user's response to the message box in the variable.
What I would like to do is something similar to the following pseudo-code:
$StandardMessage = [System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
While(true){
If(condition){
$StandardMessage
}
If(condition2){
$StandardMessage
}
}
Where the conditions would be time-based. This is essentially displaying a message at specified times during the day.
Asked another way (and perhaps more clearly): Is it possible to 'define' a messagebox without actually 'showing' it?
You need to use a Function my good man!
Function Show-MyMessage{
[System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
}
While(true){
If(condition){
Show-MyMessage
}
If(condition2){
Show-MyMessage
}
}
Edit: Personally I have this function on hand for several of my scripts to use as needed:
Function Show-MsgBox ($Text,$Title="",[Windows.Forms.MessageBoxButtons]$Button = "OK"){
[Windows.Forms.MessageBox]::Show("$Text", "$Title", [Windows.Forms.MessageBoxButtons]::$Button, [Windows.Forms.MessageBoxIcon]::Information) | ?{(!($_ -eq "OK"))}
}
Then I can just call it as needed, like:
Show-MsgBox -Title "You want the truth?" -Text "You can't handle the truth!"
And I've got a pop up with the text and title I want, and an OK button.
Buttons can be specified (there's a pop-up for it in the ISE to give options), and title can be excluded if I am feeling lazy. Only thing I really have to feed it is the message.

Mirc code to Spell check before adding variable

on *:text:#btag*:#: {
if ( ## isin $2 ] {
Set %Tag. [ $+ [ $nick ] ] $2 {
Describe # $nick Has saved their Battletag
}
else {
Describe # $nick $+ , Please enter your real Btag
}
}
This is the code I have.
What I require is for the Code to Look at the text and only save it as a variable if it contains the symbol (#) hash tag.
I am finding this hard to code as the Hashtag (#) is part of the Coding language...
Lmk what you guys can do for me
'#' char in mIRC remote code is evaluate as the channel the event fired from.
When you want to express explicitly the Hash tag character you should use $chr(35), 35 is the hashtag ascii number.
The code below will check:
If in any channel a user wrote #btag some-text-contains-#-char
and if so, it will save inside the tag-user variable the word that contained #hash tag.
Then will send him has saved...
Else will send him Nick, Please enter..
Code
on *:text:#btag*:#: {
if ($chr(35) isin $2) {
set %Tag. [ $+ [ $nick ] ] $2
Describe # $nick Has saved their Battletag
}
else {
Describe # $nick $+ , Please enter your real Btag
}
}
The code isn't perfect and will work also, when a user will write the following lines:
#btagBLA some-text-contains-#-char
#btagSOMETEXT some-text-contains-#-char
And so on.. To solve it, you should change event definition to
on *:text:#btag *:#: {
The $chr() function is what you need. It accepts the ASCII value of a character and generates the character in question. So, for example, /echo -a $chr(35) would echo a pound sign (i.e. a hash tag).
You may also want to look at $asc() which will give you the ASCII code of the character you type. Or you could search online for "ASCII table".
Both functions should be adequately explained in the mIRC help file - or at least they were when I last used it.

mIRC bot - copy/paste lines in 2 channels

I’m a noob in mirc scripting, and I need some help.
there’s 2 irc channels. let’s call then #channel1 and #channel2;
There’s 2 bots. One is mine, let’s call him “mybot” (my bot is in both channels). The other bot is from a third person, let’s call him “otherBot”;
What I need is… let me make an example to better explain.
a) in #channel1 some user type:
[14:38:48] <#someuser> !user xpto
At this time, “mybot” is in both channels. he reads the command “!user*” and copy/paste it in #channel2, where the “otherBot” will recognize the command “!user*” and will paste some information about this command.
b) so, in #channel2 it will append something like:
[14:38:50] <# mybot > !user xpto
[14:38:52] <# otherBot > User name is xpto and he likes popatos.
Now I want that “mybot” reads the information provided by the “otherBot” and then paste it on #channel1
c) so, in #channel1:
[14:38:54] <# mybot > User name is xpto and he likes popatos.
So far I have the fowling code in my remote:
on *:TEXT:!user*:#channel1 {
/msg # channel2 $1-
}
on *:TEXT:User name*:#channel2 {
if $address($nick,2) == *!*#otherBot.users.gameea {
/msg # channel1 $1-
}
}
This works fine, but have a problem: if someone else ( not “mybot” ) type “!user kakaka” in #channel2, “mybot” will also copy/paste the information provided by the “otherBot” and then paste it on #channel1. And I only want that “mybot” copy/paste only the information that “mybot” ask to “otherBot”.
A very simple (but not a particularly nice) way of doing this could be to set a global variable when someone types !user in #channel1, and check whether or not this is set in the other part which is listening on #channel2. For example:
on *:TEXT:!user *:#channel1: {
set %repeatUser 1
msg channel2 $1-
}
on *:TEXT:User name*:#channel2: {
if ($address($nick,2) == *!*#otherBot.users.gameea && %repeatUser == 1) {
unset %repeatUser
msg #channel1 $1-
}
}
This isn't a perfect solution, since if the bot says something else between the time it takes for the script to send '!user' to the other channel and for the bot to respond, then it will print out that reply instead of the one for your request, but this is only relevant if #channel2 is ridiculously busy, otherbot is very laggy, or it just so happens that both your bot and someone else type !user on #channel2 within a fraction of a second of eachother.

KRL and Yahoo Local Search

I'm trying to use Yahoo Local Search in a Kynetx Application.
ruleset avogadro {
meta {
name "yahoo-local-ruleset"
description "use results from Yahoo local search"
author "randall bohn"
key yahoo_local "get-your-own-key"
}
dispatch { domain "example.com"}
global {
datasource local:XML <- "http://local.yahooapis.com/LocalSearchService/V3/localsearch";
}
rule add_list {
select when pageview ".*" setting ()
pre {
ds = datasource:local("?appid=#{keys:yahoo_local()}&query=pizza&zip=#{zip}&results=5");
rs = ds.pick("$..Result");
}
append("body","<ul id='my_list'></ul>");
always {
set ent:pizza rs;
}
}
rule add_results {
select when pageview ".*" setting ()
foreach ent:pizza setting pizza
pre {
title = pizza.pick("$..Title");
}
append("#my_list", "<li>#{title}</li>");
}
}
The list I wind up with is
. [object Object]
and 'title' has
{'$t' => 'Pizza Shop 1'}
I can't figure out how to get just the title. It looks like the 'text content' from the original XML file turns into {'$t' => 'text content'} and the '$t' give problems to pick().
When XML datasources and datasets get converted into JSON, the text value within an XML node gets assigned to $t. You can pick the text of the title by changing your pick statement in the pre block to
title = pizza.pick("$..Title.$t");
Try that and see if that solves your problem.
Side notes on things not related to your question to consider:
1) Thank you for sharing the entire ruleset, what problem you were seeing and what you expected. Made answering your question much easier.
2) The ruleset identifier should not be changed from what AppBuilder or the command-line gem generate for you. Your identifier that is currently
ruleset avogadro {
should look something more like
ruleset a60x304 {
3) You don't need the
setting ()
in the select statement unless you have a capture group in your regular expression
Turns out that pick("$..Title.$t") does work. It looks funny but it works. Less funny than a clown hat I guess.
name = pizza.pick("$..Title.$t");
city = pizza.pick("$..City.$t");
phone = pizza.pick("$..Phone.$t");
list_item = "<li>#{name}/#{city} #{phone}</li>"
Wish I had some pizza right now!