I'm working on an auto voice/devoice script snippet for an mIRC bot when a nick is lower case it'll voice the nick. Then when the nick is changed and it's upper it should devoice people or if there's an upper nick to lower case nick it voices them. My issue is it won't recognize nick changes to voice or devoice a user.
#lowercheck on
alias -l _c return #
alias startwithlower {
if ( $1 ) {
return $islower($left($regsubex($$1,/\W+/g,$null),1))
}
else return $false
}
on #*:JOIN:#Tristram_Halls:{
if ( $startwithlower($nick) == $true ) {
mode $_c +v $nick
}
}
on #*:NICK:{
if ( ( $startwithlower($newnick) == $false ) && ( $newnick !isvoice $_c ) ) {
mode $_c -v $newnick
}
elseif ( ( $startwithlower($newnick) == $true ) && ( $newnick isvoice $_c ) ) {
mode $_c +v $newnick
}
}
ON NICK is action that happens on nick and execute for every channel, than if your bot should handle many channels it should change how you voice the user in every channel you want to grant him a voice.
If the bot only has OP+ control in 1 channel than the following will fix you issue (you switched between isvoice for both cases):
on #*:NICK:{
if ( ( $startwithlower($newnick) == $false ) && ( $newnick isvoice $_c ) ) {
mode $_c -v $newnick
}
elseif ( ( $startwithlower($newnick) == $true ) && ( $newnick !isvoice $_c ) ) {
mode $_c +v $newnick
}
}
A nicer implementation will be:
#lowercheck on
alias -l _c return #
alias startwithlower {
return $1 && $islower($left($regsubex($$1,/\W+/g,$null),1))
}
on #*:JOIN:#Tristram_Halls:{
if ($startwithlower($nick)) {
mode $_c +v $nick
}
}
on #*:NICK:{
if ($startwithlower($newnick)) {
if ($newnick !isvoice $_c) {
mode $_c +v $newnick
}
}
else
{
if ($newnick isvoice $_c) {
mode $_c -v $newnick
}
}
}
Related
I have two different shipping method on my WooCommerce site COD & local pickup, I want to redirect on two different thank you page depending on which shipping method the buyer choose. I tried this but its showing an error after purchase
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] )) {
if( $order->has_shipping_method('flat_rate:21') ){
wp_redirect( 'mysite.com/thank-you-1/' );
exit;
}
elseif( $order->has_shipping_method('local_pickup:24') ) {
wp_redirect( 'mysite.com/thank-you-2/' );
exit;
}
}
}
You can use woocommerce_thankyou
add_action( 'woocommerce_thankyou', 'woo_custom_redirect_after_purchase');
function woo_custom_redirect_after_purchase( $order_id ){
$order = wc_get_order( $order_id );
if( $order->has_shipping_method('flat_rate:21') ){
wp_redirect( 'mysite.com/thank-you-1/' );
exit;
}elseif( $order->has_shipping_method('local_pickup:24') ) {
wp_redirect( 'mysite.com/thank-you-2/' );
exit;
}
}
i am trying to fix the next issue:
A lot of file descriptors opened by fluent-bit are kept always opened, even after calling flb_destroy().
Scenario:
I am developing a C++ application that wraps fluent-bit as library, stopping and starting the fluent-bit engine upon received events.
Problem:
Fluent-bit runs out of available file descriptors some time later, after restarting the engine several times without stopping the C++ app, ending with the error trace "lib backend failed".
Details:
I extracted a couple of methods available in the fluent-bit.c source file of the project as a helper on loading the configuration for runtime, by calling the next one:
flb_service_conf("path/to/fluent-bit.conf")
Every time an event is received, flb_stop() and flb_destroy() are called first, doing the same with flb_service_conf() and flb_start() inmediately after.
I got stucked at this point and am still researching about how could fix the issue.
Any clue, idea or suggestion would be very appreciated.
Here is a bit of code, hoping it helps to explain:
bool FluentBit::start( ) {
if ( isStopped() ) {
LOG_DEBUG( ) << "Starting fluent-bit";
m_ctx = ::flb_create( );
if( m_ctx == nullptr ) {
throw std::bad_alloc( );
}
running = configureEngine() && startEngine();
}
return running;
}
void FluentBit::stop( ) {
if ( isRunning() ) {
LOG_DEBUG( ) << "Stopping fluent-bit";
::flb_stop( m_ctx );
while( m_ctx->status == FLB_LIB_OK ) {
std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
}
::flb_destroy( m_ctx );
running = false;
}
}
bool FluentBit::isRunning( ) {
return running;
}
bool FluentBit::isStopped( ) {
return ( !running ) ;
}
bool FluentBit::configureEngine( ) {
auto returnConf = ::flb_service_conf( m_ctx->config, settings.filePath() );
if ( returnConf < 0 ) {
LOG_ERROR() << "Failed loading fluent-bit configuration file: " << settings.filePath();
::flb_destroy( m_ctx );
}
return ( returnConf < 0 ) ? false : true;
}
bool FluentBit::startEngine( ) {
LOG_DEBUG( ) << "Starting fluent-bit engine";
auto retStart = ::flb_start( m_ctx );
if( retStart < 0 ) {
LOG_ERROR( ) << "Could not start fluent-bit engine";
::flb_destroy( m_ctx );
}
running = ( retStart < 0 ) ? false : true;
return running;
}
Thanks in advance for your (possible) replies :)
Kind Regards,
Pablo.
I need help with import about 25 millions items from Elasticsearch to Mongodb. I wrote php script to do it but when the script reaches 16 millions items it fails on memory limit and throws me an error: VirtualAlloc() failed: [0x000005af] The paging file is too small for this operation to complete. I changed the system settings - virtual memory (paging file) to 100 000 according this web, but it is still not enough. I dont understand why it allocates so much memory. To get data from Elasticsearch I use scroll api. Look at the script:
<?php
error_reporting( E_ALL );
ini_set( 'memory_limit', -1 );
ini_set( 'max_execution_time', -1 );
/** #var \Nette\DI\Container $container */
$container = require( __DIR__ . '/../app/bootstrap.php' );
echo "----------------------------------------------------------------\n";
echo "--------------------- EVENT INDEX IMPORT -----------------------\n";
echo "----------------------------------------------------------------\n";
echo 'memory_limit: ' . ini_get( 'memory_limit' ) . "\n";
/** #var MongoConnect $mongo */
$mongo = $container->getService( 'mongo' );
/** #var \MongoDB\Collection $eventsCollection */
$eventsCollection = $mongo->selectCollection( 'Events', 'events' );
/** #var Elastica\Client $elastic */
$elastic = new Elastica\Client();
/** #var Elastica\Index $elasticIndex */
$elasticScrollData = $elastic->getIndex( 'event' )->request( '_search?scroll=10s', 'GET', ['size' => 250, 'sort' => ['_doc']] )->getData();
$countAll = $elasticScrollData['hits']['total'];
echo 'ES ALL ITEMS COUNT ' . $countAll . "\n";
$offset = 0;
saveToMongo( $elasticScrollData, $countAll, $offset, $elastic, $eventsCollection );
function saveToMongo( $scrollData, $countAll, $offset, \Elastica\Client $elastic, \MongoDB\Collection $mongoCollection )
{
$documents = [];
foreach ( $scrollData['hits']['hits'] as $item )
{
$doc = [];
$doc['ico'] = (array)$item['_source']['ico'];
$doc['data'] = $item['_source'];
if( isset( $item['_type'] ) ) $doc['type'] = $item['_type'];
if( isset( $item['_source']['key'] ) ) $doc['key'] = $item['_source']['key'];
if( isset( $item['_source']['action'] ) ) $doc['action'] = $item['_source']['action'];
if( isset( $item['_source']['publishDate'] ) ) $doc['publishDate'] = stringToDate( $item['_source']['publishDate'] );
if( isset( $item['_source']['generateDate'] ) ) $doc['generateDate'] = stringToDate( $item['_source']['generateDate'] );
if( isset( $item['_source']['eventDate'] ) ) $doc['eventDate'] = stringToDate( $item['_source']['eventDate'] );
$documents[] = $doc;
$offset++;
}
try
{
$mongoCollection->insertMany( $documents, ['ordered' => FALSE] );
echo '--- offest ' . ( $offset ) . ' OK' . "\n";
}
catch( \Exception $e )
{
echo '+++ insert exception: ' . $e->getMessage() . "\n";
}
if( $offset < $countAll )
{
$scrollData = $elastic->request( '_search/scroll', 'GET', ['scroll' => '10s', 'scroll_id' => $scrollData['_scroll_id']] )->getData();
saveToMongo( $scrollData, $countAll, $offset, $elastic, $mongoCollection );
}
}
function stringToDate( $string )
{
if( preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+\+[\d:]+$/', $string ) ) $format = 'Y-m-d\TH:i:s.uT';
elseif( preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+$/', $string ) ) $format = 'Y-m-d\TH:i:s.u';
elseif ( preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+[\d:]+$/', $string ) ) $format = 'Y-m-d\TH:i:sT';
elseif ( preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/', $string ) ) $format = 'Y-m-d\TH:i:s';
elseif ( preg_match( '/^\d{4}-\d{2}-\d{2}\+[\d:]+$/', $string ) ) $format = 'Y-m-dT';
elseif ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $string ) ) $format = 'Y-m-d';
return DateTime::createFromFormat( $format, $string );
}
echo "------------------------------------------------------------------------\n";
echo "------------------------- EVERYTHING IS DONE ---------------------------\n";
echo "------------------------------------------------------------------------\n";
Can anyone explain following piece of code in https://github.com/simondeziel/custom-nagios-plugins/blob/master/plugins/check_megaraid_sas . (line num 220-223)
Why this code is there
} elsif ( $slotnumber != 255 ) {
$pdbad++;
$status = 'CRITICAL';
}
It makes sense to look at the complete section:
PDISKS: while (<PDLIST>) {
if ( m/Slot Number\s*:\s*(\d+)/ ) {
$slotnumber = $1;
$pdcount++;
} elsif ( m/(\w+) Error Count\s*:\s*(\d+)/ ) {
if ( $1 eq 'Media') {
$mediaerrors += $2;
} else {
$othererrors += $2;
}
} elsif ( m/Predictive Failure Count\s*:\s*(\d+)/ ) {
$prederrors += $1;
} elsif ( m/Firmware state\s*:\s*(\w+)/ ) {
$fwstate = $1;
if ( $fwstate eq 'Hotspare' ) {
$hotsparecount++;
} elsif ( $fwstate eq 'Online' ) {
# Do nothing
} elsif ( $fwstate eq 'Unconfigured' ) {
# A drive not in anything, or a non drive device
$pdcount--;
} elsif ( $slotnumber != 255 ) {
$pdbad++;
$status = 'CRITICAL';
}
}
} #PDISKS
That section loops over a list of PDs (Primary Disks?), and I assume that this file / program output contains a human readable status for every attached device. The code looks at every line and performs some actions depending on the content of that line:
$slotnumber is assigned whenever there is Slot Number : ... in the contents of PDLIST. From looking at the logic, if there is a Firmware state line that is not Hotspare, Online or Unconfigured, and the $slotnumber is not 255, then something went horribly wrong and the status is considered CRITICAL. The number of bad PDs ($pdbad) is then increased by one.
I have command line program that has a menu with multiple choice. I can pass the parameter via program.exe < input.txt but I am having problems sending the 'Enter' command (the program crashes if I attempt to send anything else; such as a ' ' character).
I enter 'All' as Proc name. It then prints 'enter proc name' again and I have to hit Enter for the code to continue. What I cannot work out is how to send this Enter to the program. I have tried a black line in input.txt but that did not work.
while( !end )
{
for( legal=0; !legal; )
{
printf("\tEnter Proc Name: ");
if( fgets( str, 70, stdin ) == NULL )
{
printf("Bye.\n");
exit(0);
}
ret = sscanf(str, "%s", p.name );
if( ret > 0 || str[0] == '\n' ) legal = 1;
else printf("Please enter a legal proc name, none, or all\n");
}
if( str[0] == '\n' ) {
end = 1;
} else if( !strcmp( p.name, "all" )) {
for( i=0; i < Conf_num_procs( &Cn ); i++ )
Status_vector[i] = 1;
} else if( !strcmp( p.name, "none" )) {
for( i=0; i < Conf_num_procs( &Cn ); i++ )
Status_vector[i] = 0;
} else {
proc_index = Conf_proc_by_name( p.name, &p );
if( proc_index != -1 ) {
Status_vector[proc_index] = 1;
} else printf("Please! enter a legal proc name, none, or all\n");
}
}