Ensure channel & user data is updated every run

This commit is contained in:
chylex 2020-06-25 15:20:04 +02:00
parent e298853518
commit 1992bf6b22
2 changed files with 36 additions and 31 deletions

View File

@ -34,6 +34,7 @@ avatar
author
type
state
name
position
topic
nsfw

View File

@ -108,19 +108,21 @@ class SAVEFILE{
}
findOrRegisterUser(userId, userName, userDiscriminator, userAvatar){
if (!(userId in this.meta.users)){
this.meta.users[userId] = {
"name": userName
};
if (userDiscriminator){
this.meta.users[userId].tag = userDiscriminator;
}
if (userAvatar){
this.meta.users[userId].avatar = userAvatar;
}
var wasPresent = userId in this.meta.users;
var userObj = wasPresent ? this.meta.users[userId] : {};
userObj.name = userName;
if (userDiscriminator){
userObj.tag = userDiscriminator;
}
if (userAvatar){
userObj.avatar = userAvatar;
}
if (!wasPresent){
this.meta.users[userId] = userObj;
this.meta.userindex.push(userId);
return this.tmp.userlookup[userId] = this.meta.userindex.length-1;
}
@ -152,27 +154,29 @@ class SAVEFILE{
if (!this.meta.servers[serverIndex]){
return undefined;
}
else if (channelId in this.meta.channels){
var wasPresent = channelId in this.meta.channels;
var channelObj = wasPresent ? this.meta.channels[channelId] : { "server": serverIndex };
channelObj.name = channelName;
if (extraInfo.position){
channelObj.position = extraInfo.position;
}
if (extraInfo.topic){
channelObj.topic = extraInfo.topic;
}
if (extraInfo.nsfw){
channelObj.nsfw = extraInfo.nsfw;
}
if (wasPresent){
return false;
}
else{
this.meta.channels[channelId] = {
"server": serverIndex,
"name": channelName
};
if (extraInfo.position){
this.meta.channels[channelId].position = extraInfo.position;
}
if (extraInfo.topic){
this.meta.channels[channelId].topic = extraInfo.topic;
}
if (extraInfo.nsfw){
this.meta.channels[channelId].nsfw = extraInfo.nsfw;
}
this.meta.channels[channelId] = channelObj;
this.tmp.channelkeys.add(channelId);
return true;
}