Skip to content

Commit e80ff1b

Browse files
author
hker9527
committed
twitter: Check for send message permission before executing
1 parent 3878181 commit e80ff1b

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

src/modules/twitter.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StealthModule } from "@type/StealthModule";
22
import { ZAPIVXTwitter } from "@type/api/VXTwitter";
3-
import { APIEmbed } from "discord.js";
3+
import { APIEmbed, PermissionsBitField } from "discord.js";
44

55
export const twitter: StealthModule = {
66
name: "twitter",
@@ -13,34 +13,41 @@ export const twitter: StealthModule = {
1313
try {
1414
const json = JSON.parse(response);
1515
if (ZAPIVXTwitter.check(json)) {
16-
await obj.message.suppressEmbeds();
17-
return {
18-
type: "send",
19-
result: {
20-
embeds: ([
21-
{
22-
author: {
23-
name: `${json.user_name} (@${json.user_screen_name})`,
24-
icon_url: "https://cdn-icons-png.flaticon.com/512/179/179342.png",
25-
url: `https://twitter.com/${json.user_screen_name}`
26-
},
27-
color: 0x1DA1F2,
28-
// Remove https://t.co/... links
29-
description: json.text.replace(/https:\/\/t\.co\/\w+/g, ""),
30-
timestamp: new Date(json.date_epoch * 1000).toISOString(),
16+
// Check if message channel can send message permission
17+
const member = obj.message.guild!.members.cache.get(obj.message.client.user!.id)!;
18+
if (member.permissions.has(PermissionsBitField.Flags.SendMessages)) {
19+
try {
20+
await obj.message.suppressEmbeds();
21+
} catch (e) {}
22+
23+
return {
24+
type: "send",
25+
result: {
26+
embeds: ([
27+
{
28+
author: {
29+
name: `${json.user_name} (@${json.user_screen_name})`,
30+
icon_url: "https://cdn-icons-png.flaticon.com/512/179/179342.png",
31+
url: `https://twitter.com/${json.user_screen_name}`
32+
},
33+
color: 0x1DA1F2,
34+
// Remove https://t.co/... links
35+
description: json.text.replace(/https:\/\/t\.co\/\w+/g, ""),
36+
timestamp: new Date(json.date_epoch * 1000).toISOString(),
37+
image: {
38+
url: json.mediaURLs[0]
39+
},
40+
url: json.tweetURL
41+
}
42+
] as APIEmbed[]).concat(json.mediaURLs.splice(1).map((url: string) => ({
3143
image: {
32-
url: json.mediaURLs[0]
44+
url
3345
},
3446
url: json.tweetURL
35-
}
36-
] as APIEmbed[]).concat(json.mediaURLs.splice(1).map((url: string) => ({
37-
image: {
38-
url
39-
},
40-
url: json.tweetURL
41-
})))
42-
}
43-
};
47+
})))
48+
}
49+
};
50+
}
4451
}
4552
return false;
4653
} catch (e) {

0 commit comments

Comments
 (0)