CTCV2/app/src/main/java/com/discord/stores/StoreMessages.java

102 lines
4.7 KiB
Java

package com.discord.stores;
import com.PatchConfig;
import com.discord.models.domain.ModelAllowedMentions;
import com.discord.models.domain.ModelApplication;
import com.discord.models.domain.ModelMessage;
import com.discord.models.domain.ModelUser;
import com.discord.models.domain.NonceGenerator;
import com.discord.models.domain.activity.ModelActivity;
import com.discord.models.sticker.dto.ModelSticker;
import com.discord.utilities.messagesend.MessageResult;
import com.discord.utilities.time.Clock;
import com.discord.utilities.time.TimeUtils;
import com.lytefast.flexinput.model.Attachment;
import java.util.List;
import cutthecord.commands.CommandHandler;
import lanchon.dexpatcher.annotation.DexAdd;
import lanchon.dexpatcher.annotation.DexEdit;
import lanchon.dexpatcher.annotation.DexIgnore;
import lanchon.dexpatcher.annotation.DexWrap;
import rx.Observable;
@DexEdit
public final class StoreMessages extends Store {
// TODO extra patch that allows @ user selection window to appear when entering a slash command
@DexIgnore
public StoreMessages(StoreStream storeStream, Dispatcher dispatcher, Clock clock2) {
}
@DexIgnore
private final Dispatcher dispatcher = null;
@DexIgnore
private final StoreMessagesHolder holder = new StoreMessagesHolder();
@DexIgnore
private final Clock clock = null;
// slashmessages patch
// Wrap edit function to check for commands
@SuppressWarnings("InfiniteRecursion") // Wrapped method
@DexWrap
public final void editMessage(long messageId, long channelId, String content) {
if (!PatchConfig.SLASH_COMMANDS_ENABLED) {
// Patch not enabled
editMessage(messageId, channelId, content);
return;
}
String interceptEditMessage = CommandHandler.interceptEditMessage(this, channelId, content);
editMessage(messageId, channelId, interceptEditMessage);
}
// Wrap send function to check for commands
@SuppressWarnings("InfiniteRecursion") // Wrapped method
@DexWrap
public final Observable<MessageResult> sendMessage(long channel,
ModelUser author,
String message,
List<? extends ModelUser> mentionedUsers,
List<? extends Attachment<?>> attachments,
List<ModelSticker> stickers,
ModelMessage.MessageReference messageReference,
ModelAllowedMentions modelAllowedMentions,
ModelApplication application,
ModelActivity modelActivity,
ModelMessage.Activity activity,
Long l,
Long l2,
Integer num) {
if (!PatchConfig.SLASH_COMMANDS_ENABLED) {
// Patch not enabled
return sendMessage(channel, author, message, mentionedUsers, attachments, stickers, messageReference, modelAllowedMentions, application, modelActivity, activity, l, l2, num);
}
String interceptEditMessage = CommandHandler.interceptSendMessage(this, channel, message);
return sendMessage(channel, author, interceptEditMessage, mentionedUsers, attachments, stickers, messageReference, modelAllowedMentions, application, modelActivity, activity, l, l2, num);
}
// Helper methods for slashcommands etc
// Sends a bot message to a channel, only visible by the local client
// TODO for whatever reason these can't be deleted.. when type -1/0
// this is a big workaround, we add an additional check in ModelMessage to see if this is an internal message or not, to prevent resends, and send internal responses as error messages
@DexAdd
@StoreThread
public void sendCTCBotMessageToChannel(long channelId, String content) {
long computeNonce = NonceGenerator.computeNonce();
ModelMessage modelMessage = new ModelMessage(computeNonce, String.valueOf(computeNonce), channelId, -2 /* Send failed */, content, ModelUser.CTC_BOT, null, TimeUtils.currentTimeUTCDateString(clock), null, null, null, false, null, false, null, null, null, null, null, false, null, false, null, null, null, null, null, null, null, null);
modelMessage.setCTCMessage(true);
this.dispatcher.schedule(new StoreMessages$sendMessage$1(this, modelMessage));
}
}