Hotfix 1# - fixed unsafe message sending, fixed fallbackchannel cache and a few silly bugs

This commit is contained in:
Ben
2020-08-05 16:04:34 +01:00
parent e56d3b9092
commit df2cb2fa39
4 changed files with 51 additions and 32 deletions

View File

@@ -76,7 +76,7 @@ module.exports.newMessage = async function(message)
command.callback(message, args);
return;
}
Discord.bot.createMessage(message.channel.id, 'The `administrator` privaledge is required to execute that command');
DiscordHelpers.SendMessageSafe(message.channel.id, 'The `administrator` privaledge is required to execute that command');
return;
}
command.callback(message, args);
@@ -123,8 +123,8 @@ async function InitializeGuild(message, args)
Database.UpdateGuildLogChannel(guild.id, message.channel.id);
}
Discord.bot.createMessage(message.channel.id, 'Server successfully initialized, the fallback events channel has been set to this channel, you can change this at any time with *setfallbackchannel');
Discord.bot.createMessage(message.channel.id, 'By using Logori 2.0, You agree to the private policy clearly outlined at https://logori.xyz/privatepolicy and it is your responsibility as guild administrators to inform members of data collection - as this is a logging bot');
DiscordHelpers.SendMessageSafe(message.channel.id, 'Server successfully initialized, the fallback events channel has been set to this channel, you can change this at any time with *setfallbackchannel');
DiscordHelpers.SendMessageSafe(message.channel.id, 'By using Logori 2.0, You agree to the private policy clearly outlined at https://logori.xyz/privatepolicy and it is your responsibility as guild administrators to inform members of data collection - as this is a logging bot');
}
@@ -132,7 +132,7 @@ async function SetPrefix(message, args)
{
if (!args[0])
{
Discord.bot.createMessage(message.channel.id, 'You must provide a new prefix');
DiscordHelpers.SendMessageSafe(message.channel.id, 'You must provide a new prefix');
return;
}
@@ -143,17 +143,17 @@ async function SetPrefix(message, args)
// Update cache
GuildsAndPrefixs[message.guildID] = NewPrefix;
Discord.bot.createMessage(message.channel.id, `New prefix for guild : \`${NewPrefix}\``)
DiscordHelpers.SendMessageSafe(message.channel.id, `New prefix for guild : \`${NewPrefix}\``);
}
async function SetLogChannel(message, args)
{
Database.UpdateGuildLogChannel(guild.id, message.channel.id);
Discord.bot.createMessage(message.channel.id, 'Logging fallback channel set to this channel');
DiscordHelpers.SendMessageSafe(message.channel.id, 'Logging fallback channel set to this channel');
}
async function MeCommand(message, args)
{
Discord.bot.createMessage(message.channel.id, `All of your data can be accessed here: https://logori.xyz/api/v1/user/${message.author.id}`);
DiscordHelpers.SendMessageSafe(message.channel.id, `All of your data can be accessed here: https://logori.xyz/api/v1/user/${message.author.id}`);
}

View File

@@ -102,17 +102,19 @@ const INTEGRATION_DELETE = 82;
// Handlers / Helpers
// TODO: this should cache properly
async function GetLogChannel(guildID)
{
// if there's aready a fallback channel - need to add a clause to update
// this if the guild's log channel is changed during runtime which is likely
if (GuildsAndLogChannels[guildID] != -1) return GuildsAndLogChannels[guildID];
// if there's no log channel check if the database has been updated
if (GuildsAndLogChannels[guildID] == -1)
{
const guild = await Database.FetchGuild(guildID);
return guild == -1 ? -1 : guild.logchannel;
}
// if (GuildsAndLogChannels[guildID] != -1) return GuildsAndLogChannels[guildID];
// // if there's no log channel check if the database has been updated
// if (GuildsAndLogChannels[guildID] == -1)
// {
// }
const guild = await Database.FetchGuild(guildID);
return guild == -1 ? -1 : guild.logchannel;
}
function BuildObjDiff(before, after) {
@@ -226,7 +228,7 @@ async function ChannelCreate(channel)
footer: { text: `ID: ${channel.id}` }
});
Discord.bot.createMessage(FallbackChannel, {embed: embed.sendable});
DiscordHelpers.SendMessageSafe(FallbackChannel, {embed: embed.sendable});
}
@@ -250,7 +252,7 @@ async function ChannelDelete(channel)
footer: { text: `ID: ${channel.id}` }
});
Discord.bot.createMessage(FallbackChannel, {embed: embed.sendable});
DiscordHelpers.SendMessageSafe(FallbackChannel, {embed: embed.sendable});
}
async function ChannelPinUpdate(channel, timestamp, oldtimestamp)
@@ -272,13 +274,13 @@ async function ChannelPinUpdate(channel, timestamp, oldtimestamp)
{ name: 'Author', value: LatestPin.author.mention, inline: true },
{ name: 'Content', value: LatestPin.content ? LatestPin.content : "Blank Message", inline: false }
],
colour: '#42A832',
colour: ColourConvert('#42A832'),
url: 'https://logori.xyz',
timestamp: new Date(timestamp),
footer: { text: `ID: ${LatestPin.id}` }
});
Discord.bot.createMessage(FallbackChannel, {embed: embed.sendable});
DiscordHelpers.SendMessageSafe(FallbackChannel, {embed: embed.sendable});
} else
{
let embed = new DiscordEmbed({
@@ -292,7 +294,7 @@ async function ChannelPinUpdate(channel, timestamp, oldtimestamp)
footer: { text: `ID: ${LatestPin.id}` }
});
Discord.bot.createMessage(FallbackChannel, {embed: embed.sendable});
DiscordHelpers.SendMessageSafe(FallbackChannel, {embed: embed.sendable});
}
}
@@ -348,7 +350,7 @@ async function ChannelUpdate(channel, oldchannel)
embed.field('Channel', channel.mention, true);
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
}
if (channel.permissionOverwrites != oldchannel.permissionOverwrites)
@@ -385,7 +387,7 @@ async function ChannelUpdate(channel, oldchannel)
footer: { text: `ID: ${channel.id}` }
});
Discord.bot.createMessage(FallbackChannel, {embed: embed.sendable});
DiscordHelpers.SendMessageSafe(FallbackChannel, {embed: embed.sendable});
return;
}
// Role overwrite removed
@@ -408,7 +410,7 @@ async function ChannelUpdate(channel, oldchannel)
footer: { text: `ID: ${channel.id}` }
});
Discord.bot.createMessage(FallbackChannel, {embed: embed.sendable});
DiscordHelpers.SendMessageSafe(FallbackChannel, {embed: embed.sendable});
return;
}
@@ -420,7 +422,7 @@ async function ChannelUpdate(channel, oldchannel)
}
} else if (Type == voice)
} else if (Type == 'Voice')
{
}
@@ -460,7 +462,7 @@ async function GuildBanAdd(guild, user)
**Responsible Moderator**: ${Banner.mention}
**Reason**: ${BanReason}`, false);
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
}
async function GuildBanRemove(guild, user)
@@ -493,7 +495,7 @@ async function GuildBanRemove(guild, user)
embed.field('', `**Name**: ${user.mention}
**Responsible Moderator**: ${Banner.mention}`, false);
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
}
async function GuildEmojisUpdate(guild, emojis, oldemojis)
@@ -563,7 +565,7 @@ async function GuildMemberAdd(guild, member)
// embed.field('', `${member.mention} is ${AddOrdinalSuffix(DiscordHelpers.GetMemberJoinPos(member.id, guild))} to join`);
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
}
async function GuildMemberRemove(guild, member)
@@ -586,9 +588,10 @@ async function GuildMemberRemove(guild, member)
embed.field('', `**Member:** ${member.mention}`);
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
}
// FIXME: this is broken af lmao
async function MessageDelete(message)
{
// Logger.debug(JSON.stringify(message, null, 4));
@@ -618,13 +621,12 @@ async function MessageDelete(message)
**Responsible Moderator**: ${LastAuditEntry.user.mention}
**Channel:** ${message.channel.mention}
**Message Content:** ${DeletedMessage.content} `);
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
} catch (e)
{
Logger.warn('The stupid messagedelete function messed up again');
}
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
}
async function MessageUpdate(message, oldmessage)
@@ -652,5 +654,5 @@ async function MessageUpdate(message, oldmessage)
**Old Message:**: ${oldmessage.content}
**New Message:**: ${message.content}`);
Discord.bot.createMessage(FallbackChannel, { embed: embed.sendable });
DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable });
}

View File

@@ -1,3 +1,5 @@
const Discord = require('./discord.js');
const Logger = require('./logger.js');
module.exports.IsMemberAdmin = (member) => member.permission.has('administrator') || member.id == process.env.BOT_OWNER;
module.exports.GetGuildCatatory = (guild, catid) => guild.channels.find(c => c.id == catid);
@@ -12,4 +14,13 @@ module.exports.GetMemberJoinPos = (memberid, guild) =>
if (arr[i].id == memberid) return i; // When you find the user, return it's position
}
}
module.exports.SendMessageSafe = async (channelid, message) =>
{
// TODO: make this an actual check instead of a guess
try {
Discord.bot.createMessage(channelid, message);
} catch (e)
{
Logger.warn(`Unable to send message in channel ${channelid}`);
}
}

View File

@@ -32,6 +32,12 @@ module.exports.setup = async function()
this.bot.editStatus('online', {name: game, type: type});
// let array = await this.bot.getMessages('346104470901358595', 20)
// for (message of array)
// {
// console.log(`${message.author.username}#${message.author.discriminator}: ${message.content}`);
// }
});
// settup events