8
8
User ,
9
9
} from 'discord.js' ;
10
10
import { REACTION_ROLE , REACTION_ROLE_CHANNEL } from '../config' ;
11
- import { wrap_in_embed } from './embed_helpers' ;
12
11
13
12
export async function hasPermission (
14
13
reaction : MessageReaction | PartialMessageReaction ,
@@ -76,14 +75,12 @@ export async function sendReactionRoleMessage(client: Client) {
76
75
) ;
77
76
messageArray . push ( '\n**<#879007560429088800>**' ) ;
78
77
messageArray . push (
79
- "If you'd like to get involved with Tauri development you can react to the Tauri Contributor role below to be able to chat in the various channels ." ,
78
+ "Get involved with Tauri development and browse the different projects ." ,
80
79
) ;
81
80
messageArray . push ( '\n**<#683637724116418561>**' ) ;
82
81
messageArray . push (
83
82
"See what the community is working on outside of Tauri. Reach out if you have a passion project you'd like to talk about." ,
84
83
) ;
85
- messageArray . push ( '\n**Server Roles**' ) ;
86
- messageArray . push ( 'React below to receive the relative role' ) ;
87
84
88
85
let messageBody = messageArray . join ( '\n' ) ;
89
86
@@ -93,71 +90,24 @@ export async function sendReactionRoleMessage(client: Client) {
93
90
94
91
console . debug ( 'Got messages' ) ;
95
92
93
+ // Get an existing message with identical contents
96
94
let message = messages
97
95
. filter ( ( item ) => item . content === messageBody )
98
96
. last ( ) ;
99
97
100
98
if ( message && message . author . id == message . client . user . id ) {
101
99
console . debug ( 'Attempting to edit message...' ) ;
100
+ // Edit the message
102
101
await message . edit ( messageBody ) ;
103
102
console . debug ( 'Message edited' ) ;
104
103
} else {
104
+ // Delete old messages from the bot
105
+ messages . filter ( ( item ) => item . author . id == item . client . user . id ) . forEach ( ( item ) => item . delete ( ) )
105
106
console . debug ( 'Attempting to send message...' ) ;
107
+ // Send the message
106
108
message = await channel . send ( messageBody ) ;
107
109
console . debug ( 'Message sent' ) ;
108
110
}
109
-
110
- // Loop all available reaction roles
111
- REACTION_ROLE . forEach ( async ( role ) => {
112
- // Get the reaction
113
- console . debug ( 'Attempting to get reactions...' ) ;
114
- const reaction = await message . reactions . resolve ( role . emojiId ) ;
115
- console . debug ( 'Got reactions' ) ;
116
-
117
- // No reactions yet
118
- if ( ! reaction ) {
119
- return ;
120
- }
121
-
122
- // Get all users that reacted minus the bot
123
- console . debug ( 'Getting users who reacted...' ) ;
124
- const reactedUsers = ( await reaction . users . fetch ( ) ) . filter (
125
- ( user ) => user . id !== message . author . id ,
126
- ) ;
127
- console . debug ( 'Finished fetching users' ) ;
128
-
129
- // Loop all users and add the role
130
- let counter = 0 ;
131
- reactedUsers . forEach ( async ( user ) => {
132
- try {
133
- const result = await hasPermission ( reaction , user ) ;
134
- counter += 1 ;
135
- const localCounter = counter ;
136
- console . debug (
137
- `(${ localCounter } / ${ reactedUsers . size } ) Attempting to add role...` ,
138
- ) ;
139
- if ( result ) {
140
- await result . member . roles . add ( result . roleId ) ;
141
- console . debug (
142
- `(${ localCounter } / ${ reactedUsers . size } ) Role added` ,
143
- ) ;
144
- }
145
- } catch ( error ) {
146
- console . error ( `Issue adding role: ${ error } ` ) ;
147
- }
148
- } ) ;
149
- } ) ;
150
-
151
- var roleDescription : string [ ] = [ ] ;
152
-
153
- REACTION_ROLE . forEach ( async ( reaction ) => {
154
- message . react ( reaction . emojiId ) ;
155
- roleDescription . push (
156
- `<:${ reaction . emojiName } :${ reaction . emojiId } > ${ reaction . description } ` ,
157
- ) ;
158
- } ) ;
159
-
160
- await message . edit ( wrap_in_embed ( roleDescription . join ( '\n' ) ) ) ;
161
111
} catch ( error ) {
162
112
console . error ( `Issue starting up reaction: ${ error } ` ) ;
163
113
}
0 commit comments