-
Notifications
You must be signed in to change notification settings - Fork 1
/
omertaPrices.tcl
105 lines (89 loc) · 4.37 KB
/
omertaPrices.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
#########################################################
# Title : Omerta Prices
# Name : omertaPrices.tcl
# Author : vBm ( [email protected] )
# Version : 0.8
#########################################################
# Information:
# Script has been written for sole purpose of using it at #beyond at Omerta Network.
# Some of bugs are prolly present, I'll do my best to solve those problems ASAP.
#
# At the moment only cocaine prices are shown.
#
# Usage :
# Usage is rather simple.
# All you need to do is to define public commands you want to use at your channel.
#
#########################################################
#
# Versions :
# 0.1 - Initial Release
# 0.2 - Change GMT Offset regardless of timezone where shell
# from which this script runs is.
# 0.3 - Added v3 beta prices
# 0.4 - Instead of using 'split $prices "\n"' i'm gonna use regexp now
# that will give us always correct prices even if there's some errors
# on page that displays 'em
# 0.5 - Removed obsolete beta link
# 0.6 - Rewritten script totally to cope with new API
# - Removed all obsolete version links
# - Added checker for http errors
# 0.7 - Added back .dm link
# 0.8 - Update links
#
#########################################################
#
# Configuration :
# Script depends on usage of http and tdom tcl packages
package require http
package require tdom
# Public command that will trigger the script.
# The prefix goes before like '!' or '.'
set cmdprefix "!"
# The suffix comes after like 'prices' or 'p'
set cmdsuffix "p"
# END CONFIG
# SCRIPT START
bind pub - $cmdprefix$cmdsuffix show:prices
proc show:prices { nick host hand chan arg } {
if { $arg == "" } { set url "http://www.barafranca.com/BeO/webroot/index.php?module=API&action=smuggling_prices"; set version ".com" }
if { $arg == "com" } { set url "http://www.barafranca.com/BeO/webroot/index.php?module=API&action=smuggling_prices"; set version ".com" }
if { $arg == "dm" } { set url "http://omerta.dm/BeO/webroot/index.php?module=API&action=smuggling_prices"; set version ".dm" }
if { $arg == "nl" } { set url "http://www.barafranca.nl/BeO/webroot/index.php?module=API&action=smuggling_prices"; set version ".nl" }
if { $arg == "pt" } { set url "http://omerta.pt/BeO/webroot/index.php?module=API&action=smuggling_prices"; set version ".pt" }
if { $arg == "tr" } { set url "http://www.barafranca.gen.tr/BeO/webroot/index.php?module=API&action=smuggling_prices"; set version ".tr" }
if {[catch {set tok [::http::geturl $url -timeout 10000]} msg]} {
putlog "oops get:url error:: $msg"
} else {
set nrcode [::http::ncode $tok]
}
if {$nrcode == "200"} {
set data [::http::data $tok]
::http::cleanup $tok
}
set dom [dom parse $data]
set root [$dom documentElement]
set time [[$root selectNodes /smugglingprices/epochtimestamp/text()] nodeValue]
set hour [clock format $time -format {%H} -gmt 1]
set mins [clock format $time -format {%M} -gmt 1]
if {"$mins" < "30"} { set mins "00" } else { set mins "30" }
set cokeList [$root selectNodes /smugglingprices/cities/city/prices/cocaine/text()]
set detroCoke [[lindex $cokeList 0] nodeValue]
set chiCoke [[lindex $cokeList 1] nodeValue]
set palermoCoke [[lindex $cokeList 2] nodeValue]
set nyCoke [[lindex $cokeList 3] nodeValue]
set lvCoke [[lindex $cokeList 4] nodeValue]
set phillyCoke [[lindex $cokeList 5] nodeValue]
set baltiCoke [[lindex $cokeList 6] nodeValue]
set corleCoke [[lindex $cokeList 7] nodeValue]
## Cleaning up tdom...
$dom delete
set list "$detroCoke $chiCoke $palermoCoke $nyCoke $lvCoke $phillyCoke $baltiCoke $corleCoke"
set max [lindex [lsort -real $list] end]
set min [lindex [lsort -real $list] 0]
foreach item [list detroCoke chiCoke palermoCoke nyCoke lvCoke phillyCoke baltiCoke corleCoke] {
if { [set $item] == $max } { set $item "\0034\002[set $item]\002\003" }
if { [set $item] == $min } { set $item "\0033\002[set $item]\002\003" }
}
putquick "PRIVMSG $chan : \002$version\002 Coke at\: $hour:$mins OT \| Baltimore\: $baltiCoke \| Chicago\: $chiCoke \| New York\: $nyCoke \| Philadelphia\: $phillyCoke \| Detroit\: $detroCoke \| Las Vegas\: $lvCoke \| Corleone\: $corleCoke \| Palermo\: $palermoCoke"
}