This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

BlaCkSHaDow's GsmArena.tcl Version 1.1

Help for those learning Tcl or writing their own scripts.
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

BlaCkSHaDow's GsmArena.tcl Version 1.1

Post by Goga »

Code: Select all

#######################################################################################################
## GsmArena.tcl 1.1  (16/10/2020)  			  								Copyright 2008 - 2020 @ WwW.TCLScripts.NET ##
##                        _   _   _   _   _   _   _   _   _   _   _   _   _   _                      ##
##                       / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \                     ##
##                      ( T | C | L | S | C | R | I | P | T | S | . | N | E | T )                    ##
##                       \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/                     ##
##                                                                                                   ##
##                                      ® BLaCkShaDoW Production ®                                   ##
##                                                                                                   ##
##                                              PRESENTS                                             ##
##									                          																										 ® ##
############################################  GSM ARENA TCL   #########################################
##									                             ##
##  DESCRIPTION: 							                             ##
##  Gives detailed information about mobile phones. You can view the whole information or by	     ##
##  using one or more options available								     ##
##									                             ##
##  Tested on Eggdrop v1.8.3 (Debian Linux 3.16.0-4-amd64) Tcl version: 8.6.6                        ##
##									                             ##
#######################################################################################################
##									                             ##
##  INSTALLATION: 							                             ##
##     ++ http & json packages are REQUIRED for this script to work.                                 ##
##     ++ Edit the gsmarena.tcl script and place it into your /scripts directory,           	     ##
##     ++ add "source scripts/gsmarena.tcl" to your eggdrop config and rehash the bot.       	     ##
##									                             ##
#######################################################################################################
##									                             ##
##  OFFICIAL LINKS:                                                                                  ##
##   E-mail      : BLaCkShaDoW[at]tclscripts.net                                                     ##
##   Bugs report : http://www.tclscripts.net                                                         ##
##   GitHub page : https://github.com/tclscripts/ 			                             ##
##   Online help : irc://irc.undernet.org/tcl-help                                                   ##
##                 #TCL-HELP / UnderNet        	                                                     ##
##                 You can ask in english or romanian                                                ##
##									                             ##
##     paypal.me/DanielVoipan = Please consider a donation. Thanks!                                  ##
##									                             ##
#######################################################################################################
##									                             ##
##                           You want a customised TCL Script for your eggdrop?                      ##
##                                Easy-peasy, just tell me what you need!                            ##
##                I can create almost anything in TCL based on your ideas and donations.             ##
##                  Email blackshadow@tclscripts.net or info@tclscripts.net with your                ##
##                    request informations and I'll contact you as soon as possible.                 ##
##									                             ##
#######################################################################################################
##
##  COMMANDS, ACTIVATION and EXAMPLES
##	To activate use : .set or .chanset #channel +gsmarena
##
##	!gsm <mobile name> | <number> (taken from the list) | <slug> [options] | help
##
##
##If you dont want to see the whole specs of your desired phone,
##you can specify them after the <slug> or <number>
##
##Options available:
##network launch body display platform memory main_camera selfie_camera sound comms features battery misc camera
##
##Usage:
##
##[22:01:47] <@BLaCkShaDoW> !gsm samsung s10
##[22:01:52] <@BT> [GSM] #1.samsung_galaxy_s10_plus_-9535, #2.samsung_galaxy_s10-9536, #3.samsung_galaxy_s10e-9537, #4.samsung_galaxy_s10_lite-9917, #5.samsung_galaxy_s10_5g-9588, #6.samsung_s100-313
#[22:01:53] <@BT> [GSM] Use !gsm <slug> or <number> to get info about the phone.
##
##[22:02:36] <@BLaCkShaDoW> !gsm 1
##[22:02:39] <@BT> [PHONE] Samsung Galaxy S10+
##[22:02:40] <@BT> [IMG] https://fdn2.gsmarena.com/vv/bigpic/samsung-galaxy-s10-plus-new.jpg
##[22:02:41] <@BT> [SOUND] loudspeaker_: Yes, with stereo speakers 35mm_jack_: Yes | 32-bit/384kHz audio  Active noise cancellation with dedicated mic  Dolby Atmos sound  Tuned by AKG
##[22:02:44] <@BT> [BATTERY] : Non-removable Li-Ion 4100 mAh battery charging: Fast battery charging 15W  USB Power Delivery 2.0  Fast Qi/PMA wireless charging 15W  Power bank/Reverse wireless charging 9W
##[22:02:47] <@BT> [DISPLAY] type: Dynamic AMOLED capacitive touchscreen, 16M colors size: 6.4 inches, 103.8 cm2 (~88.9% screen-to-body ratio) resolution: 1440 x 3040 pixels, 19:9 ratio (~522 ppi density) ##protection: Corning Gorilla Glass 6 | HDR10+  Always-on display
##.......
##[22:06:16] <@BLaCkShaDoW> !gsm 1 main_camera
##[22:06:18] <@BT> [PHONE] Samsung Galaxy S10+
##[22:06:19] <@BT> [IMG] https://fdn2.gsmarena.com/vv/bigpic/samsung-galaxy-s10-plus-new.jpg
##[22:06:20] <@BT> [MAIN CAMERA] triple: 12 MP, f/1.5-2.4, 26mm (wide), 1/2.55", 1.4µm, Dual Pixel PDAF, OIS  12 MP, f/2.4, 52mm (telephoto), 1/3.6", 1.0µm, AF, OIS, 2x optical zoom  16 MP, f/2.2, 12mm ##(ultrawide), 1.0µm, Super Steady video features: LED flash, auto-HDR, panorama video: 2160p@60fps (no EIS), 2160p@30fps, 1080p@30/60/240fps, 720p@960fps, HDR10+, dual-video rec., stereo sound rec., gyro-EIS ##&OIS
##
##
##								BLaCkShaDoW Production
#######################################################################################################
##									                             ##
##  LICENSE:                                                                                         ##
##   This code comes with ABSOLUTELY NO WARRANTY.                                                    ##
##                                                                                                   ##
##   This program is free software; you can redistribute it and/or modify it under the terms of      ##
##   the GNU General Public License version 3 as published by the Free Software Foundation.          ##
##                                                                                                   ##
##   This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of          ##
##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                            ##
##   USE AT YOUR OWN RISK.                                                                           ##
##                                                                                                   ##
##   See the GNU General Public License for more details.                                            ##
##        (http://www.gnu.org/copyleft/library.txt)                                                  ##
##                                                                                                   ##
##  			          Copyright 2008 - 2019 @ WwW.TCLScripts.NET                         ##
##                                                                                                   ##
#######################################################################################################

#######################################################################################################
###                               CONFIGURATION FOR GSM ARENA TCL	                            ###
#######################################################################################################

#Set here the flags for cmd usage
#
##
set gsm(flags_needed) "mn|MN"


#Here you can set the maximum number of entries to show on search
#
##
set gsm(search_entries) "10"

#Uppon search the eggdrop will store the data for the current user
#for a couple of minutes so you can use !gsm <number> to get info
#about a phone. The data ofcourse will be replaced if another search is done
#Set here the userhost to use uppon search
#
###

#1 - *!*@host
#2 - *!user@host
#3 - nick!user@host
#4 - nick!*@*
#5 - *!user@*

set gsm(user_host) "1"

#How many minutes the data should be saved for the user ?
#Use 0 if you want to expire on restart or kill.
#
###
set gsm(expire_data) "5"

#######################################################################################################
###                       DO NOT MODIFY HERE UNLESS YOU KNOW WHAT YOU'RE DOING                      ###
#######################################################################################################


setudef flag gsmarena
package require http
package require json


bind pub $gsm(flags_needed) !gsm gsm:search


proc gsm:search {nick host hand chan arg} {
	global gsm
if {![channel get $chan gsmarena]} {
	return
}
	set search_text [lrange [split $arg] 0 end]
	set slug [lindex [split $arg] 0]
	set options [lrange [split $arg] 1 end]
	set mask [gsm:mask $gsm(user_host) $host $nick]
if {[string equal -nocase $slug "help"]} {
	putserv "PRIVMSG $chan :\[GSM\] Usage !gsm \002<mobile name>\002 | \002<number>\002 (taken from the list) | \002<slug>\002 \[options\]"
	putserv "PRIVMSG $chan :\[GSM\] Valid options : \002network launch body display platform memory main_camera selfie_camera sound comms features battery misc camera\002"
	return
}

if {[regexp {^[0-9]} $slug]} {
if {![info exists gsm(data_save:$mask)]} {
	puthelp "PRIVMSG $chan :\[GSM\] You didnt search for anything or you search data expired."
	return
}
	set slug_search [lsearch -nocase $gsm(data_save:$mask) "$slug:*"]
if {$slug_search == "-1"} {
	puthelp "PRIVMSG $chan :\[GSM\] The number is unavailable in your latest search."
	return
}
	set slug_entry [lindex $gsm(data_save:$mask) $slug_search]
	set split_entry [split $slug_entry ":"]
	set slug [lindex $split_entry 1]
	set data_slug [gsm:getdata $slug 1]
	gsm:slug_info $nick $chan $data_slug $slug $options
	return
} elseif {[regexp {[_]} $slug]} {
	set data_slug [gsm:getdata $slug 1]
	gsm:slug_info $nick $chan $data_slug $slug $options
	return
	}
	set counter 0
	set text ""
	set data_search [gsm:getdata $search_text 2]
	set json_data [gsm:getjson "data" $data_search]
	set llength [llength $json_data]
if {$llength == "1"} {
	set title [lindex $json_data 0]
	set slug [lindex $json_data 1]
} else {
if {[info exists gsm(data_save:$mask)]} {
	unset gsm(data_save:$mask)
}
	foreach line $json_data {
	set counter [expr $counter + 1]
if {$counter <= $gsm(search_entries)} {
	set title [lindex $line 1]
	set slug [lindex $line 3]
	lappend text \002\#$counter\002.$slug
	lappend gsm(data_save:$mask) $counter:$slug
			}
		}
foreach tmr [utimers] {
if {[string match "*gsm:unset_saved_data $mask*" [join [lindex $tmr 1]]]} {
	killutimer [lindex $tmr 2]
		}
	}
if {[info exists gsm(data_save:$mask)]} {
if {$gsm(expire_data) > 0} {
	utimer [expr $gsm(expire_data) * 60] [list gsm:unset_saved_data $mask]
	}
}
	set text [join $text  ", "]
if {$text != ""} {
foreach w [gsm:wrap $text 440] {
	putserv "PRIVMSG $chan :\[GSM\] $w"
}
	putserv "PRIVMSG $chan :\[GSM\] Use \002!gsm <slug>\002 or \002<number>\002 to get info about the phone."
		} else {
	puthelp "PRIVMSG $chan :\[GSM\] Couldn't find anything related to \002$search_text\002"
		}
	}
}


# Credits
set gsm(projectName) "GsmArena.tcl"
set gsm(author) "BLaCkShaDoW"
set gsm(website) "wWw.TCLScriptS.NeT"
set gsm(email) "blackshadow\[at\]tclscripts.net"
set gsm(version) "v1.1"

###
proc gsm:slug_info {nick chan data slug options} {
	global gsm
if {[string match -nocase "*Fatal error*" $data]} {
	putserv "PRIVMSG $chan :\[GSM\] Couldn't find anything related to slug \002$slug\002. Did you typed it corectly ?"
	return
}
	array set data_list [list]
	set entries {network launch body display platform memory main_camera selfie_camera sound comms features battery misc camera}
	set phone_title [gsm:getjson "title" $data]
	set phone_data [gsm:getjson "data" $data]
	set phone_img [gsm:getjson "img" $data]

foreach e $entries {
if {$options != ""} {
if {[lsearch -nocase $options $e] < 0} {
	continue
	}
}
if {[string equal -nocase $e "main_camera"]} {
	set e "main camera"
} elseif {[string equal -nocase $e "main_camera"]} {
	set e "selfie camera"
}
	set get_item [gsm:get_it $e $phone_data]
if {$get_item != "-1"} {
	set data_list($e) $get_item
	}
}
if {$phone_title != "-1"} {
	putserv "PRIVMSG $chan :\[PHONE\] $phone_title"
}
if {$phone_img != "-1"} {
	putserv "PRIVMSG $chan :\[IMG\] $phone_img"
}
if  {[array size data_list] == "0"} {
	putserv "PRIVMSG $chan :\[GSM\] N/A (did you check if the option is correct ?)."
	putserv "PRIVMSG $chan :\[GSM\] End of phone info."
	return
}
foreach entry [array names data_list] {
	putserv "PRIVMSG $chan :\[[string toupper $entry]\] [gsm:filter [gsm:utf8 $data_list($entry)]]"
	}
	putserv "PRIVMSG $chan :\[GSM\] End of phone info."
}

###
proc gsm:get_it {type data} {
	global gsm
	set pos [lsearch -nocase $data $type]
if {$pos < 0} {
	return -1
}
	set pos_details [lindex $data [expr $pos + 1]]
	set llength [llength $pos_details]
for {set i 0} { $i < $llength } {incr i} {
if {[expr $i % 2] == 0} {
	lappend info \002[lindex $pos_details $i]:\002
		} else {
	lappend info [lindex $pos_details $i]
		}
	}
	return [string map {"<br>" "\002 | \002"} [join $info]]
}

###

proc gsm:utf8 {string} {
	global gsm
   set map {}
    foreach {entity number} [regexp -all -inline {&#(\d+)} $string] {
        lappend map $entity [format \\u%04x [scan $number %d]]
    }
    set string [string map [subst -nocomm -novar $map] $string]
	return $string
 }


###
proc gsm:filter {string} {
	global gsm
	set text [string map {"; " ""} $string]
	return $text
}


###
proc gsm:unset_saved_data {mask} {
	global gsm
if {[info exists gsm(data_save:$mask)]} {
	unset gsm(data_save:$mask)
	}
}

###
proc gsm:getdata {search type} {
	global gsm
switch $type {
	1 {
	set link "http://gsmarena-info.000webhostapp.com/index.php?slug=$search"
	}
	2 {
	set search [join $search "%20"]
	set link "http://gsmarena-info.000webhostapp.com/index.php?query=$search"
	}
}
	set ipq [http::config -useragent "lynx"]
	set ipq [::http::geturl "$link" -timeout 100000]
	set data [http::data $ipq]
	::http::cleanup $ipq
	return $data
}

###
proc gsm:getjson {get data} {
	global imdb
	set parse [::json::json2dict $data]
	set return ""
foreach {name info} $parse {
if {[string equal -nocase $name $get]} {
	set return $info
	break;
		}
	}
	return $return
}

###
proc gsm:wrap {str {len 100} {splitChr {,}}} {
   set out [set cur {}]; set i 0
   foreach word [split [set str][unset str] $splitChr] {
     if {[incr i [string len $word]]>$len} {
         lappend out [join $cur $splitChr]
         set cur [list $word]
         set i [string len $word]
      } {
         lappend cur $word
      }
      incr i
   }
   lappend out [join $cur $splitChr]
}


###

proc gsm:mask {type uhost user} {
	global black
	set ident [lindex [split $uhost "@"] 0]
	set host [lindex [split $uhost @] 1]
switch $type {

1 {
	return "*!*@$host"
}
2 {
	return "*!$ident@$host"
}
3 {
	return "$user!$ident@$host"
}
4 {
	return "$user!*@*"
}
5 {
	return "*!$ident@*"
		}
	}
}

putlog "\002$gsm(projectName) $gsm(version)\002 coded by\002 $gsm(author)\002 ($gsm(website)): Loaded & initialised.."
Getting this error :
Tcl error [gsm:search]: unexpected '<' in TOP mode
User avatar
CrazyCat
Revered One
Posts: 1215
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Type .set errorInfo in party-line when getting this error to give us more detals.
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

[07:41:37] Tcl error [gsm:search]: unexpected '<' in TOP mode
.set errorinfo
What? You need '.help'
User avatar
CrazyCat
Revered One
Posts: 1215
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

In your config file, comment the following lines if they are not commented:

Code: Select all

unbind dcc n tcl *dcc:tcl
unbind dcc n set *dcc:set
Check the value of must-be-owner. If it's equal to 1 (default), check that you are well setted as permanent owner (set owner "Goga"). The value in owner must be your handle.

Then, you'll be able to use .set errorInfo (with capital I).
Last edited by CrazyCat on Sat Sep 11, 2021 7:43 am, edited 1 time in total.
User avatar
BLaCkShaDoW
Op
Posts: 117
Joined: Sun Jan 11, 2009 4:50 am
Location: Romania
Contact:

Post by BLaCkShaDoW »

Goga wrote:[07:41:37] Tcl error [gsm:search]: unexpected '<' in TOP mode
.set errorinfo
What? You need '.help'
Download the latest version at https://tclscripts.net/downloads/gsmarena-tcl/
BLaCkShaDoW Production @ WwW.TclScripts.Net
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

BLaCkShaDoW wrote:
Goga wrote:[07:41:37] Tcl error [gsm:search]: unexpected '<' in TOP mode
.set errorinfo
What? You need '.help'
Download the latest version at https://tclscripts.net/downloads/gsmarena-tcl/
Still having that error after installing Latest version of GSMAREANA.TCL.
User avatar
mabrook
Halfop
Posts: 60
Joined: Mon Jun 14, 2021 9:41 am

Post by mabrook »

<@Mabrook> !gsm s10

Code: Select all

<BOT> Tcl error [gsm:search]: unexpected token ":" at position 1; expecting VALUE
<@Mabrook> !gsm 1 main_camera
<BOT> [GSM] You didnt search for anything or you search data expired.

<@Mabrook> !gsm help
<BOT> [GSM] Usage !gsm <mobile name> | <number> (taken from the list) | <slug> [options]
<BOT> [GSM] Valid options : network launch body display platform memory main_camera selfie_camera sound comms features battery misc camera

Code: Select all

<Mabrook> .errorInfo
<BOT> [14:04:34] ----------------
<BOT> [14:04:34] can't find package tcllibc
<BOT>     while executing
<BOT> "package require tcllibc"
<BOT> [14:04:34] errorCode : TCL PACKAGE UNFOUND

hope @Goga you have the same issue. i'm just testing it to help.
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

mabrook wrote:<@Mabrook> !gsm s10

Code: Select all

<BOT> Tcl error [gsm:search]: unexpected token ":" at position 1; expecting VALUE
<@Mabrook> !gsm 1 main_camera
<BOT> [GSM] You didnt search for anything or you search data expired.

<@Mabrook> !gsm help
<BOT> [GSM] Usage !gsm <mobile name> | <number> (taken from the list) | <slug> [options]
<BOT> [GSM] Valid options : network launch body display platform memory main_camera selfie_camera sound comms features battery misc camera

Code: Select all

<Mabrook> .errorInfo
<BOT> [14:04:34] ----------------
<BOT> [14:04:34] can't find package tcllibc
<BOT>     while executing
<BOT> "package require tcllibc"
<BOT> [14:04:34] errorCode : TCL PACKAGE UNFOUND

hope @Goga you have the same issue. i'm just testing it to help.
I dont know why .errorinfo command doesn't work for me.

My Error is
[GSM] Couldn't find anything related to Samsung s10
User avatar
CrazyCat
Revered One
Posts: 1215
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Goga, read my post a little bit above:
CrazyCat wrote:In your config file, comment the following lines if they are not commented:

Code: Select all

unbind dcc n tcl *dcc:tcl
unbind dcc n set *dcc:set
Check the value of must-be-owner. If it's equal to 1 (default), check that you are well setted as permanent owner (set owner "Goga"). The value in owner must be your handle.

Then, you'll be able to use .set errorInfo (with capital I).
Note: after changing the value in .conf, you have to .restart the eggdrop, not rehash

.errorInfo is a non-standard alias which doesn't exist for me, probably mabrook has a script adding aliases
Last edited by CrazyCat on Sat Sep 11, 2021 7:43 am, edited 1 time in total.
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

Okay, But what is the reason of Showing no Result ?
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

BLaCkShaDoW wrote:
Goga wrote:[07:41:37] Tcl error [gsm:search]: unexpected '<' in TOP mode
.set errorinfo
What? You need '.help'
Download the latest version at https://tclscripts.net/downloads/gsmarena-tcl/
Your comments Please, Why gsmarean is not showing any result?
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

It's .set errorInfo not .set errorinfo (it requires a capital I) :lol:
ComputerTech
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Based on the message he gets:
.set errorinfo
What? You need '.help'
he didn't follow CrazyCat's instructions to activate .set in the console.
Once the game is over, the king and the pawn go back in the same box.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

caesar wrote:Based on the message he gets:
.set errorinfo
What? You need '.help'
he didn't follow CrazyCat's instructions to activate .set in the console.
Oh, you are also correct caesar :shock: but as am i :P
ComputerTech
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

ComputerTech wrote:
caesar wrote:Based on the message he gets:
.set errorinfo
What? You need '.help'
he didn't follow CrazyCat's instructions to activate .set in the console.
Oh, you are also correct caesar :shock: but as am i :P
But you have Idea, why this TCL is not working?
Post Reply