DictionaryAPI.tcl - latest version - mabrook - 21/08/2021
Hi, need help on this.. thanks
<@ mabrook> .define
<GAWAIN> DictionaryAPI: flag 'definiciones' not set on '#mychannel'
BOT DCC: <GAWAIN> [11:44:40] DictionaryAPI: flag 'definiciones' not set on '#mychannel'
Code: #########################################################################################
# Name Dictionary-API
# Description Uses Dictionary v2 API to search and Get word definitions
# auteur ZarTek <Deffice@GMail.Com>
# version 1.2
#########################################################################################
if { [::tcl::info::commands ::DictionaryAPI::unload] eq "::DictionaryAPI::unload" } { ::DictionaryAPI::unload }
if { [package vcompare [regexp -inline {^[[:digit:]\.]+} $::version] 1.6.20] == -1 } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 La version de votre Eggdrop est\00304 ${::version}\003; DictionaryAPI ne fonctionnera correctement que sur les Eggdrops version 1.6.20 ou supérieure." ; return }
if { [::tcl::info::tclversion] < 8.5 } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite que Tcl 8.5 (ou plus) soit installé pour fonctionner. Votre version actuelle de Tcl est\00304 ${::tcl_version}\003." ; return }
if { [catch { package require tls}] } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite le package tls 1.7 (ou plus) pour fonctionner. Le chargement du script a été annulé." ; return }
if { [catch { package require http}] } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite le package http 2.9 (ou plus) pour fonctionner. Le chargement du script a été annulé." ; return }
if { [catch { package require json}] } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite le package json 1.3 (ou plus) pour fonctionner. Le chargement du script a été annulé." ; return }
namespace eval ::DictionaryAPI {
######################################################
## Flag
setudef flag definiciones
######################################################
###############################################################################
### Configuration
###############################################################################
# Commande publique
variable public_cmd ".define .Definiciones"
# Autorisations pour la commande publique
variable public_cmd_auth "-"
# Langue de sortie
# en,hi,es,fr,ja,ru,de,it,ko,pt-br,ar,tr
variable Lang "en"
# Annonce prefix-> devant les annonce irc
variable Annonce_Prefix "\00301,00DictionaryAPI\003> "
##
# ANNONCES "BLOCK" STYLE VARIABLES
# Add colors etc
##
# "\${DICT_DEFINITION}" : definition
# "\${DICT_NUMBER}" : Le numero de la definition
# "\${DICT_WORD}" : le mot en question
# "\${DICT_TYPE}" : partOfSpeech
# "\${DICT_EXAMPLE}" : Exemple de la definition
# "\${DICT_SYNONYMS}" : Les synonimes de la definition
# "\${DICT_ANTONYMS}" : Les antonimes de la definition
# "\${DICT_PHONETICS}" : DICT_PHONETICS de la definition
# "\n" : Retour a la ligne, nouvelle phrase??
###
variable BLOCK_DEFINITION " > \${DICT_DEFINITION}"
variable BLOCK_NUMBER " \${DICT_NUMBER} "
variable BLOCK_WORD "\002\00301,00\"\${DICT_WORD}\"\003\002"
variable BLOCK_TYPE " - \${DICT_TYPE}"
variable BLOCK_EXAMPLE " > \00302\"\${DICT_EXAMPLE}\"\003"
variable BLOCK_SYNONYMS " > (\${DICT_SYNONYMS})"
variable BLOCK_ANTONYMS " != \${DICT_ANTONYMS}"
variable BLOCK_PHONETICS " (\${DICT_PHONETICS})"
##
# ANNONCES VARIABLES POSITION (if exists)
##
# "\${BLOCK_DEFINITION}"
# "\${BLOCK_NUMBER}"
# "\${BLOCK_WORD}"
# "\${BLOCK_TYPE}"
# "\${BLOCK_EXAMPLE}"
# "\${BLOCK_SYNONYMS}"
# "\${BLOCK_ANTONYMS}"
# "\${BLOCK_PHONETICS}"
# "\n" : Retour a la ligne, nouvelle phrase
###
# Multi exemple:
#variable Annonce_Show "\${DICT_WORD}\${DICT_PHONETICS}\${DICT_TYPE}\${DICT_SYNONYMS}\${DICT_ANTONYMS}\${DICT_NUMBER}\${DICT_DEFINITION}\${DICT_EXAMPLE}"
#variable Annonce_Show "\${DICT_WORD}\${DICT_PHONETICS}\${DICT_SYNONYMS}\${DICT_ANTONYMS}\${DICT_NUMBER}\${DICT_DEFINITION}\${DICT_EXAMPLE}"
variable Annonce_Show "\${DICT_NUMBER}\${DICT_WORD}\${DICT_TYPE}\n\${DICT_DEFINITION}\n\${DICT_EXAMPLE}"
# Annonce notfound
## "\${WORD_SEARCH}" : word not found
## "\${URL_Link}" : url not found
#variable Annonce_notfound "No se encontraron definiciones para 6\${WORD_SEARCH}\002."
variable Annonce_notfound "No se encontraron definiciones para 6\${WORD_SEARCH}\002. (\${URL_Link})"
# Nombre de resultats maximun
variable max_annonce_default 2
# Nombre de resultats maximun defini par l'utilisateur
variable max_annonce_user 10
# Après combien de secondes décide-t-on que le site web utilisé par le script
# pour afficher les définitions est offline (ou trop lent) en l'absence de
# réponse de sa part ?
variable HTTP_TIMEOUT 10
# USE HTTPS (1) OR HTTP (0)
variable USE_HTTP_SSL 1
# URL (n'y touchez pas à moins d'avoir une bonne raison de le faire)
variable HTTP_URL_API "api.dictionaryapi.dev/api/v2/entries"
# User agent for http
variable HTTP_USERAGENT "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"
###############################################################################
### Fin de la configuration
###############################################################################
#############################################################################
### Initialisation
#############################################################################
variable scriptname "DictionaryAPI"
variable scriptauteur "ZarTek <Deffice@GMail.Com>"
variable version "1.2"
if { $USE_HTTP_SSL == 1 } {
variable HTTP_URL_API "https://${HTTP_URL_API}"
} else {
variable HTTP_URL_API "http://${HTTP_URL_API}"
}
setudef flag definiciones
proc unload {args} {
putlog "Désallocation des ressources de ${::DictionaryAPI::scriptname}..."
foreach binding [lsearch -inline -all -regexp [binds *[set ns [::tcl::string::range [namespace current] 2 end]]*] " \{?(::)?$ns"] {
unbind [lindex $binding 0] [lindex $binding 1] [lindex $binding 2] [lindex $binding 4]
}
foreach running_utimer [utimers] {
if { [::tcl::string::match "*[namespace current]::*" [lindex $running_utimer 1]] } { killutimer [lindex $running_utimer 2] }
}
namespace delete ::DictionaryAPI
}
}
proc ::DictionaryAPI::GetURL { URL_Link } {
if { $::DictionaryAPI::USE_HTTP_SSL == 1 } { ::http::register https 443 [list ::tls::socket -autoservername true] }
# on modifie l'urlencoding car dicoreverso.net ne comprend que l'utf-8 dans ses URLs.
array set httpconfig [::http::config]
::http::config -urlencoding utf-8 -useragent $::DictionaryAPI::HTTP_USERAGENT
# on restaure l'urlencoding comme il était avant qu'on y touche
::http::config -urlencoding $httpconfig(-urlencoding)
if { [catch { set URL_TOKEN [::http::geturl $URL_Link -timeout [expr $::DictionaryAPI::HTTP_TIMEOUT * 1000]] } ERR] } {
putlog "::DictionaryAPI::GetURL \00314La connexion à \00312\037[set URL_Link]\037\003\00314 n'a pas pu être établie. Il est possible que le site rencontre un problème technique.\003"
putlog "::DictionaryAPI::ERROR $ERR"
if { $::DictionaryAPI::USE_HTTP_SSL == 1 } { ::http::unregister https }
return 0
}
# on extrait la partie qui nous intéresse et sur laquelle on va travailler
set URL_DATA [::http::data $URL_TOKEN]
set URL_DATA [encoding convertfrom utf-8 $URL_DATA]
::http::cleanup $URL_TOKEN
if { $::DictionaryAPI::USE_HTTP_SSL == 1 } { ::http::unregister https }
return $URL_DATA;
}
###############################################################################
### Procédure principale
###############################################################################
proc ::DictionaryAPI::SetBlock { WHAT VALUE } {
set DICT_$WHAT $VALUE
set ::DictionaryAPI::DICT_$WHAT [subst [subst $[join ::DictionaryAPI::BLOCK_$WHAT]]]
}
proc ::DictionaryAPI::Search {nick host hand chan arg} {
if { ![channel get $chan definiciones] } {
set MSG "DictionaryAPI: flag 'definiciones' not set on '$chan'"
putlog $MSG
putserv "PRIVMSG $chan :$MSG"
return
}
set WORD_SEARCH [stripcodes * $arg]
if {$WORD_SEARCH == ""} {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}HELP : [join $::DictionaryAPI::public_cmd "|"] <word> "
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}LANG : \[-lang=<en,hi,es,fr,ja,ru,de,it,ko,pt-br,ar,tr>\] | default lang: $::DictionaryAPI::Lang "
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}LIMIT : \[-limit=<1-$::DictionaryAPI::max_annonce_user>\] | default limit: $::DictionaryAPI::max_annonce_default "
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}EXAMPLE : [lindex $::DictionaryAPI::public_cmd 0] test -lang=ru -limit=6"
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}HELP : [join $::DictionaryAPI::public_cmd "|"] SetLang <en,hi,es,fr,ja,ru,de,it,ko,pt-br,ar,tr> | Set lang per default"
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}EXAMPLE : [lindex $::DictionaryAPI::public_cmd 0] SetLang es"
return
}
if {[string match -nocase [lindex $arg 0] "SetLang"] } {
if {[lindex $arg 1] != ""} {
set ::DictionaryAPI::Lang [lindex $arg 1]
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix} Default lang is now : $::DictionaryAPI::Lang"
} else {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix} Current lang is : $::DictionaryAPI::Lang"
}
return
}
set RE {-limit[\s|=](\S+)}
if { [regexp -nocase -- $RE $WORD_SEARCH -> limit]} {
regsub -nocase -- $RE $WORD_SEARCH {} WORD_SEARCH
set WORD_SEARCH [string trim $WORD_SEARCH]
if {$limit > $::DictionaryAPI::max_annonce_user} {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix} limit max is $::DictionaryAPI::max_annonce_user"
set limit $::DictionaryAPI::max_annonce_user
}
} else {
set limit $::DictionaryAPI::max_annonce_default
}
set RE {-lang[\s|=](\S+)}
if { [regexp -nocase -- $RE $WORD_SEARCH -> lang]} {
regsub -nocase -- $RE $WORD_SEARCH {} WORD_SEARCH
set WORD_SEARCH [string trim $WORD_SEARCH]
set URL_Link "${::DictionaryAPI::HTTP_URL_API}/${lang}/${WORD_SEARCH}"
} else {
set URL_Link "${::DictionaryAPI::HTTP_URL_API}/${::DictionaryAPI::Lang}/${WORD_SEARCH}"
}
set URL_DATA [::DictionaryAPI::GetURL $URL_Link]
foreach { PARENT } [::json::json2dict $URL_DATA] {
if { $PARENT == "title" } {
putserv "PRIVMSG $chan :[subst $::DictionaryAPI::Annonce_notfound]"
return
}
# init/reset vars
variable DICT_DEFINITION ""
variable DICT_WORD ""
variable DICT_TYPE ""
variable DICT_NUMBER 0
variable DICT_EXAMPLE ""
variable DICT_SYNONYMS ""
variable DICT_ANTONYMS ""
variable DICT_PHONETICS ""
set SUBCAT [dict get $PARENT]
set TMP_phonetics [dict get $SUBCAT phonetics]
::DictionaryAPI::SetBlock WORD [dict get $SUBCAT word]
if {$TMP_phonetics != "{}"} {
::DictionaryAPI::SetBlock PHONETICS $phonetics
unset TMP_phonetics
}
set SUBMEANINGS [dict get $SUBCAT meanings]
foreach { ENFANT } [dict get $SUBCAT meanings] {
set TMP_partOfSpeech [dict get $ENFANT partOfSpeech]
if {$TMP_partOfSpeech != "{}"} {
::DictionaryAPI::SetBlock TYPE $TMP_partOfSpeech
unset TMP_partOfSpeech
}
foreach { SUBDEFINITION } [dict get $ENFANT definitions] {
::DictionaryAPI::SetBlock DEFINITION [dict get $SUBDEFINITION definition]
if {
[dict exists $SUBDEFINITION synonyms] && \
[dict get $SUBDEFINITION synonyms] != ""
} {
::DictionaryAPI::SetBlock SYNONYMS [join [dict get $SUBDEFINITION synonyms] ", "]
}
if { [dict exists $SUBDEFINITION example] } {
::DictionaryAPI::SetBlock EXAMPLE [dict get $SUBDEFINITION example]
}
::DictionaryAPI::SetBlock NUMBER [expr $DICT_NUMBER+1]
foreach Annonce [split [subst ${::DictionaryAPI::Annonce_Show}] "\n"] {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}$Annonce"
}
if {$limit == $DICT_NUMBER} { return }
}
}
}
}
###############################################################################
### Binds
###############################################################################
foreach b $::DictionaryAPI::public_cmd {
bind pub $::DictionaryAPI::public_cmd_auth $b ::DictionaryAPI::Search
}
bind evnt - prerehash ::DictionaryAPI::unload
putlog "DictionaryAPI $::DictionaryAPI::version by $::DictionaryAPI::scriptauteur loaded"
RE: DictionaryAPI.tcl - latest version - CrazyCat - 21/08/2021
(21/08/2021, 13:49)mabrook Wrote: Hi, need help on this.. thanks
<@ mabrook> .define
<GAWAIN> DictionaryAPI: flag 'definiciones' not set on '#mychannel'
BOT DCC: <GAWAIN> [11:44:40] DictionaryAPI: flag 'definiciones' not set on '#mychannel'
The eggdrop gives you the explanation: you didn't set the +definiciones on #mychannel. Try .chanset #mychannel +definiciones , I'm sure it will work.
RE: DictionaryAPI.tcl - latest version - ZarTek - 22/08/2021
A new version (1.2.1) allows to define the authorization of channels in a variable rather than by flags.
URL: TCL-DictionaryAPI v1.2.1
RE: DictionaryAPI.tcl - latest version - mabrook - 22/08/2021
<mabrook> .chanset #mychannel +definiciones
<BOT DCC> Error trying to set +definiciones for #mychannel, invalid mode.
<BOT DCC> [05:15:01] Tcl error [::DictionaryAPI::Search]: Invalid strip-flags: *
still this issue.
RE: DictionaryAPI.tcl - latest version - CrazyCat - 22/08/2021
if you use the last release, there is no more flag:
(22/08/2021, 00:31)ZarTek Wrote: A new version (1.2.1) allows to define the authorization of channels in a variable rather than by flags. You have to put channel in the script:
tcl # List of salons where the script will be active put "*" for all channels
# Example to allow #channel1 and #channel2
# define the channels(Allow) "#channel1 #channel2"
set Channels(Allow) "*"
RE: DictionaryAPI.tcl - latest version - mabrook - 22/08/2021
hello CrazyCat, i'm using the latest version URL: TCL-DictionaryAPI v1.2.1 (ZarTek) and put the
set Channels(Allow) "#mychannel"
<BOT> [10:27:57] DictionaryAPI 1.2.1 by MalaGaM <MalaGaM.ARTiSPRETiS@GMail.Com> @ url/MalaGaM loaded.
now.. in dcc
.chanset #mychannel +definiciones
<BOT REPLY> [10:28:13] Tcl error [::DictionaryAPI::Search]: Invalid strip-flags: *
if you can try it from your bot also... you will this error..
RE: DictionaryAPI.tcl - latest version - ZarTek - 22/08/2021
(22/08/2021, 12:33)mabrook Wrote: hello CrazyCat, i'm using the latest version URL: TCL-DictionaryAPI v1.2.1 (ZarTek) and put the
set Channels(Allow) "#mychannel"
<BOT> [10:27:57] DictionaryAPI 1.2.1 by MalaGaM <MalaGaM.ARTiSPRETiS@GMail.Com> @ url/MalaGaM loaded.
now.. in dcc
.chanset #mychannel +definiciones
<BOT REPLY> [10:28:13] Tcl error [::DictionaryAPI::Search]: Invalid strip-flags: *
if you can try it from your bot also... you will this error..
In the version of MalaGaM (1.2.1) you must in the TCL modify
Code: set Channels(Allow) "#mychannel"
Replace you #mychannel by your channel or your channels list. to authorize everywhere where your eggdrop can be found you can put "*".
In ZarTek 1.2 version you had to set the flag as Crazycat to tell you
Code: .chanset #mychannel +definiciones
Replace you #mychannel by your channel
How to proceed:
- Remove the old dictionary scripts (delete file DictionaryAPI.tcl from scripts/)
- Download the latest version 1.2.1: https://raw.githubusercontent.com/MalaGaM/TCL-DictionaryAPI/master/DictionaryAPI.tcl
- put in your scripts/ the file DictionaryAPI.tcl
- Check in your (eggdrop).conf file that you load with "source scripts/DictionaryAPI.tcl"
- Edit the file scripts/DictionaryAPI.tcl and change the value : set Channels(Allow) "#mychannel"
- restart/start completely your eggdrop
- The bot joins your channels, try the ".define" IRC command on a channel configured in Channels(Allow) variable.
Extra informations for channels(Allow):
# List of salons where the script will be active put "*" for all channels
# Example to allow #channel1 and #channel2
# define the channels(Allow) "#channel1 #channel2"
Good Luck
RE: DictionaryAPI.tcl - latest version - mabrook - 22/08/2021
thank you guys, it seems my issue is this one...
Code: package tls 1.7 - ok.. update to latest version
package http 2.9
package json 1.3
i hope you can help on how to update this packages in debian ..
thank you..
RE: DictionaryAPI.tcl - latest version - ZarTek - 22/08/2021
Some of the above packages are part of tcllib:
Try to install or update tcllib.
On debian for package tls
Code: apt update
apt install tcllib
from source:
https://www.tcl.tk/software/tcllib/
https://core.tcl-lang.org/tcllib/
On debian for package tls
Code: apt update
apt install tcl-tls
or from source :
https://core.tcl-lang.org/tcltls
RE: DictionaryAPI.tcl - latest version - mabrook - 23/08/2021
sorry man.. i tried it all .. but still i'm getting this error..
<BOT REPLY> [10:28:13] Tcl error [::DictionaryAPI::Search]: Invalid strip-flags: *
thank you for the support..
RE: DictionaryAPI.tcl - latest version - CrazyCat - 23/08/2021
Which version of eggdrop do you use ? Looks like you're using 1.6.21, the "*" flag has been added in 1.8.x branch.
You can use the "normal" all filtering by replacing set WORD_SEARCH [stripcodes * $arg] with set WORD_SEARCH [stripcodes bcruag $arg] but the better is to have an up2date eggdrop
RE: DictionaryAPI.tcl - latest version - mabrook - 23/08/2021
yes i am using .. 1.6.21 .. ok.. let me try with 1.8 and post a feedback from here.. thanks CrazyCat
RE: DictionaryAPI.tcl - latest version - CrazyCat - 23/08/2021
You'd better use 1.9.x which is the last stable branch.
RE: DictionaryAPI.tcl - latest version - mabrook - 23/08/2021
hi, here it is now.. i'm using 1.9x .. with all the updates.. all the instructions from the script as posted in here..
Code: set WORD_SEARCH [stripcodes * $arg]
in DCC chat:
[09:13:42] Tcl error [::DictionaryAPI::Search]: can't read "::DictionaryAPI::max_annonce_default": no such variable
Code: set WORD_SEARCH [stripcodes bcruag $arg]
<ALTNICK> [09:17:27] #mabrook# set errorInfo
<ALTNICK> Currently: can't read "::DictionaryAPI::max_annonce_default": no such variable
<ALTNICK> Currently: while executing
<ALTNICK> Currently: "set limit$::DictionaryAPI::max_annonce_default"
<ALTNICK> Currently: (procedure "::DictionaryAPI::Search" line 37)
<ALTNICK> Currently: invoked from within
<ALTNICK> Currently: "::DictionaryAPI::Search $_pub1 $_pub2 $_pub3 $_pub4 $_pub5"
i'm so sorry guys for disturbing you all.. am really trying myself to work it and done to this script. that's the latest error from my bot..
thank you..
FULL SCRIPT
Code: ###############################################################################################
#
# Name :
# DictionaryAPI.tcl
#
# Description :
# TCL script for eggdrop that uses Dictionary v2 API to find
# and get word definitions
#
# Script TCL pour eggdrop qui utilise l'API Dictionary v2 pour rechercher et
# obtenir des définitions de mots
#
# Version :
# 1.2.1
#
# Donation :
# https://github.com/MalaGaM/DONATE
#
# Auteur :
# MalaGaM <MalaGaM.ARTiSPRETiS@GMail.Com> @ https://github.com/MalaGaM
#
# Website :
# https://github.com/MalaGaM/TCL-DictionaryAPI
#
# Support :
# https://github.com/MalaGaM/TCL-DictionaryAPI/issues
#
# Docs :
# https://github.com/MalaGaM/TCL-DictionaryAPI/wiki
#
# Thanks to :
# CrazyCat - community french and help of eggdrop : https://www.eggdrop.fr
# MenzAgitat - tips/toolbox : https://boulets.eggdrop.fr/
#
###############################################################################################
if { [::tcl::info::commands ::DictionaryAPI::unload] eq "::DictionaryAPI::unload" } { ::DictionaryAPI::unload }
if { [package vcompare [regexp -inline {^[[:digit:]\.]+} $::version] 1.6.20] == -1 } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 La version de votre Eggdrop est\00304 ${::version}\003; DictionaryAPI ne fonctionnera correctement que sur les Eggdrops version 1.6.20 ou supérieure." ; return }
if { [::tcl::info::tclversion] < 8.5 } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite que Tcl 8.5 (ou plus) soit installé pour fonctionner. Votre version actuelle de Tcl est\00304 ${::tcl_version}\003." ; return }
if { [catch { package require tls}] } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite le package tls 1.7 (ou plus) pour fonctionner. Le chargement du script a été annulé." ; return }
if { [catch { package require http}] } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite le package http 2.9 (ou plus) pour fonctionner. Le chargement du script a été annulé." ; return }
if { [catch { package require json}] } { putloglev o * "\00304\[DictionaryAPI - erreur\]\003 DictionaryAPI nécessite le package json 1.3 (ou plus) pour fonctionner. Le chargement du script a été annulé." ; return }
namespace eval ::DictionaryAPI {
###############################################################################
### Configuration
###############################################################################
# List of salons where the script will be active put "*" for all channels
# Example to allow #channel1 and #channel2
# define the channels(Allow) "#channel1 #channel2"
#
# Liste des salons où le script sera active mettre "*" pour tout les salons
# Exemple pour autoriser #channel1 et #channel2
# set Channels(Allow) " #channel1 #channel2"
set Channels(Allow) "#nytcrwlrz"
### Public IRC commands | Commandes IRC publique
# Define the IRC commands that the script should respond to and look for definitions.
# Définissez les commandes IRC auquel le script doit répondre et chercher les definitions.
variable public_cmd ".define !DictionaryAPI .definition"
# Autorisations pour la commande publique
variable public_cmd_auth "-"
### Default language for output | Langue par défaut pour la sorties
# List: en,hi,es,fr,ja,ru,de,it,ko,pt-br,ar,tr
variable Lang "en"
# Annonce prefix-> devant les annonce irc
variable Annonce_Prefix "\00301,00DictionaryAPI\003> "
##
# ANNONCES "BLOCK" STYLE VARIABLES
# Add colors etc
##
# "\${DICT_DEFINITION}" : definition
# "\${DICT_NUMBER}" : Le numero de la definition
# "\${DICT_WORD}" : le mot en question
# "\${DICT_TYPE}" : partOfSpeech
# "\${DICT_EXAMPLE}" : Exemple de la definition
# "\${DICT_SYNONYMS}" : Les synonimes de la definition
# "\${DICT_ANTONYMS}" : Les antonimes de la definition
# "\${DICT_PHONETICS}" : DICT_PHONETICS de la definition
# "\n" : Retour a la ligne, nouvelle phrase??
###
variable BLOCK_DEFINITION " > \${DICT_DEFINITION}"
variable BLOCK_NUMBER " \${DICT_NUMBER} "
variable BLOCK_WORD "\002\00301,00\"\${DICT_WORD}\"\003\002"
variable BLOCK_TYPE " - \${DICT_TYPE}"
variable BLOCK_EXAMPLE " > \00302\"\${DICT_EXAMPLE}\"\003"
variable BLOCK_SYNONYMS " > (\${DICT_SYNONYMS})"
variable BLOCK_ANTONYMS " != \${DICT_ANTONYMS}"
variable BLOCK_PHONETICS " (\${DICT_PHONETICS})"
##
# ANNONCES VARIABLES POSITION (if exists)
##
# "\${BLOCK_DEFINITION}"
# "\${BLOCK_NUMBER}"
# "\${BLOCK_WORD}"
# "\${BLOCK_TYPE}"
# "\${BLOCK_EXAMPLE}"
# "\${BLOCK_SYNONYMS}"
# "\${BLOCK_ANTONYMS}"
# "\${BLOCK_PHONETICS}"
# "\n" : Retour a la ligne, nouvelle phrase
###
# Multi exemple:
#variable Annonce_Show "\${DICT_WORD}\${DICT_PHONETICS}\${DICT_TYPE}\${DICT_SYNONYMS}\${DICT_ANTONYMS}\${DICT_NUMBER}\${DICT_DEFINITION}\${DICT_EXAMPLE}"
#variable Annonce_Show "\${DICT_WORD}\${DICT_PHONETICS}\${DICT_SYNONYMS}\${DICT_ANTONYMS}\${DICT_NUMBER}\${DICT_DEFINITION}\${DICT_EXAMPLE}"
variable Annonce_Show "\${DICT_NUMBER}\${DICT_WORD}\${DICT_TYPE}\n\${DICT_DEFINITION}\n\${DICT_EXAMPLE}"
# Annonce notfound
## "\${WORD_SEARCH}" : word not found
## "\${URL_Link}" : url not found
variable Annonce_notfound "Aucune définition trouvée pour \00306\${WORD_SEARCH}\002. (\${URL_Link})"
#variable Annonce_notfound "No definition found for \00306\${WORD_SEARCH}\002. (\${URL_Link})"
# Maximum number of results | Nombre de resultats maximun
variable max_annonce_defaul 2
# Maximum number of results defined by the user | Nombre de résultats maximum défini par l'utilisateur
variable max_annonce_user 10
# After how many seconds do we decide that the website used by the script to display
# the definitions is offline (or too ready) without a response from it?
#
# Après combien de secondes décide-t-on que le site web utilisé par le script
# pour afficher les définitions est offline (ou trop lent) en l'absence de
# réponse de sa part ?
variable HTTP_TIMEOUT 10
# USE HTTPS (1) OR HTTP (0)
variable USE_HTTP_SSL 1
# URL (n'y touchez pas à moins d'avoir une bonne raison de le faire)
variable HTTP_URL_API "api.dictionaryapi.dev/api/v2/entries"
# User agent for http
variable HTTP_USERAGENT "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"
###############################################################################
### Fin de la configuration
###############################################################################
#############################################################################
### Initialisation
#############################################################################
variable scriptname "DictionaryAPI"
variable scriptauteur "MalaGaM <MalaGaM.ARTiSPRETiS@GMail.Com> @ https://github.com/MalaGaM"
variable version "1.2.1"
if { $USE_HTTP_SSL == 1 } {
variable HTTP_URL_API "https://${HTTP_URL_API}"
} else {
variable HTTP_URL_API "http://${HTTP_URL_API}"
}
proc unload {args} {
putlog "Désallocation des ressources de ${::DictionaryAPI::scriptname}..."
foreach binding [lsearch -inline -all -regexp [binds *[set ns [::tcl::string::range [namespace current] 2 end]]*] " \{?(::)?$ns"] {
unbind [lindex $binding 0] [lindex $binding 1] [lindex $binding 2] [lindex $binding 4]
}
foreach running_utimer [utimers] {
if { [::tcl::string::match "*[namespace current]::*" [lindex $running_utimer 1]] } { killutimer [lindex $running_utimer 2] }
}
namespace delete ::DictionaryAPI
}
}
proc ::DictionaryAPI::GetURL { URL_Link } {
if { $::DictionaryAPI::USE_HTTP_SSL == 1 } { ::http::register https 443 [list ::tls::socket -autoservername true] }
# on modifie l'urlencoding car dicoreverso.net ne comprend que l'utf-8 dans ses URLs.
array set httpconfig [::http::config]
::http::config -urlencoding utf-8 -useragent $::DictionaryAPI::HTTP_USERAGENT
# on restaure l'urlencoding comme il était avant qu'on y touche
::http::config -urlencoding $httpconfig(-urlencoding)
if { [catch { set URL_TOKEN [::http::geturl $URL_Link -timeout [expr $::DictionaryAPI::HTTP_TIMEOUT * 1000]] } ERR] } {
putlog "::DictionaryAPI::GetURL \00314La connexion à \00312\037[set URL_Link]\037\003\00314 n'a pas pu être établie. Il est possible que le site rencontre un problème technique.\003"
putlog "::DictionaryAPI::ERROR $ERR"
if { $::DictionaryAPI::USE_HTTP_SSL == 1 } { ::http::unregister https }
return 0
}
# on extrait la partie qui nous intéresse et sur laquelle on va travailler
set URL_DATA [::http::data $URL_TOKEN]
set URL_DATA [encoding convertfrom utf-8 $URL_DATA]
::http::cleanup $URL_TOKEN
if { $::DictionaryAPI::USE_HTTP_SSL == 1 } { ::http::unregister https }
return $URL_DATA;
}
###############################################################################
### Procédure principale
###############################################################################
proc ::DictionaryAPI::SetBlock { WHAT VALUE } {
set DICT_$WHAT $VALUE
set ::DictionaryAPI::DICT_$WHAT [subst [subst $[join ::DictionaryAPI::BLOCK_$WHAT]]]
}
proc ::DictionaryAPI::Search {nick host hand chan arg} {
if { $::DictionaryAPI::Channels(Allow) != "*" && [lsearch -nocase $::DictionaryAPI::Channels(Allow) $chan] == "-1" } {
set MSG "DictionaryAPI: The channel '$chan' is not in allow channel."
putlog $MSG
putserv "PRIVMSG $chan :$MSG"
return
}
set WORD_SEARCH [stripcodes bcruag $arg]
if {$WORD_SEARCH == ""} {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}HELP : [join $::DictionaryAPI::public_cmd "|"] <word> "
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}LANG : \[-lang=<en,hi,es,fr,ja,ru,de,it,ko,pt-br,ar,tr>\] | default lang: $::DictionaryAPI::Lang "
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}LIMIT : \[-limit=<1-$::DictionaryAPI::max_annonce_user>\] | default limit: $::DictionaryAPI::max_annonce_default "
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}EXAMPLE : [lindex $::DictionaryAPI::public_cmd 0] test -lang=ru -limit=6"
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}HELP : [join $::DictionaryAPI::public_cmd "|"] SetLang <en,hi,es,fr,ja,ru,de,it,ko,pt-br,ar,tr> | Set lang per default"
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}EXAMPLE : [lindex $::DictionaryAPI::public_cmd 0] SetLang es"
return
}
if {[string match -nocase [lindex $arg 0] "SetLang"] } {
if {[lindex $arg 1] != ""} {
set ::DictionaryAPI::Lang [lindex $arg 1]
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix} Default lang is now : $::DictionaryAPI::Lang"
} else {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix} Current lang is : $::DictionaryAPI::Lang"
}
return
}
set RE {-limit[\s|=](\S+)}
if { [regexp -nocase -- $RE $WORD_SEARCH -> limit]} {
regsub -nocase -- $RE $WORD_SEARCH {} WORD_SEARCH
set WORD_SEARCH [string trim $WORD_SEARCH]
if {$limit > $::DictionaryAPI::max_annonce_user} {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix} limit max is $::DictionaryAPI::max_annonce_user"
set limit $::DictionaryAPI::max_annonce_user
}
} else {
set limit $::DictionaryAPI::max_annonce_default
}
set RE {-lang[\s|=](\S+)}
if { [regexp -nocase -- $RE $WORD_SEARCH -> lang]} {
regsub -nocase -- $RE $WORD_SEARCH {} WORD_SEARCH
set WORD_SEARCH [string trim $WORD_SEARCH]
set URL_Link "${::DictionaryAPI::HTTP_URL_API}/${lang}/${WORD_SEARCH}"
} else {
set URL_Link "${::DictionaryAPI::HTTP_URL_API}/${::DictionaryAPI::Lang}/${WORD_SEARCH}"
}
set URL_DATA [::DictionaryAPI::GetURL $URL_Link]
foreach { PARENT } [::json::json2dict $URL_DATA] {
if { $PARENT == "title" } {
putserv "PRIVMSG $chan :[subst $::DictionaryAPI::Annonce_notfound]"
return
}
# init/reset vars
variable DICT_DEFINITION ""
variable DICT_WORD ""
variable DICT_TYPE ""
variable DICT_NUMBER 0
variable DICT_EXAMPLE ""
variable DICT_SYNONYMS ""
variable DICT_ANTONYMS ""
variable DICT_PHONETICS ""
set SUBCAT [dict get $PARENT]
set TMP_phonetics [dict get $SUBCAT phonetics]
::DictionaryAPI::SetBlock WORD [dict get $SUBCAT word]
if {$TMP_phonetics != "{}"} {
::DictionaryAPI::SetBlock PHONETICS $phonetics
unset TMP_phonetics
}
set SUBMEANINGS [dict get $SUBCAT meanings]
foreach { ENFANT } [dict get $SUBCAT meanings] {
set TMP_partOfSpeech [dict get $ENFANT partOfSpeech]
if {$TMP_partOfSpeech != "{}"} {
::DictionaryAPI::SetBlock TYPE $TMP_partOfSpeech
unset TMP_partOfSpeech
}
foreach { SUBDEFINITION } [dict get $ENFANT definitions] {
::DictionaryAPI::SetBlock DEFINITION [dict get $SUBDEFINITION definition]
if {
[dict exists $SUBDEFINITION synonyms] \
&& [dict get $SUBDEFINITION synonyms] != ""
} {
::DictionaryAPI::SetBlock SYNONYMS [join [dict get $SUBDEFINITION synonyms] ", "]
}
if { [dict exists $SUBDEFINITION example] } {
::DictionaryAPI::SetBlock EXAMPLE [dict get $SUBDEFINITION example]
}
::DictionaryAPI::SetBlock NUMBER [expr $DICT_NUMBER+1]
foreach Annonce [split [subst ${::DictionaryAPI::Annonce_Show}] "\n"] {
putserv "PRIVMSG $chan :${::DictionaryAPI::Annonce_Prefix}$Annonce"
}
if {$limit == $DICT_NUMBER} { return }
}
}
}
}
###############################################################################
### Binds
###############################################################################
foreach b $::DictionaryAPI::public_cmd {
bind pub $::DictionaryAPI::public_cmd_auth $b ::DictionaryAPI::Search
}
bind evnt - prerehash ::DictionaryAPI::unload
putlog "DictionaryAPI $::DictionaryAPI::version by $::DictionaryAPI::scriptauteur loaded."
RE: DictionaryAPI.tcl - latest version - CrazyCat - 23/08/2021
Typo error in script.
Find:
tcl # Maximum number of results | Nombre de resultats maximun
variable max_annonce_defaul 2
Replace with:
tcl # Maximum number of results | Nombre de resultats maximun
variable max_annonce_default 2
|