feat: accept discord messages when the bot isn't logged in + some refactors in CorePlugin and GuildMessageEventHandler
This commit is contained in:
parent
8290473631
commit
ac319b6281
3 changed files with 49 additions and 35 deletions
build-number.txt
src/main/java/me/chayapak1/chomens_bot
|
@ -1 +1 @@
|
|||
2920
|
||||
2923
|
|
@ -53,7 +53,7 @@ public class GuildMessageEventHandler extends ListenerAdapter {
|
|||
for (final Bot bot : Main.bots) {
|
||||
final String channelId = Main.discord.servers.get(bot.getServerString(true));
|
||||
|
||||
if (!bot.loggedIn || !event.getChannel().getId().equals(channelId)) continue;
|
||||
if (!event.getChannel().getId().equals(channelId)) continue;
|
||||
|
||||
final Message messageObject = event.getMessage();
|
||||
final String messageString = messageObject.getContentDisplay();
|
||||
|
@ -72,32 +72,7 @@ public class GuildMessageEventHandler extends ListenerAdapter {
|
|||
|
||||
if (isForwarded) {
|
||||
for (final MessageSnapshot snapshot : messageObject.getMessageSnapshots()) {
|
||||
final List<Component> extraComponents = new ArrayList<>();
|
||||
|
||||
addExtraComponents(
|
||||
extraComponents,
|
||||
snapshot.getAttachments(),
|
||||
snapshot.getEmbeds(),
|
||||
snapshot.getStickers(),
|
||||
bot
|
||||
);
|
||||
|
||||
final String replacedMessageContent = replaceMessageContent(snapshot.getContentRaw());
|
||||
|
||||
Component messageComponent = Component.text(replacedMessageContent);
|
||||
|
||||
if (!extraComponents.isEmpty()) {
|
||||
if (!replacedMessageContent.isBlank())
|
||||
messageComponent = messageComponent.append(Component.space());
|
||||
|
||||
messageComponent = messageComponent
|
||||
.append(
|
||||
Component.join(
|
||||
JoinConfiguration.spaces(),
|
||||
extraComponents
|
||||
)
|
||||
);
|
||||
}
|
||||
final Component messageComponent = getForwardedMessageComponent(bot, snapshot);
|
||||
|
||||
output = Component
|
||||
.translatable(
|
||||
|
@ -138,6 +113,37 @@ public class GuildMessageEventHandler extends ListenerAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
private Component getForwardedMessageComponent (final Bot bot, final MessageSnapshot snapshot) {
|
||||
final List<Component> extraComponents = new ArrayList<>();
|
||||
|
||||
addExtraComponents(
|
||||
extraComponents,
|
||||
snapshot.getAttachments(),
|
||||
snapshot.getEmbeds(),
|
||||
snapshot.getStickers(),
|
||||
bot
|
||||
);
|
||||
|
||||
final String replacedMessageContent = replaceMessageContent(snapshot.getContentRaw());
|
||||
|
||||
Component messageComponent = Component.text(replacedMessageContent);
|
||||
|
||||
if (!extraComponents.isEmpty()) {
|
||||
if (!replacedMessageContent.isBlank())
|
||||
messageComponent = messageComponent.append(Component.space());
|
||||
|
||||
messageComponent = messageComponent
|
||||
.append(
|
||||
Component.join(
|
||||
JoinConfiguration.spaces(),
|
||||
extraComponents
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return messageComponent;
|
||||
}
|
||||
|
||||
private Component getMessageComponent (
|
||||
final Bot bot,
|
||||
final Message message
|
||||
|
|
|
@ -96,13 +96,15 @@ public class CorePlugin implements Listener {
|
|||
|
||||
if (!pendingCommands.isEmpty() && exists) {
|
||||
// people that pre-order on TEMU application. Shop Like A Billionaire!!!
|
||||
if (pendingCommands.size() > 150) pendingCommands.clear();
|
||||
if (pendingCommands.size() > 256) {
|
||||
pendingCommands.clear();
|
||||
} else {
|
||||
for (final String pendingCommand : pendingCommands) {
|
||||
run(pendingCommand);
|
||||
}
|
||||
|
||||
for (final String pendingCommand : pendingCommands) {
|
||||
run(pendingCommand);
|
||||
pendingCommands.clear();
|
||||
}
|
||||
|
||||
pendingCommands.clear();
|
||||
}
|
||||
|
||||
if (placeBlockQueue.size() > 300) {
|
||||
|
@ -187,6 +189,12 @@ public class CorePlugin implements Listener {
|
|||
}
|
||||
|
||||
public void run (final String command) {
|
||||
if (!exists) {
|
||||
// Add to TEMU shopping cart
|
||||
pendingCommands.add(command);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ready || command.length() > 32767) return;
|
||||
|
||||
if (bot.options.useCore) {
|
||||
|
@ -197,8 +205,7 @@ public class CorePlugin implements Listener {
|
|||
|
||||
if (isRateLimited() && hasRateLimit()) return;
|
||||
|
||||
if (exists) forceRun(command);
|
||||
else pendingCommands.add(command);
|
||||
forceRun(command);
|
||||
|
||||
if (hasRateLimit()) commandsPerSecond.incrementAndGet();
|
||||
} else if (command.length() < 256) {
|
||||
|
@ -465,6 +472,7 @@ public class CorePlugin implements Listener {
|
|||
@Override
|
||||
public void disconnected (final DisconnectedEvent event) {
|
||||
ready = false;
|
||||
exists = false;
|
||||
}
|
||||
|
||||
public void recalculateRelativePositions () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue