eggdrop icon indicating copy to clipboard operation
eggdrop copied to clipboard

WIP: Add `timerexistsname` and `utimerexistsname` Tcl commands to check timer existence

Open ZarTek-Creole opened this issue 10 months ago โ€ข 3 comments

โœ… Title

WIP: Add `timerexists` and `utimerexists` Tcl commands to check timer existence

๐Ÿ“ Description

## Summary

This pull request introduces two new experimental Tcl commands for Eggdrop:

- `timerexists <name>`
- `utimerexists <name>`

These commands allow script authors to check whether a timer or utimer with a given name currently exists.  
This is meant to complement `killtimer` and `killutimer` by providing a safe way to check existence before attempting to remove a timer.

---

## ๐Ÿ”ง Status

๐Ÿšง **Draft / WIP** โ€” Not tested yet.  
Needs review and validation from Eggdrop core devs.

---

## ๐Ÿ“š Proposed Commands

### `timerexists <timerName>`
Returns `1` if a timer with this name exists, `0` otherwise.

### `utimerexists <timerName>`
Same as above, but for secondly-based timers.

---

## ๐Ÿ’ก Motivation

Currently, scripts must use complex or error-prone workarounds to detect timers.  
This patch introduces a clean, reliable way to check if a timer/utimer exists by name.

### Example: current workaround

```tcl
set t [utimer 1 myTimer] 0 myTimer
if {[info exists t] && [catch {killutimer myTimer} error]} {
  putlog "Warning: Unable to kill utimer ($error)."
}

With this feature:

utimer 1 myTimer 0 myTimer
if {[utimerexists myTimer]} {
  killutimer myTimer
}

๐Ÿงฉ Integration details

  • Implemented in src/tclmisc.c
  • Reuses the logic from killtimer / killutimer
  • No known side-effects
  • Syntax is consistent with existing Eggdrop command naming (explicit and clear)

โš ๏ธ Notes

  • โŒ Not yet tested
  • โ— Documentation still needs to be updated (doc/tcl-commands.doc)
  • ๐Ÿงช Needs review by maintainers to confirm viability, naming, behavior, etc.
  • ๐Ÿค Suggestions and improvements welcome

ZarTek-Creole avatar Apr 10 '25 13:04 ZarTek-Creole

i guess you want to add the documentation to doc/sphinx_source/using/tcl-commands.rst

michaelortmann avatar Apr 10 '25 20:04 michaelortmann

is there any relation to #507?

michaelortmann avatar Apr 10 '25 21:04 michaelortmann

Good idea but with another name, as (u)timerexists is already existing in alltools.tcl and used by several scripts and doesn't search on the same argument (command vs name).

crazycatdevs avatar Apr 20 '25 22:04 crazycatdevs