Skip to content

Commit f499233

Browse files
Merge remote-tracking branch 'upstream/develop' into tdns.strerror
2 parents b94a559 + 5c34bd6 commit f499233

26 files changed

+258
-188
lines changed

configure

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.ac 95f630ee.
2+
# From configure.ac 9068a673.
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.71 for Eggdrop 1.9.5.
55
#
@@ -10638,7 +10638,6 @@ printf "%s\n" "#define EGG_TDNS 1" >>confdefs.h
1063810638
1063910639
1064010640
# Check for Python
10641-
EGG_PYTHON_ENABLE
1064210641
1064310642
1064410643
# Check whether --with-python-config was given.

configure.ac

-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ EGG_TLS_DETECT
164164
EGG_TDNS_ENABLE
165165

166166
# Check for Python
167-
EGG_PYTHON_ENABLE
168167
EGG_PYTHON_WITHCONFIG
169168

170169

doc/sphinx_source/modules/mod/python.rst

+5-102
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Python Module
88

99
This module adds a Python interpreter to Eggdrop, allowing you to run Python scripts.
1010

11+
-------------------
12+
System Requirements
13+
-------------------
14+
This module requires Python version 3.8 or higher in order to run. Similar to Tcl requirements, Eggdrop requires both python and python development libraries to be installed on the host machine. On Debian/Ubuntu machines, this means the packages ``python``, ``python-dev`` AND ``python-is-python3`` to be installed. The python-is-python3 updates symlinks on the host system that allow Eggdrop to find it.
15+
1116
--------------
1217
Loading Python
1318
--------------
@@ -50,105 +55,3 @@ pysource <path/to/file>
5055
^^^^^^^^^^^^^^^^^^^^^^^
5156

5257
The ``pysource`` command is analogous to the Tcl ``source`` command, except that it loads a Python script into Eggdrop instead of a Tcl script.
53-
54-
-----------------------
55-
Eggdrop Python Commands
56-
-----------------------
57-
58-
The Python module is built to use the existing core Tcl commands integrated into Eggdrop via the ``eggdrop.tcl`` module. To call an existing Tcl command from Python, you can either load the entire catalog by running ``import eggdrop.tcl``, or be more specific by ``from eggdrop.tcl import putserv, putlog, chanlist``, etc.
59-
60-
Arguments to the Tcl functions are automatically converted as follows:
61-
62-
* ``None`` is converted to an empty Tcl object (the empty string, ``""``)
63-
* ``List`` and ``Tuple`` is converted to a ``Tcl list``
64-
* ``Dict`` is converted to a ``Tcl dictionary``
65-
* Everything else is converted to a string using the str() method
66-
67-
Return values from Tcl functions must be manually converted:
68-
69-
* ``""`` the empty string is automatically converted to None
70-
* everything else is returned as string
71-
* ``Tcl list`` as string can be converted to a Python ``List`` using ``parse_tcl_list``
72-
* ``Tcl dictionary`` as string can be converted to a Python ``Dict`` using ``parse_tcl_list``
73-
74-
Additionally, a few extra python commands have been created for use without these conversions:
75-
76-
^^^^^^^^^^^^^^^^
77-
bind <arguments>
78-
^^^^^^^^^^^^^^^^
79-
80-
The python version of the bind command is used to create a bind that triggers a python function. The python bind takes the same arguments as the Tcl binds, but here each argument is passed individually. For example, a bind that would look like ``bind pub * !foo myproc`` in Tcl is written as ``bind("pub", "*", "!foo", myproc)``. For more information on Eggsrop bind argument syntax please see :ref:`bind_types`. The eggdrop.tcl.bind command should not be used as it will attempt to call a Tcl proc.
81-
82-
^^^^^^^^^^^^^^^^^^^^^^^
83-
parse_tcl_list <string>
84-
^^^^^^^^^^^^^^^^^^^^^^^
85-
86-
When a python script calls a Tcl command that returns a list via the eggdrop.tcl module, the return value will be a Tcl-formatted list- also simply known as a string. The ``parse_tcl_list`` command will convert the Tcl-formatted list into a Python list, which can then freely be used within the Python script.
87-
88-
^^^^^^^^^^^^^^^^^^^^^^^
89-
parse_tcl_dict <string>
90-
^^^^^^^^^^^^^^^^^^^^^^^
91-
92-
When a python script calls a Tcl command that returns a dict via the eggdrop.tcl module, the return value will be a Tcl-formatted dict- also simply known as a string. The ``parse_tcl_dict`` command will c
93-
onvert the Tcl-formatted dict into a Python list, which can then freely be used within the Python script.
94-
95-
----------------
96-
Config variables
97-
----------------
98-
99-
There are also some variables you can set in your config file:
100-
101-
set allow-resync 0
102-
When two bots get disconnected, this setting allows them to create a
103-
resync buffer which saves all changes done to the userfile during
104-
the disconnect. When they reconnect, they will not have to transfer
105-
the complete user file, but, instead, just send the resync buffer.
106-
107-
--------------------------------
108-
Writing an Eggdrop Python script
109-
--------------------------------
110-
111-
This is how to write a python script for Eggdrop.
112-
113-
You can view examples of Python scripts in the exampleScripts folder included with this module.
114-
115-
.. glossary::
116-
117-
bestfriend.py
118-
This example script demonstrates how to use the parse_tcl_list() python command to convert a list returned by a Tcl command into a list that is usable by Python.
119-
120-
greet.py
121-
This is a very basic script that demonstrates how a Python script with binds can be run by Eggdrop.
122-
123-
imdb.py
124-
This script shows how to use an existing third-party module to extend a Python script, in this case retrieving information from imdb.com.
125-
126-
listtls.py
127-
This script demonstrates how to use parse-tcl_list() and parse_tcl_dict() to convert a list of dicts provided by Tcl into something that is usable by Python.
128-
129-
urltitle.py
130-
This script shows how to use an existing third-party module to extend a Python script, in this case using an http parser to collect title information from a provided web page.
131-
132-
133-
^^^^^^^^^^^^^^
134-
Header section
135-
^^^^^^^^^^^^^^
136-
137-
An Eggdrop python script requires you to import X Y and Z, in this format.
138-
139-
^^^^^^^^^^^^
140-
Code Section
141-
^^^^^^^^^^^^
142-
143-
Normal python code works here. To run a command from the Eggdrop Tcl library, use this format.
144-
145-
Use this format all over.
146-
147-
-------------------------------------
148-
Writing a module for use with Eggdrop
149-
-------------------------------------
150-
151-
This is how you import a module for use with an egg python script.
152-
153-
154-
Copyright (C) 2000 - 2024 Eggheads Development Team

doc/sphinx_source/using/python.rst

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
=======================
2+
Using the Python Module
3+
=======================
4+
5+
In Eggdrop 1.10.0, Eggdrop was shipped with a Python module that, similar to the existing core Tcl capability, allows Eggdrop to run python scripts.
6+
7+
-------------------
8+
System Requirements
9+
-------------------
10+
Similar to Tcl requirements, Eggdrop requires both python and python development libraries to be installed on the host machine. On Debian/Ubuntu machines, this requires the packages python-dev AND python-is-python3 to be installed. The python-is-python3 updates symlinks on the host system that allow Eggdrop to find it.
11+
12+
--------------
13+
Loading Python
14+
--------------
15+
16+
Put this line into your Eggdrop configuration file to load the python module::
17+
18+
loadmodule python
19+
20+
To load a python script from your config file, place the .py file in the scripts/ folder and add the following line to your config::
21+
22+
pysource scripts/myscript.py
23+
24+
-----------------------
25+
Eggdrop Python Commands
26+
-----------------------
27+
28+
The Python module is built to use the existing core Tcl commands integrated into Eggdrop via the ``eggdrop.tcl`` module. To call an existing Tcl command from Python, you can either load the entire catalog by running ``import eggdrop.tcl``, or be more specific by ``from eggdrop.tcl import putserv, putlog, chanlist``, etc.
29+
30+
Arguments to the Tcl functions are automatically converted as follows:
31+
32+
* ``None`` is converted to an empty Tcl object (the empty string, ``""``)
33+
* ``List`` and ``Tuple`` is converted to a ``Tcl list``
34+
* ``Dict`` is converted to a ``Tcl dictionary``
35+
* Everything else is converted to a string using the str() method
36+
37+
Return values from Tcl functions must be manually converted:
38+
39+
* ``""`` the empty string is automatically converted to None
40+
* everything else is returned as string
41+
* ``Tcl list`` as string can be converted to a Python ``List`` using ``parse_tcl_list``
42+
* ``Tcl dictionary`` as string can be converted to a Python ``Dict`` using ``parse_tcl_list``
43+
44+
^^^^^^^^^^^^^^^^
45+
bind <arguments>
46+
^^^^^^^^^^^^^^^^
47+
48+
An important difference to note is that Eggdrop Python has its own ``bind`` command implemented. You will generally want to create binds using the Python ``bind`` command and not import bind from eggdrop.tcl because a Python bind will call a Python function, whereas using the Tcl bind will call a Tcl function (not one from the script you are writing).
49+
50+
The python version of the bind command is used to create a bind that triggers a python function. The python bind takes the same arguments as the Tcl binds, but here each argument is passed individually. For example, a bind that would look like ``bind pub * !foo myproc`` in Tcl is written as ``bind("pub", "*", "!foo", myproc)``. For more information on Eggsrop bind argument syntax please see :ref:`bind_types`. The eggdrop.tcl.bind command should not be used as it will attempt to call a Tcl proc.
51+
52+
^^^^^^^^^^^^^^^^^^^^^^^
53+
parse_tcl_list <string>
54+
^^^^^^^^^^^^^^^^^^^^^^^
55+
56+
When a python script calls a Tcl command that returns a list via the eggdrop.tcl module, the return value will be a Tcl-formatted list- also simply known as a string. The ``parse_tcl_list`` command will convert the Tcl-formatted list into a Python list, which can then freely be used within the Python script.
57+
58+
^^^^^^^^^^^^^^^^^^^^^^^
59+
parse_tcl_dict <string>
60+
^^^^^^^^^^^^^^^^^^^^^^^
61+
62+
When a python script calls a Tcl command that returns a dict via the eggdrop.tcl module, the return value will be a Tcl-formatted dict- also simply known as a string. The ``parse_tcl_dict`` command will convert the Tcl-formatted dict into a Python list, which can then freely be used within the Python script.
63+
64+
--------------------------------
65+
Writing an Eggdrop Python script
66+
--------------------------------
67+
68+
Some example scripts, complete with documentation, are included with the Python module that ships with Eggdrop (src/mod/python.mod/scripts). These scripts are included to help demonstrate script formatting and usage. The scripts are:
69+
70+
71+
.. glossary::
72+
73+
bestfriend.py
74+
This example script demonstrates how to use the parse_tcl_list() python command to convert a list returned by a Tcl command into a list that is usable by Python.
75+
76+
greet.py
77+
This is a very basic script that demonstrates how a Python script with binds can be run by Eggdrop.
78+
79+
imdb.py
80+
This script shows how to use an existing third-party module to extend a Python script, in this case retrieving information from imdb.com.
81+
82+
listtls.py
83+
This script demonstrates how to use parse-tcl_list() and parse_tcl_dict() to convert a list of dicts provided by Tcl into something that is usable by Python.
84+
85+
urltitle.py
86+
This script shows how to use an existing third-party module to extend a Python script, in this case using an http parser to collect title information from a provided web page.
87+
88+
89+
^^^^^^^^^^^^^^
90+
Header section
91+
^^^^^^^^^^^^^^
92+
93+
Python is able to call any Tcl command by importing the ``eggdrop`` module. For example, to use the ``putlog`` command in a python script, you would import it as::
94+
95+
from eggdrop.tcl import putlog
96+
97+
and then call it using::
98+
99+
putlog("This is a logged message")
100+
101+
102+
An important difference to note is that Eggdrop Python has its own ``bind`` command implemented. You will generally want to create binds using the Python ``bind`` command and not import bind from eggdrop.tcl because a Python bind will call a Python function, whereas using the Tcl bind will call a Tcl function (not one from the script you are writing).
103+
104+
Where does python print go?
105+
106+
-------------------------------------
107+
Writing a module for use with Eggdrop
108+
-------------------------------------
109+
110+
This is how you import a module for use with an egg python script.
111+
112+
Copyright (C) 2000 - 2024 Eggheads Development Team
113+

eggdrop.conf

+9-14
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ loadmodule pbkdf2
656656
# This setting is planned to be enabled by default in Eggdrop 2.0.
657657
#set remove-pass 0
658658

659+
659660
#### BLOWFISH MODULE ####
660661
#
661662
# This module is planned to be removed in Eggdrop 2.0
@@ -676,21 +677,14 @@ loadmodule blowfish
676677
set blowfish-use-mode cbc
677678

678679

679-
#### DNS MODULE (Deprecated) ####
680-
681-
## This module provided asynchronous dns support, but as of v1.9.2, this
682-
## functionality was moved into the core code. If you are having issues with the
683-
## new DNS functionality, or just want to continue using this module, compile
684-
## Eggdrop with the --disable-tdns flag (./configure --disdable-tdns).
685-
#
686-
## You really probably don't want to uncomment this!!!!
680+
#### PYTHON MODULE #####
687681
#
688-
#loadmodule dns
689-
#set dns-servers "8.8.8.8 1.1.1.1 185.222.222.222"
690-
#set dns-cache 86400
691-
#set dns-negcache 600
692-
#set dns-maxsends 4
693-
#set dns-retrydelay 3
682+
# This module gives Eggdrop the ability to run python scripts. if loaded,
683+
# Python scripts can be loaded at the end of the config file using the pysouce
684+
# command to tell Eggdrop where the file is loaded. The module requires Python
685+
# version 3.8 or higher to run. To load the python module, uncomment it below.
686+
#loadmodule python
687+
694688

695689
#### CHANNELS MODULE ####
696690

@@ -1448,6 +1442,7 @@ set xfer-timeout 30
14481442
# be v1.9.0 or higher).
14491443
#set sharefail-unlink 1
14501444

1445+
14511446
#### SHARE MODULE ####
14521447

14531448
# This module provides userfile sharing support between two directly

src/Makefile.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ modules.o: modules.c main.h ../config.h ../eggint.h ../lush.h lang.h \
176176
net.o: net.c main.h ../config.h ../eggint.h ../lush.h lang.h eggdrop.h \
177177
compat/in6.h flags.h proto.h misc_file.h cmdt.h tclegg.h tclhash.h \
178178
chan.h users.h compat/compat.h compat/base64.h compat/inet_aton.h \
179-
../src/main.h compat/snprintf.h compat/explicit_bzero.h compat/strlcpy.h
179+
../src/main.h compat/snprintf.h compat/explicit_bzero.h compat/strlcpy.h \
180+
modules.h mod/modvals.h
180181
rfc1459.o: rfc1459.c main.h ../config.h ../eggint.h ../lush.h lang.h \
181182
eggdrop.h compat/in6.h flags.h proto.h misc_file.h cmdt.h tclegg.h \
182183
tclhash.h chan.h users.h compat/compat.h compat/base64.h \

src/cmds.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1908,18 +1908,19 @@ static int add_to_handle(struct userrec *u, int idx, char *handle, char *host, i
19081908
}
19091909
}
19101910
if ( !type && !glob_botmast(fr) && !chan_master(fr) && get_user_by_host(host)) {
1911-
dprintf(idx, "You cannot add %s matching another user!\n",
1912-
type ? "an account" : "a host");
1911+
dprintf(idx, "You cannot add a host matching another user!\n");
19131912
return 1;
19141913
}
19151914
if (type) {
1915+
// host-variable contains account
19161916
u2 = get_user_by_account(host);
19171917
if (u2) {
19181918
dprintf(idx, "That account already exists for user %s\n", u2->handle);
19191919
return 1;
19201920
}
19211921
addaccount_by_handle(handle, host);
19221922
} else {
1923+
// host
19231924
for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
19241925
if (!strcasecmp(q->extra, host)) {
19251926
dprintf(idx, "That %s is already there.\n",

src/main.c

+4
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,10 @@ int main(int arg_c, char **arg_v)
10231023
sigaction(SIGILL, &sv, NULL);
10241024
sv.sa_handler = got_alarm;
10251025
sigaction(SIGALRM, &sv, NULL);
1026+
// Added for python.mod because the _signal handler otherwise overwrites it
1027+
// see https://discuss.python.org/t/asyncio-skipping-signal-handling-setup-during-import-for-python-embedded-context/37054/6
1028+
sv.sa_handler = got_term;
1029+
sigaction(SIGINT, &sv, NULL);
10261030

10271031
/* Initialize variables and stuff */
10281032
now = time(NULL);

src/mod/compress.mod/configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.ac 95f630ee.
2+
# From configure.ac 9068a673.
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.71 for Eggdrop Compress Module 1.9.5.
55
#

src/mod/dns.mod/configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.ac 95f630ee.
2+
# From configure.ac 9068a673.
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.71 for Eggdrop DNS Module 1.9.5.
55
#

0 commit comments

Comments
 (0)