Python

From EggWiki
Revision as of 02:42, 14 October 2024 by Geo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Known Issues

Eggdrop's Python module duplicates bindings after a rehash

Eggdrop currently has trouble tracking python binds through a rehash. This results in multiple binds being set for the same trigger in some cases. Example code on how to get around this issue is below- basically, have the python script track its binds and, upon load, check that variable. If there are binds in it- remove them!

# Check for previously-existing binds when the script is loaded and delete them if they exist
if 'GREET_BINDS' in globals():
  for greetbind in GREET_BINDS:
    greetbind.unbind()
  del GREET_BINDS

# Continuing from the above section of code, the GREET_BINDS list is created to track the binds
# created by this script, and then the binds are added to it.
GREET_BINDS = list()
# Append the bind to the list you just made
GREET_BINDS.append(bind("join", "*", "*", joinGreetUser))

The python print() function doesn't do anything

The print() function in python only prints to stdout, it won't write to IRC or the partyline (unless you started Eggdrop in terminal mode with the -t flag). In order to print something to a channel, you'd need to import the putserv or putmsg Tcl command, or the putlog command to write to the partyline.

from eggdrop.tcl import putmsg, putlog

putlog("This sends to the partyline!")
putmsg(chan, "This sends to a channel!")