Skip to content

Commit

Permalink
v5.0.1 (#29)
Browse files Browse the repository at this point in the history
This update includes fixes to commands:
* userinfo -> corrected default avatar handling.
* config -> Patch bug where supplying 'next' to the default results in the bot having a fit about json in console, not continuing for user.
* botcontrols -> You can now restart the bot and actually restart it. No more reloading everything but the main bot.js file.

Also including fixes to:
* All events requiring audit log pulling -> Patched bug where fetching audit log data got the wrong user. For instance, for a user deleting their own message, it would show the last user who deleted their message prior.
* ready event -> Patched bug where invite caching causes 429 (ratelimit) errors and possible improper logging of invites.
* verification -> Patched bug where running multiple verification may cause the database to freak out because the primary key was set to serverID and not something like code.
  • Loading branch information
Aisuruneko authored Mar 15, 2022
1 parent df16e2c commit edf32d2
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 81 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This guide will assume you've left `app` in `src` (the way it should be).
| Version | Release Date |
| ------- | ------------ |
| 5.0.0 | 3/10/2022 |
| 5.0.1 | 3/15/2022 |

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
6 changes: 3 additions & 3 deletions src/app/cfg/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const app = {
version: {
major: 5,
minor: 0,
revision: 0,
buildType: "A",
revision: 1,
buildType: "R",
toString: function() {
var major = app.version.major,
minor = app.version.minor,
Expand Down Expand Up @@ -590,4 +590,4 @@ const app = {
]
}

module.exports = app;
module.exports = app;
7 changes: 6 additions & 1 deletion src/app/cmds/General/userinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = {
user.tag = `${user.username}#${user.discriminator}`; // Manually add this so it looks cool

var embed = {
thumbnail: { url: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.${app.functions.isAnimated(user.avatar) ? "gif": "png"}?size=1024` },
title: `${app.config.system.emotes.information} **${user.tag} ${(user.bot ? "*[BOT]*" : "")}**`,
color: (user["accent_color"]) ? user["accent_color"] : app.config.system.embedColors.blue,
fields: [
Expand All @@ -40,6 +39,12 @@ module.exports = {
]
};

if (user.avatar != null)
embed["thumbnail"] = { url: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.${app.functions.isAnimated(user.avatar) ? "gif": "png"}?size=1024` };
else
embed["thumbnail"] = { url: `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png?size=1024` };


if (user.banner != null)
embed["image"] = { url: `https://cdn.discordapp.com/banners/${user.id}/${user.banner}.${app.functions.isAnimated(user.banner) ? "gif": "png"}?size=600` };

Expand Down
8 changes: 4 additions & 4 deletions src/app/cmds/Moderation/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ module.exports = {
msgCollector.stop("cancelled by user");
m.react(app.config.system.emotes.success).catch(err => {});
} else if (m.content == "next") {
var tmpContent = JSON.parse(serverSettings.get("other")[val]) || { msg: defaults[val][msg], channel: null };
var tmpContent = (serverSettings.get("other")[val]) ? JSON.parse(serverSettings.get("other")[val]) || { msg: defaults[val]["msg"], channel: null } : { msg: defaults[val]["msg"], channel: null };
if (tmpContent["msg"]) {
msgCollector.stop("done");
await collectJoinLeaveChannel(val, null);
await collectJoinLeaveChannel(val, tmpContent);
m.react(app.config.system.emotes.success).catch(err => {});
} else m.react(app.config.system.emotes.error).catch(err => {});
} else {
msgCollector.stop("done");
var tmpContent = { msg: m.content || defaults[val][msg], channel: null };
var tmpContent = { msg: m.content || defaults[val]["msg"], channel: null };
await collectJoinLeaveChannel(val, tmpContent);
m.react(app.config.system.emotes.success).catch(err => {});
}
Expand Down Expand Up @@ -432,7 +432,7 @@ module.exports = {
embeds: [{
title: `${app.config.system.emotes.success} Configure ${app.name}`,
color: app.config.system.embedColors.lime,
description: `Woohoo! We're done here!\nYour ${evtType} message & channel are both ready to go!`
description: `Woohoo! We're done here!\nYour ${evtType} message & channel are both ready to go!\n\n\`${evtData["msg"]}\``
}],
components: [],
author: message.author
Expand Down
7 changes: 3 additions & 4 deletions src/app/cmds/Owner/botcontrols.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
title: `${app.config.system.emotes.warning} **${type}**`,
color: app.config.system.embedColors.yellow,
fields: [
{ name: `Are you sure you wish for me to ${type}?`, value: `To confirm, use the buttons.${((type == "Restart") ? "\n*This will not reload the main bot file.*" : "")}` }
{ name: `Are you sure you wish for me to ${type}?`, value: `To confirm, use the buttons.` }
]
}],
components: [row]
Expand All @@ -51,10 +51,9 @@ module.exports = {
}, 1, true, (async() => {
app.logger.debug("SYS", `${app.name} ${actionDoing.toLowerCase()} as of ${new Date()}.`);
if (type == "Restart") {
await process.exitHandler({ app: app, cleanup: true, exit: false }, 0);
try { app.modules.fs.writeFileSync(process.cwd() + "/cache/restart.tmp", msg.channel.id + "-" + msg.id); } catch (Ex) {};
await process.exitHandler({ app: app, cleanup: true, exit: false, restart: true }, 0);

await app.functions.clearCache();
await app.botStart(msg.channel.id + "-" + msg.id);
} else { process.exitHandler({ app: app, cleanup: true, exit: true }, 0); };
}));
denied = false, buttonStuffWaiting = false;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/channelCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = async(app, newChannel) => {

//define channelLog
const channelLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the channel was created.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (channelLog) {
const { executor } = channelLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/channelDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = async(app, oldChannel) => {
if (fetchedLogs) {
//define channelLog
const channelLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the channel was deleted.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (channelLog) {
const { executor } = channelLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/channelUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = async(app, oldChannel, newChannel) => {

//define channelLog
const channelLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the channel was updated.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (channelLog) {
const { executor } = channelLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/emojiCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = async(app, newEmoji) => {

//define emojiLog
const emojiLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the emoji was created.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (emojiLog) {
const { executor } = emojiLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/emojiDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = async(app, oldEmoji) => {

//define emojiLog
const emojiLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the emoji was created.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (emojiLog) {
const { executor } = emojiLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/emojiUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = async(app, oldEmoji, newEmoji) => {

//define emojiLog
const emojiLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the emoji was updated.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (emojiLog) {
const { executor } = emojiLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/guildBanAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = async(app, ban) => {

//define banLog
const banLog = fetchedLogs.entries.find(entry => { // To avoid false positives, we look for a timeframe of when the ban was created, and if the user banned is the correct entry.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
});
if (banLog) {
const { executor } = banLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/guildBanRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = async(app, ban) => {

//define banLog
const banLog = fetchedLogs.entries.find(entry => { // To avoid false positives, we look for a timeframe of when the ban was created, and if the user banned is the correct entry.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
});
if (banLog) {
const { executor } = banLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/guildMemberRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = async(app, oldMember) => {

//define kickLog
const kickLog = fetchedLogs.entries.find(entry => { // To avoid false positives, we look for a timeframe of when the ban was created, and if the user banned is the correct entry.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
});
if (kickLog) {
const { executor } = kickLog;
Expand Down
4 changes: 2 additions & 2 deletions src/app/evts/guildMemberUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = async(app, oldMember, newMember) => {
else if (oldMember.roles.cache.size < newMember.roles.cache.size) embed.fields.push({ name: "Roles Added", value: roleUpdated.join(", ") || "Failed to get roles added" }); // ooo features
};

if (!embed.fields.length > 3) return; // Since we aren't subscribing to all updates, stop here if it was something else non-related to what we have.
if (embed.fields.length < 3) return; // Since we aren't subscribing to all updates, stop here if it was something else non-related to what we have.

embed.fields.push({ name: "Updated At", value: new Date().toString() })

Expand All @@ -53,7 +53,7 @@ module.exports = async(app, oldMember, newMember) => {

//define memberLog
const memberLog = fetchedLogs.entries.filter(e => e.action === "MEMBER_UPDATE" || e.action === "MEMBER_ROLE_UPDATE").find(entry => // To avoid false positives, we look for a timeframe of when the member was updated.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (memberLog) {
const { executor } = memberLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/guildUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = async(app, oldGuild, newGuild) => {

//define guildLog
const guildLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the guild was updated.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (guildLog) {
const { executor } = guildLog;
Expand Down
4 changes: 2 additions & 2 deletions src/app/evts/messageDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ module.exports = async(app, message) => {
}).catch(err => {});
if (fetchedLogs) {
const deleteLog = fetchedLogs.entries.find(entry => // To avoid false positives, we sort by message author, message channel, and a timeframe of when the message was deleted.
(message.author) ? entry.executor.id !== message.author.id : true &&
((message.author) ? entry.executor.id !== message.author.id : true) &&
entry.extra.channel.id === message.channel.id &&
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (deleteLog) { // If none, we may be missing permissions to fetch audit log.
const { executor } = deleteLog;
Expand Down
37 changes: 27 additions & 10 deletions src/app/evts/ready.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = (app) => {
if (!app.client) return app.logger.error("SYS", "CLIENT IS NOT READY YET!!");

app.config["tokendata"] = undefined; // This makes it so no crazy people can find the token (tho, the only way is through eval and uh.. you should keep that to yourself..)
// app.client.connections.success = true;
// clearInterval(client.connections.updateTime);
Expand Down Expand Up @@ -41,7 +43,7 @@ module.exports = (app) => {

setTimeout(async function() {
// Reaction Roles
app.logger.info("DISCORD", `Initializing Reaction Roles...`);
if (app.client.isReady()) app.logger.info("DISCORD", `Initializing Reaction Roles...`);
var serverSettings = await app.DBs.serverSettings.findAll({ where: {}, raw: true }); // WARNING: Do not expose this variable.
for (server in serverSettings) {
server = serverSettings[server];
Expand Down Expand Up @@ -78,25 +80,40 @@ module.exports = (app) => {

// Cache invites
app.logger.info("DISCORD", `Caching all invites of ${app.client.guilds.cache.size} servers...`);
var inviteCount = 0;
await app.client.guilds.cache.forEach(async guild => {
try {
if (!guild) return;
if (guild.partial) await guild.fetch().catch(err => app.logger.error("DISCORD", "Something went wrong while fetching the guild " + guild.id + " | " + err.message));

var inviteCount = 0,
serverCount = 0,
done = false,
guilds = Array.from(app.client.guilds.cache.keys());

for (var i = 0; i < guilds.length; i++) {
const guild = app.client.guilds.cache.get(guilds[i]);

// check guild existence, etc.
if (!guild) break;
if (guild.partial) await guild.fetch().catch(err => app.logger.error("DISCORD", "Something went wrong while fetching the guild " + guild.id + " | " + err.message));

if (i != 0 && (i % 15) == 0)
await app.functions.sleep(1500);

// try to get invites
try {
const firstInvites = await guild.invites.fetch();
app.client.guildInvites.set(guild.id, new Map(firstInvites.map((invite) => [invite.code, invite.uses])));
app.logger.debug("DISCORD", `Cached ${firstInvites.size} invites from ${guild.id}.`);
inviteCount += firstInvites.size;
serverCount = (serverCount + 1);
} catch (err) {
if (err.code !== app.modules["discord.js"].Constants.APIErrors.MISSING_PERMISSIONS) {
app.logger.error("DISCORD", `Failed to cache invites for ${guild.name} (${guild.id}) | ${err.message}.`);
};
return;
} finally {
if ((i + 1) === guilds.length)
done = true;
};
});
setTimeout(async function() { app.logger.success("DISCORD", `Cached ${inviteCount} invites from ${app.client.guildInvites.size} servers.`); }, (app.client.guilds.cache.size / 2) * 100);

};
while (!done) await app.functions.sleep(1500);
app.logger.success("DISCORD", `Cached ${inviteCount} invites from ${((serverCount == app.client.guilds.cache.size) ? serverCount : serverCount + "/" + app.client.guilds.cache.size)} servers.`);
}, 3500); // Wait an addition 3.5 seconds
}, 2000);

Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/roleCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = async(app, newRole) => {

//define roleLog
const roleLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the role was created.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (roleLog) {
const { executor } = roleLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/roleDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = async(app, oldRole) => {

//define roleLog
const roleLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the role was deleted.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (roleLog) {
const { executor } = roleLog;
Expand Down
2 changes: 1 addition & 1 deletion src/app/evts/roleUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = async(app, oldRole, newRole) => {

//define roleLog
const roleLog = fetchedLogs.entries.find(entry => // To avoid false positives, we look for a timeframe of when the role was updated.
Date.now() - entry.createdTimestamp < 20000
Date.now() - entry.createdTimestamp < 5000
);
if (roleLog) {
const { executor } = roleLog;
Expand Down
11 changes: 8 additions & 3 deletions src/app/functions/bootloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,21 @@ class BootLoader {
verification: app.db.define('verification', {
serverID: { // The executing server
type: Sequelize.STRING,
primaryKey: true
defaultValue: null,
unique: false
},
userID: { // The executing user
type: Sequelize.STRING,
defaultValue: null,
allowNull: true
allowNull: true,
unique: true,
primaryKey: true

},
messageID: { // Allows us to edit the same message (if in a server)
type: Sequelize.STRING,
defaultValue: null,
unique: true,
allowNull: true
},
userCode: { // The code generated
Expand Down Expand Up @@ -329,4 +334,4 @@ class BootLoader {
}


module.exports = BootLoader;
module.exports = BootLoader;
Loading

0 comments on commit edf32d2

Please sign in to comment.