mIRC chat bot doesn't acknowledge commands - irc

Below is some code I have written for my ever growing bird-related chat bot.
If I use the mIRC consolse, I can execute the alias blocks (eg. //fchirp [user] ), but for some reason, the bot doesn't acknowledge somebody typing "!chirp" from the main chat window. It doesn't even execute the first //echo statement in the on-text-event.
The weirdest part is: this code worked before and I've been using it regularly. I haven't changed any part of what is shown here aside from the //echo statements which I use for debugging.
addWorms and giveWorms are both aliases I wrote and function correctly on their own. The main issue I'm running into is get the bot to do anything at all when someone types"!chirp". (It should be noted that other unrelated on-text-events earlier in the code work just fine with identical syntax.)
alias fchirp {
/writeini chirp.ini $1 First $adate
/writeini chirp.ini $1 Last $adate
/writeini chirp.ini $1 Count 1
msg $chan /w $1 Welcome to the Nest! Thanks for checking in! :D
addWorms $1
msg $chan /w $1 Type !worms to see how many you have!
//echo -a first chirp
}
alias chirp {
var %a $readini(chirp.ini, $1, Count)
var %count $calc( %a + 1 )
if ( $readini(worms.ini, $1, Breed) == $null ) {
addWorms $1
//echo -a addWorms done
}
if ( $readini(chirp.ini, $1, Last) === $adate ) { msg $chan /w $nick You've already checked in today! BabyRage | halt }
/writeini chirp.ini $1 Last $adate
/writeini chirp.ini $1 Count %count
//echo -a last/count updated
if ( $calc( $readini(chirp.ini, $1, Count) % 5 ) == 0 ) {
giveWorms $1 10
msg $chan /w $1 Welcome back! Lucky day!
}
else {
giveWorms $1 5
msg $chan /w $1 Welcome back! Here's your worms! Don't forget to !hunt ! ^_^
}
//echo -a giveWorms
}
on *:TEXT:!chirp:#: {
//echo -a acknowledged
if ( $readini(chirp.ini, $nick, First) != $null ) {
//echo -a true
chirp $nick
}
else {
//echo -a false
fchirp $nick
}
msg $chan /w $nick Don't forget to !hunt for worms! :D
}

The Event catching can be interfere by two main reasons.
Error
You have an error above your code on the same remote file. e.g. missing bracket or syntax error.
Other event already been captured
mIRC will not process event that already been matched by another pattern on the same file.
example.ini
ON *:TEXT:* dog *: echo -ag This will be called if we wrote the word dog in a sentence.
ON *:TEXT:*:#: echo -ag This will be called
ON *:TEXT:*test*: echo -ag This will never be called. Even if we wrote the word test in sentence.
You can merge your TEXT events to handle both actions, although if they aren't logic related, i would separated them for another remote file.
on *:TEXT:*:#: {
if ($1- == !chirp) {
; In here put your code.
}
; Another code over here..
; Count some stuff in here..
}
Remark: / is useless on alias/popup/remote code, and it is just for identifying text vs commands for console mIRC window.

Related

Code fails with stdin from SED

I have a bash script that finds files with particular extension and then pass the files into a function that checks every line in the file for only files that contain a library imported. For example:
function testing() {
while IFS='' read -r line; do
if [[ "$line" =~ .*log\" ]]; then
echo "log is imported in the file" $1
break
else
echo "log is not imported in the file" $1
break
fi
done < <(sed -n '/import (/,/)/p' "$1")
}
function main() {
for file in $(find "$1" -name "*.go"); do
if [[ $file == *test.go ]]; then
:
else
var1=$(testing $file)
echo "$var1"
fi
done;
}
main $1
The problem is the script works without the else block in the testing function but with the introduction of the else block in the testing function it just defaults to echoing the log is not imported in the file blah even if log is used in some of the files.
Any idea(s) on what is the problem?
Thanks.
Here is a sample input file:
package main
import (
"fmt"
"io/ioutil"
logger "log"
"net/http"
)
type webPage struct {
url string
body []byte
err error
}
...
And the output is basically to echo if log is imported or not.
You need to rewrite the logic of your testing function as it will only test the first line of the file. Indeed, each branch of the if [[ "$line" =~ .*log\" ]] has a break statement, so in practice, a break is reached whenever the first line is read.

Expect script output at Perl console

I have a exp script -script.exp to enter a name and password. it calls test.sh file like below.
set timeout -1
spawn ./test.sh -create
match_max 100000
expect -exact "Enter the name: "
send -- "abcd\r"
expect -exact "\r
Please confirm password: "
send -- "xxy\r"
expect -exact "\r
expect eof
It gives me a output at expect window -
"Successfully entered the name"
if some issue there it throws exception or error message.
I run this expect script in a Perl file-- like below
$cmd="expect script.exp";
system($cmd);
$outputfromexp=?
I need a output of fail or passed status of exp at Perl console after running the script.
How can i do this? Please help me.
I tried calling as suggested in my Perl script--
use strict;
use warnings;
sub sysrun {
my ($command) ="expect script.exp";
my $ret_code;
$ret_code = system("$command");
if ( $ret_code == 0 ) {
# Job suceeded
$ret_code = 1;
}
else {
# Job Failed
$ret_code = 0;
}
return ($ret_code);
}
my $ret_code=sysrun();
print "reuturmsfg- $ret_code\n";
But its printing nothing-- just reuturmsfg-.
I made the changes-
my $ret_code=sysrun();
it gives me 0 and 1 return code.
If I understand the question correctly, to get the return code you want to do:
system($cmd);
my $ret_code = $?;
To get STDOUT output from the execution:
my #out = `$cmd`;
my $ret_code = $?;
I strongly suggest using strict and warnings in your code.

if condition using telnet in perl not working

I'm trying to use if condition to check if command has passed, but its not working. Even though the mount has been successful it goes to failed message. When i enter this command, it retruns to the prompt without any message, hence i'm comparing with a "". And when i do a "ls" of destination folder, it shows all contents of source folder. Any help? Is my if condition correct?
my $port = new Net::Telnet->new(Host=>$ip,Port=>$ip_port,Timeout => "$timeout", Dump_Log => "dumplog.log", Errmode=> "return" );
if($port->cmd("mount -t nfs -o nolock <path-of-source-folder> <destination-folder>") eq "")
{
print "Successful\n";
}
else{
print "Failed.\n ";
}
In scalar context, the Net::Telnet cmd method returns 1 on success (not a string). Your check should be something like:
if ($port->cmd("mount -t nfs -o nolock <path-of-source-folder> <destination-folder>") == 1)
{
print "Successful\n";
} else {
print "Failed.\n";
}
If you actually want to collect the output from the mount command and inspect it, you will have to either call it in list context or pass a stringref argument, like so:
my #outlines = $port->cmd("mount ...");
Or:
my $out;
my $ret = $port->cmd("mount ...", [Output => \$out]);
if ($ret == 1)
{
# inspect $out
}
See the Net::Telnet documentation for more.
Your check for the result seems to be wrong. The documenation of Net::Telnet says that
This method sends the command $string, and reads the characters sent back by the command up until and including the matching prompt. It's assumed that the program to which you're sending is some kind of command prompting interpreter such as a shell.
The command $string is automatically appended with the output_record_separator, by default it is "\n". This is similar to someone typing a command and hitting the return key. Set the output_record_separator to change this behavior.
In a scalar context, the characters read from the remote side are discarded and 1 is returned on success.
So you need to check in a scalar context
if ($port->cmd("..") ) {
...
}

How to auto copy paste between different channels on different network in mIRC, if it matches predefined word?

I'm a person with zero programming skill, thus everything related to programming seems like the hardest thing.
I wanted to auto copy paste between different channels on different network using mIRC, if it matches predefined word. For example:
My predefined word is: hello
If someone in #channelA (on network1) or #channelB (on network2) or #channelC (on network3) says hello, it will appear on #channel4 (on network4) as: said "hello" without channel's name or anything and no duplicate from rest of the networks(if said hello there as well) will appear on network 4's channel, i.e only first one will appear for each keyword.
I have tried searching for a solution and found this:
mIRC bot - copy/paste lines in 2 channels
But it's not helpful to me. Any guidance would be appreciated.
Usually we never built someone a script but asks him for what he done so far and then pointing him the failures or helping him a little bit.
But because the script you mentioned sounds nice, i took the liberty of implementing it myself.
If you not familiar with mSL i suggest you to only touch the following identifiers:FromNetwork, FromChannel, ToNetwork and ToChannel
Code
;###
;### TextPublisher v1
;### Author: Orel Eraki
;### Email: orel.eraki#gmail.com
;###
;### Usage:
;### - Pretty simple, just edit the identifier settings.
;### - For enable/disable change "TextPublisherEnable" identifier to 1 or 0
;### Settings
alias -l TextPublisherEnable return 1
alias -l TextPublisherFormat return &timestamp < &+ &nick &+ > &1-
alias -l TextPublisherMatchText return *text*
alias -l TextPublisherFromNetwork return Network1
alias -l TextPublisherFromChannel return #Channel1
alias -l TextPublisherToNetwork return Network2
alias -l TextPublisherToChannel return #Channel2
;### Functions
alias -l FindNetworkCid {
if ($1) {
var %i = 1, %n = $scon(0), %temp
while (%i <= %n) {
if ($scon(%i).status == connected && $scon(%i).network == $1) {
return $scon(%i).cid
}
inc %i
}
}
return
}
;### Events
on *:text:$($TextPublisherMatchText):$($TextPublisherFromChannel): {
if ($TextPublisherEnable && $network == $TextPublisherFromNetwork) {
var %networkId = $FindNetworkCid($TextPublisherToNetwork)
if (%networkId) {
scid -t1 %networkId if ($TextPublisherToChannel ischan) { msg $TextPublisherToChannel $eval($replace($TextPublisherFormat, &, $chr(36)), 2) }
}
}
}
This might help, Its taken from my Nick Mention and will work with any word you want. It comes up in the room you are in highlighted and also opens a new window and records what/who and time it was said. It may lead you in the direction you are looking for if it is not exactly what you are looking for..
;; Word mention ;;
on *:START: {
window -De #WordMention
echo #WordMention Your word mentioned and what was said goes here
}
on *:text:*:#:{
if (# == $active) halt
if (%me isin $strip($1-)) || ($me isin $strip($1-)) {
if (%mention. [ $+ [ $nick ] ] == $true) halt
echo -a 2,4 # $nick said : $1-
echo #WordMention =======================================
echo #WordMention 0,4 $+ $timestamp $nick said your word at $asctime(h:nn:sstt) in #
echo #WordMention $nick said: $1-
echo #WordMention =======================================
set -u10 %mention. [ $+ [ $nick ] ] $true
}
}
menu channel {
.Word mention ( $+ %mynick $+ )
..Set My word $iif(%me == $null,(no word set),( $+ %me $+ )):/set %me $$?="Enter word eg = word to watch for" | echo -a %me Set
..$iif(%myword == on,$style(2),$style(0)) On:/set %mynick on
..$iif(%myword == off,$style(2),$style(0)) Off:/set %mynick off
}

Send request parameters when calling a PHP script via command line

When you run a PHP script through a browser it looks something like
http://somewebsite.com/yourscript?param1=val1&param2=val2.
I am trying to achieve the same thing via command line without having to rewrite the script to accept argv instead of $_REQUEST. Is there a way to do something like this:
php yourscript.php?param1=val1&param2=val2
such that the parameters you send show up in the $_REQUEST variable?
In case you don't want to modify running script, you can specify parameters using in -B parameter to specify code to run before the input file. But in this case you must also add -F tag to specify your input file:
php -B "\$_REQUEST = array('param1' => 'val1', 'param2' => 'val2');" -F yourscript.php
I can't take credit for this but I adopted this in my bootstrap file:
// Concatenate and parse string into $_REQUEST
if (php_sapi_name() === 'cli') {
parse_str(implode('&', array_slice($argv, 1)), $_REQUEST);
}
Upon executing a PHP file from the command line:
php yourscript.php param1=val1 param2=val2
The above will insert the keys and values into $_REQUEST for later retrieval.
No, there is no easy way to achieve that. The web server will split up the request string and pass it into the PHP interpreter, who will then store it in the $_REQUEST array.
If you run from the command line and you want to accept similar parameters, you'll have to parse them yourself. The command line has completely different syntax for passing parameters than HTTP has. You might want to look into getopt.
For a brute force approach that doesn't take user error into account, you can try this snippet:
<?php
foreach( $argv as $argument ) {
if( $argument == $argv[ 0 ] ) continue;
$pair = explode( "=", $argument );
$variableName = substr( $pair[ 0 ], 2 );
$variableValue = $pair[ 1 ];
echo $variableName . " = " . $variableValue . "\n";
// Optionally store the variable in $_REQUEST
$_REQUEST[ $variableName ] = $variableValue;
}
Use it like this:
$ php test.php --param1=val1 --param2=val2
param1 = val1
param2 = val2
I wrote a short function to handle this situation -- if command line arguments are present and the $_REQUEST array is empty (ie, when you're running a script from the command line instead of though a web interface), it looks for command line arguments in key=value pairs,
Argv2Request($argv);
print_r($_REQUEST);
function Argv2Request($argv) {
/*
When $_REQUEST is empty and $argv is defined,
interpret $argv[1]...$argv[n] as key => value pairs
and load them into the $_REQUEST array
This allows the php command line to subsitute for GET/POST values, e.g.
php script.php animal=fish color=red number=1 has_car=true has_star=false
*/
if ($argv !== NULL && sizeof($_REQUEST) == 0) {
$argv0 = array_shift($argv); // first arg is different and is not needed
foreach ($argv as $pair) {
list ($k, $v) = split("=", $pair);
$_REQUEST[$k] = $v;
}
}
}
The sample input suggested in the function's comment is:
php script.php animal=fish color=red number=1 has_car=true has_star=false
which yields the output:
Array
(
[animal] => fish
[color] => red
[number] => 1
[has_car] => true
[has_star] => false
)