FEAT(灵车 WIP): CHAT SETTINGS

This commit is contained in:
CrescentLeaf
2025-10-08 02:51:58 +08:00
parent aeafcb5b97
commit 0df1149618
4 changed files with 91 additions and 2 deletions

View File

@@ -1,8 +1,41 @@
import chalk from "chalk"
import Chat from "./Chat.ts"
import User from "./User.ts"
import GroupSettingsBean from "./GroupSettingsBean.ts"
class GroupSettings {
declare chat: ChatGroup
declare settings: GroupSettingsBean
constructor(chat: ChatGroup) {
this.chat = chat
this.settings = JSON.parse(chat.bean.settings)
}
update(bean: GroupSettingsBean) {
const updateValue = (key: string) => {
if (key in bean)
this.settings[key] = bean[key]
}
for (const k of [
'allow_new_member_join',
'allow_new_member_from_invitation',
'new_member_join_method',
'answered_and_allowed_by_admin_question',
])
updateValue(k)
this.apply()
}
apply() {
this.chat.setAttr('settings', JSON.stringify(this.settings))
}
}
export default class ChatGroup extends Chat {
getSettings() {
return new GroupSettings(this)
}
static fromChat(chat: Chat) {
return new ChatGroup(chat.bean)
}