default.bot.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. class defaultBot extends xuanBot
  3. {
  4. /**
  5. * 机器人的显示名称
  6. * Display name of this bot.
  7. *
  8. * @var string
  9. * @access public
  10. */
  11. public $name = '默认';
  12. /**
  13. * 机器人的代号
  14. * Bot code.
  15. *
  16. * @var string
  17. * @access public
  18. */
  19. public $code = 'default';
  20. /**
  21. * 机器人的命令列表
  22. * Command list of this bot.
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $commands = array();
  28. /**
  29. * 机器人的帮助信息
  30. * Help message of this bot.
  31. *
  32. * @var string
  33. * @access public
  34. */
  35. public $help = '';
  36. /**
  37. * 构造函数
  38. * Constructor.
  39. *
  40. * @access public
  41. * @return void
  42. */
  43. public function __construct()
  44. {
  45. $this->commands[] = array('command' => 'server', 'alias' => array('服务器', 'serverinfo'), 'description' => 'Get server information.', 'adminOnly' => true);
  46. $this->commands[] = array('command' => 'license', 'alias' => array('授权'), 'description' => 'Get license information.', 'adminOnly' => true);
  47. $this->commands[] = array('command' => 'searchUser', 'alias' => array('sch', 'schuser', 'searchuser', '搜索', '搜索用户', '查看用户'), 'description' => 'Search user with keyword.', 'argsRequired' => true);
  48. }
  49. /**
  50. * 获取服务器信息的命令,仅管理员可以使用
  51. * Get server information.
  52. *
  53. * @param array $args
  54. * @param integer $userID
  55. * @return void
  56. */
  57. public function server($args = array(), $userID = 0)
  58. {
  59. $users = $this->im->userGetList();
  60. $online = 0;
  61. $offline = 0;
  62. foreach($users as $user) $user->clientStatus == 'offline' ? $offline++ : $online++;
  63. $info = array();
  64. $info['PHP Version'] = PHP_VERSION;
  65. $info['PHP OS'] = PHP_OS;
  66. $info['64bit PHP'] = PHP_INT_SIZE === 8 ? 'Yes' : 'No';
  67. $info['PHP Binary dir'] = PHP_BINDIR;
  68. $info['Total Users'] = count($users);
  69. $info['Online Users'] = $online;
  70. $info['Offline Users'] = $offline;
  71. return self::printMarkdownTable(array('Item', 'Value'), $info);
  72. }
  73. /**
  74. * 获取授权信息的示例命令,仅管理员可以使用
  75. * Get license information.
  76. *
  77. * @access public
  78. * @return string
  79. */
  80. public function license()
  81. {
  82. if(!method_exists('commonModel', 'getLicenseProperties')) return $this->im->lang->im->bot->license->noLicense;
  83. $licenseData = commonModel::getLicenseProperties();
  84. if(empty($licenseData)) return $this->im->lang->im->bot->license->noLicense;
  85. $this->im->app->loadLang('license');
  86. $license = array();
  87. $license[$this->im->lang->license->licensedTo] = isset($licenseData['company']) ? $licenseData['company']['value'] : '';
  88. $license['IP'] = isset($licenseData['ip']) ? $licenseData['ip']['value'] : '';
  89. $license['MAC'] = isset($licenseData['mac']) ? $licenseData['mac']['value'] : '';
  90. $license[$this->im->lang->license->userLimit] = isset($licenseData['user']) ? $licenseData['user']['value'] : '';
  91. $license[$this->im->lang->license->expireDate] = isset($licenseData['expireDate']) ? $licenseData['expireDate']['value'] : '';
  92. $license[$this->im->lang->license->startDate] = isset($licenseData['startDate']) ? $licenseData['startDate']['value'] : '';
  93. $license[$this->im->lang->license->permissions] = isset($licenseData['permissions']) ? $licenseData['permissions']['value'] : '';
  94. $license[$this->im->lang->license->conferencePermission] = isset($licenseData['unlimitedParticipants']) ? (empty($licenseData['unlimitedParticipants']['value']) ? sprintf($this->lang->license->conferenceLimited, $licenseData['unlimitedParticipants']['value']) : $this->im->lang->license->unlimited) : '';
  95. return self::printMarkdownTable($this->im->lang->im->bot->license->title, $license);
  96. }
  97. /**
  98. * 搜索用户的命令
  99. * Search for users.
  100. *
  101. * @param array $args
  102. * @access public
  103. * @return string
  104. */
  105. public function searchUser($args = array())
  106. {
  107. $keyword = current($args);
  108. if(empty($keyword)) return $this->im->lang->im->bot->searchUser->keywordRequired;
  109. $users = $this->im->userSearch($keyword);
  110. if(empty($users)) return $this->im->lang->im->bot->searchUser->notFound;
  111. $result = array();
  112. $imUser = $this->im->user;
  113. $depts = $this->im->loadModel('dept')->getDeptPairs();
  114. $deptList = array_map(function($k, $v) {return (object)array('id' => $k, 'name' => $v);}, array_keys($depts), $depts);
  115. $roleList = $this->im->lang->user->roleList;
  116. $this->im->user = $imUser;
  117. foreach($users as $user)
  118. {
  119. $deptsObj = array_filter($deptList, function($dept) use ($user) {return $dept->id == $user->dept;});
  120. $dept = current($deptsObj);
  121. $result[] = array("[{$user->realname}](xxc://showContextMenu/member.profile/{$user->id})", isset($dept->name) ? $dept->name : '', zget($roleList, $user->role, $user->role), empty($user->mobile) ? $user->phone : $user->mobile, $user->email, $this->im->lang->im->userStatus[$user->status]);
  122. }
  123. $this->im->app->loadLang('user');
  124. return self::printMarkdownTable(array($this->im->lang->user->account, $this->im->lang->user->dept, $this->im->lang->user->role, $this->im->lang->user->phone, $this->im->lang->user->email, $this->im->lang->user->clientStatus), $result);
  125. }
  126. }