-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsmarena.tcl
406 lines (371 loc) · 15.9 KB
/
gsmarena.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#######################################################################################################
## GsmArena.tcl 1.0 (26/11/2019) Copyright 2008 - 2019 @ 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.0"
###
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-tcl.000webhostapp.com/index.php?slug=$search"
}
2 {
set search [join $search "%20"]
set link "http://gsmarena-tcl.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.."