File tree Expand file tree Collapse file tree 3 files changed +84
-11
lines changed Expand file tree Collapse file tree 3 files changed +84
-11
lines changed Original file line number Diff line number Diff line change
1
+ import { button } from 'jellycommands' ;
2
+ import { MODERATOR_IDS } from '../config' ;
3
+ import { get_member , has_any_role_or_id } from '../utils/snowflake' ;
4
+ import type advise from '../events/on_message/_advise' ;
5
+
6
+ /**
7
+ * Handle interaction responses in {@link advise}.
8
+ */
9
+ export default button ( {
10
+ id : / ^ e m b e d _ \w + $ / ,
11
+
12
+ async run ( { interaction } ) {
13
+ const [ , action , author_id ] = interaction . customId . split ( '_' ) as [
14
+ string ,
15
+ 'keep' | 'hide' ,
16
+ string ,
17
+ ] ;
18
+
19
+ /**
20
+ * Interacting user is either the author of the original message
21
+ * or a moderator.
22
+ */
23
+ const valid_user = has_any_role_or_id ( await get_member ( interaction ) , [
24
+ author_id ,
25
+ ...MODERATOR_IDS ,
26
+ ] ) ;
27
+
28
+ if ( ! valid_user ) {
29
+ await interaction . reply ( {
30
+ content :
31
+ 'Only the original author or a moderator may interact with this post.' ,
32
+ flags : 'Ephemeral' ,
33
+ } ) ;
34
+ return ;
35
+ }
36
+
37
+ if ( action === 'hide' ) {
38
+ await interaction . message . suppressEmbeds ( true ) ;
39
+ }
40
+ await interaction . update ( { components : [ ] } ) ;
41
+ } ,
42
+ } ) ;
Original file line number Diff line number Diff line change @@ -11,14 +11,16 @@ export const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
11
11
// #region people
12
12
const ADMIN_ROLES = [
13
13
// Moderators role in main server
14
- // '919214972557484073',
14
+ '919214972557484073' ,
15
15
16
16
// // Maintainers role
17
17
// '571775211431526410',
18
18
19
19
// // Admins role
20
- // '476141440091815947',
20
+ '476141440091815947' ,
21
+ ] ;
21
22
23
+ const PRIVILEGED_ROLES = [
22
24
// Threadlords
23
25
'949258457352114176' ,
24
26
] ;
@@ -29,14 +31,16 @@ const TEST_ADMIN_ROLES = ['918888136581476402'];
29
31
/**
30
32
* List of roles/user IDs allowed to delete tags even if they're not the author.
31
33
*/
32
- export const TAG_DEL_PERMITTED_IDS = DEV_MODE ? TEST_ADMIN_ROLES : ADMIN_ROLES ;
34
+ export const TAG_DEL_PERMITTED_IDS = DEV_MODE
35
+ ? TEST_ADMIN_ROLES
36
+ : PRIVILEGED_ROLES ;
33
37
34
38
/**
35
39
* List of roles/user IDs allowed to create tags.
36
40
*/
37
41
export const TAG_CREATE_PERMITTED_IDS = DEV_MODE
38
42
? TEST_ADMIN_ROLES
39
- : ADMIN_ROLES ;
43
+ : PRIVILEGED_ROLES ;
40
44
41
45
export const BOT_DEVS = [
42
46
// cirilla
@@ -50,9 +54,11 @@ export const BOT_DEVS = [
50
54
*/
51
55
export const THREAD_ADMIN_IDS = [
52
56
...BOT_DEVS ,
53
- ...( DEV_MODE ? TEST_ADMIN_ROLES : ADMIN_ROLES ) ,
57
+ ...( DEV_MODE ? TEST_ADMIN_ROLES : PRIVILEGED_ROLES ) ,
54
58
] ;
55
59
60
+ export const MODERATOR_IDS = DEV_MODE ? TEST_ADMIN_ROLES : ADMIN_ROLES ;
61
+
56
62
// #endregion
57
63
58
64
// #region channels
Original file line number Diff line number Diff line change 1
- import { type Message } from 'discord.js' ;
1
+ import {
2
+ ActionRowBuilder ,
3
+ ButtonBuilder ,
4
+ ButtonStyle ,
5
+ MessagePayload ,
6
+ userMention ,
7
+ type Message ,
8
+ } from 'discord.js' ;
2
9
import urlRegex from 'url-regex' ;
3
10
4
11
export default async function mutate_content ( message : Message ) {
@@ -19,12 +26,30 @@ export default async function mutate_content(message: Message) {
19
26
20
27
const link_term = updated_link_list . length === 1 ? 'link' : 'links' ;
21
28
22
- // Reply inline
23
- try {
24
- await message . reply (
25
- `I converted your \`x.com\` ${ link_term } to use \`xcancel.com\` so that server members won't require an account to view content and threads:\n${ updated_link_list } ` ,
26
- ) ;
29
+ const content = `${ userMention ( message . author . id ) } I converted your \`x.com\` ${ link_term } to use \`xcancel.com\` so that server members won't require an account to view content and threads:\n${ updated_link_list } ` ;
30
+
31
+ const hide_button = new ButtonBuilder ( )
32
+ . setLabel ( 'Hide embed' )
33
+ . setCustomId ( `embed_hide_${ message . author . id } ` )
34
+ . setStyle ( ButtonStyle . Secondary ) ;
35
+
36
+ const keep_button = new ButtonBuilder ( )
37
+ . setLabel ( 'Keep embed' )
38
+ . setCustomId ( `embed_keep_${ message . author . id } ` )
39
+ . setStyle ( ButtonStyle . Primary ) ;
27
40
41
+ const row = new ActionRowBuilder < ButtonBuilder > ( {
42
+ components : [ hide_button , keep_button ] ,
43
+ } ) ;
44
+
45
+ const payload = new MessagePayload ( message . channel , {
46
+ content,
47
+ components : [ row ] ,
48
+ } ) ;
49
+
50
+ // Send message with interactions
51
+ try {
52
+ await message . channel . send ( payload ) ;
28
53
await message . suppressEmbeds ( true ) ;
29
54
} catch {
30
55
// don't handle failures
You can’t perform that action at this time.
0 commit comments