-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.php
204 lines (187 loc) · 7.84 KB
/
index.php
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
<?php
//TODO:
//IT
$browsers = array("chrome", "firefox", "ie", "edge", "safari", "opera");
$data["browsers"] = json_decode(file_get_contents("https://raw.githubusercontent.com/Fyrd/caniuse/master/fulldata-json/data-2.0.json"), true);
$helper_config["log"] = true;
$helper_config["intent-function"] = true;
include("helper/google-assistant_api-ai_helper.php");
//--------------------------------------------------------------------------------------------------
function getFeature($feat){
global $data;
$data["data"][$feat] = json_decode(file_get_contents("https://raw.githubusercontent.com/Fyrd/caniuse/master/features-json/" . $feat . ".json"), true);
}
//--------------------------------------------------------------------------------------------------
function How_much_Feature(){
global $data, $helper;
$feat = $helper["parameters"]["features"];
getFeature($feat);
if($data["data"][$feat]["usage_perc_y"] == null){
if($helper["locale"] == "de-DE"){
simple_response("Es tut mir leid, ich kenne dieses Feature nicht.");
} else {
simple_response("Sorry, I don't know this feature");
}
} else {
if($helper["locale"] == "de-DE"){
simple_response($data["data"][$feat]["usage_perc_y"] . "% der Computer können " . $feat . " nutzen.");
simple_response("Kann ich dir noch etwas anderes helfen?");
} else {
simple_response($data["data"][$feat]["usage_perc_y"] . "% of the computers can use " . $feat);
simple_response("Can I help you with something else?");
}
}
/*suggestion_chips([
"What is " . $feat,
"Which browser use " . $feat
]);*/
}
//--------------------------------------------------------------------------------------------------
function How_much_Browser(){
global $data, $helper;
if($helper["parameters"]["number"] == null){
$length = count($data["browsers"]["agents"][$helper["parameters"]["browser"]]["version_list"]);
$percent = 0;
for($i=0; $i < $length; $i++){
$percent += $data["browsers"]["agents"][$helper["parameters"]["browser"]]["version_list"][$i]["global_usage"];
}
$percent = round($percent);
if($helper["locale"] == "de-DE"){
simple_response($percent . "% der Welt nutzen " . $helper["parameters"]["browser"]);
simple_response("Kann ich dir noch etwas anderes helfen?");
} else {
simple_response($percent . "% of the world are using " . $helper["parameters"]["browser"]);
simple_response("Can I help you with something else?");
}
} else {
if($helper["locale"] == "de-DE"){
simple_response(round($data["browsers"]["agents"][$helper["parameters"]["browser"]]["usage_global"][$helper["parameters"]["number"]]) . "% der Welt nutzen " . $helper["parameters"]["browser"] . " " . $helper["parameters"]["number"]);
simple_response("Kann ich dir noch etwas anderes helfen?");
} else {
simple_response(round($data["browsers"]["agents"][$helper["parameters"]["browser"]]["usage_global"][$helper["parameters"]["number"]]) . "% of the world are using " . $helper["parameters"]["browser"] . " " . $helper["parameters"]["number"]);
simple_response("Can I help you with something else?");
}
}
}
//--------------------------------------------------------------------------------------------------
function Can_I_Use(){
global $data, $helper;
if($helper["parameters"]["number"] == null){
if(browser($helper["parameters"]["browser"], $helper["parameters"]["features"])){
if($helper["locale"] == "de-DE"){
simple_response("Ja, du kannst " . $helper["parameters"]["features"] . " in der aktuellen Version von " . $helper["parameters"]["browser"] . " nutzen.");
} else {
simple_response("Yes, you can use " . $helper["parameters"]["features"] . " in the actual version of " . $helper["parameters"]["browser"]);
}
} else {
if($helper["locale"] == "de-DE"){
simple_response("Nein, du kannst " . $helper["parameters"]["features"] . " nicht in der aktuellen Version von " . $helper["parameters"]["browser"] . " nutzen.");
} else {
simple_response("No, you can't use " . $helper["parameters"]["features"] . " in the actual version of " . $helper["parameters"]["browser"]);
}
}
} else {
if(browser($helper["parameters"]["browser"], $helper["parameters"]["features"], $helper["parameters"]["number"])){
if($helper["locale"] == "de-DE"){
simple_response("Ja, du kannst " . $helper["parameters"]["features"] . " in " . $helper["parameters"]["browser"] . " " . $helper["parameters"]["number"] . " nutzen.");
} else {
simple_response("Yes, you can use " . $helper["parameters"]["features"] . " in " . $helper["parameters"]["browser"] . " " . $helper["parameters"]["number"]);
}
} else {
if($helper["locale"] == "de-DE"){
simple_response("Nein, du kannst " . $helper["parameters"]["features"] . " in " . $helper["parameters"]["browser"] . " " . $helper["parameters"]["number"] . " nicht nutzen.");
} else {
simple_response("No, you can't use " . $helper["parameters"]["features"] . " in " . $helper["parameters"]["browser"] . " " . $helper["parameters"]["number"]);
}
}
}
if($helper["locale"] == "de-DE"){
simple_response("Kann ich dir noch etwas anderes helfen?");
} else {
simple_response("Can I help you with something else?");
}
}
//--------------------------------------------------------------------------------------------------
function Which(){
global $data, $browsers, $helper;
$browser_amount = count($browsers);
$j = 0;
for($i = 0; $i < $browser_amount; $i++){
if(browser($browsers[$i], $helper["parameters"]["features"])){
$browserresult[$j] = $browsers[$i];
$j++;
}
}
$count = count($browserresult);
if($count > 1){
$browsertext = "";
for($i = 0; $i < $count - 2; $i++){
$browsertext .= $browserresult[$i] . ", ";
}
if($helper["locale"] == "de-DE"){
$browsertext .= $browserresult[$count - 2] . " und ";
} else {
$browsertext .= $browserresult[$count - 2] . " and ";
}
$browsertext .= $browserresult[$count - 1];
} else {
$browsertext = $browserresult[0];
}
if($helper["locale"] == "de-DE"){
simple_response("Die neuste Version von " . $browsertext . " können " . $helper["parameters"]["features"] . " nutzen.");
simple_response("Kann ich dir noch etwas anderes helfen?");
} else {
simple_response("The newest version of " . $browsertext . " can use " . $helper["parameters"]["features"]);
simple_response("Can I help you with something else?");
}
/*suggestion_chips([
"How much use " . $helper["parameters"]["features"],
"What is " . $helper["parameters"]["features"]
]);*/
}
//--------------------------------------------------------------------------------------------------
function What(){
global $data, $helper;
getFeature($helper["parameters"]["features"]);
if($data["data"][$helper["parameters"]["features"]]["description"] == null){
if($helper["locale"] == "de-DE"){
simple_response("Es tut mir leid, ich kenne dieses Feature nicht.");
} else {
simple_response("Sorry, I don't know this feature");
}
} else {
if($helper["locale"] == "de-DE"){
simple_response("Die Beschreibung gibt es leider nur auf englisch.");
simple_response("Kann ich dir noch etwas anderes helfen?");
} else {
simple_response($data["data"][$helper["parameters"]["features"]]["description"]);
simple_response("Can I help you with something else?");
}
/*suggestion_chips([
"How much use " . $helper["parameters"]["features"],
"Which browser use " . $helper["parameters"]["features"]
]);*/
}
}
//--------------------------------------------------------------------------------------------------
function browser($browser, $feat, $number){
global $data, $helper;
getFeature($feat);
if($number == null){
$number = $data["browsers"]["agents"][$browser]["current_version"];
}
$raw = $data["data"][$feat]["stats"][$browser][$number];
$split = explode("", $raw);
if($split[0] == null){
$result = $raw;
} else {
$result = $split[0];
}
if($result == "y"){
return true;
} else {
return false;
}
}
function test(){
}