Sondage : Votre avis sur python dans eggdrop
Vous n’avez pas la permission de voter pour ce sondage.
Je resterai au TCL
0%
0 0%
Bof, on verra
0%
0 0%
Ca ouvre des perspectives
75.00%
3 75.00%
Je passe tout mes scripts en python
25.00%
1 25.00%
Total 4 vote(s) 100%
* Vous avez voté pour cette proposition. [Voir les résultats]

Bientôt des scripts en python
#2
Première chose gênante: si vous avez besoin des binds, ce qui est tout de même la base des scripts, il faut les importer de eggdrop et non pas d'eggdrop.tcl qui fournit l'essentiel des fonctions propres à eggdrop.
Cela veut donc dire que vous pouvez importer la bibliothèque eggdrop mais que toutes celles provenant d'eggdrop.tcl doivent être appelées une à une:
Code :
import eggdrop
from eggdrop.tcl import putmsg, putlog, chanlist, maskhost, timer, timers

La liste peut être très longue, et en python il n'est pas possible de dire qu'on veut importer tout un module sauf une fonction

EDIT
Idée donnée par Geo et 100% fonctionnelle: n'importer que egddrop et préfixer les commandes tcl par tcl.
Exemple avec le script bestfriend.py
python
# GOAL: Demonstrate how to convert a list provided by a Tcl command into a Python list
 
# Load all from eggdrop. Tcl commands must be prefixed with tcl.
from eggdrop import *
 
# And now, a totally normal python module
import random
 
# This is a proc that calls the putmsg Tcl command. Note that, slightly different than Tcl,
# each argument is separated by a comma instead of just a space
#
# This function is trivial and silly, but shows how Python can properly accept and type a Tcl list
def pickAFriend(nick, user, hand, chan, text, **kwargs):
  users = tcl.chanlist(chan)
  # Here we use a new python function called 'parse_tcl_list' to convert the Tcl list provided by chanlist
  # into a python list. Without this, you just have a long space-separated string
  userlist = parse_tcl_list(users)
  tcl.putlog(f"This is a python list of the users: {userlist}")
  bestFriend = random.choice(userlist)
  tcl.putmsg(chan, f"The first user I found was {userlist[0]}")
  tcl.putmsg(chan, f"But {bestFriend} is my new best friend!")
 
# Call binds at the end of the script, not the top- the methods must be defined!
bind("pub", "*", "!friend", pickAFriend)
 
print('Loaded bestfriend.py')


Répondre


Messages dans ce sujet
Bientôt des scripts en python - par CrazyCat - 05/04/2024, 13:42
RE: Bientôt des scripts en python - par CrazyCat - 07/04/2024, 16:08
RE: Bientôt des scripts en python - par Amand - 08/04/2024, 09:41

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté