BxDolAIToolCmtsUpdate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. use NeuronAI\Tools\PropertyType;
  10. use NeuronAI\Tools\ToolProperty;
  11. class BxDolAIToolCmtsUpdate extends BxDolAITool
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct(
  16. 'comments_update',
  17. 'Use this tool to change comments.',
  18. );
  19. }
  20. protected function properties(): array
  21. {
  22. return [
  23. new ToolProperty(
  24. name: 'module',
  25. type: PropertyType::STRING,
  26. description: 'The module name to perform content changes on. Use "system" for site accounts. ',
  27. required: true
  28. ),
  29. new ToolProperty(
  30. name: 'content_id',
  31. type: PropertyType::INTEGER,
  32. description: 'Content ID to post comments for.',
  33. required: true
  34. ),
  35. new ToolProperty(
  36. name: 'comment_text',
  37. type: PropertyType::STRING,
  38. description: 'New comments text, in HTML format.',
  39. required: true
  40. ),
  41. new ToolProperty(
  42. name: 'comment_id',
  43. type: PropertyType::INTEGER,
  44. description: 'Comment ID to update.',
  45. required: true
  46. ),
  47. ];
  48. }
  49. public function __invoke(string $module, int $content_id, string $comment_text, int $comment_id): array
  50. {
  51. $a = [];
  52. $o = BxDolCmts::getObjectInstance($module, $content_id);
  53. if ($o) {
  54. $a = $o->edit(['cmt_text' => $comment_text], $comment_id);
  55. unset($a['content']);
  56. }
  57. else {
  58. $a = ['msg' => '_sys_txt_not_found', 'code' => 404];
  59. }
  60. return $a;
  61. }
  62. }