Include user discriminators in savefile (#55)

Co-authored-by: chylex <contact@chylex.com>
This commit is contained in:
X. Cinera 2020-06-24 08:51:31 -07:00 committed by GitHub
parent e9679c616f
commit 7fb479a1b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -27,11 +27,14 @@ a
t
d
te
tag
author
type
state
id
username
bot
discriminator
timestamp
content
editedTimestamp

View File

@ -6,7 +6,8 @@
* meta: {
* users: {
* <discord user id>: {
* name: <user name>
* name: <user name>,
* tag: <user discriminator> // only present if not a bot
* }, ...
* },
*
@ -102,12 +103,16 @@ class SAVEFILE{
return parsedObj && typeof parsedObj.meta === "object" && typeof parsedObj.data === "object";
}
findOrRegisterUser(userId, userName){
findOrRegisterUser(userId, userName, userDiscriminator){
if (!(userId in this.meta.users)){
this.meta.users[userId] = {
"name": userName
};
if (userDiscriminator){
this.meta.users[userId].tag = userDiscriminator;
}
this.meta.userindex.push(userId);
return this.tmp.userlookup[userId] = this.meta.userindex.length-1;
}
@ -163,8 +168,10 @@ class SAVEFILE{
}
convertToMessageObject(discordMessage){
var author = discordMessage.author;
var obj = {
u: this.findOrRegisterUser(discordMessage.author.id, discordMessage.author.username),
u: this.findOrRegisterUser(author.id, author.username, author.bot ? null : author.discriminator),
t: discordMessage.timestamp.toDate().getTime()
};