How to make script increment value every 1.5 seconds when triggered - mirc

I have been working on adding a 1.5 second delay to the "inc %x_note_id" portion but instead of it just doing it with one message at a time until the last one, it delays and then sends them all at once. How do I make it where it delays each increment of %x_note_id in this porton of the script?
the full code is here
alias postmessage {
if ( $nick == $me ) { return }
var %x_note_id 1
while ( %noteidnick. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] > 0 ) {
msg $chan %notemsg. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ %x_note_id ] ]
unset %notenick. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ %x_note_id ] ]
unset %notemsg. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ %x_note_id ] ]
var %note_delay 10000
while ( %note_delay ) {
dec %note_delay
if ( %note_delay == 0 ) {
inc %x_note_id
dec %noteidnick. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
}
}
}
}

Fixing your existing code, will require more work and will force me to work under your code restrictions.
I've decided to construct new message queuing, which will be more explicit and detailed. Which will result in easier time when you will need to extend it.
ON $*:TEXT:/^!note\s\w+\s/iS:#: {
if ($nick isin %twitchbots) return
; Bot command flood protection, 3 messages per 10 seconds.
inc -u10 % [ $+ [ $+(bpf.,$server,.,#,.,$wildsite) ]
var %bpf = % [ $+ [ $+(bpf.,$server,.,#,.,$wildsite) ]
if (%bpf >= 4) return
; Verify the sender doesn't reach his max quota
if ($userMessages($server, #, $nick).sent == 5) {
msg # $nick $+ , Limit reached. Only 5 messages per user is allowed.
return
}
saveMessage $server # $nick $2-
msg # $nick $+ , Your message has been left for $2 $+ .
}
ON !*:JOIN:#: playmessages $server # $nick
ON *:TEXT:*:#: playmessages $server # $nick
alias -l findServerConnectionIdx {
if (!$1) return
var %i = 1, %length = $scon(0)
while (%i <= %length) {
var %server = $scon(%i).server
if (%server == $1) {
return %i
}
inc %i
}
return
}
alias -l userMessages {
; $1 = server, $2 = channel, $3 = nick
if (!$3) return
if ($prop == sent) {
var %i = 1, %length = $var($+(notemsg.,$1,.,$2,.*), 0)
var %numOfSentMsgs = 0
while (%i <= %length) {
var %messages = $var($+(notemsg.,$1,.,$2,.*), %i).value
inc %numOfSentMsgs $wildtok(%messages, $3 *, 0, 9)
inc %i
}
return %numOfSentMsgs
}
else if ($prop == recv) {
var %messages = $var($+(notemsg.,$1,.,$2,.,$3), 1).value
return $numtok(%messages, 9)
}
}
alias -l saveMessage {
; $1 = server, $2 = channel, $3 = dest-nick, $4 = src-nick, $5- = message
if (!$5) return
set % [ $+ [ $+(notemsg.,$1,.,$2,.,$3) ] ] $addtok(% [ $+ [ $+(notemsg.,$1,.,$2,.,$3) ] ], $4-, 9)
}
alias -l clearRecvMessages {
; $1 = server, $2 = channel, $3 = nick
if (!$3) return
unset % [ $+ [ $+(notemsg., $1,.,$2,.,$3) ] ]
}
alias -l playMessages {
; $1 = server, $2 = channel, $3 = nick, $4 = delay
if (!$3) return
var %messages = % [ $+ [ $+(notemsg., $1,.,$2,.,$3) ] ]
var %i = 1, %length = $numtok(%messages, 9)
while (%i <= %length) {
var %fullMessage = $gettok(%messages, %i, 9)
var %sourceNick = $gettok(%fullMessage, 1, 32)
var %message = $gettok(%fullMessage, 2-, 32)
var %sconServer = $findServerConnectionIdx($1)
$+(.timernotes.,notemsg.,$1,.,$2,.,$3,.,%i) 1 $calc((%i - 1) * 1.5) scid -t1 %sconServer msg $2 From: %sourceNick Message: %message
inc %i
}
clearRecvMessages $1-3
}

Related

MongoDB Inner Array Query

I have the following Mongo Document. I need the output for all SID =100 as shown. How can this be achieved. Tried different ways.
As seen, there are multiple array levels. The input has collection of SIDs with all products.
Input
[
{
"_id": "123456",
"Continent": {
"Country": [
[
"US",
{
"State": [
[
100,
{
"Product": "Corn",
"SID": 100
}
],
[
200,
{
"Product": "Maze",
"SID": 200
}
],
[
100,
{
"Product": "Corn-HB",
"SID": 100
}
]
],
}
]
]
}
}
]
Here the out has only the collection of SID = 100, but it preserves the input format
Output
[
{
"_id": "123456",
"Continent": {
"Country": [
[
"US",
{
"State": [
[
100,
{
"Product": "Corn",
"SID": 100
}
],
[
100,
{
"Product": "Corn-HB",
"SID": 100
}
]
],
}
]
]
}
}
]
As mentioned in the question comments, this data design is a bit odd but a solution can be achieved using the $function function (starting in v4.4 Sep 2020) which avoids maps of maps of reduce, etc.:
var keeper_sid = 100;
db.foo.aggregate([
{$replaceRoot: {newRoot: {$function: {
body: function(obj, keeper) {
var country_arr = obj['Continent']['Country'];
for(var n1 = 0; n1 < country_arr.length; n1++) {
var tuple1 = country_arr[n1];
var state_arr = tuple1[1]['State'];
// Walk the State array backwards to ease deletions.
for(var n2 = state_arr.length - 1; n2 >= 0; n2--) {
var tuple2 = state_arr[n2];
if(tuple2[1]['SID'] != keeper) {
state_arr.splice(n2,1);
}
}
}
return obj;
},
args: [ "$$ROOT", keeper_sid ],
lang: "js"
}}
}}
]);
This is straightforward but it does make assumptions about the structure e.g. extracting the second ([1]) item from the "tuples." The code can be reduced a bit more but intermediate variables (tuple1,2) are shown to make the whole thing a little more clear.

$addfield in spesific condiiton MongoDB

I have this data when get by aggregation
[{_id: 1,
name:'Abraham',
class:'V',
question_answered:[{
id:'quest1',
answer:'A',
score:10,
question:{
soal:'apa judul lagu?',
correct_answer:'A',
type_question:'Essay'
}
},
{
id:'quest2'
answer:'C',
score:null,
question:{
soal:'apa judul lagu B?',
correct_answer:'B',
type_question:'Essay'
}
},
{
id:'quest3'
answer:'C',
score:10,
question:{
soal:'apa judul lagu C?',
correct_answer:'C',
type_question:'essay_pg'
}
},
]
}
]
Now i want to addfield with condition
addfield with name
formated_status_evaluation_essay and formated_status_evaluation_essay_option,
with condition:
IF(question_answer.question.type_question === 'Essay' && score !== null)
formated_status_evaluation_essay = 'already scoring'
Elseif(question_answer.question.type_question === 'Essay' && score === null)
formated_status_evaluation_essay = 'haven't scoring'
Elseif(question_answer.question.type_question === 'Essay' is not exists
formated_status_evaluation_essay = 'No essay question'
formated_status_evaluation_essay_option is have same condition with evaluation_essay
Soo expected output would be like
[{_id: 1,
name:'Abraham',
class:'V',
question_answered:[.........]
formated_status_evaluation_essay:'havent Scoring',
formated_status_evaluation_essay_option:'Already Scoring'
}
]
How to write a correct addfield with condition in mongodb to make an output like that?
thanks before i've tried soo many ways but still got no answer.
i tried this but seems i put a wrong syntax
{
'$addFields': {
'formated_status_evaluation_essay': {
'$cond': [
{
'$and': [
{'$$question_answer.question.type_soal ':
'essay'},
{'$$question_answer.nilai':{$ne:null}},
]
},
'already scoring',
'havent scoring'
]
}
}
}
db.collection.aggregate([
{
$set: {
formated_status_evaluation_essay: {
$cond: [
{
$and: [
{
$in: [
"Essay",
"$question_answered.question.type_question"
]
},
{
$ne: [
"$question_answered.score",
null
]
}
]
},
"already scoring",
"havent scoring"
]
}
}
}
])
mongoplayground

MongoDB spatial query opposite of $geoIntersect, outside of polygon

Is it possible to perform a query where a point is outside a polygon?
I'm not really sure how to word my question, but I'm trying to do this with my query
I want to check if location A (Pickup) is in inside, and location B (dropoff) is outside
I thought of using $ne and $not but I get the error "unknown top level operator: $not"
$pickupPoint = [
'type' => 'Point',
'coordinates' => [
floatval($this->item['longitude']),
floatval($this->item['latitude'])
]
];
$dropPoint = [
'type' => 'Point',
'coordinates' => [
floatval($this->item['longitude']),
floatval($this->item['latitude'])
]
];
// Is in pickup, but outside dropoff
$pickupNotDropoff = [
'$and' => [
[
'Pickup' => [
'$geoIntersects' => [
'$geometry' => $pickupPoint,
]
]
],
[
'$not' => [
'Dropoff' => [
'$geoIntersects' => [
'$geometry' => $dropPoint,
]
]
]
]
]
];
Sample of data

To find first word of a sentence in mongodb of specified size

I want to find the first word from a sentence(phrase) whose size is less than 3 letters.Is there any way i could find it? please suggest.
I have used
.map(function(st){return st.split(" ")[0];}
function it gives me all the first words in array format.But this is not the expected output.
{ "name" : "VAS LAYER BREED FARM PRIVATE LIMITED" }
{ "name" : "UTTARA BROILER BREED FARM PRIVATE LTD" }
{ "name" : "SAI REKHA POULTRY PRIVATE LTD" }
{ "name" : "RUHITECH NUTRITION PRIVATE LTD" }
{ "name" : "SADKAR BROILER AND AGRO FARMS PRIVATE LTD" }
{ "name" : "SADAR POULTRY PRIVATE LTD" }
From this list i need the output to print only the words: ("SAI","VAS") in the output.
You may perform aggregation query.
db.collection.aggregate([
{
$project: {
name: {
$let: {
vars: {
first: {
$arrayElemAt: [
{
$split: [
"$name",
" "
]
},
0
]
}
},
in: {
$cond: [
{
$lte: [
{
$strLenCP: "$$first"
},
3
]
},
"$$first",
""
]
}
}
}
}
},
{
$match: {
name: {
$ne: ""
}
}
},
{
$group: {
_id: null,
name: {
$push: "$name"
}
}
}
])
MongoPlayground
By what I understood from your question may be you are looking for this:
INPUT
var arr = [{ "name" : "VAS LAYER BREEDER FARM PRIVATE LIMITED" },
{ "name" : "UTTARA BROILER BREEDER FARM PRIVATE LIMITED" },
{ "name" : "SAI REKHA POULTRY FARMS PRIVATE LIMITED" }
]
CODE
var outputArr = [];
for(let j=0; j<arr.length; j++){
var chars = arr[j].name.split(' ');
for(let i=0; i<chars.length; i++){
if(chars[i].length <= 3){
outputArr.push(chars[i]);
break;
}
};
}
OUTPUT
outputArr [ 'VAS', 'SAI' ]
The following mongo shell query will print all the words which are less than three characters.
db.test.find().forEach( doc => {
let words = doc.name.split(" ");
for ( let word of words ) {
if ( word.length < 3 ) {
print( word );
break;
}
}
} )
The query will print the character "&".
If you want the query to print words less than or equal to three characters, change the code word.length < 3 to word.length <= 3. This will print "&","SAI" and "VAS".
If you want the query print only words with alphabets (A to Z and a to z), change ( word.length < 3 ) to ( word.length <= 3 && word.match("^[A-Za-z]+$") ). This will print "SAI" and "VAS".
If you want to manage the same with javascript (as your sample code suggests)
// Your question suggests you need words less than 3 length, so you can write
.map((st)=> st.split(" ")[0]).filter((str)=> str.length < 3)
// Your expected output suggests you need words less than or equal to 3 length, so you can write
.map((st)=> st.split(" ")[0]).filter((str)=> str.length <= 3)

postgress import data from a database to another one which has tables with more columns

I have two postgres 9.6 databases on different machines:
db1 - older version with the data I need
db2 - the schema was updated and now it contains more columns. I only use the schema here. I don't need the data
I would like to bring all the data from db1 to db2 which has the newer schema. There are quite a few tables and I wouldn't want to alter them manually.
How would I achieve this?
You can use copy command with column name specified copy table_name (column...) to .... and copy table_name (column...) from ...
Copy to for export and copy from for import
https://www.postgresql.org/docs/10/sql-copy.html
COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
TO { 'filename' | STDOUT }
[ [ WITH ]
[ BINARY ]
[ OIDS ]
[ DELIMITER [ AS ] 'delimiter' ]
[ NULL [ AS ] 'null string' ]
[ CSV [ HEADER ]
[ QUOTE [ AS ] 'quote' ]
[ ESCAPE [ AS ] 'escape' ]
[ FORCE QUOTE { column_name [, ...] | * } ] ] ]
COPY table_name [ ( column_name [, ...] ) ]
FROM { 'filename' | STDIN }
[ [ WITH ]
[ BINARY ]
[ OIDS ]
[ DELIMITER [ AS ] 'delimiter' ]
[ NULL [ AS ] 'null string' ]
[ CSV [ HEADER ]
[ QUOTE [ AS ] 'quote' ]
[ ESCAPE [ AS ] 'escape' ]
[ FORCE NOT NULL column_name [, ...] ] ] ]