-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6 create new catalog structure for modules
- Loading branch information
Showing
12 changed files
with
1,348 additions
and
1,430 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
<?php | ||
|
||
namespace module; | ||
|
||
use library\Module; | ||
|
||
class ApiProxy extends Module | ||
{ | ||
const | ||
URL_API = 'api.touhou.pl/external', | ||
QUERY_REGEX = '~-(\w+?):([^ ]+)~'; | ||
|
||
public function loadSettings($object = null) | ||
{ | ||
$this->setCommand([ | ||
'trigger' => 'api', | ||
'action' => 'getResponseFromQuery', | ||
'arguments' => -1, | ||
'channels' => ['#touhoupl'], | ||
'permit' => true | ||
]); | ||
parent::loadSettings($this); | ||
} | ||
|
||
public function saveSettings() | ||
{ | ||
return parent::saveSettings(); | ||
} | ||
|
||
//> !api param:value query1 query2 | ||
protected function getResponseFromQuery(array $arguments = []) | ||
{ | ||
if (!$arguments) { | ||
return; | ||
} | ||
$trzeciAgrumentDoCallbacka = implode(' ', $arguments); | ||
$params = []; | ||
$query = preg_replace_callback(self::QUERY_REGEX, | ||
function($m) use (&$params) { | ||
$params[$m[1]] = $m[2]; | ||
},$trzeciAgrumentDoCallbacka); | ||
|
||
$url = self::URL_API . '?' . http_build_query(['q' => trim($query)] + $params); | ||
|
||
$response = json_decode($this->loadStreamUrl($url), true); | ||
|
||
if ($response) { | ||
return $this->reply($this->flat($response)); | ||
} | ||
} | ||
|
||
private function flat(array $array) | ||
{ | ||
$string = ''; | ||
foreach ($array as $key => $value) { | ||
if (is_array($value)) { | ||
$value = $this->flat($value); | ||
} elseif (is_string($value)) { | ||
$string .= $key . ':' . $value . ' '; | ||
} | ||
} | ||
return rtrim($string, ' '); | ||
} | ||
<?php | ||
|
||
namespace ApiProxy; | ||
|
||
use Saya\Client\Module; | ||
|
||
class ApiProxy extends Module | ||
{ | ||
const | ||
URL_API = 'api.touhou.pl/external', | ||
QUERY_REGEX = '~-(\w+?):([^ ]+)~'; | ||
|
||
public function loadSettings($object = null) | ||
{ | ||
$this->setCommand([ | ||
'trigger' => 'api', | ||
'action' => 'getResponseFromQuery', | ||
'arguments' => -1, | ||
'channels' => ['#touhoupl'], | ||
'permit' => true | ||
]); | ||
parent::loadSettings($this); | ||
} | ||
|
||
public function saveSettings() | ||
{ | ||
return parent::saveSettings(); | ||
} | ||
|
||
//> !api param:value query1 query2 | ||
protected function getResponseFromQuery(array $arguments = []) | ||
{ | ||
if (!$arguments) { | ||
return; | ||
} | ||
$trzeciAgrumentDoCallbacka = implode(' ', $arguments); | ||
$params = []; | ||
$query = preg_replace_callback(self::QUERY_REGEX, | ||
function($m) use (&$params) { | ||
$params[$m[1]] = $m[2]; | ||
},$trzeciAgrumentDoCallbacka); | ||
|
||
$url = self::URL_API . '?' . http_build_query(['q' => trim($query)] + $params); | ||
|
||
$response = json_decode($this->loadStreamUrl($url), true); | ||
|
||
if ($response) { | ||
$this->reply($this->flat($response)); | ||
} | ||
} | ||
|
||
private function flat(array $array) | ||
{ | ||
$string = ''; | ||
foreach ($array as $key => $value) { | ||
if (is_array($value)) { | ||
$value = $this->flat($value); | ||
} elseif (is_string($value)) { | ||
$string .= $key . ':' . $value . ' '; | ||
} | ||
} | ||
return rtrim($string, ' '); | ||
} | ||
} |
Oops, something went wrong.