Open DJWoodZ opened 9 months ago
Hope you don't mind, DJ, I ended up working with AI for a bit and came up with a way to not show the time played if it was over an hour, just to keep people from being embarrassed at how much they played. :-)
Not saying this is the best code, but it worked for me and added a little personalization while I was in there.
Just a bit of surgery in the /bin/server.js file.
// notify of each new join
if (data.timestamp >= initTime && (process.env.SATISFACTORY_BOT_IGNORE_POLL_STATE_WHEN_MESSAGING !== 'false' || db?.server?.online)) {
const onlinePlayers = getOnlinePlayers(db);
let string = `:meow_party: **${onlinePlayers.length}** of ${process.env.SATISFACTORY_BOT_SERVER_MAX_PLAYERS} players online${(onlinePlayers.length > 0 ? `: **${formatPlayers(onlinePlayers)}**` : '')} (${getTimestamp()}).\n`;
// Inline random message selection for join message
const joinMessage = Math.floor(Math.random() * 3) === 0
? `:lando: **${data.name}** just joined the server. Work it, girl!`
: Math.floor(Math.random() * 3) === 1
? `:bobross: Hey, why don't you jump in The Fattest Sacktory! **${data.name}** just did!`
: `:yellingderp: **${data.name}** just entered the factory. You should join him! Maybe chat in #shenanigans!? It'll be fun!`;
string += joinMessage;
sendMessage(string);
if (db?.server?.online) {
client.user.setActivity(`online: ${getOnlinePlayers(db).length}/${process.env.SATISFACTORY_BOT_SERVER_MAX_PLAYERS}`);
}
}
}
break;
case 'Connection close':
// if the player is in database
console.log('Connection close', data.userId);
if (invalidUnknownNamesAndIds.includes(data.userId)) {
if (data.timestamp >= initTime && (process.env.SATISFACTORY_BOT_IGNORE_POLL_STATE_WHEN_MESSAGING !== 'false' || db?.server?.online)) {
sendMessage(`:information_source: An **${formatList(invalidUnknownNamesAndIds)}** connection was closed.`);
}
} else if (getPlayerFromDB(data.userId)) {
// delete
leftPlayerName = getPlayerFromDB(data.userId).name;
leftPlayerJoinTime = getPlayerFromDB(data.userId).joinTime;
delete db.players[data.userId];
// notify of each leave
if (data.timestamp >= initTime && (process.env.SATISFACTORY_BOT_IGNORE_POLL_STATE_WHEN_MESSAGING !== 'false' || db?.server?.online)) {
const onlinePlayers = getOnlinePlayers(db);
const playTimeInMinutes = Math.round((new Date().getTime() - leftPlayerJoinTime) / 60000);
let string = `:meow_party: **${onlinePlayers.length}** of ${process.env.SATISFACTORY_BOT_SERVER_MAX_PLAYERS} players online${(onlinePlayers.length > 0 ? `: **${formatPlayers(onlinePlayers)}**` : '')} (${getTimestamp()}).\n`;
// Inline random message selection based on playtime
const leaveMessage = playTimeInMinutes <= 60
? (Math.floor(Math.random() * 3) === 0
? `:checkers: **${leftPlayerName}** had real life get in the way and left the Factory after playing for **${formatMinutes(playTimeInMinutes)}**.`
: Math.floor(Math.random() * 3) === 1
? `:checkers: **${leftPlayerName}** finished barricading an offline player, which took just **${formatMinutes(playTimeInMinutes)}**.`
: `:checkers: It only took **${formatMinutes(playTimeInMinutes)}** for **${leftPlayerName}** to get bored and leave.`)
: (Math.floor(Math.random() * 3) === 0
? `:checkers: **${leftPlayerName}** finally finished doing "one more thing" and left after an epic session.`
: Math.floor(Math.random() * 3) === 1
? `:checkers: **${leftPlayerName}** would rather not admit how long they played and finally left.`
: `:checkers: **${leftPlayerName}** might have fallen asleep while playing because they just logged off after a marathon session.`);
string += leaveMessage;
sendMessage(string);
if (db?.server?.online) {
client.user.setActivity(`online: ${getOnlinePlayers(db).length}/${process.env.SATISFACTORY_BOT_SERVER_MAX_PLAYERS}`);
}
}
Suggested in #27.