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.

Counter help

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
O
ORATEGOD
Halfop
Posts: 42
Joined: Mon Jun 08, 2020 5:50 pm

Counter help

Post by ORATEGOD »

I found this counter with time and date but I can't get it to work correctly, I hope someone can help me or guide me how to correct it so that it can work

Thank you in advance as always for your help in the forum

excuse my bad english


Code: Select all

# Script to greet new users and count their visits

# Path to the counter file
set contadorFile "scripts/Lobby.txt"

# Define a function to greet new users and count their visits
proc greetAndCount {nick chan} {
    # Get the current date and time
    set fecha [clock format [clock seconds] -format "%Y-%m-%d"]
    set hora [clock format [clock seconds] -format "%H:%M:%S"]

    # Increment the counter
    set contador [expr {file exists $contadorFile ? [readfile $contadorFile] + 1 : 1}]

    # Save the counter
    writefile $contadorFile $contador

    # Build the greeting message with colors and bold
    set saludo "Hello, \002$nick\002! Welcome to channel \002$chan\002. The current date is: \002$fecha\002, and the current time is: \002$hora\002. This is visit number \002$contador\002 to the channel."

    # Send the message to the channel
    putquick "PRIVMSG $chan :$saludo"
}

# Function to read a file
proc readfile {filename} {
    set file [open $filename]
    set content [read $file]
    close $file
    return $content
}

# Function to write to a file
proc writefile {filename content} {
    set file [open $filename w]
    puts -nonewline $file $content
    close $file
}

# Bind the join event to the greetAndCount function for the #Lobby channel
bind join - "chan #Lobby greetAndCount"

# Define the global variable `argv`
global argv

# Check for errors in the counter file
if {![file exists $contadorFile]} {
    set contador 1
}

# Initialize the global variable `nick`
global nick
set nick ""

# Assign the value of the first element of the `argv` list to the `nick` variable
set nick [lindex $argv 1]

putlog "=== #Lobby @ Count ==="
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

lets start with :

what are u expecting it to do?

and what error does it output if any ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Look at the bind statement and take it from there. If i where to guess, he asked ChatGTP to make this piece of code. :lol:
Once the game is over, the king and the pawn go back in the same box.
O
ORATEGOD
Halfop
Posts: 42
Joined: Mon Jun 08, 2020 5:50 pm

Post by ORATEGOD »

This error is the one that shows when turning on the eggdrop

Code: Select all

can't read "argv": no such variable
    while executing
"lindex $argv 1"
    (file "scripts/welcome.tcl" line 56)
    invoked from within
"source scripts/welcome.tcl"
O
ORATEGOD
Halfop
Posts: 42
Joined: Mon Jun 08, 2020 5:50 pm

Post by ORATEGOD »

caesar wrote:Look at the bind statement and take it from there. If i where to guess, he asked ChatGTP to make this piece of code. :lol:

Hello.... I don't know if it was written by ChatGPT, if so, could that be the error?
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

The script isn't designed to be used with an eggdrop but to be run from shell.
$argv is the list of arguments sent to a script.
The bind is not complete (bind join - "#lobby *" greetAndCount) and the greetAndCount defintion is false (proc greetAndCount {nick uhost handle chan} { ... })

Want some other errors ?
O
ORATEGOD
Halfop
Posts: 42
Joined: Mon Jun 08, 2020 5:50 pm

Post by ORATEGOD »

CrazyCat wrote:The script isn't designed to be used with an eggdrop but to be run from shell.
$argv is the list of arguments sent to a script.
The bind is not complete (bind join - "#lobby *" greetAndCount) and the greetAndCount defintion is false (proc greetAndCount {nick uhost handle chan} { ... })

Want some other errors ?


I understand... thank you very much for the clarification
Post Reply