This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

transfer of variables

Old posts that have not been replied to for several years.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

If you share user files, maybe the easiest way is to create a fake user, and use setuser xtra to add whatever variables you want to him. Then they will be transferred automatically when the bots link.

Actually I'm not sure if xtra vars are transferred or not... but they might be!
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

Hi guys,

I tried to use Sir_Fz's method, but my problem is:
Let's say i have in my first bot in a certain procedure:

set usertotaltime($nick) [duration [expr [clock seconds] - [getchanjoin nickname #channel]]]

So i would like that the variable %usertotaltime for that specific nick is sent to my second bot.

Will that work with:
putbot bot2_name var %usertotaltime(%nick) -> so my second bot will react on that putbot starting with "var"...(as Sir_Fz initiated)
BUT let's say if my bot has in his memory 5 nicks with their uptime, how can i get those 5 nick uptimes into my second bot?
This is my problem.

Also, for those var exchanges, this will only happen between the bots...so do i need to put as flag b ?

Thnx in advance!

Best regards,

Buffy
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

So let's say i can add in my procedures the following:

"set jointime($nick) [getchanjoin $nick #channel]"

How can i send for each $nick, the jointime to my second bot pls?
So that my 2nd bot will get the following information:
%jointime(David) xxxxxxxxx
%jointime(Belle) xxxxxxxx
....

Is that with a for each loop? Or another way to do it?
So i presume that my 1st bot has all the getchanjoins of each nick in his memory and need to send it to my 2nd bot (maybe through putbot or bind msg). Can i put this into a islinked command, so when 2nd bot joins, he gets automatically all my %jointime($nick's)

Thnx.

Best regards,

Buffy
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

I tried the following:

on Bot1 (that is already online, and Bot2 is temporarily not online):

Code: Select all

bind link - * detect:bot
bind bot - "!Transferftpinfo" ftp:transferinfo
bind bot - "!Transferuserinfo" user:transferinfo
bind link - * getchanjoin:transfert
bind pub - "test" chantest
bind bot - "jointime" procbot
bind join - * joinproc

#when a person joins, his getchanjoin is added into $mychanjoin(with nick and channel info also) from Bot1
proc joinproc {nick uhost hand chan} {
global mychanjoin
set channel #channel
set mychanjoin($nick,$channel) [getchanjoin $nick $channel]
}

#when Bot2 was online, and Bot1 came online (opposite as normal), then Bot2 will send his getchanjoins to Bot1, starting with "jointime". Bot1 will store those info's into variables
proc procbot {bot command text} {
global mychanjoin
set nick [lindex [split $text] 0]
set channel [lindex [split $text] 1]
set mychanjoin($nick,$channel) [lindex [split $text] 2]
}

#This is for testing. When i type in #channel : test1 a_nickname_online , then i should get the getchanjoin value from that nick
proc chantest {nick uhost hand chan arg} {
global mychanjoin
set channel #channel
set nick [lindex [split $arg] 0]
puthelp "PRIVMSG #channel : $mychanjoin($nick,$channel)"
}

#If Bot2 (that was not on #channel) and joins #channel, then Bot1 sends all the getchanjoins that he had, to Bot2 (so that Bot2, get all the getchanjoins too). Is same as "proc procbot", but then for Bot1
proc getchanjoin:transfert {botname via} {
if {[islinked "Bot2"]} {
global mychanjoin
set channel #channel
foreach user [chanlist #channel] {
putbot Bot2 "jointime $user $channel $mychanjoin($user,$channel)"
puthelp "PRIVMSG #channel1 : jointime $user $channel $mychanjoin($user,$channel)"
}
}
}

#If Bot2 wasn't online, and then comes online, then Bot1 will send all his info that is in "usersuptime_backup.txt" to Bot2 (those are send in privmsg beginning with !transferuserinfo or !transferftpinfo). Bot2 will detect those first words, and will write them down in a txt file.
proc detect:bot {botname via} {
if {[islinked "Bot2"]} {
timer 10 {
set file [open /usr/home/eggdrop/logs/usersuptime_backup.txt w+]
set buf [read $file]
foreach line [split $buf \n] {
set line [string trim $line " "]
if {$line == ""} {continue}
#putserv "PRIVMSG Bot1 :\001!Transferuserinfo $line"
putbot Bot1 !Transferuserinfo $line
}
set file [open /usr/home/eggdrop/logs/ftpsuptime_backup.txt w+]
set buf1 [read $file]
foreach line [split $buf1 \n] {
set line [string trim $line " "]
if {$line == ""} {continue}
#putserv "PRIVMSG Bot2 :\001!Transferftpinfo $line"
putbot Bot1 !Transferftpinfo $line
}
timer 60 { file delete /usr/home/eggdrop/logs/usersuptime_backup.txt
file delete /usr/home/eggdrop/logs/ftpsuptime_backup.txt }
}
}
}

#Bot1 will write down info coming from Bot2 starting with !tTransferftpinfo
proc ftp:transferinfo {botnick command arg} {
set file [open /home/eggdrop/logs/ftpsuptime.txt a+]
puts $file "$arg"
close $file
}

#Bot1 will write down info coming from Bot2 starting with !Transferuserinfo
proc user:transferinfo {botnick command arg} {
set file [open /home/eggdrop/logs/usersuptime.txt a+]
puts $file "$arg"
close $file
}

Now my questions are:
How come i don't get a file getting created when i get from another bot the msg starting with !Transferftpinfo , and then in getting in useruptime.txt some info in it :-/
Secondly, how come, when i do on the bot that joined as Bot2, and i want to see the value in $mychanjoin($nick,$channel), this value gives me all the time "0" and not the right getchanjoin (i.e. 1077132933)?

Is there anything wrong in my coding plz?

Thnx in advance.

Best regards,

Buffy
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

One thing that jumps out at me is that you can not read from a file that you have opened in write mode (w)..... open the file in read mode (r) to get the contents.
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

why not transfer the data via putbot / bind bot ?
i do it the same way with my scripts since a leaf bot does all the HTML parsing / exec's and so on...a quick&dirty multithread workaround ;)
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

Hi,

Strikelight, thnx for that info. I changed it. But it still doesn't work the transfert of variables...i got all the time the error:
[12:57] Tcl error [chantest]: can't read "mychanjoin(a_nickname,#channel)": no such element inrray

So i tried another way of working. Can you guys pls check if this is possible?

Let's say i have one bot1 in my channel #blabla.
Persons are joining and my bot1 takes their [getchanjoin $nick #channel] in an array:
(script on bot1)
bind join - * joinproc
proc joinproc {nick uhost hand chan} {
if {[onchan bot2 #blabla]} {return 0}
array set mychanjoin {
$nick [getchanjoin $nick #blabla]
}
}

Now when bot2 get's online, i would like that bot1 sends all the info, in his array mychanjoin, to bot2:
(script on bot1)
bind link - * detect:bot
proc detect:bot {botname via} {
if {[islinked "bot2"]} {
foreach {$nick} [array get mychanjoin] {
putbot bot2 "accept $nick [getchanjoin $nick #blabla]"
}
}
}

Now bot2 recieves this info, and i would like to put it in an array on bot2:
(script on bot2)
bind bot - "accept" procbot
proc procbot {bot command text} {
set nick [lindex [split $text] 0]
set timein [lindex [split $text] 1]
set array mychanjoin {
$nick $timein
}
}

Will now bot2 have the same value of [getchanjoin $nick #blabla] as my bot1?

Is this the right way to work?
Thnx.

Best regards,
Buffy
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

GodOfSuicide,

I tried as you said with bind/putbot, but still didn't work.

I did like this:
1) Added the code on both bots

bot1:

Code: Select all

bind join - * joinproc 
proc joinproc {nick uhost hand chan} { 
if {[string equal -nocase $nick "bot1"] || [string match -nocase "*@blabla.com" $uhost]} { 
foreach nick [chanlist #channel] { 
putbot bot2 [list accept $nick [getchanjoin $nick #channel]] 
puthelp "PRIVMSG #controlchan : [list accept $nick [getchanjoin $nick #channel]]" 
} 
} 
} 

bot2:

Code: Select all

bind bot - "accept" procbot 
proc procbot {bot command text} { 
global mychanjoin 
set nick [lindex [split $text] 0] 
set jointime [lindex [split $text] 1] 
set [getchanjoin $nick #channel] jointime 
} 

3) Then i rehashed both of them (and restarted bot1...and bot1 rejoined in the mean time)
4) I quited my mirc
5) I restarted bot2
6) My mirc joined the channel (bot1 got his getchanjoin)
7) My bot2 rejoined the channel
I saw in #controlchan ->
[09:37] Tcl error [procbot]: nick1 is not on #channel
[09:37] Tcl error [procbot]: nick2 is not on #channel
[09:37] Tcl error [procbot]: nick3 is not on #channel
[09:37] Tcl error [procbot]: nick4 is not on #channel
... (for all the nicks in my channel)

9) But then i was in my #controlchan:
<bot1> accept my_mirc_nick 1079853981
<bot1> accept bot2 1079854108
<bot1> accept bot1 1079853942
<bot1> accept nick1 0
<bot1> accept nick2 0
<bot1> accept nick3 0
(all the other nicks got "0" 'cause my bot1 has been restarted and doesn't have a getchanjoin for them...isn't it?)

Now i would like to see if both bots would have the same getchanjoin for my join (mirc). So i would have hoped that bot1 would have passed his getchanjoin of me to bot2...

so i did like this to check the getchanjoin of my_mirc_nick on both bots:

bot1:

Code: Select all

bind pub - "test1" chantest 
proc chantest {nick uhost hand chan arg} { 
global mychanjoin 
set channel #channel 
set nick [lindex [split $arg] 0] 
puthelp "PRIVMSG #controlchan : [getchanjoin $nick #channel]" 
} 

bot2:

Code: Select all

bind pub - "test" chantest 
proc chantest {nick uhost hand chan arg} { 
global mychanjoin 
set channel #channel 
set nick [lindex [split $arg] 0] 
puthelp "PRIVMSG #controlchan : [getchanjoin $nick #channel]" 
} 

So i typed in #controlchan :
test1 my_mick (-> i got as response : <bot1> 1079853981)
test my_nick (-> i got as response : <bot2> 0)

So it seems that getchanjoin hasn't been transferred to bot2
I don't know if this is a correct statement : set [getchanjoin $nick #flightsim] jointime (i think we can't modify a getchanjoin...or am i wrong?). But i don't know what else i can try to get that getchanjoin from bot1 to bot2

I hope with this information you can help me a bit more.

Thnx in advance.

Best regards,

Buffy
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Buffy_25 wrote:
bot2:

Code: Select all

bind bot - "accept" procbot 
proc procbot {bot command text} { 
global mychanjoin 
set nick [lindex [split $text] 0] 
set jointime [lindex [split $text] 1] 
set [getchanjoin $nick #channel] jointime 
} 
I think the point of this code was to use the var mychanjoin, not [getchanjoin].

So it seems that getchanjoin hasn't been transferred to bot2
I don't know if this is a correct statement : set [getchanjoin $nick #flightsim] jointime (i think we can't modify a getchanjoin...or am i wrong?). But i don't know what else i can try to get that getchanjoin from bot1 to bot2

I hope with this information you can help me a bit more.

Thnx in advance.

Best regards,

Buffy
You are right, set [getchanjoin ...] blah does not modify the getchanjoin. You have to store it in your own variable and use that instead.
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

Hi stdragon,

The point is that i also tried to work with the var mychanjoin (cfr some msg's before in this post), but even with that i got on bot2 the value "0" iso having the right time stamp from bot1 :(

Do you or anyone else know how i could solve this matter of transferring the [getchanjoin $nick #channel] to my bot2?

I tried arrays, putbot and var mychanjoin but still without luck :-?

Thnx in advance.

Regards,
Buffy
Locked