Initial commit
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
const GuildDataIdentityModifiedPacket = require("../Packets/GuildDataIdentityModified");
|
||||
|
||||
const Game = require("../Game/Game");
|
||||
const { players } = Game;
|
||||
|
||||
const constants = require("../Data/constants");
|
||||
const { GUILD_COOLDOWNS } = constants;
|
||||
const { GUILD_COOLDOWN_EDIT_TAG, GUILD_COOLDOWN_EDIT_NAME, GUILD_COOLDOWN_EDIT_DESCRIPTION } = GUILD_COOLDOWNS;
|
||||
|
||||
module.exports = async function (ws, message, player) {
|
||||
if (!player.guild.id) return;
|
||||
|
||||
const memberAuthor = player.guild.getMember(player.id);
|
||||
if (!memberAuthor) return;
|
||||
|
||||
const hasEditIdentitiyPermission = memberAuthor.permission & 8;
|
||||
// if (!hasEditIdentitiyPermission) return;
|
||||
|
||||
const guildTagLength = message.getUint8(1);
|
||||
const guildNameLength = message.getUint8(1 + 1 + guildTagLength);
|
||||
const guildDescriptionLength = message.getUint8(1 + 1 + 1 + guildTagLength + guildNameLength);
|
||||
|
||||
const guildTag = message.buffer.slice(2, 2 + guildTagLength);
|
||||
const guildName = message.buffer.slice(2 + 1 + guildTagLength, 2 + 1 + guildTagLength + guildNameLength);
|
||||
const guildDescription = message.buffer.slice(2 + 1 + 1 + guildTagLength + guildNameLength, 2 + 1 + 1 + guildNameLength + guildTagLength + guildDescriptionLength);
|
||||
|
||||
const guildTagBuffer = Buffer.from(guildTag);
|
||||
const guildNameBuffer = Buffer.from(guildName);
|
||||
const guildDescriptionBuffer = Buffer.from(guildDescription);
|
||||
|
||||
const noww = new Date();
|
||||
const now = noww.getTime();
|
||||
|
||||
const isCooldownOverTag = player.guild.timestamps.tagEditedAt * 1000 + GUILD_COOLDOWN_EDIT_TAG < now;
|
||||
const isCooldownOverName = player.guild.timestamps.nameEditedAt * 1000 + GUILD_COOLDOWN_EDIT_NAME < now;
|
||||
const isCooldownOverDescription = player.guild.timestamps.descriptionEditedAt * 1000 + GUILD_COOLDOWN_EDIT_DESCRIPTION < now;
|
||||
console.info(guildTagLength, guildTagBuffer, player.guild.tag, isCooldownOverTag, isCooldownOverName, isCooldownOverDescription);
|
||||
let queryField = [];
|
||||
let queryArguments = [];
|
||||
|
||||
const r = [0, 0, 0];
|
||||
|
||||
if (guildTagLength
|
||||
&& !guildTagBuffer.equals(player.guild.tag)
|
||||
&& isCooldownOverTag) {
|
||||
queryField.push("tag", "tagEditedAt");
|
||||
queryArguments.push(guildTag, noww);
|
||||
r[0] = 1;
|
||||
|
||||
player.guild.timestamps.tagEditedAt = now / 1000;
|
||||
};
|
||||
|
||||
if (guildNameLength
|
||||
&& !guildNameBuffer.equals(player.guild.name)
|
||||
&& isCooldownOverName) {
|
||||
queryField.push("name", "nameEditedAt");
|
||||
queryArguments.push(guildName, noww);
|
||||
r[1] = 1;
|
||||
|
||||
player.guild.timestamps.nameEditedAt = now / 1000;
|
||||
};
|
||||
|
||||
if (guildDescriptionLength
|
||||
&& !guildDescriptionBuffer.equals(player.guild.description)
|
||||
&& isCooldownOverDescription) {
|
||||
queryField.push("description", "descriptionEditedAt");
|
||||
queryArguments.push(guildDescription, noww);
|
||||
r[2] = 1;
|
||||
|
||||
player.guild.timestamps.descriptionEditedAt = now / 1000;
|
||||
};
|
||||
|
||||
if (!queryArguments.length) return console.info("can't modify anything");
|
||||
|
||||
queryArguments.push(player.guild.id);
|
||||
|
||||
const queryBody = queryField.map(f => `${f} = ?`).join(", ");
|
||||
const guildIdentityEditQuery = await execute(`UPDATE guilds SET ${queryBody} WHERE id = ?`, queryArguments);
|
||||
if (!guildIdentityEditQuery.data) return;
|
||||
|
||||
if (guildIdentityEditQuery.data.changedRows === 1) {
|
||||
player.guild.tag = guildTagBuffer;
|
||||
player.guild.name = guildNameBuffer;
|
||||
player.guild.description = guildDescriptionBuffer;
|
||||
console.info(guildTagBuffer, guildNameBuffer, guildDescriptionBuffer);
|
||||
const guildDataIdentityModified = {
|
||||
r,
|
||||
timestamps: {
|
||||
tagEditedAt: (player.guild.timestamps.tagEditedAt + GUILD_COOLDOWN_EDIT_TAG / 1000),
|
||||
nameEditedAt: (player.guild.timestamps.nameEditedAt + GUILD_COOLDOWN_EDIT_NAME / 1000),
|
||||
descriptionEditedAt: (player.guild.timestamps.descriptionEditedAt + GUILD_COOLDOWN_EDIT_DESCRIPTION / 1000)
|
||||
},
|
||||
bufferTag: guildTagBuffer,
|
||||
bufferName: guildNameBuffer,
|
||||
bufferDescription: guildDescriptionBuffer
|
||||
};
|
||||
|
||||
const topic = Game.getTopic(player.guild.topic);
|
||||
const guildDataIdentityModifiedPacket = GuildDataIdentityModifiedPacket(guildDataIdentityModified);
|
||||
topic.push(guildDataIdentityModifiedPacket);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user