/
WEATHER.PPA
687 lines (646 loc) · 22.2 KB
/
WEATHER.PPA
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
; #= ppweather -rs
; ########################################
; Peace and Protection
; PnP Weather (standard addon)
; ########################################
#.ppa.info off
[addon]
name=Weather
group=Tutorial
popup=Weather
author=acvxqs
version=1.11
url=https://github.com/acvxqs/PnPAddons422
email=
id=ppweather
ppver=4.22
config=weather
unload=weather.unload
vars2=weather.apiurl weather.apikey weather.pchar weather.qstring weather.ustring weather.astring weather.mstring weather.kstring weather.istring weather.trigger
windows=
dialogs=weather
[files]
1=weather.ppa
[notes]
1=This addon allows you to retrieve weather information from OpenWeatherMap.org using command: /weather {city},{country code} or respond in channel to a !weather {city},{country code} trigger.
2=Please note that city name and country code are divided by comma, use ISO 3166 country codes.
#.ppa.info end
on *:LOAD:{
; PnP check
if (!$_ispnp) {
echo 4 -ati2 *** This addon requires Peace and Protection by pai to use.
echo 4 -ati2 *** You can download Peace and Protection at http://www.kristshell.net/pnp/
.timer -mio 1 0 .unload -rs " $+ $script $+ "
halt
}
; Invalid load method check
if (!$istok($_cfgx(addons,ids),$readini($script,n,addon,id),32)) {
.timer -mio 1 0 .unload -rs " $+ $script $+ "
dispa Unloading ' $+ $script $+ ' $chr(40) $+ addon is not properly loaded; use /addon to load it $+ $chr(41)
halt
}
if ($version < 7.52) {
.timer -mio 1 0 .unload -rs " $+ $script $+ "
dispa Unloading ' $+ $script $+ ' $chr(40) $+ This script requires mIRC version 7.52+ $+ $chr(41)
halt
}
if ($version < 7.56) {
dispa This script requires SReject's JSON For mIRC!
dispa Please get it from: https://github.com/SReject/JSON-For-Mirc/archive/v1.0.4000.zip
}
else getJFM
}
dialog weather {
title "Weather Central"
size -1 -1 202 214
option dbu
icon script\pnp.ico
box "Respond to trigger on networks:", 1, 5 5 95 90
combo 2, 10 15 50 50, size
button "Add", 3, 65 15 27 11, disable
button "Remove", 4, 65 30 27 11, disable
radio "Whitelist channels", 5, 10 70 60 10, group disable
radio "Blacklist channels", 6, 10 80 60 10, disable
box "Specify channels:", 7, 103 5 95 90
combo 8, 108 15 50 50, size disable
button "Add", 9, 163 15 27 11, disable
button "Remove", 10, 163 30 27 11, disable
box "", 11, 5 100 193 90
check "City", 12, 10 110 50 10, disable
check "Country", 13, 10 120 50 10, disable
check "Weather short", 14, 10 130 50 10, disable
check "Weather long", 15, 10 140 50 10, disable
check "Humidity", 16, 10 150 50 10, disable
check "Temperature", 17, 65 110 50 10, disable
check "Temp. min.", 18, 65 120 50 10, disable
check "Temp. max.", 19, 65 130 50 10, disable
check "Pressure", 20, 65 140 50 10, disable
check "Visibility", 21, 65 150 50 10, disable
check "Wind speed", 22, 120 110 50 10, disable
check "Wind degree", 23, 120 120 50 10, disable
check "Sunrise", 24, 120 130 50 10, disable
check "Sunset", 25, 120 140 50 10, disable
check "Clouds", 26, 120 150 50 10, disable
radio "Kelvin", 27, 10 175 50 10, group disable
radio "Metric", 28, 65 175 50 10, disable
radio "Imperial", 29, 120 175 50 10, disable
text "Unit format:", 30, 10 165 37 8
button "OK", 100, 5 195 40 12, ok
button "Cancel", 101, 65 195 37 12, cancel
button "API Key", 102, 120 195 37 12
}
on *:DIALOG:weather:init:0:{
; convert active entries to entries the dialog can work with
var %anetworks $hget(pnp.weather,anetworks)
hadd pnp.weather networks %anetworks
if (%anetworks) {
; iterate over networks
var %n 1
while ($gettok(%anetworks,%n,44)) {
; there's two net specific hashes: -opt and -channels
; make sure they are ported from 'anet' to 'net'
; data should exist in them already, but cannot hurt to check:
var %network $v1
if ($hget(pnp.weather,$+(anet-,%network,-opt))) hadd pnp.weather $+(net-,%network,-opt) $v1
if ($hget(pnp.weather,$+(anet-,%network,-channels))) hadd pnp.weather $+(net-,%network,-channels) $v1
; now let's focus on all the channels for the network, if
; they exist!
; grab $v1 from previous if-check, handy!
var %achannels $v1
if (%achannels) {
var %c 1
while ($gettok(%achannels,%c,44)) {
var %chan $v1
if ($hget(pnp.weather,$+(achan-,%network,-,%chan))) hadd pnp.weather $+(chan-,%network,-,%chan) $v1
inc %c
}
}
inc %n
}
; well we have to load networks if they exist!
didtok $dname 2 44 %anetworks
}
}
alias -l wedloadnet {
var %network $1
if (!$hget(pnp.weather,$+(net-,%network,-opt))) hadd pnp.weather $+(net-,%network,-opt) 1,1100010000000001
tokenize 44 $hget(pnp.weather,$+(net-,%network,-opt))
if ($1) {
did -u $dname 5
did -c $dname 6
wesetopt $2
}
else {
did -c $dname 5
did -u $dname 6
}
did -r $dname 8
if ($hget(pnp.weather,$+(net-,%network,-channels))) {
didtok $dname 8 44 $v1
}
did -u $dname 8
}
alias -l wedloadchan {
var %network $1
var %chan $2
if (!$hget(pnp.weather,$+(chan-,%network,-,%chan))) hadd pnp.weather $+(chan-,%network,-,%chan) 1100010000000001
if ($did(5).state) wesetopt $hget(pnp.weather,$+(chan-,%network,-,%chan))
}
alias -l wedu {
goto $did(2,0).sel $+ $did(8,0).sel $+ $did(6).state
:000 | :001 | :010
;echo -a 000 001 010 $caller
did -b $dname 4,5,6,8,9,10,12-29
did -r $dname 8
return
:011
;echo -a 011 $caller
did -r $dname 8
did -ra $dname 11 Settings
did -b $dname 5,6,8,9,10,12-29
did -u $dname 12-29
return
:100
;echo -a 100 $caller
did -bu $dname 12-29
did -e $dname 4,5,6,8
did -ra $dname 11 Settings
return
:101
;echo -a 101 $caller
did -e $dname 4,5,6,8,12-29
did -ra $dname 11 Settings for network: $did(2,0).text
return
:110
;echo -a 110 $caller
did -e $dname 8,10,12-29
did -ra $dname 11 Settings for channel: $replace($did(8,0).text,&,&&) on network: $did(2,0).text
return
:111
;echo -a 111 $caller
did -e $dname 10
did -ra $dname 11 Settings for network: $did(2,0).text
return
}
on *:DIALOG:weather:sclick:*:{
if ($did < 1) return
elseif ($did == 2) {
if ($did(2,0).sel) wedloadnet $did(2,0).text | wedu
}
elseif ($did == 3) {
_ddadd $dname 2 $did(2,0).text
hadd pnp.weather networks $addtok($hget(pnp.weather,networks),$did(2,0).text,44)
did -uf $dname 2
}
elseif ($did == 4) {
hadd pnp.weather networks $remtok($hget(pnp.weather,networks),$did(2,0).text,1,44)
did -d $dname 2 $did(2,1).sel
did -r $dname 8
did -uf $dname 2
did -b $dname 3,4,5,6,8,9,10,12-29
did -ra $dname 11 Settings
}
elseif ($did == 5) {
var %do $+(net-,$did(2,0).text,-opt)
hadd pnp.weather %do $puttok($hget(pnp.weather,$+(net-,$did(2,0).text,-opt)),0,1,44)
if ($did(8,0).text) wedloadchan $did(2,0).text $did(8,0).text
wedu
}
elseif ($did == 6) {
var %do $+(net-,$did(2,0).text,-opt)
hadd pnp.weather %do $puttok($hget(pnp.weather,$+(net-,$did(2,0).text,-opt)),1,1,44)
wedloadnet $did(2,0).text
wedu
}
elseif ($did == 8) {
if ($did(8,0).sel) wedloadchan $did(2,0).text $did(8,0).text | wedu
}
elseif ($did == 9) {
_ddadd $dname 8 $did(8,0).text
hadd pnp.weather $+(net-,$did(2,0).text,-channels) $addtok($hget(pnp.weather,$+(net-,$did(2,0).text,-channels)),$did(8,0).text,44)
did -uf $dname 8
}
elseif ($did == 10) {
hadd pnp.weather $+(net-,$did(2,0).text,-channels) $remtok($hget(pnp.weather,$+(net-,$did(2,0).text,-channels)),$did(8,0).text,1,44)
hdel pnp.weather $+(chan-,$did(2,0).text,-,$did(8,0).text)
did -d $dname 8 $did(8,1).sel
did -uf $dname 8
if ($did(5).state) did -b $dname 12-29
else did -e $dname 12-29
did -b $dname 10
did -ra $dname 11 Settings
}
elseif ($istok(12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29,$did,32)) {
;editing for channel?
if ($did(5).state) {
hadd pnp.weather $+(chan-,$did(2,0).text,-,$did(8,0).text) $wegetopt
}
; editing for network?
elseif ($did(6).state) {
var %do $+(net-,$did(2,0).text,-opt)
hadd pnp.weather %do $puttok($hget(pnp.weather,%do),$wegetopt,2,44)
}
}
elseif ($did == 100) {
; purging channels that were removed...
var %rn 1
while ($gettok($hget(pnp.weather,anetworks),%rn,44)) {
var %rc 1,%rnetwork $v1
while ($gettok($hget(pnp.weather,$+(anet-,%rnetwork,-channels)),%rc,44)) {
var %rchan $v1
if (!$istok($hget(pnp.weather,$+(net-,%rnetwork,-channels)),%rchan,44)) {
hdel pnp.weather $+(achan-,%rnetwork,-,%rchan))
}
inc %rc
}
inc %rn
}
var %networks $hget(pnp.weather,networks)
hadd pnp.weather anetworks %networks
if (%networks) {
; iterate over networks
var %n 1
while ($gettok(%networks,%n,44)) {
; there's two net specific hashes: -opt and -channels
; make sure they are ported from 'net' to 'anet'
var %network $v1
`weather $+(anet-,%network,-opt) $hget(pnp.weather,$+(net-,%network,-opt))
`weather $+(anet-,%network,-channels) $hget(pnp.weather,$+(net-,%network,-channels))
; now let's focus on all the channels for the network, if
; they exist!
; grab $v1 from previous if-check, handy!
var %channels $hget(pnp.weather,$+(net-,%network,-channels))
if (%channels) {
var %c 1
while ($gettok(%channels,%c,44)) {
var %chan $v1
if ($hget(pnp.weather,$+(chan-,%network,-,%chan))) `weather $+(achan-,%network,-,%chan) $v1
inc %c
}
}
inc %n
}
}
; throw away dialog data
hdel -w pnp.weather net-*
hdel -w pnp.weather chan-*
hdel pnp.weather networks
}
elseif ($did == 101) {
; throw away changes
hdel -w pnp.weather net-*
hdel -w pnp.weather chan-*
hdel pnp.weather networks
}
elseif ($did == 102) {
`set weather.apikey $_entry(-1,$hget(pnp.config,weather.apikey),What is your API key?)
}
}
on *:DIALOG:weather:edit:2:{
if ($did(2,0).text == $null) {
did -b $dname 3
}
elseif ($_scandid($dname,2,$did(2,0).text)) {
did -c $dname 2 $v1
did -b $dname 3
did -e $dname 4
wedloadnet $did(2,0).text
}
else {
did -e $dname 3
did -b $dname 4,8
}
wedu
}
on *:DIALOG:weather:edit:8:{
if ($did(8,0).text == $null) {
did -b $dname 9
did -ra $dname 11 Settings
}
elseif ($_scandid($dname,8,$did(8,0).text)) {
did -c $dname 8 $v1
did -b $dname 9
wedloadchan $did(8,0).text
wedu
}
else {
did -e $dname 9
did -b $dname 10
}
wedu
}
alias -l wesetopt {
if ($left($1,1)) did -c $dname 12
else did -u $dname 12
if ($mid($1,2,1)) did -c $dname 13
else did -u $dname 13
if ($mid($1,3,1)) did -c $dname 14
else did -u $dname 14
if ($mid($1,4,1)) did -c $dname 15
else did -u $dname 15
if ($mid($1,5,1)) did -c $dname 16
else did -u $dname 16
if ($mid($1,6,1)) did -c $dname 17
else did -u $dname 17
if ($mid($1,7,1)) did -c $dname 18
else did -u $dname 18
if ($mid($1,8,1)) did -c $dname 19
else did -u $dname 19
if ($mid($1,9,1)) did -c $dname 20
else did -u $dname 20
if ($mid($1,10,1)) did -c $dname 21
else did -u $dname 21
if ($mid($1,11,1)) did -c $dname 22
else did -u $dname 22
if ($mid($1,12,1)) did -c $dname 23
else did -u $dname 23
if ($mid($1,13,1)) did -c $dname 24
else did -u $dname 24
if ($mid($1,14,1)) did -c $dname 25
else did -u $dname 25
if ($mid($1,15,1)) did -c $dname 26
else did -u $dname 26
if ($right($1,1) == 1) {
did -u $dname 27
did -c $dname 28
did -u $dname 29
}
elseif ($right($1,1) == 2) {
did -u $dname 27
did -u $dname 28
did -c $dname 29
}
else {
did -c $dname 27
did -u $dname 28
did -u $dname 29
}
}
alias -l wegetopt {
var %opt,%i 12
while (%i <= 26) {
%opt = %opt $+ $did(%i).state
inc %i
}
if ($did(27).state) %opt = %opt $+ 0
elseif ($did(28).state) %opt = %opt $+ 1
elseif ($did(29).state) %opt = %opt $+ 2
else %opt = %opt $+ 1
return %opt
}
alias -l weather.load {
if ($hget(pnp.weather)) hdel -w pnp.weather *
else hmake pnp.weather 30
var %file $_cfg(weather.dat)
if ($isfile(%file)) hload pnp.weather " $+ %file $+ "
}
alias weather.unload {
if ($islias(jsonclose)) jsonclose -w PPWEATHER.*
weather.save 1
if (!$_yesno(1,Would you like to keep weather configuration data?)) .remove $_cfg(weather.dat)
}
alias -l weather.save {
var %file $_cfg(weather.dat)
if ($hget(pnp.weather)) {
hsave pnp.weather " $+ %file $+ "
if ($1) hfree pnp.weather
}
}
alias -l weather.setup {
if ($hget(pnp.weather) == $null) weather.load
if (!$hget(pnp.config,weather.apiurl)) `set weather.apiurl $weather.owm(apiurl)
if (!$hget(pnp.config,weather.pchar)) `set weather.pchar $weather.owm(pchar)
if (!$hget(pnp.config,weather.qstring)) `set weather.qstring $weather.owm(qstring)
if (!$hget(pnp.config,weather.ustring)) `set weather.ustring $weather.owm(ustring)
if (!$hget(pnp.config,weather.astring)) `set weather.astring $weather.owm(astring)
if (!$hget(pnp.config,weather.mstring)) `set weather.mstring $weather.owm(mstring)
if (!$hget(pnp.config,weather.istring)) `set weather.istring $weather.owm(istring)
if (!$hget(pnp.config,weather.kstring)) `set weather.kstring $weather.owm(kstring)
if (!$hget(pnp.config,weather.trigger)) `set weather.trigger !weather
}
alias weather.owm {
if ($istok(apiurl dunits pchar qstring ustring astring mstring istring kstring,$1,32)) goto $1
else return $null
:apiurl | return http://api.openweathermap.org/data/2.5/weather
:pchar | return ?
:qstring | return q=
:ustring | return &units=
:astring | return &appid=
:mstring | return metric
:istring | return imperial
:kstring | return kelvin
}
on *:START:{ if ($_ispnp) _startup.add _weather.start Initializing weather addon }
on *:EXIT:{ weather.save | jsonclose -w PPWEATHER.* }
alias _weather.start { weather.setup }
; `weather varname [value]
; varname should not include the %`
alias `weather {
if ($hget(pnp.weather,$1) == $2-) return
if ($2- == $null) {
hdel pnp.weather $1
write -ds [ $+ [ $1 ] ] config\ $+ $hget(pnp,user) $+ \weather.dat
_broadcastp hdel pnp.weather $1
}
else {
hadd pnp.weather $1 $2-
write -s [ $+ [ $1 ] ] config\ $+ $hget(pnp,user) $+ \weather.dat $1-
_broadcastp _`weather $1
}
}
alias _`weather hadd pnp.config $1 $read(config\ $+ $hget(pnp,user) $+ \weather.dat,nts,$1)
alias weather {
var %caller $caller
if ($isid) return
var %switch,%rest
if (+* iswm $1) {
%switch = $mid($1,2)
%rest = $2-
}
else {
if (%caller == editbox) %switch = m
elseif (%caller == event) {
if ($istok($hget(pnp.weather,anetworks),$network,44)) {
var %netopt $hget(pnp.weather,$+(anet-,$network,-opt))
if ($gettok(%netopt,1,44)) {
if ($right($gettok(%netopt,2,44),1) == 0) %switch = k
elseif ($right($gettok(%netopt,2,44),1) == 1) %switch = m
elseif ($right($gettok(%netopt,2,44),1) == 2) %switch = i
}
elseif ($istok($hget(pnp.weather,$+(anet-,$network,-channels)),$chan,44)) {
var %chanopt $hget(pnp.weather,$+(achan-,$network,-,$chan))
if ($right(%chanopt,1) == 0) %switch = k
elseif ($right(%chanopt,1) == 1) %switch = m
elseif ($right(%chanopt,1) == 2) %switch = i
}
}
}
else %switch = m
%rest = $1-
}
if (%rest) {
if (%switch === m) {
var %units $+($hget(pnp.config,weather.ustring),$hget(pnp.config,weather.mstring))
%switch = metric
}
elseif (%switch === i) {
var %units $+($hget(pnp.config,weather.ustring),$hget(pnp.config,weather.istring))
%switch = imperial
}
elseif (%switch === k) {
var %units $+($hget(pnp.config,weather.ustring),$hget(pnp.config,weather.kstring))
%switch = kelvin
}
if (!$hget(pnp.config,weather.apikey)) {
dispa Weather: API key not set!
halt
}
var %city $gettok(%rest,1,44)
%city = $replace(%city,$chr(32),$chr(37) $+ 20)
var %cc $gettok(%rest,2,44)
var %pattern /^[-%20a-z]{2,}$/i
if (($regex(%city,%pattern)) && ($regex(%cc,/^[a-z]{2}$/i))) {
var %jsonname $lower($+(PPWEATHER.,%city,.,%cc,.,%switch))
if (!$JSON(%jsonname)) {
weatherfetch %caller %jsonname %city %cc %units
}
else {
var %dt $json(%jsonname,dt).value
if ((!%dt) || ($calc($ctime - %dt) >= 600)) {
JSONCLOSE %jsonname
weatherfetch %caller %jsonname %city %cc %units
}
else {
if (%caller == editbox) dispa [Weather] (cached) $regsubex($json(%jsonname).string,/(\d)/g,$:t(\1)))
elseif (%caller == event) {
if ($_weatherfetchresult(%jsonname)) msg $chan [Weather] (cached) $v1 }
}
}
}
else {
if (%caller == editbox) dispa Usage: /weather {+{m|i|k}} {city},{country code}
elseif (%caller == event) msg $chan Usage: $hget(pnp.config,weather.trigger ) {+{m|i|k}} {city},{country code} | msg $chan Example: $hget(pnp.config,weather.trigger) +m Vlissingen,nl
}
}
else _dialog -am weather weather
}
alias -l _weatherfetchresult {
var %jsonname $1, %result
; respond to network?
if ($istok($hget(pnp.weather,anetworks),$network,44)) {
; blacklist channels? If so, respond to all channels!
var %netopt $hget(pnp.weather,$+(anet-,$network,-opt))
if ($gettok(%netopt,1,44)) {
; if channel not blacklisted, then proceed
if (!$istok($hget(pnp.weather,$+(anet-,$network,-channels)),$chan,44)) {
if ($gettok(%netopt,2,44)) {
var %opt $v1
%result = $_weatherfetchresult2(%jsonname,%opt)
}
}
}
; whitelist channels?
; check if channel is in the list and if it is
; check its options
elseif ($istok($hget(pnp.weather,$+(anet-,$network,-channels)),$chan,44)) {
var %opt $hget(pnp.weather,$+(achan-,$network,-,$chan))
%result = $_weatherfetchresult2(%jsonname,%opt)
}
else %result = $null
}
else %result = $null
return %result
}
alias -l _weatherfetchresult2 {
var %jsonname $1
var %opt $2
var %city $json(%jsonname,name).value
var %cc $json(%jsonname,sys,country).value
var %short $json(%jsonname,weather,0,main).value
var %long $json(%jsonname,weather,0,description).value
var %hum $json(%jsonname,main,humidity).value
var %temp $json(%jsonname,main,temp).value
var %min_temp $json(%jsonname,main,temp_min).value
var %max_temp $json(%jsonname,main,temp_max).value
var %pressure $json(%jsonname,main,pressure).value
var %vis $json(%jsonname,visibility).value
var %wspeed $json(%jsonname,wind,speed).value
var %wdegree $json(%jsonname,wind,deg).value
var %sunrise $json(%jsonname,sys,sunrise).value
var %sunset $json(%jsonname,sys,sunset).value
var %clouds $json(%jsonname,clouds,all).value
var %result
if ($left(%opt,1)) %result = City: %city •
if ($mid(%opt,2,1)) %result = %result Country: %cc •
if ($mid(%opt,3,1)) %result = %result Weather: %short •
if ($mid(%opt,4,1)) %result = %result Description: %long •
if ($mid(%opt,5,1)) %result = %result Humidity: %hum •
if ($mid(%opt,6,1)) %result = %result Temperature: %temp •
if ($mid(%opt,7,1)) %result = %result Min. temp.: %min_temp •
if ($mid(%opt,8,1)) %result = %result Max. temp: %max_temp •
if ($mid(%opt,9,1)) %result = %result Pressure: %pressure •
if ($mid(%opt,10,1)) %result = %result Visibility: %vis •
if ($mid(%opt,11,1)) %result = %result Wind speed: %wspeed •
if ($mid(%opt,12,1)) %result = %result Wind degree: %wdegree •
if ($mid(%opt,13,1)) %result = %result Sunrise: ETA $duration($remove($calc($ctime - %sunrise),-),3) •
if ($mid(%opt,14,1)) %result = %result Sunset: ETA $duration($remove($calc($ctime - %sunset),-),3) •
if ($mid(%opt,15,1)) %result = %result Clouds: %clouds •
return %result
}
alias -l weatherfetch {
var %caller $1
var %jsonname $2
var %city $3
var %cc $4
var %units $5
var %page $+($hget(pnp.config,weather.apiurl),$hget(pnp.config,weather.pchar))
%page = $+(%page,$hget(pnp.config,weather.qstring),%city,$chr(44),%cc)
%page = $+(%page,%units))
%page = $+(%page,$hget(pnp.config,weather.astring),$hget(pnp.config,weather.apikey))
JSONOPEN -u %jsonname %page
if ($json(%jsonname).httpStatus == 200) {
if (%caller == editbox) dispa [Weather] $regsubex($json(%jsonname).string,/(\d)/g,$:t(\1)))
elseif (%caller == event) {
if ($_weatherfetchresult(%jsonname)) msg $chan [Weather] $v1
}
else dispa %caller
}
elseif ($json(%jsonname).string) {
if (%caller == editbox) dispa Weather: $json(%jsonname).string
elseif (%caller == event) msg $chan [Weather] $json(%jsonname).string
}
else dispa Weather: $json(%jsonname).httpStatus - $json(%jsonname).httpStatusText
}
on *:TEXT:$($hget(pnp.config,weather.trigger) *):#:weather $2-
alias getJFM {
; sha-512 of JSON For mIRC.mrc v1.0.4000
var %sha512-1 b29de8c964b002d089fa030a9a5357e3c737f17cd16309c0fa82142120a590db2223d4703cafe97f37b65de170bb4d9dbf7bb508f4052a47a2127fc74c10a6d6
; group enabled hash
var %sha512-2 183153806705c99fce8fb3003ea7e5522e9f67c40b3e064280ad83111e3d8f92b4cfae106b8827a9d99c2377c32d6d6892fe878a027bcaea24a466450cfeead8
; check if JSON For mIRC is loaded
if ($isalias(JSONVersion)) {
; script is loaded, but what version?
var %file $isalias(JSONVersion).fname
if (!$istok(%sha512-1 %sha512-2,$sha512(%file,2),32)) {
dispa Unloading $JSONVersion ...
.unload -rs $qt(%file) | .timer -mio 1 0 getJFM
}
else return 0
}
elseif ($1 isnum) {
if ($urlget($1).state == fail) { dispa Downloading JSON For mIRC failed. Are you connected to the internet? | halt }
elseif ($zip($urlget($1).target,eo,scripts)) {
var %file $qt($findfile(scripts\JSON-For-Mirc-1.0.4000,JSON For mIRC.mrc,1))
if ($sha512(%file,2) == %sha512-1) dispa Loading JSON For mIRC ver1.0.4000 | .load -rs %file
else dispa Wrong sha512 hash for %file $+ !
.remove $urlget($1).target
}
else { dispa Something went wrong unzipping $:t($urlget($1).target) }
}
else {
var %url https://github.com/SReject/JSON-For-Mirc/archive/v1.0.4000.zip
var %target JFM.zip
dispa Obtaining JSON For mIRC...
return $urlget(%url,gf,%target,getJFM)
}
}