Skip to content

Commit

Permalink
Merge pull request #34 from alanfilho184/dev
Browse files Browse the repository at this point in the history
v4.13.2 - Remoção do cache
  • Loading branch information
alanfilho184 authored Aug 12, 2024
2 parents 1203324 + 091d098 commit d445fac
Show file tree
Hide file tree
Showing 38 changed files with 1,507 additions and 1,210 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kami",
"version": "4.13.0",
"version": "4.13.2",
"description": "Um BOT para Discord com foco em ajudar em mesas de RPG online, tendo suas principais funções criar fichas e rolar dados.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gerais/ajuda.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = class ajuda {
}

async execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "geral")
const secret = client.utils.secret(await client.cache.get(int.user.id), "geral")
await int.deferReply({ ephemeral: secret })

const mainHelp = new client.Discord.EmbedBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/gerais/botinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = class botinfo {
}

async execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), 'geral');
const secret = client.utils.secret(await client.cache.get(int.user.id), 'geral');
await int.deferReply({ ephemeral: secret });

const promises = [
Expand All @@ -57,7 +57,7 @@ module.exports = class botinfo {

const ram = stats.memory / 1024 / 1024;

const commands = client.cache.getCount();
const commands = await client.cache.getCount();

var uptime = process.uptime();
var days = Math.floor((uptime % 31536000) / 86400);
Expand Down
26 changes: 13 additions & 13 deletions src/commands/gerais/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = class config {
var botmsg

while (repeat) {
const userConfig = client.cache.get(int.user.id) || {
const userConfig = await client.cache.get(int.user.id) || {
lang: null,
fPadrao: null,
roll: null,
Expand Down Expand Up @@ -122,51 +122,51 @@ module.exports = class config {

if (choice == "rollS") {
if (userConfig.roll == "true") {
await client.cache.update(int.user.id, "false", "roll", false)
await await client.cache.update(int.user.id, "false", "roll", false)
return
}
else {
await client.cache.update(int.user.id, "true", "roll", false)
await await client.cache.update(int.user.id, "true", "roll", false)
return
}
}
else if (choice == "insS") {
if (userConfig.insan == "true") {
await client.cache.update(int.user.id, "false", "insan", false)
await await client.cache.update(int.user.id, "false", "insan", false)
return
}
else {
await client.cache.update(int.user.id, "true", "insan", false)
await await client.cache.update(int.user.id, "true", "insan", false)
return
}
}
else if (choice == "geralS") {
if (userConfig.geral == "true") {
await client.cache.update(int.user.id, "false", "geral", false)
await await client.cache.update(int.user.id, "false", "geral", false)
return
}
else {
await client.cache.update(int.user.id, "true", "geral", false)
await await client.cache.update(int.user.id, "true", "geral", false)
return
}
}
else if (choice == "fichaS") {
if (userConfig.ficha == "true") {
await client.cache.update(int.user.id, "false", "ficha", false)
await await client.cache.update(int.user.id, "false", "ficha", false)
return
}
else {
await client.cache.update(int.user.id, "true", "ficha", false)
await await client.cache.update(int.user.id, "true", "ficha", false)
return
}
}
else if (choice == "enviarS") {
if (userConfig.enviar == "true") {
await client.cache.update(int.user.id, "false", "enviar", false)
await await client.cache.update(int.user.id, "false", "enviar", false)
return
}
else {
await client.cache.update(int.user.id, "true", "enviar", false)
await await client.cache.update(int.user.id, "true", "enviar", false)
return
}
}
Expand All @@ -178,11 +178,11 @@ module.exports = class config {
}
else {
if (interaction.values[0] == "excluir") {
await client.cache.update(int.user.id, null, "fPadrao", false)
await await client.cache.update(int.user.id, null, "fPadrao", false)
return
}
else {
await client.cache.update(int.user.id, interaction.values[0], "fPadrao", false)
await await client.cache.update(int.user.id, interaction.values[0], "fPadrao", false)
return
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/gerais/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = class invite {
}
}

execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "geral")
async execute(client, int) {
const secret = client.utils.secret(await client.cache.get(int.user.id), "geral")
int.deferReply({ ephemeral: secret })
.then(() => {
const inviteEmbed = new client.Discord.EmbedBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/gerais/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ module.exports = class lang {
}
}

execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "geral")
async execute(client, int) {
const secret = client.utils.secret(await client.cache.get(int.user.id), "geral")
int.deferReply({ ephemeral: secret })
.then(async () => {
const local = int.inGuild() ? "server" : "user"
Expand Down
5 changes: 2 additions & 3 deletions src/commands/gerais/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ module.exports = class ping {
run: this.execute
};
}

execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "geral")
async execute(client, int) {
const secret = client.utils.secret(await client.cache.get(int.user.id), "geral")
int.deferReply({ ephemeral: secret })
.then(async () => {

Expand Down
5 changes: 2 additions & 3 deletions src/commands/gerais/termos.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ module.exports = class termos {
run: this.execute
}
}

execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "geral")
async execute(client, int) {
const secret = client.utils.secret(await client.cache.get(int.user.id), "geral")
int.deferReply({ ephemeral: secret })
.then(() => {
const termEmbed = new client.Discord.EmbedBuilder()
Expand Down
5 changes: 2 additions & 3 deletions src/commands/gerais/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ module.exports = class vote {
run: this.execute
}
}

execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "geral")
async execute(client, int) {
const secret = client.utils.secret(await client.cache.get(int.user.id), "geral")
int.deferReply({ ephemeral: secret })
.then(() => {
const voteEmbed = new client.Discord.EmbedBuilder()
Expand Down
8 changes: 4 additions & 4 deletions src/commands/owner/addbl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ module.exports = class addbl {

execute(client, int) {
int.deferReply({ ephemeral: true })
.then(() => {
.then(async () => {
const args = client.utils.args(int)

const banid = args.get("id")
const bans = args.get("bans")
const banAtual = args.get("banatual")
const duracaoBan = args.get("duracaoban")

client.cache.updateBl(banid, { bans: bans, banAtual: banAtual, duracaoBan: time.now().ts + toMs.parse(duracaoBan) })
await client.cache.updateBl(banid, { bans: bans, banAtual: banAtual, duracaoBan: time.now().ts + toMs.parse(duracaoBan) })
.then(bl => {
return int.editReply(bl)
})
})
}

autocomplete(client, int) {
async autocomplete(client, int) {
const options = int.options._hoistedOptions
let BlUser = client.cache.getBl(options[0].value)
let BlUser = await client.cache.getBl(options[0].value)

if (!BlUser) {
BlUser = { id: options[0].value, bans: 0, banAtual: null, duracaoBan: null }
Expand Down
8 changes: 4 additions & 4 deletions src/commands/rpg/add_imagem.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = class adicionar_imagem {
return
}
else {
const fichas = client.cache.getFichasUser(int.user.id)
const fichas = await client.cache.getFichasUser(int.user.id)

const uniqueID = `${Date.now()}`
const menu = new client.Discord.SelectMenuBuilder()
Expand All @@ -87,15 +87,15 @@ module.exports = class adicionar_imagem {

var filter = (interaction) => interaction.user.id === int.user.id && interaction.customId.split("|")[1] === uniqueID
botmsg.awaitMessageComponent({ filter, time: 60000 })
.then((interaction) => {
.then(async (interaction) => {
interaction.deferUpdate()

const nomerpg = interaction.values[0]

client.cache.updateFicha(int.user.id, nomerpg, { imagem: attach.url }, { query: "update" })
await client.cache.updateFicha(int.user.id, nomerpg, { imagem: attach.url }, { query: "update" })
.then(async r => {
client.emit("updateFichaBot", int.user.id, nomerpg)
var infoUIRT = await client.cache.getIrt(int.user.id, nomerpg)
var infoUIRT = await await client.cache.getIrt(int.user.id, nomerpg)

if (infoUIRT != "") {
client.emit("updtFicha", int, { id: int.user.id, nomerpg: nomerpg, irt: infoUIRT })
Expand Down
26 changes: 13 additions & 13 deletions src/commands/rpg/apagar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Ex: **${"/"}apagar RPG_Kami irt**
autocomplete: this.autocomplete
}
}
execute(client, int) {
const secret = client.utils.secret(client.cache.get(int.user.id), "ficha")
async execute(client, int) {
const secret = client.utils.secret(await client.cache.get(int.user.id), "ficha")
int.deferReply({ ephemeral: secret })
.then(() => {
const args = client.utils.args(int)
Expand All @@ -89,10 +89,10 @@ Ex: **${"/"}apagar RPG_Kami irt**
client.db.query(`select * from irt where id = :id and nomerpg = :nomerpg`, {
replacements: { id: int.user.id, nomerpg: nomerpg }
})
.then(irt => {
.then(async irt => {
if (irt[0][0]) {

client.cache.getIrt(int.user.id, nomerpg)
await client.cache.getIrt(int.user.id, nomerpg)
.then(async fichasIrt => {
for (var f of fichasIrt) {
const c = client.channels.cache.get(f.chid)
Expand All @@ -109,7 +109,7 @@ Ex: **${"/"}apagar RPG_Kami irt**
.then(r => {
return int.editReply(client.tl({ local: int.lang + "af-deacIrt", nomerpg: nomerpg }))
})
client.cache.deleteIrt(int.user.id, nomerpg)
await client.cache.deleteIrt(int.user.id, nomerpg)
}
else {
return int.editReply(client.tl({ local: int.lang + "af-irtNF", nomerpg: nomerpg }))
Expand Down Expand Up @@ -143,23 +143,23 @@ Ex: **${"/"}apagar RPG_Kami irt**
client.db.query(`delete from fichas where id = :id and nomerpg = :nomerpg`, {
replacements: { id: int.user.id, nomerpg: nomerpg }
})
.then(() => {
.then(async () => {
client.emit("deleteFichaBot", int.user.id, nomerpg)
client.cache.deleteFicha(int.user.id, nomerpg)
client.cache.deleteFichaUser(int.user.id, nomerpg)
await client.cache.deleteFicha(int.user.id, nomerpg)
await client.cache.deleteFichaUser(int.user.id, nomerpg)

try {
const fPadrao = client.cache.get(int.user.id).fPadrao
const fPadrao = await client.cache.get(int.user.id).fPadrao

if (fPadrao == nomerpg) {
client.cache.update(int.user.id, null, "fPadrao", false)
await client.cache.update(int.user.id, null, "fPadrao", false)
}
}
catch (err) { }

int.editReply({ content: client.tl({ local: int.lang + "af-fApg", nomerpg: nomerpg }), components: [] })
.then(async function () {
client.cache.getIrt(int.user.id, nomerpg)
await client.cache.getIrt(int.user.id, nomerpg)
.then(infoUIRT => {
if (infoUIRT != "") {
client.emit("apgFicha", { id: int.user.id, nomerpg: nomerpg })
Expand Down Expand Up @@ -191,9 +191,9 @@ Ex: **${"/"}apagar RPG_Kami irt**
autocomplete(client, int) {
const options = int.options._hoistedOptions

options.forEach(opt => {
options.forEach(async opt => {
if (opt.name == "sheet_name" && opt.focused) {
const fichasUser = client.cache.getFichasUser(int.user.id)
const fichasUser = await client.cache.getFichasUser(int.user.id)

if (fichasUser.length >= 1) {
const find = client.utils.matchNomeFicha(opt.value, fichasUser)
Expand Down
Loading

0 comments on commit d445fac

Please sign in to comment.