mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
enhancement for BotCommand and CommandArgument
This commit is contained in:
@@ -67,7 +67,7 @@ class PluginGenerator
|
||||
'{class}' => $this->convertClassName(),
|
||||
];
|
||||
$main_php = str_replace(array_keys($replace), array_values($replace), $template);
|
||||
file_put_contents(zm_dir($plugin_base_dir . '/src/PluginMain.php'), $main_php);
|
||||
file_put_contents(zm_dir($plugin_base_dir . '/src/' . $this->convertClassName() . '.php'), $main_php);
|
||||
// 写入 composer.json
|
||||
$composer_json = [
|
||||
'autoload' => [
|
||||
|
||||
@@ -64,6 +64,11 @@ class MessageUtil
|
||||
public static function convertToArr(MessageSegment|\Stringable|array|string $message)
|
||||
{
|
||||
if (is_array($message)) {
|
||||
foreach ($message as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
$message[$k] = new MessageSegment('text', ['text' => $v]);
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
if ($message instanceof MessageSegment) {
|
||||
@@ -74,4 +79,48 @@ class MessageUtil
|
||||
}
|
||||
return new MessageSegment('text', ['text' => $message]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分割消息字符串
|
||||
*
|
||||
* @param array $includes 需要进行切割的字符串,默认包含空格及制表符(\t)
|
||||
*/
|
||||
public static function splitMessage(string $msg, array $includes = [' ', "\t"]): array
|
||||
{
|
||||
$msg = trim($msg);
|
||||
foreach ($includes as $v) {
|
||||
$msg = str_replace($v, "\n", $msg);
|
||||
}
|
||||
$msg_seg = explode("\n", $msg);
|
||||
$ls = [];
|
||||
foreach ($msg_seg as $v) {
|
||||
if (empty(trim($v))) {
|
||||
continue;
|
||||
}
|
||||
$ls[] = trim($v);
|
||||
}
|
||||
return $ls;
|
||||
}
|
||||
|
||||
public static function getAltMessage(null|array|string|MessageSegment $message): string
|
||||
{
|
||||
if ($message === null) {
|
||||
return '';
|
||||
}
|
||||
if (is_string($message)) {
|
||||
return $message;
|
||||
}
|
||||
if ($message instanceof MessageSegment) {
|
||||
$message = [$message];
|
||||
}
|
||||
$message_string = '';
|
||||
foreach ($message as $segment) {
|
||||
if ($segment->type === 'text') {
|
||||
$message_string .= $segment->data['text'];
|
||||
} else {
|
||||
$message_string .= '[富文本:' . $segment->type . ']';
|
||||
}
|
||||
}
|
||||
return $message_string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user