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.

special seen script

Old posts that have not been replied to for several years.
Locked
M
Moonshine
Voice
Posts: 19
Joined: Sat Aug 09, 2003 4:19 pm

special seen script

Post by Moonshine »

hi .. i made a script (by coping parts of several scripts) that saves the nick and the time/date (now()) in a mysql-db if a user leaves my chan.
I use libmysqltcl3.01.so to connect to the db.


Now i would like to have another script that tells me the time that user was seen.

<user> !seen <nick> <how many leaves you want to get (perhaps max = 5)>


i have only 3 columns in the sql-db
||id||nick||time||
for example:
||1||John||29.07.2005 00:35:49||

the answer should look like

<bot> User John was seen 0 days 15 min and 54 seks ago.

If somebody could help me with that i have onle one wish ... please keep it as simple as possible ... i would like to learn from the script.

TIA
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

what exactly do you need help with?

it seems you are already familiar with interfacing mySQL from Tcl, so just do SELECT time FROM yourtable WHERE nick=$who on a !seen request from [bind pub] and use [duration] to display the time difference between now ([unixtime]) and $time
M
Moonshine
Voice
Posts: 19
Joined: Sat Aug 09, 2003 4:19 pm

Post by Moonshine »

like i wrote, i really copy and pasted that script together without understanding it totaly :?
(so sometimes if many ppl leave the chan in a short time i get a message that max connection for that db-user has reached, but that another story :)

i know the select-statement.
should be something like:

select nick, leavetime from mydb where nick like '%$user%'

but i really dont know how to programm the rest.

i have that ...

Code: Select all

###
# MySQL variables:
###

## hostname
set db(host) ""

## user
set db(id) ""

## password
set db(pass) ""

## database
set db(dbase) ""

## table 
#set db(table) ""

load libmysqltcl3.01.so
set mysql(libsql) "home/user/libmysqltcl3.01.so"

# --------------------------------------------------------------------
# binding
# --------------------------------------------------------------------

bind pubm - !seen seen

so far so good
... but now i mess it up...

Code: Select all

#### seen
proc seen {nick uhost handle channel arg} {
   global db
   set sqlhand [mysqlconnect -host $db(host) -user $db(id) -password $db(pass)]
   mysqluse $sqlhand $db(dbase)
   mysqlexec $sqlhand "SELECT NICK, LEAVETIME FROM MYDB WHERE NICK LIKE '%$arg%'" 
mysqlclose $sqlhand

How to post the results ?
How do i post more than one result.
And get the difference between the two times ?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

so, basically, you want to make your own script without really knowing what you're actually doing, just by copy & paste stuff from other scripts?

you are in dire need to R T F M first

I already told you how to obtain the time difference; what you need to do is read tcl-commands.doc and find out about [duration]

also, read mysqltcl's docs (google for "mysqltcl"); the way you use it by loading that library directly is wrong, you should use [package require]
M
Moonshine
Voice
Posts: 19
Joined: Sat Aug 09, 2003 4:19 pm

Post by Moonshine »

so, basically, you want to make your own script without really knowing what you're actually doing, just by copy & paste stuff from other scripts?
I would say u nailed it.
you are in dire need to R T F M first

I already told you how to obtain the time difference; what you need to do is read tcl-commands.doc and find out about [duration]

also, read mysqltcl's docs (google for "mysqltcl"); the way you use it by loading that library directly is wrong, you should use [package require]
You're right that i should start learn to cide myself, but this is basically a Script Requests forum and that is what i did. It's just not need to learn to code if u only need it for one script. I think my request is not really difficult for somebody who is use to program in tcl.
Anyway and nevertheless i will also read the docs!

about the [package require] thing ... not sure if i can use it like that. mysql is not installed on the provider shell i use.

THX anyway ...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

but you didn't request a script, you requested help with what you've done so far... anyway

btw, you can install mysqltcl locally in your home dir, without being root, and then use it the proper way (with [package require])
M
Moonshine
Voice
Posts: 19
Joined: Sat Aug 09, 2003 4:19 pm

Post by Moonshine »

:lol: ... this becomes more and more a discussion about nonsense.

But i make it officially :

I REQUEST A SCRIPT BASED ON MY FIRST POST!

(I only posted the code, because u asked what I exactly do need help with.)
And btw. i dont want to bather, beg or annoy you.

Just want such a script. :-)

anyway ... have to go to bed now ... it's almost 6 am here in old europe :-)
and who knows ... perhaps if i stand up in a few hours somebody helped me.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

I'm a little bit puzzled why you require SQL-based seen script, gseen module and bseen script both work pretty well without being SQL-based

and if, as you stated initially, you want to learn from such a script, I'd recommend you study bseen.tcl or some of the many SQL-aware scripts (or better yet, study the docs and try to write simple code doing single SELECT and displaying the result set)
M
Moonshine
Voice
Posts: 19
Joined: Sat Aug 09, 2003 4:19 pm

ok... i R T F M

Post by Moonshine »

after reading several manuels and several sleepless nights, everything works fine so far.

but now i have a problem.

i have a unixtime-stamp from the datebase saved in [lindex $column 1] and the time now() .

how do i get the differenz between these two times like i want

for example:

the user was seen 5 days 13 min and 12 seks ago.

and please if u want to help me, please post more than just a hint :-)

TIA
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

see [duration] in tcl-commands.doc
Locked