FEAT(灵车 WIP): CHAT SETTINGS
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
10
server/data/GroupSettingsBean.ts
Normal file
10
server/data/GroupSettingsBean.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
interface GroupSettingsBean {
|
||||
allow_new_member_join?: boolean
|
||||
allow_new_member_from_invitation?: boolean
|
||||
new_member_join_method?: 'disabled' | 'allowed_by_admin' | 'answered_and_allowed_by_admin'
|
||||
answered_and_allowed_by_admin_question?: string
|
||||
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export default GroupSettingsBean
|
||||
Reference in New Issue
Block a user