mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 08:12:04 +02:00
Prevent URL embeds in phone messages
This commit is contained in:
@@ -17,3 +17,4 @@ command-last-run.json
|
||||
*.traineddata
|
||||
|
||||
# In-Development Commands
|
||||
commands/music/
|
||||
|
||||
+2
-1
@@ -73,7 +73,8 @@
|
||||
"text-diff": "^1.0.1",
|
||||
"tictactoe-minimax-ai": "^1.2.1",
|
||||
"valid-url": "^1.0.9",
|
||||
"winston": "^3.3.3"
|
||||
"winston": "^3.3.3",
|
||||
"ytdl-core": "^4.4.5"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"bufferutil": "^4.0.3",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const { stripIndents } = require('common-tags');
|
||||
const moment = require('moment');
|
||||
require('moment-duration-format');
|
||||
const { shorten, stripInvites, verify } = require('../../util/Util');
|
||||
const { shorten, stripInvites, preventURLEmbeds, verify } = require('../../util/Util');
|
||||
|
||||
module.exports = class PhoneCall {
|
||||
constructor(client, startUser, origin, recipient, adminCall) {
|
||||
@@ -133,18 +133,17 @@ module.exports = class PhoneCall {
|
||||
setTimeout(() => this.ratelimitMeters.set(msg.author.id, 0), 5000);
|
||||
}
|
||||
}
|
||||
const attachments = hasImage ? msg.attachments.map(a => a.url).join('\n') : null;
|
||||
const attachments = hasImage ? msg.attachments.map(a => this.cleanContent(a.url)).join('\n') : null;
|
||||
if (!hasText && hasImage) return channel.send(`☎️ **${msg.author.tag}:**\n${attachments}`);
|
||||
if (!hasText && hasEmbed) return channel.send(`☎️ **${msg.author.tag}** sent an embed.`);
|
||||
let content = stripInvites(msg.content);
|
||||
content = content.length > 1000 ? `${shorten(content, 500)} (Message too long)` : content;
|
||||
return channel.send(`☎️ **${msg.author.tag}:** ${content}\n${attachments || ''}`.trim());
|
||||
const content = content.length > 1000 ? `${shorten(content, 500)} (Message too long)` : content;
|
||||
return channel.send(`☎️ **${msg.author.tag}:** ${this.cleanContent(content)}\n${attachments || ''}`.trim());
|
||||
}
|
||||
|
||||
sendVoicemail(channel, msg) {
|
||||
return channel.send(stripIndents`
|
||||
☎️ New Voicemail from **${this.originDM ? `${this.startUser.tag}'s DMs` : this.origin.guild.name}:**
|
||||
**${msg.author.tag}:** ${stripInvites(msg.content)}
|
||||
**${msg.author.tag}:** ${this.cleanContent(msg.content)}
|
||||
`);
|
||||
}
|
||||
|
||||
@@ -157,4 +156,10 @@ module.exports = class PhoneCall {
|
||||
get durationDisplay() {
|
||||
return moment.duration(Date.now() - this.timeStarted).format('hh[h]mm[m]ss[s]');
|
||||
}
|
||||
|
||||
cleanContent(str) {
|
||||
str = stripInvites(str);
|
||||
str = preventURLEmbeds(str);
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -200,6 +200,10 @@ module.exports = class Util {
|
||||
return str;
|
||||
}
|
||||
|
||||
static preventURLEmbeds(str) {
|
||||
return str.replace(/(https?:\/\/\S+)/g, '<$1>');
|
||||
}
|
||||
|
||||
static async reactIfAble(msg, user, emoji, fallbackEmoji) {
|
||||
const dm = !msg.guild;
|
||||
if (fallbackEmoji && (!dm && !msg.channel.permissionsFor(user).has('USE_EXTERNAL_EMOJIS'))) {
|
||||
|
||||
Reference in New Issue
Block a user