More reacts
This commit is contained in:
parent
b68456e6f4
commit
f266924a9a
6 changed files with 37 additions and 30 deletions
|
@ -38,7 +38,7 @@ public class ChromaBot {
|
||||||
* @param message
|
* @param message
|
||||||
* The message to send, duh (use {@link MessageChannel#createMessage(String)})
|
* The message to send, duh (use {@link MessageChannel#createMessage(String)})
|
||||||
*/
|
*/
|
||||||
public void sendMessage(Function<MessageChannel, Mono<Message>> message) {
|
public void sendMessage(Function<Mono<MessageChannel>, Mono<Message>> message) {
|
||||||
MCChatUtils.forAllMCChat(ch -> message.apply(ch).subscribe());
|
MCChatUtils.forAllMCChat(ch -> message.apply(ch).subscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class ChromaBot {
|
||||||
* @param message The message to send, duh
|
* @param message The message to send, duh
|
||||||
* @param toggle The toggle type for channelcon
|
* @param toggle The toggle type for channelcon
|
||||||
*/
|
*/
|
||||||
public void sendMessageCustomAsWell(Function<MessageChannel, Mono<Message>> message, @Nullable ChannelconBroadcast toggle) {
|
public void sendMessageCustomAsWell(Function<Mono<MessageChannel>, Mono<Message>> message, @Nullable ChannelconBroadcast toggle) {
|
||||||
MCChatUtils.forCustomAndAllMCChat(ch -> message.apply(ch).subscribe(), toggle, false);
|
MCChatUtils.forCustomAndAllMCChat(ch -> message.apply(ch).subscribe(), toggle, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,4 +145,8 @@ public final class DPUtils {
|
||||||
}).filter(ch -> ch instanceof MessageChannel).cast(MessageChannel.class);
|
}).filter(ch -> ch instanceof MessageChannel).cast(MessageChannel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Mono<MessageChannel> getMessageChannel(ConfigData<Snowflake> config) {
|
||||||
|
return getMessageChannel(config.getPath(), config.get());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import buttondevteam.lib.TBMCDebugMessageEvent;
|
||||||
import discord4j.core.object.entity.MessageChannel;
|
import discord4j.core.object.entity.MessageChannel;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public class DebugMessageListener implements Listener {
|
public class DebugMessageListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -18,7 +19,7 @@ public class DebugMessageListener implements Listener {
|
||||||
if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(ExceptionListenerModule.class))
|
if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(ExceptionListenerModule.class))
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
MessageChannel mc = ExceptionListenerModule.getChannel();
|
Mono<MessageChannel> mc = ExceptionListenerModule.getChannel();
|
||||||
if (mc == null) return;
|
if (mc == null) return;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("```").append("\n");
|
sb.append("```").append("\n");
|
||||||
|
@ -26,7 +27,7 @@ public class DebugMessageListener implements Listener {
|
||||||
message = message.substring(0, 2000);
|
message = message.substring(0, 2000);
|
||||||
sb.append(message).append("\n");
|
sb.append(message).append("\n");
|
||||||
sb.append("```");
|
sb.append("```");
|
||||||
mc.createMessage(sb.toString()).subscribe();
|
mc.flatMap(ch -> ch.createMessage(sb.toString())).subscribe();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.plugin.AuthorNagException;
|
import org.bukkit.plugin.AuthorNagException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -110,11 +111,11 @@ public class MCChatUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forAllMCChat(Consumer<MessageChannel> action) {
|
public static void forAllMCChat(Consumer<Mono<MessageChannel>> action) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
action.accept(module.chatChannel().get());
|
action.accept(module.chatChannelMono());
|
||||||
for (LastMsgData data : MCChatPrivate.lastmsgPerUser)
|
for (LastMsgData data : MCChatPrivate.lastmsgPerUser)
|
||||||
action.accept(data.channel);
|
action.accept(Mono.just(data.channel));
|
||||||
// lastmsgCustom.forEach(cc -> action.accept(cc.channel)); - Only send relevant messages to custom chat
|
// lastmsgCustom.forEach(cc -> action.accept(cc.channel)); - Only send relevant messages to custom chat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,11 +126,11 @@ public class MCChatUtils {
|
||||||
* @param toggle The toggle to check
|
* @param toggle The toggle to check
|
||||||
* @param hookmsg Whether the message is also sent from the hook
|
* @param hookmsg Whether the message is also sent from the hook
|
||||||
*/
|
*/
|
||||||
public static void forCustomAndAllMCChat(Consumer<MessageChannel> action, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
public static void forCustomAndAllMCChat(Consumer<Mono<MessageChannel>> action, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
if (!GeneralEventBroadcasterModule.isHooked() || !hookmsg)
|
if (!GeneralEventBroadcasterModule.isHooked() || !hookmsg)
|
||||||
forAllMCChat(action);
|
forAllMCChat(action);
|
||||||
final Consumer<MCChatCustom.CustomLMD> customLMDConsumer = cc -> action.accept(cc.channel);
|
final Consumer<MCChatCustom.CustomLMD> customLMDConsumer = cc -> action.accept(Mono.just(cc.channel));
|
||||||
if (toggle == null)
|
if (toggle == null)
|
||||||
MCChatCustom.lastmsgCustom.forEach(customLMDConsumer);
|
MCChatCustom.lastmsgCustom.forEach(customLMDConsumer);
|
||||||
else
|
else
|
||||||
|
@ -143,7 +144,7 @@ public class MCChatUtils {
|
||||||
* @param sender The sender to check perms of or null to send to all that has it toggled
|
* @param sender The sender to check perms of or null to send to all that has it toggled
|
||||||
* @param toggle The toggle to check or null to send to all allowed
|
* @param toggle The toggle to check or null to send to all allowed
|
||||||
*/
|
*/
|
||||||
public static void forAllowedCustomMCChat(Consumer<MessageChannel> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle) {
|
public static void forAllowedCustomMCChat(Consumer<Mono<MessageChannel>> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
MCChatCustom.lastmsgCustom.stream().filter(clmd -> {
|
MCChatCustom.lastmsgCustom.stream().filter(clmd -> {
|
||||||
//new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel).shouldSendTo(clmd.dcp) - Thought it was this simple hehe - Wait, it *should* be this simple
|
//new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel).shouldSendTo(clmd.dcp) - Thought it was this simple hehe - Wait, it *should* be this simple
|
||||||
|
@ -152,7 +153,7 @@ public class MCChatUtils {
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
return true;
|
return true;
|
||||||
return clmd.groupID.equals(clmd.mcchannel.getGroupID(sender));
|
return clmd.groupID.equals(clmd.mcchannel.getGroupID(sender));
|
||||||
}).forEach(cc -> action.accept(cc.channel)); //TODO: Send error messages on channel connect
|
}).forEach(cc -> action.accept(Mono.just(cc.channel))); //TODO: Send error messages on channel connect
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,29 +164,29 @@ public class MCChatUtils {
|
||||||
* @param toggle The toggle to check or null to send to all allowed
|
* @param toggle The toggle to check or null to send to all allowed
|
||||||
* @param hookmsg Whether the message is also sent from the hook
|
* @param hookmsg Whether the message is also sent from the hook
|
||||||
*/
|
*/
|
||||||
public static void forAllowedCustomAndAllMCChat(Consumer<MessageChannel> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
public static void forAllowedCustomAndAllMCChat(Consumer<Mono<MessageChannel>> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
if (!GeneralEventBroadcasterModule.isHooked() || !hookmsg)
|
if (!GeneralEventBroadcasterModule.isHooked() || !hookmsg)
|
||||||
forAllMCChat(action);
|
forAllMCChat(action);
|
||||||
forAllowedCustomMCChat(action, sender, toggle);
|
forAllowedCustomMCChat(action, sender, toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Consumer<MessageChannel> send(String message) {
|
public static Consumer<Mono<MessageChannel>> send(String message) {
|
||||||
return ch -> ch.createMessage(DPUtils.sanitizeString(message)).subscribe();
|
return ch -> ch.flatMap(mc -> mc.createMessage(DPUtils.sanitizeString(message))).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forAllowedMCChat(Consumer<MessageChannel> action, TBMCSystemChatEvent event) {
|
public static void forAllowedMCChat(Consumer<Mono<MessageChannel>> action, TBMCSystemChatEvent event) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
if (event.getChannel().isGlobal())
|
if (event.getChannel().isGlobal())
|
||||||
action.accept(module.chatChannel().get());
|
action.accept(module.chatChannelMono());
|
||||||
for (LastMsgData data : MCChatPrivate.lastmsgPerUser)
|
for (LastMsgData data : MCChatPrivate.lastmsgPerUser)
|
||||||
if (event.shouldSendTo(getSender(data.channel.getId(), data.user)))
|
if (event.shouldSendTo(getSender(data.channel.getId(), data.user)))
|
||||||
action.accept(data.channel);
|
action.accept(Mono.just(data.channel)); //TODO: Only store ID?
|
||||||
MCChatCustom.lastmsgCustom.stream().filter(clmd -> {
|
MCChatCustom.lastmsgCustom.stream().filter(clmd -> {
|
||||||
if (!clmd.brtoggles.contains(event.getTarget()))
|
if (!clmd.brtoggles.contains(event.getTarget()))
|
||||||
return false;
|
return false;
|
||||||
return event.shouldSendTo(clmd.dcp);
|
return event.shouldSendTo(clmd.dcp);
|
||||||
}).map(clmd -> clmd.channel).forEach(action);
|
}).map(clmd -> Mono.just(clmd.channel)).forEach(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,8 +210,8 @@ public class MCChatUtils {
|
||||||
*/
|
*/
|
||||||
public static void resetLastMessage(Channel channel) {
|
public static void resetLastMessage(Channel channel) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
if (channel.getId().asLong() == module.chatChannel().get().getId().asLong()) {
|
if (channel.getId().asLong() == module.chatChannel().get().asLong()) {
|
||||||
(lastmsgdata == null ? lastmsgdata = new LastMsgData(module.chatChannel().get(), null)
|
(lastmsgdata == null ? lastmsgdata = new LastMsgData(module.chatChannelMono().block(), null)
|
||||||
: lastmsgdata).message = null;
|
: lastmsgdata).message = null;
|
||||||
return;
|
return;
|
||||||
} // Don't set the whole object to null, the player and channel information should be preserved
|
} // Don't set the whole object to null, the player and channel information should be preserved
|
||||||
|
|
|
@ -51,9 +51,9 @@ class MCListener implements Listener {
|
||||||
if (dp != null) {
|
if (dp != null) {
|
||||||
val user = DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID())).block();
|
val user = DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID())).block();
|
||||||
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
||||||
new DiscordPlayerSender(user, Objects.requireNonNull(user).getPrivateChannel().block(), p));
|
new DiscordPlayerSender(user, Objects.requireNonNull(user).getPrivateChannel().block(), p)); //TODO: Don't block
|
||||||
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
||||||
new DiscordPlayerSender(user, module.chatChannel().get(), p)); //Stored per-channel
|
new DiscordPlayerSender(user, module.chatChannelMono().block(), p)); //Stored per-channel
|
||||||
}
|
}
|
||||||
final String message = e.GetPlayer().PlayerName().get() + " joined the game";
|
final String message = e.GetPlayer().PlayerName().get() + " joined the game";
|
||||||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
|
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
|
||||||
|
@ -124,7 +124,7 @@ class MCListener implements Listener {
|
||||||
String msg = (e.getValue() ? "M" : "Unm") + "uted user: " + user.getUsername() + "#" + user.getDiscriminator();
|
String msg = (e.getValue() ? "M" : "Unm") + "uted user: " + user.getUsername() + "#" + user.getDiscriminator();
|
||||||
DPUtils.getLogger().info(msg);
|
DPUtils.getLogger().info(msg);
|
||||||
if (modlog != null)
|
if (modlog != null)
|
||||||
return modlog.createMessage(msg);
|
return modlog.flatMap(ch -> ch.createMessage(msg));
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
})).subscribe();
|
})).subscribe();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.discordplugin.DPUtils;
|
import buttondevteam.discordplugin.DPUtils;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.architecture.ConfigData;
|
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||||
import discord4j.core.event.domain.role.RoleCreateEvent;
|
import discord4j.core.event.domain.role.RoleCreateEvent;
|
||||||
import discord4j.core.event.domain.role.RoleDeleteEvent;
|
import discord4j.core.event.domain.role.RoleDeleteEvent;
|
||||||
import discord4j.core.event.domain.role.RoleEvent;
|
import discord4j.core.event.domain.role.RoleEvent;
|
||||||
|
@ -13,6 +13,7 @@ import discord4j.core.object.entity.MessageChannel;
|
||||||
import discord4j.core.object.entity.Role;
|
import discord4j.core.object.entity.Role;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -33,7 +34,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConfigData<MessageChannel> logChannel() {
|
private ReadOnlyConfigData<Mono<MessageChannel>> logChannel() {
|
||||||
return DPUtils.channelData(getConfig(), "logChannel", 239519012529111040L);
|
return DPUtils.channelData(getConfig(), "logChannel", 239519012529111040L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,13 +50,13 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
||||||
return; //Deleted or not a game role
|
return; //Deleted or not a game role
|
||||||
GameRoles.add(role.getName());
|
GameRoles.add(role.getName());
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
logChannel.createMessage("Added " + role.getName() + " as game role. If you don't want this, change the role's color from the default.").subscribe();
|
logChannel.flatMap(ch -> ch.createMessage("Added " + role.getName() + " as game role. If you don't want this, change the role's color from the default.")).subscribe();
|
||||||
}, 100);
|
}, 100);
|
||||||
} else if (roleEvent instanceof RoleDeleteEvent) {
|
} else if (roleEvent instanceof RoleDeleteEvent) {
|
||||||
Role role=((RoleDeleteEvent) roleEvent).getRole().orElse(null);
|
Role role=((RoleDeleteEvent) roleEvent).getRole().orElse(null);
|
||||||
if(role==null) return;
|
if(role==null) return;
|
||||||
if (GameRoles.remove(role.getName()) && logChannel != null)
|
if (GameRoles.remove(role.getName()) && logChannel != null)
|
||||||
logChannel.createMessage("Removed " + role.getName() + " as a game role.").subscribe();
|
logChannel.flatMap(ch -> ch.createMessage("Removed " + role.getName() + " as a game role.")).subscribe();
|
||||||
} else if (roleEvent instanceof RoleUpdateEvent) {
|
} else if (roleEvent instanceof RoleUpdateEvent) {
|
||||||
val event = (RoleUpdateEvent) roleEvent;
|
val event = (RoleUpdateEvent) roleEvent;
|
||||||
if(!event.getOld().isPresent()) {
|
if(!event.getOld().isPresent()) {
|
||||||
|
@ -65,7 +66,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
||||||
Role or=event.getOld().get();
|
Role or=event.getOld().get();
|
||||||
if (!grm.isGameRole(event.getCurrent())) {
|
if (!grm.isGameRole(event.getCurrent())) {
|
||||||
if (GameRoles.remove(or.getName()) && logChannel != null)
|
if (GameRoles.remove(or.getName()) && logChannel != null)
|
||||||
logChannel.createMessage("Removed " + or.getName() + " as a game role because it's color changed.").subscribe();
|
logChannel.flatMap(ch -> ch.createMessage("Removed " + or.getName() + " as a game role because it's color changed.")).subscribe();
|
||||||
} else {
|
} else {
|
||||||
if (GameRoles.contains(or.getName()) && or.getName().equals(event.getCurrent().getName()))
|
if (GameRoles.contains(or.getName()) && or.getName().equals(event.getCurrent().getName()))
|
||||||
return;
|
return;
|
||||||
|
@ -73,9 +74,9 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
||||||
GameRoles.add(event.getCurrent().getName()); //Add it because it has no color
|
GameRoles.add(event.getCurrent().getName()); //Add it because it has no color
|
||||||
if (logChannel != null) {
|
if (logChannel != null) {
|
||||||
if (removed)
|
if (removed)
|
||||||
logChannel.createMessage("Changed game role from " + or.getName() + " to " + event.getCurrent().getName() + ".").subscribe();
|
logChannel.flatMap(ch -> ch.createMessage("Changed game role from " + or.getName() + " to " + event.getCurrent().getName() + ".")).subscribe();
|
||||||
else
|
else
|
||||||
logChannel.createMessage("Added " + event.getCurrent().getName() + " as game role because it has the default color.").subscribe();
|
logChannel.flatMap(ch -> ch.createMessage("Added " + event.getCurrent().getName() + " as game role because it has the default color.")).subscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue