Skip to content

Commit 8d8fe72

Browse files
committed
Revert "Building Speech Strings"
This reverts commit fda4b47.
1 parent fda4b47 commit 8d8fe72

29 files changed

+40
-187
lines changed

api.php

+7-35
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require_once dirname(__FILE__) . '/php/fetchers.php';
66
require_once dirname(__FILE__) . '/php/body.php';
77
require_once dirname(__FILE__) . '/php/JsonXmlElement.php';
8-
require_once dirname(__FILE__) . '/php/helpers/dialogFlow/DialogFlow.php';
8+
require_once dirname(__FILE__) . '/php/dialogFlow/DialogFlow.php';
99
require_once dirname(__FILE__) . '/php/multiCurl.php';
1010

1111
use digitalhigh\DialogFlow\DialogFlow;
@@ -2883,7 +2883,6 @@ function mapApiRequest($request)
28832883
break;
28842884
case 'help':
28852885
case 'welcome.help':
2886-
case 'helpRequest':
28872886
write_log("Help request!!", "INFO");
28882887
break;
28892888
default:
@@ -3360,8 +3359,6 @@ function buildQueryInfo($params)
33603359
case 'recent':
33613360
$mediaType = $params['type'] ?? false;
33623361
write_log("Media type is $mediaType");
3363-
$result['media'] = fetchHubList($type, $mediaType);
3364-
$results['type'] = $mediaType;
33653362
break;
33663363
case 'ondeck':
33673364
$mediaType = 'show';
@@ -3569,18 +3566,10 @@ function buildSpeech($params, $results)
35693566
$speech = buildSpeechWelcome();
35703567
$wait = true;
35713568
}
3572-
if ($params['intent'] == 'helpRequest') {
3569+
if ($params['intent'] == 'help' || $params['intent'] == 'welcome.help') {
35733570
$help = buildSpeechHelp();
35743571
$speech = $help[0];
3575-
if ($_SESSION['amazonRequest'] ?? false) {
3576-
$sugs = [];
3577-
foreach($help[1] as $sug) array_push($sugs, "'$sug'");
3578-
$strings = join(", ",$sugs);
3579-
$speech .= $strings;
3580-
} else {
3581-
$suggestions = $help[1];
3582-
}
3583-
3572+
$suggestions = $help[1];
35843573
$wait = true;
35853574
}
35863575
write_log("Cards?: " . json_encode($cards));
@@ -3707,20 +3696,7 @@ function buildSpeechInfoQuery($params, $cards)
37073696

37083697
function buildSpeechNoResults($request)
37093698
{
3710-
write_log("Request: ".json_encode($request));
37113699
$title = is_string($request) ? $request : ($request['request'] ?? $request['type'] ?? 'that request');
3712-
if (isset($request['infoRequests'])) {
3713-
$type = $request['infoRequests'];
3714-
if ($type == 'recent') {
3715-
if ($request['type'] == 'movie') {
3716-
$title = "recent movies";
3717-
} else {
3718-
$title = "recent shows";
3719-
}
3720-
}
3721-
if ($type == 'ondeck') $title = "on deck items";
3722-
if ($type == 'airings') $title = "upcoming shows";
3723-
}
37243700
write_log("No results for request '$request'");
37253701
$array = lang('speechNoInfoResultsArray');
37263702
do {
@@ -3767,14 +3743,10 @@ function buildSpeechHelp()
37673743
$show = ($_SESSION['sickEnabled'] ?? false) || ($_SESSION['sonarrEnabled'] ?? false);
37683744
$music = ($_SESSION['headphonesEnabled'] ?? false) || ($_SESSION['lidarrEnabled'] ?? false);
37693745
$dvr = $_SESSION['plexDvrId'] ?? false;
3770-
$movieSuggestions = $appSuggestions['movie'];
3771-
$showSuggestions = $appSuggestions['show'];
3772-
$musicSuggestions = $appSuggestions['music'];
3773-
$dvrSuggestions = $appSuggestions['dvr'];
3774-
if ($movie) array_push($helpSuggestions, $movieSuggestions[array_rand($movieSuggestions)]);
3775-
if ($show) array_push($helpSuggestions, $showSuggestions[array_rand($showSuggestions)]);
3776-
if ($music) array_push($helpSuggestions, $musicSuggestions[array_rand($musicSuggestions)]);
3777-
if ($dvr) array_push($helpSuggestions, $dvrSuggestions['array_rand($dvrSuggestions']);
3746+
if ($movie) $helpSuggestions = array_merge($helpSuggestions, $appSuggestions['movie']);
3747+
if ($show) $helpSuggestions = array_merge($helpSuggestions, $appSuggestions['show']);
3748+
if ($music) $helpSuggestions = array_merge($helpSuggestions, $appSuggestions['music']);
3749+
if ($dvr) $helpSuggestions = array_merge($helpSuggestions, $appSuggestions['dvr']);
37783750
$helpSuggestions[] = "Cancel";
37793751
$suggestions = $helpSuggestions;
37803752
return [

composer.phar

1.78 MB
Binary file not shown.

php/helpers/configs/DbConfig.php php/DbConfig.php

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
<?php
22
namespace digitalhigh;
3-
require_once dirname(__FILE__) . "/ConfigException.php";
43
use mysqli;
5-
require_once(dirname(__FILE__) . "/util.php");
4+
require_once(dirname(__FILE__)."/util.php");
65
class DbConfig {
76

87

9-
/**
10-
* DbConfig constructor.
11-
* @throws ConfigException
12-
*/
13-
public function __construct()
8+
public function __construct()
149
{
1510
$this->connection = $this->connect();
1611
if ($this->connection === false) {
17-
throw new ConfigException("Error connecting to database!!");
12+
write_log("Error connecting to db.","ERROR");
1813
}
1914
return ($this->connection !== false);
2015
}
2116

22-
23-
public function isValid()
24-
{
25-
return ($this->connection ? true : false);
26-
}
27-
2817
protected $connection;
2918

3019
protected function connect() {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
namespace digitalhigh;
3-
require_once dirname(__FILE__) . "/ConfigException.php";
4-
use ArrayObject;
52

63
class JsonConfig extends ArrayObject {
74

@@ -12,44 +9,19 @@ class JsonConfig extends ArrayObject {
129

1310
public $data;
1411

15-
/**
16-
* JsonConfig constructor.
17-
* @param $filename - The file to use.
18-
* @param bool $secure - Whether or not to add a "Access denied flag" to the file. (Needs to be .php)
19-
* @throws ConfigException - Pukes all over you if the file can't be written to.
20-
*/
2112
public function __construct($filename, $secure=true)
2213
{
2314
$this->fileName = $filename;
2415
$this->header = ";<?php die('Access denied');?>";
2516
$this->secure = $secure;
2617

2718
$this->data = [];
28-
$this->cache = [];
2919

30-
if (!$this->validate()) throw new ConfigException("Error accessing specified config file.");
31-
32-
$data = $this->read();
33-
if (is_array($data)) {
34-
$this->data = $data;
35-
$this->cache = $data;
36-
} else {
37-
throw new ConfigException("Error reading data from file.");
20+
if (file_exists($filename)) {
21+
$this->read();
3822
}
3923
}
4024

41-
public function isValid() {
42-
return ($this->read ? true : false);
43-
}
44-
45-
/**
46-
* @param $section
47-
* @param $data
48-
* @param null $selector
49-
* @param null $search
50-
* @param bool $new
51-
* @throws ConfigException
52-
*/
5325
public function set($section, $data, $selector=null, $search=null, $new=false) {
5426
write_log("Trying to set data for $section with sel of $selector and sea of $search: ".json_encode($data),"ALERT");
5527
$temp = $this->data[$section] ?? [];
@@ -81,7 +53,7 @@ public function set($section, $data, $selector=null, $search=null, $new=false) {
8153
}
8254

8355
public function get($section, $keys=false, $selector=null, $search=null) {
84-
$data = $this->cache[$section] ?? [];
56+
$data = $this->data[$section] ?? [];
8557
if ($data) {
8658
if ($selector && $search) {
8759
$results = [];
@@ -112,12 +84,6 @@ public function get($section, $keys=false, $selector=null, $search=null) {
11284
return $data;
11385
}
11486

115-
/**
116-
* @param $section
117-
* @param null $selectors
118-
* @param null $values
119-
* @throws ConfigException
120-
*/
12187
public function delete($section, $selectors=null, $values=null) {
12288
$sectionData = $this->data[$section] ?? false;
12389
if ($sectionData) {
@@ -153,73 +119,25 @@ public function delete($section, $selectors=null, $values=null) {
153119
}
154120
}
155121

156-
protected function validate() {
157-
if (!file_exists($this->fileName)) {
158-
if (touch($this->fileName)) {
159-
if (chmod($this->fileName,0666)) {
160-
write_log("Creating file at path '$this->fileName'.","INFO");
161-
$data = $this->header . PHP_EOL .json_encode([],JSON_PRETTY_PRINT);
162-
if (file_put_contents($this->fileName,$data)) {
163-
return true;
164-
}
165-
}
166-
}
167-
} else {
168-
return is_writable($this->fileName);
169-
}
170-
return false;
171-
}
172-
173122
protected function read() {
174-
$path = $this->fileName;
175-
if (!file_exists($path)) {
176-
write_log("File doesn't exist?");
177-
return false;
178-
}
179-
$file = fopen($path,'r');
180-
$data = fread($file,filesize($path));
181-
fclose($file);
182-
183-
if ($data !== false) {
123+
$data = file_get_contents($this->fileName);
124+
if ($data) {
184125
$data = str_replace($this->header, "", $data);
185-
$data = json_decode($data,true);
126+
$data = trim($data) ? json_decode($data, true) : [];
186127
}
187-
188-
return $data;
128+
if (!$data) {
129+
write_log("Error reading data.","WARN");
130+
$data = [];
131+
}
132+
$this->data = $data;
189133
}
190134

191-
/**
192-
* @return mixed
193-
* @throws ConfigException
194-
*/
195135
protected function save() {
196136
$data = json_encode($this->data,JSON_PRETTY_PRINT);
197137
$output = $this->header . PHP_EOL . $data;
198-
$i = 0;
199-
do {
200-
$result = $this->write($output);
201-
$i++;
202-
} while (!$result && $i >=5);
203-
204-
if (!$result) {
205-
throw New ConfigException("Error saving file, this is bad!!");
206-
} else {
207-
$this->cache = $this->data;
208-
}
209-
return $result;
210-
}
211-
212-
protected function write($contents) {
213-
$path = $this->fileName;
214-
$fp = fopen($path, 'w+');
215-
if(!flock($fp, LOCK_EX))
216-
{
217-
return false;
218-
}
219-
$result = fwrite($fp, $contents);
220-
flock($fp, LOCK_UN);
221-
fclose($fp);
222-
return $result !== false;
138+
$success = file_put_contents($this->fileName,$output,LOCK_EX);
139+
if (!$success) write_log("Save " . ($success ? 'was' : 'was not') . ' successful.',($success ? "INFO": "ALERT"));
140+
return $success;
223141
}
224142

225143
}
File renamed without changes.
File renamed without changes.

php/fetchers.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
require_once dirname(__FILE__) . '/vendor/autoload.php';
33
require_once dirname(__FILE__) . '/webApp.php';
4-
require_once dirname(__FILE__) . '/helpers/fetchers/digitalhigh/watcher/src/Watcher.php';
5-
require_once dirname(__FILE__) . '/helpers/fetchers/digitalhigh/lidarr/src/Lidarr.php';
6-
require_once dirname(__FILE__) . '/helpers/fetchers/digitalhigh/headphones/src/Headphones.php';
4+
require_once dirname(__FILE__) . '/fetchers/digitalhigh/watcher/src/Watcher.php';
5+
require_once dirname(__FILE__) . '/fetchers/digitalhigh/lidarr/src/Lidarr.php';
6+
require_once dirname(__FILE__) . '/fetchers/digitalhigh/headphones/src/Headphones.php';
77
require_once dirname(__FILE__) . '/util.php';
88
require_once dirname(__FILE__) . '/multiCurl.php';
99
use Kryptonit3\CouchPotato\CouchPotato;
File renamed without changes.

php/helpers/configs/ConfigException.php

-15
This file was deleted.

php/lang/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
]
4848
},
4949
"errorHelpSuggestionsArray": [
50-
"Here are some suggestions you can try.",
50+
"Below are some suggestions you can try.",
5151
"Here are some possible commands.",
5252
"Sure, why don't you try one of these?"
5353
],

php/webApp.php

+12-23
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22
require_once dirname(__FILE__). '/util.php';
33
require_once dirname(__FILE__) . '/vendor/autoload.php';
4-
require_once dirname(__FILE__) . '/helpers/git/GitUpdate.php';
4+
require_once dirname(__FILE__) . '/git/GitUpdate.php';
55
$useDb = file_exists(dirname(__FILE__) . "/db.conf.php");
66

7-
require_once dirname(__FILE__) . ($useDb ? '/helpers/configs/DbConfig.php' : '/helpers/configs/JsonConfig.php');
7+
require_once dirname(__FILE__) . ($useDb ? '/DbConfig.php' : '/JsonConfig.php');
88
checkDefaults();
99
use digitalhigh\GitUpdate;
1010
$isWebapp = isWebApp();
@@ -25,31 +25,17 @@ function updateUserPreferenceArray($data) {
2525
writeSessionArray($data);
2626
}
2727

28-
function initConfig() {
29-
if (isset($_SESSION['config'])) {
30-
$config = $_SESSION['config'];
31-
} else {
32-
$error = false;
33-
$useDb = file_exists(dirname(__FILE__) . "/db.conf.php");
34-
$configFile = file_build_path(dirname(__FILE__), "..", "rw", "config.php");
35-
try {
36-
$config = $useDb ? new \digitalhigh\DbConfig() : new \digitalhigh\JsonConfig($configFile);
37-
} catch (\digitalhigh\ConfigException $e) {
38-
write_log("An exception occurred creating the configuration. '$e'","ERROR");
39-
$error = true;
40-
}
41-
if (!$error) writeSession('config',$config);
42-
}
43-
return $config;
44-
}
45-
4628
function setPreference($section, $data, $selector=null, $search=null, $new=false) {
47-
$config = initConfig();
29+
$useDb = file_exists(dirname(__FILE__) . "/db.conf.php");
30+
$configFile = file_build_path(dirname(__FILE__), "..","rw","config.php");
31+
$config = $useDb ? new \digitalhigh\DbConfig() : new JsonConfig($configFile);
4832
$config->set($section, $data, $selector, $search, $new);
4933
}
5034

5135
function getPreference($section, $keys=false, $default=false, $selector=null, $search=null,$single=true) {
52-
$config = initConfig();
36+
$useDb = file_exists(dirname(__FILE__) . "/db.conf.php");
37+
$configFile = file_build_path(dirname(__FILE__), "..","rw","config.php");
38+
$config = $useDb ? new \digitalhigh\DbConfig() : new JsonConfig($configFile);
5339
$data = $config->get($section, $keys, $selector, $search);
5440
$ignore = false;
5541
//if ($section == 'general') write_log("Raw data: ".json_encode($data));
@@ -63,11 +49,14 @@ function getPreference($section, $keys=false, $default=false, $selector=null, $s
6349
$data = $default;
6450
}
6551
if ($single && !is_string($data)) $data = (count($data) == 1) ? $data[0] : $data;
52+
//if ($section == 'commands') write_log("Outgoing data: ".json_encode($data));
6653
return $data;
6754
}
6855

6956
function deleteData($section, $selector=null, $value=null) {
70-
$config = initConfig();
57+
$useDb = file_exists(dirname(__FILE__) . "/db.conf.php");
58+
$configFile = file_build_path(dirname(__FILE__), "..","rw","config.php");
59+
$config = $useDb ? new \digitalhigh\DbConfig() : new JsonConfig($configFile);
7160
$config->delete($section, $selector, $value);
7261
}
7362

0 commit comments

Comments
 (0)