mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 08:35:35 +08:00
更新下一个大版本,基本上算是重写了一遍吧~
This commit is contained in:
105
src/cqbot/item/Group.php
Normal file
105
src/cqbot/item/Group.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: jerry
|
||||
* Date: 2018/5/2
|
||||
* Time: 下午1:59
|
||||
*/
|
||||
|
||||
class Group
|
||||
{
|
||||
private $group_id;
|
||||
private $group_name;
|
||||
private $prefix;
|
||||
private $members = [];
|
||||
|
||||
public function __construct($group_id, $info) {
|
||||
$this->group_id = $group_id;
|
||||
$this->group_name = $info["group_name"];
|
||||
$this->prefix = $info["prefix"];
|
||||
$member_list = $info["member"];
|
||||
$this->members = [];
|
||||
foreach ($member_list as $k => $v) {
|
||||
$this->members[$v["user_id"]] = new GroupMember($v["user_id"], $this, $v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGroupId() {
|
||||
return $this->group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGroupName() {
|
||||
return $this->group_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPrefix() {
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMembers(): array {
|
||||
return $this->members;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @return GroupMember|null
|
||||
*/
|
||||
public function getMember($user_id) {
|
||||
return isset($this->members[$user_id]) ? $this->members[$user_id] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $group_name
|
||||
*/
|
||||
public function setGroupName($group_name) {
|
||||
$this->group_name = $group_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* set自定义群称号的方法
|
||||
* @param mixed $prefix
|
||||
*/
|
||||
public function setPrefix($prefix) {
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* set群成员的类
|
||||
* @param array $members
|
||||
*/
|
||||
public function setMembers(array $members) {
|
||||
$this->members = $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* set群成员的类
|
||||
* @param $user_id
|
||||
* @param GroupMember $member
|
||||
*/
|
||||
public function setMember($user_id, GroupMember $member) {
|
||||
$this->members[$user_id] = $member;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新群信息
|
||||
* @param bool $with_members
|
||||
*/
|
||||
public function updateData($with_members = false) {
|
||||
CQUtil::sendAPI(["action" => "get_group_list"], ["update_group_info", $this->getGroupId()]);
|
||||
if ($with_members) {
|
||||
CQUtil::sendAPI(["action" => "get_group_member_list", "params" => ["group_id" => $this->getGroupId()]], ["update_group_member_list", strval($this->getGroupId())]);
|
||||
}
|
||||
}
|
||||
}
|
||||
138
src/cqbot/item/GroupMember.php
Normal file
138
src/cqbot/item/GroupMember.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: jerry
|
||||
* Date: 2018/5/2
|
||||
* Time: 下午2:43
|
||||
*/
|
||||
|
||||
class GroupMember extends User
|
||||
{
|
||||
private $group = 0;
|
||||
private $card = "";
|
||||
private $join_time = 0;
|
||||
private $last_sent_time = 0;
|
||||
private $role = "member";
|
||||
private $attribute = [];
|
||||
|
||||
public function __construct($qid, Group $group, $data) {
|
||||
parent::__construct($qid);
|
||||
$this->group = $group;
|
||||
$this->card = $data["card"];
|
||||
$this->join_time = $data["join_time"];
|
||||
$this->last_sent_time = $data["last_sent_time"];
|
||||
$this->role = $data["role"];
|
||||
$this->attribute = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Group
|
||||
*/
|
||||
public function getGroup(): Group {
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCard() {
|
||||
return $this->card;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJoinTime() {
|
||||
return $this->join_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLastSentTime() {
|
||||
return $this->last_sent_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回角色
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRole() {
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回用户是不是群管理员
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdmin(){
|
||||
return in_array($this->getRole(), ["owner", "admin"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $card
|
||||
*/
|
||||
public function setCard(string $card) {
|
||||
$this->card = $card;
|
||||
$data = [
|
||||
"action" => "set_group_card",
|
||||
"params" => [
|
||||
"group_id" => $this->getGroup()->getGroupId(),
|
||||
"user_id" => $this->getId(),
|
||||
"card" => $card
|
||||
]
|
||||
];
|
||||
CQUtil::sendAPI($data, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $join_time
|
||||
*/
|
||||
public function setJoinTime(int $join_time) {
|
||||
$this->join_time = $join_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $last_sent_time
|
||||
*/
|
||||
public function setLastSentTime(int $last_sent_time) {
|
||||
$this->last_sent_time = $last_sent_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*/
|
||||
public function setRole(string $role) {
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAttribute(): array {
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attribute
|
||||
*/
|
||||
public function setAttribute(array $attribute) {
|
||||
$this->attribute = $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新群组成员信息
|
||||
*/
|
||||
public function updateData(){
|
||||
$user_id = $this->getId();
|
||||
CQUtil::sendAPI([
|
||||
"action" => "get_group_member_info",
|
||||
"params" => [
|
||||
"group_id" => $this->getGroup()->getGroupId(),
|
||||
"user_id" => $user_id,
|
||||
"no_cache" => true
|
||||
]
|
||||
], ["update_group_member_info", $this->getGroup()->getGroupId(), $user_id]);
|
||||
}
|
||||
|
||||
}
|
||||
78
src/cqbot/item/User.php
Executable file
78
src/cqbot/item/User.php
Executable file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: jerry
|
||||
* Date: 2018/4/14
|
||||
* Time: 13:29
|
||||
*/
|
||||
|
||||
use DataProvider as DP;
|
||||
|
||||
class User
|
||||
{
|
||||
private $id;
|
||||
private $word_status = [];
|
||||
private $permission;
|
||||
private $is_friend = false;
|
||||
|
||||
private $buffer = null;
|
||||
|
||||
public function __construct($qid){
|
||||
$this->id = $qid;
|
||||
$this->permission = DP::getJsonData("permissions.json")[$qid] ?? 0;
|
||||
$this->is_friend = isset(Buffer::get("friend_list")[$qid]) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户QQ号
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId(){ return $this->id; }
|
||||
|
||||
/**
|
||||
* 获取用户添加词库的状态
|
||||
* @return array
|
||||
*/
|
||||
public function getWordStatus() : array{ return $this->word_status; }
|
||||
|
||||
/**
|
||||
* 获取用户权限值
|
||||
* @return int
|
||||
*/
|
||||
public function getPermission() : int{ return $this->permission; }
|
||||
|
||||
/**
|
||||
* @param array $word_status
|
||||
* @return User
|
||||
*/
|
||||
public function setWordStatus(array $word_status): User{
|
||||
$this->word_status = $word_status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $permission
|
||||
* @return User
|
||||
*/
|
||||
public function setPermission(int $permission): User{
|
||||
$this->permission = $permission;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 和用户是否是好友//TODO功能
|
||||
* @return bool
|
||||
*/
|
||||
public function isFriend(): bool{
|
||||
return $this->is_friend;
|
||||
}
|
||||
|
||||
public function getBuffer(){
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
public function setBuffer($buffer){
|
||||
$this->buffer = $buffer;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user