I have this command for a onjoin event:
on !*:join:#:{ msg $chan MESSAGE }
How can i switch this message on/off by using example:
!onjoin on OR !onjoin off
Thanks
You can use a variable that indicate the status for this option. This variable will be set by the command you specified.
Script should be as follow:
on !*:join:#: if (%onJoinMessage) { msg # MESSAGE }
on *:text:!onjoin *:#: {
if ($1 == on) { inc %onJoinMessage }
elseif ($1 == off) { unset %onJoinMessage }
}
Related
i have the below code to read emails and check if the subject is matching with the expected message
Message[] messages = folder.getMessages();
String message="Thanks for contacting";
if(folder.getUnreadMessageCount()!=0)
{
for (Message mail : messages)
{
if(!mail.isSet(Flags.Flag.SEEN) && mail.getSubject().contains("Thanks"))//if mail is unread and the message matches
{
mail.setFlag(Flags.Flag.SEEN, true);
softAssert.assertTrue(true,"Email received ->");
Reporter.log("Email received ->" + mail.getSubject(), true);
break;
}
if(!mail.isSet(Flags.Flag.SEEN) && !mail.getSubject().contains("Thanks"))//if mail is unread and the message does not match
{
System.out.println(mail.getSubject() + "-> is not the email we are looking for");
}
}
}
else
{
softAssert.assertTrue(false,"Email not received");
Reporter.log("Email not received ->" + message, true);
}
The problem is I want to fail this test if both the conditions inside the for loop fail. if i put the else inside the for loop it prints not received for reach element in the loop. how do i go about this?
You can use boolean expression. See the below simple example,
boolean test = true;
boolean test2 = true;
for (int i = 0; i < 3; i++) {
if (!test) {
System.out.println("Test value is false.");
} else {
test = false;
}
if (!test2) {
System.out.println("Test2 value is false.");
} else {
test2 = false;
}
if(!test && !test2) {
System.out.println("Breaking loop.");
break;
}
}
Create two boolean variables and set their values as true incase if your if condition fails inside the loop then by using else block change the boolean value to false and do the same for your second if condition as well. In the last if condition if both statements fails then break the loop.
I'm trying to list all files in a directory with this function:
sub list-directory($dir = '.') {
my #todo = $dir.IO.dir;
#todo = #todo.duckmap( -> $_ where $_.d { #todo.push($_.IO.dir); } );
#todo = #todo.duckmap( -> $_ where IO {.Str} );
return #todo;
}
The first duckmap is to list all subdirectories and the second one (this doesn't finish) is to convert the IO objects to Str.
Anyone knows why the second one isn't stopping?
As Hakon has said, it was a infinite loop. Here is the code fixed:
sub list-directory($dir = '.') {
my #todo = $dir.IO.dir;
#todo = #todo.duckmap( -> $_ where $_.d { #todo.push($_.IO.dir); $_; } );
grep { !.IO.d }, #todo.List.flat;
#todo.map({.Str});
}
What I would like to do:
when(transaction.state) {
Transaction.Type.EXPIRED,
//about 10 more types
Transaction.Type.BLOCKED -> {
if (transaction.type == Transaction.Type.BLOCKED && transaction.closeAnyway) {
close(transaction)
break //close if type is blocked and has 'closeAnyway' flag
}
//common logic
}
//other types
}
I cannot write break:
'break' and 'continue' are not allowed in 'when' statements. Consider using labels to continue/break from the outer loop.
Is it a way to return/break from when statements? Or what is the best way to solve it?
You can use run with a return at label:
when(transaction.state) {
Transaction.Type.EXPIRED,
//about 10 more types
Transaction.Type.BLOCKED -> run {
if (transaction.type == Transaction.Type.BLOCKED && transaction.closeAnyway) {
close(transaction)
return#run //close if type is blocked and has 'closeAnyway' flag
}
//common logic
}
//other types
}
You can use labels to break/continue/return. e.g.:
transactions# for (transaction in transactions) {
when (transaction.state) {
Transaction.Type.EXPIRED,
Transaction.Type.BLOCKED -> {
break#transactions
}
}
}
See Returns and Jumps - Kotlin Programming Language for more details.
Work around using apply():
transaction.apply {
when(state) {
Transaction.Type.EXPIRED,
//about 10 more types
Transaction.Type.BLOCKED -> {
if (type == Transaction.Type.BLOCKED && closeAnyway) {
close(this)
return#apply
}
//common logic
}
//other types
}
}
I've an awk script which processes .ICS calendar files.
I need to add the ATTENDEE line if it's missing.
I already have a script which parses all the events taking in considerations only the ones I need given a CHECKPARM criteria. I need to add the ATTENDEE if it's not present already.
/BEGIN:VEVENT/ { cache = 1; }
/CHECKPARM/ {
if( index( $0, var ) )
printf( "%s", cached_lines );
else
drop = 1;
cached_lines = "";
cache = 0;
}
# this doesn't work
#!~ /ATTENDEE/ {
# printf ("ATTENDEE: %s", organizer);
#}
cache {
cached_lines = cached_lines $0 "\n";
next;
};
!drop { print; }
/END:VEVENT/ { drop = 0; }
Try using a flag, if line is present, set it, if not, add line.
Something like this:
/ATTENDEE/ {att = 1}
!att {
printf ("ATTENDEE: %s\n", organizer)
}
I have the following awk script where I seem to need to next curly brackets. But this is not allowed in awk. How can I fix this issue in my script here?
The problem is in the if(inqueued == 1).
BEGIN {
print "Log File Analysis Sequencing for " + FILENAME;
inqueued=0;
connidtext="";
thisdntext="";
}
/message EventQueued/ {
inqueued=1;
print $0;
}
if(inqueued == 1) {
/AttributeConnID/ { connidtext = $0; }
/AttributeThisDN / { thisdntext = $2; } #space removes DNRole
}
#if first chars are a timetamp we know we are out of queued text
/\#?[0-9]+:[0-9}+:[0-9]+/
{
if(thisdntext != 0) {
print connidtext;
print thisdntext;
}
inqueued = 0; connidtext=""; thisdntext="";
}
try to change
if(inqueued == 1) {
/AttributeConnID/ { connidtext = $0; }
/AttributeThisDN / { thisdntext = $2; } #space removes DNRole
}
to
inqueued == 1 {
if($0~ /AttributeConnID/) { connidtext = $0; }
if($0~/AttributeThisDN /) { thisdntext = $2; } #space removes DNRole
}
or
inqueued == 1 && /AttributeConnID/{connidtext = $0;}
inqueued == 1 && /AttributeThisDN /{ thisdntext = $2; } #space removes DNRole
awk is made up of <condition> { <action> } segments. Within an <action> you can specify conditions just like you do in C with if or while constructs. You have a few other problems too, just re-write your script as:
BEGIN {
print "Log File Analysis Sequencing for", FILENAME
}
/message EventQueued/ {
inqueued=1
print
}
inqueued == 1 {
if (/AttributeConnID/) { connidtext = $0 }
if (/AttributeThisDN/) { thisdntext = $2 } #space removes DNRole
}
#if first chars are a timetamp we know we are out of queued text
/\#?[0-9]+:[0-9}+:[0-9]+/ {
if (thisdntext != 0) {
print connidtext
print thisdntext
}
inqueued=connidtext=thisdntext=""
}
I don't know if that'll do what you want or not, but it's syntactically correct at least.