|
73 | 73 | import java.util.stream.Collectors; |
74 | 74 |
|
75 | 75 | import static me.duncte123.botcommons.messaging.MessageUtils.sendMsg; |
76 | | -import static me.duncte123.skybot.utils.AirUtils.setJDAContext; |
77 | 76 | import static me.duncte123.skybot.utils.CommandUtils.isDev; |
78 | 77 | import static me.duncte123.skybot.utils.ModerationUtils.modLog; |
79 | 78 | import static net.dv8tion.jda.api.requests.ErrorResponse.MISSING_PERMISSIONS; |
@@ -115,140 +114,134 @@ protected void onGuildMessageUpdate(MessageUpdateEvent event) { |
115 | 114 | return; |
116 | 115 | } |
117 | 116 |
|
118 | | - this.handlerThread.submit(() -> { |
119 | | - try { |
120 | | - final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables); |
121 | | - final GuildSetting settings = guild.getSettings(); |
| 117 | + try { |
| 118 | + final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables); |
| 119 | + final GuildSetting settings = guild.getSettings(); |
122 | 120 |
|
123 | | - if (settings.isMessageLogging()) { |
124 | | - final MessageData edited = MessageData.from(message); |
125 | | - final MessageData original = this.redis.getAndUpdateMessage(message.getId(), edited); |
| 121 | + if (settings.isMessageLogging()) { |
| 122 | + final MessageData edited = MessageData.from(message); |
| 123 | + final MessageData original = this.redis.getAndUpdateMessage(message.getId(), edited); |
126 | 124 |
|
127 | | - // data will be null if the message expired |
128 | | - if (original != null) { |
129 | | - this.logEditedMessage(original, edited, guild); |
130 | | - } |
| 125 | + // data will be null if the message expired |
| 126 | + if (original != null) { |
| 127 | + this.logEditedMessage(original, edited, guild); |
131 | 128 | } |
| 129 | + } |
132 | 130 |
|
133 | | - if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) && |
134 | | - !event.getMember().hasPermission(Permission.MESSAGE_MANAGE)) { |
135 | | - |
136 | | - if (blacklistedWordCheck(guild, message, event.getMember(), settings.getBlacklistedWords())) { |
137 | | - return; |
138 | | - } |
| 131 | + if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) && |
| 132 | + !event.getMember().hasPermission(Permission.MESSAGE_MANAGE)) { |
139 | 133 |
|
140 | | - checkSwearFilter(message, event, guild); |
| 134 | + if (blacklistedWordCheck(guild, message, event.getMember(), settings.getBlacklistedWords())) { |
| 135 | + return; |
141 | 136 | } |
142 | | - } catch (Exception e) { |
143 | | - LOGGER.error("Exception on message update", e); |
| 137 | + |
| 138 | + checkSwearFilter(message, event, guild); |
144 | 139 | } |
145 | | - }); |
| 140 | + } catch (Exception e) { |
| 141 | + LOGGER.error("Exception on message update", e); |
| 142 | + } |
146 | 143 | } |
147 | 144 |
|
148 | 145 | @SuppressWarnings("PMD.UseConcurrentHashMap") |
149 | 146 | protected void onMessageBulkDelete(final MessageBulkDeleteEvent event) { |
150 | | - this.handlerThread.submit(() -> { |
151 | | - try { |
152 | | - final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables); |
| 147 | + try { |
| 148 | + final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables); |
153 | 149 |
|
154 | | - if (!guild.getSettings().isMessageLogging()) { |
155 | | - // just delete the message here as we don't want to keep it around |
156 | | - this.redis.deleteMessages(event.getMessageIds()); |
157 | | - return; |
158 | | - } |
| 150 | + if (!guild.getSettings().isMessageLogging()) { |
| 151 | + // just delete the message here as we don't want to keep it around |
| 152 | + this.redis.deleteMessages(event.getMessageIds()); |
| 153 | + return; |
| 154 | + } |
159 | 155 |
|
160 | | - final List<MessageData> dataList = this.redis.getAndDeleteMessages(event.getMessageIds()); |
161 | | - final StringBuilder builder = new StringBuilder(); |
162 | | - // temporarily store the users to prevent spamming discord for the data |
163 | | - final Map<Long, User> tmpUsers = new HashMap<>(); |
164 | | - final JDA jda = event.getJDA(); |
165 | | - |
166 | | - // reverse the list to preserve the correct order |
167 | | - Collections.reverse(dataList); |
168 | | - |
169 | | - for (final MessageData data : dataList) { |
170 | | - final long authorId = data.getAuthorId(); |
171 | | - |
172 | | - final Consumer<User> userConsumer = (user) -> { |
173 | | - builder.append('[') |
174 | | - .append(data.getCratedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME)) |
175 | | - .append("] (") |
176 | | - .append(user.getAsTag()) |
177 | | - .append(" - ") |
178 | | - .append(user.getIdLong()) |
179 | | - .append(") [") |
180 | | - .append(data.getMessageId()) |
181 | | - .append("]: ") |
182 | | - .append(data.getContent()) |
183 | | - .append('\n'); |
184 | | - }; |
185 | | - |
186 | | - if (tmpUsers.containsKey(authorId)) { |
187 | | - userConsumer.accept(tmpUsers.get(authorId)); |
188 | | - } else { |
189 | | - // try to fetch the user since we don't cache them |
190 | | - // calls are sequential making sure the messages are still in order |
191 | | - jda.retrieveUserById(authorId).queue( |
192 | | - (user) -> { |
193 | | - tmpUsers.put(authorId, user); |
194 | | - userConsumer.accept(user); |
195 | | - }, |
196 | | - (error) -> userConsumer.accept(new UnknownUser(authorId)) |
197 | | - ); |
198 | | - } |
| 156 | + final List<MessageData> dataList = this.redis.getAndDeleteMessages(event.getMessageIds()); |
| 157 | + final StringBuilder builder = new StringBuilder(); |
| 158 | + // temporarily store the users to prevent spamming discord for the data |
| 159 | + final Map<Long, User> tmpUsers = new HashMap<>(); |
| 160 | + final JDA jda = event.getJDA(); |
| 161 | + |
| 162 | + // reverse the list to preserve the correct order |
| 163 | + Collections.reverse(dataList); |
| 164 | + |
| 165 | + for (final MessageData data : dataList) { |
| 166 | + final long authorId = data.getAuthorId(); |
| 167 | + |
| 168 | + final Consumer<User> userConsumer = (user) -> { |
| 169 | + builder.append('[') |
| 170 | + .append(data.getCratedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME)) |
| 171 | + .append("] (") |
| 172 | + .append(user.getAsTag()) |
| 173 | + .append(" - ") |
| 174 | + .append(user.getIdLong()) |
| 175 | + .append(") [") |
| 176 | + .append(data.getMessageId()) |
| 177 | + .append("]: ") |
| 178 | + .append(data.getContent()) |
| 179 | + .append('\n'); |
| 180 | + }; |
| 181 | + |
| 182 | + if (tmpUsers.containsKey(authorId)) { |
| 183 | + userConsumer.accept(tmpUsers.get(authorId)); |
| 184 | + } else { |
| 185 | + // try to fetch the user since we don't cache them |
| 186 | + // calls are sequential making sure the messages are still in order |
| 187 | + jda.retrieveUserById(authorId).queue( |
| 188 | + (user) -> { |
| 189 | + tmpUsers.put(authorId, user); |
| 190 | + userConsumer.accept(user); |
| 191 | + }, |
| 192 | + (error) -> userConsumer.accept(new UnknownUser(authorId)) |
| 193 | + ); |
199 | 194 | } |
| 195 | + } |
200 | 196 |
|
201 | | - final MessageChannel channel = event.getChannel(); |
202 | | - final EmbedBuilder embed = EmbedUtils.embedField( |
203 | | - "Bulk Delete", |
204 | | - "Bulk deleted messages from <#%s> are available in the attached file.".formatted(channel.getIdLong()) |
205 | | - ) |
206 | | - .setColor(0xE67E22) |
207 | | - .setTimestamp(Instant.now()); |
208 | | - |
209 | | - modLog( |
210 | | - new MessageConfig.Builder() |
211 | | - .addEmbed(true, embed) |
212 | | - .setActionConfig( |
213 | | - (action) -> action.addFiles( |
214 | | - FileUpload.fromData( |
215 | | - builder.toString().getBytes(StandardCharsets.UTF_8), |
216 | | - "bulk_delete_%s.txt".formatted(System.currentTimeMillis()) |
217 | | - ) |
| 197 | + final MessageChannel channel = event.getChannel(); |
| 198 | + final EmbedBuilder embed = EmbedUtils.embedField( |
| 199 | + "Bulk Delete", |
| 200 | + "Bulk deleted messages from <#%s> are available in the attached file.".formatted(channel.getIdLong()) |
| 201 | + ) |
| 202 | + .setColor(0xE67E22) |
| 203 | + .setTimestamp(Instant.now()); |
| 204 | + |
| 205 | + modLog( |
| 206 | + new MessageConfig.Builder() |
| 207 | + .addEmbed(true, embed) |
| 208 | + .setActionConfig( |
| 209 | + (action) -> action.addFiles( |
| 210 | + FileUpload.fromData( |
| 211 | + builder.toString().getBytes(StandardCharsets.UTF_8), |
| 212 | + "bulk_delete_%s.txt".formatted(System.currentTimeMillis()) |
218 | 213 | ) |
219 | | - ), |
220 | | - guild |
221 | | - ); |
222 | | - } catch (Exception e) { |
223 | | - LOGGER.error("Exception on message bulk delete", e); |
224 | | - } |
225 | | - }); |
| 214 | + ) |
| 215 | + ), |
| 216 | + guild |
| 217 | + ); |
| 218 | + } catch (Exception e) { |
| 219 | + LOGGER.error("Exception on message bulk delete", e); |
| 220 | + } |
226 | 221 | } |
227 | 222 |
|
228 | 223 | protected void onGuildMessageDelete(final MessageDeleteEvent event) { |
229 | 224 | if (!event.isFromGuild()) { |
230 | 225 | return; |
231 | 226 | } |
232 | 227 |
|
233 | | - this.handlerThread.submit(() -> { |
234 | | - try { |
235 | | - final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables); |
| 228 | + try { |
| 229 | + final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables); |
236 | 230 |
|
237 | | - if (!guild.getSettings().isMessageLogging()) { |
238 | | - // just delete the message here as we don't want to keep it around |
239 | | - this.redis.deleteMessage(event.getMessageId()); |
240 | | - return; |
241 | | - } |
| 231 | + if (!guild.getSettings().isMessageLogging()) { |
| 232 | + // just delete the message here as we don't want to keep it around |
| 233 | + this.redis.deleteMessage(event.getMessageId()); |
| 234 | + return; |
| 235 | + } |
242 | 236 |
|
243 | | - final MessageData data = this.redis.getAndDeleteMessage(event.getMessageId()); |
| 237 | + final MessageData data = this.redis.getAndDeleteMessage(event.getMessageId()); |
244 | 238 |
|
245 | | - if (data != null) { |
246 | | - this.logDeletedMessage(data, guild); |
247 | | - } |
248 | | - } catch (Exception e) { |
249 | | - LOGGER.error("Exception on message delete", e); |
| 239 | + if (data != null) { |
| 240 | + this.logDeletedMessage(data, guild); |
250 | 241 | } |
251 | | - }); |
| 242 | + } catch (Exception e) { |
| 243 | + LOGGER.error("Exception on message delete", e); |
| 244 | + } |
252 | 245 | } |
253 | 246 |
|
254 | 247 | protected void onGuildMessageReceived(MessageReceivedEvent event) { |
@@ -295,15 +288,12 @@ protected void onGuildMessageReceived(MessageReceivedEvent event) { |
295 | 288 | return; |
296 | 289 | } |
297 | 290 |
|
298 | | - this.handlerThread.submit(() -> { |
299 | | - try { |
300 | | - setJDAContext(event.getJDA()); |
301 | | - handleMessageEventChecked(raw, guild, event); |
302 | | - } catch (Exception e) { |
303 | | - Sentry.captureException(e); |
304 | | - e.printStackTrace(); |
305 | | - } |
306 | | - }); |
| 291 | + try { |
| 292 | + handleMessageEventChecked(raw, guild, event); |
| 293 | + } catch (Exception e) { |
| 294 | + LOGGER.error("Error handling message event", e); |
| 295 | + Sentry.captureException(e); |
| 296 | + } |
307 | 297 | } |
308 | 298 |
|
309 | 299 | protected void onSlashCommandInteraction(SlashCommandInteractionEvent event) { |
@@ -671,7 +661,8 @@ private void logEditedMessage(MessageData original, MessageData edited, Dunctebo |
671 | 661 | .setColor(0xF1C40F) |
672 | 662 | .setAuthor( |
673 | 663 | "%s (%s)".formatted(user.getAsTag(), edited.getAuthorId()), |
674 | | - "https://duncte.bot/", |
| 664 | +// "https://duncte.bot/", |
| 665 | + edited.getJumpUrl(guild.getIdLong()), |
675 | 666 | user.getEffectiveAvatarUrl().replace(".gif", ".png") |
676 | 667 | ) |
677 | 668 | .setDescription( |
|
0 commit comments