Add one half of broadcasted message check and move mcchat classes

This commit is contained in:
Norbi Peti 2022-07-06 23:55:02 +02:00
parent 6183c034c6
commit a4f1463314
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
32 changed files with 78 additions and 54 deletions

View file

@ -8,12 +8,14 @@ name := "Chroma-Discord"
version := "1.1"
scalaVersion := "3.0.0"
scalaVersion := "3.1.0"
resolvers += "spigot-repo" at "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
resolvers += "jitpack.io" at "https://jitpack.io"
resolvers += Resolver.mavenLocal
// assembly / assemblyOption := (assembly / assemblyOption).value.copy(includeScala = false)
libraryDependencies ++= Seq(
"org.spigotmc" % "spigot-api" % "1.12.2-R0.1-SNAPSHOT" % Provided,
"org.spigotmc" % "spigot" % "1.12.2-R0.1-SNAPSHOT" % Provided,

View file

@ -10,3 +10,9 @@ commands:
description: 'Main command for Chroma-Discord'
website: 'https://github.com/TBMCPlugins/Chroma-Discord'
api-version: '1.13'
#libraries:
# - 'org.slf4j:slf4j-jdk14:1.7.32'
# - 'com.vdurmont:emoji-java:5.1.1'
# - 'org.mockito:mockito-core:4.2.0'
# - 'io.projectreactor:reactor-scala-extensions_2.13:0.8.0'
# - 'org.scala-lang:scala3-library_3:3.1.0'

View file

@ -8,6 +8,7 @@ import buttondevteam.discordplugin.exceptions.ExceptionListenerModule
import buttondevteam.discordplugin.fun.FunModule
import buttondevteam.discordplugin.listeners.{CommonListeners, MCListener}
import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import buttondevteam.discordplugin.mcchat.sender.{DiscordPlayer, DiscordSenderBase}
import buttondevteam.discordplugin.mccommands.DiscordMCCommand
import buttondevteam.discordplugin.role.GameRoleModule
import buttondevteam.discordplugin.util.{DPState, Timings}
@ -32,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration
import org.mockito.internal.util.MockUtil
import reactor.core.Disposable
import reactor.core.scala.publisher.SMono
import reactor.core.scala.publisher.scalaOption2JavaOptional
import java.io.File
import java.nio.charset.StandardCharsets
@ -129,16 +131,11 @@ import java.util.Optional
}
}
starting = true
//System.out.println("This line should show up for sure");
val cb = DiscordClientBuilder.create(token).build.gateway
//System.out.println("Got gateway bootstrap");
cb.setInitialPresence((si: ShardInfo) => ClientPresence.doNotDisturb(ClientActivity.playing("booting")))
//cb.setStore(new JdkStoreService) //The default doesn't work for some reason - it's waaay faster now
//System.out.println("Initial status and store service set");
cb.login.doOnError((t: Throwable) => {
def foo(t: Throwable): Unit = {
stopStarting()
//System.out.println("Got this error: " + t); t.printStackTrace();
}
foo(t)
@ -192,10 +189,10 @@ import java.util.Optional
CommonListeners.register(DiscordPlugin.dc.getEventDispatcher)
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener, this)
TBMCCoreAPI.RegisterUserClass(classOf[DiscordPlayer], () => new DiscordPlayer)
ChromaGamerBase.addConverter((sender: CommandSender) => Optional.ofNullable(sender match {
case dsender: DiscordSenderBase => dsender.getChromaUser
case _ => null
}))
ChromaGamerBase.addConverter((sender: CommandSender) => sender match {
case dsender: DiscordSenderBase => Some(dsender.getChromaUser)
case _ => None
})
IHaveConfig.pregenConfig(this, null)
ChromaBot.enabled = true //Initialize ChromaBot
Component.registerComponent(this, new GeneralEventBroadcasterModule)

View file

@ -1,8 +0,0 @@
package buttondevteam.discordplugin
import buttondevteam.discordplugin.playerfaker.VCMDWrapper
import org.bukkit.entity.Player
trait IMCPlayer[T] extends Player {
def getVanillaCmdListener: VCMDWrapper
}

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.announcer
import buttondevteam.discordplugin.{DPUtils, DiscordPlayer, DiscordPlugin}
import buttondevteam.discordplugin.mcchat.sender.DiscordPlayer
import buttondevteam.discordplugin.{DPUtils, DiscordPlugin}
import buttondevteam.lib.TBMCCoreAPI
import buttondevteam.lib.architecture.{Component, ComponentMetadata}
import buttondevteam.lib.player.ChromaGamerBase
@ -9,6 +10,7 @@ import discord4j.core.`object`.entity.channel.MessageChannel
import reactor.core.scala.publisher.SMono
import scala.annotation.tailrec
import scala.collection.mutable
/**
* Posts new posts from Reddit to the specified channel(s). It will pin the regular posts (not the mod posts).
@ -55,8 +57,8 @@ import scala.annotation.tailrec
if (isEnabled) try { //If not enabled, just wait
val body = TBMCCoreAPI.DownloadString(subredditURL.get + "/new/.json?limit=10")
val json = new JsonParser().parse(body).getAsJsonObject.get("data").getAsJsonObject.get("children").getAsJsonArray
val msgsb = new StringBuilder
val modmsgsb = new StringBuilder
val msgsb = new mutable.StringBuilder
val modmsgsb = new mutable.StringBuilder
var lastanntime = lastAnnouncementTime.get
for (i <- json.size - 1 to 0 by -1) {
val item = json.get(i).getAsJsonObject

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin.broadcaster
import buttondevteam.discordplugin.mcchat.MCChatUtils
import buttondevteam.discordplugin.playerfaker.DelegatingMockMaker
import buttondevteam.discordplugin.mcchat.playerfaker.DelegatingMockMaker
import buttondevteam.lib.TBMCCoreAPI
import org.bukkit.Bukkit
import org.mockito.Mockito

View file

@ -1,6 +1,6 @@
package buttondevteam.discordplugin.commands
import buttondevteam.discordplugin.DiscordPlayer
import buttondevteam.discordplugin.mcchat.sender.DiscordPlayer
import buttondevteam.lib.chat.{Command2, CommandClass}
import buttondevteam.lib.player.{TBMCPlayer, TBMCPlayerBase}
import com.google.common.collect.HashBiMap

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.commands
import buttondevteam.discordplugin.{DiscordPlayer, DiscordPlugin}
import buttondevteam.discordplugin.DiscordPlugin
import buttondevteam.discordplugin.mcchat.sender.DiscordPlayer
import buttondevteam.lib.chat.{Command2, CommandClass}
import buttondevteam.lib.player.ChromaGamerBase
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget

View file

@ -3,7 +3,8 @@ package buttondevteam.discordplugin.listeners
import buttondevteam.discordplugin.commands.ConnectCommand
import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import buttondevteam.discordplugin.util.DPState
import buttondevteam.discordplugin.{DiscordPlayer, DiscordPlugin}
import buttondevteam.discordplugin.DiscordPlugin
import buttondevteam.discordplugin.mcchat.sender.DiscordPlayer
import buttondevteam.lib.ScheduledServerRestartEvent
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent
import discord4j.common.util.Snowflake

View file

@ -4,6 +4,7 @@ import buttondevteam.core.component.channel.{Channel, ChatRoom}
import buttondevteam.discordplugin.*
import buttondevteam.discordplugin.ChannelconBroadcast.ChannelconBroadcast
import buttondevteam.discordplugin.commands.{Command2DCSender, ICommand2DC}
import buttondevteam.discordplugin.mcchat.sender.{DiscordConnectedPlayer, DiscordPlayer}
import buttondevteam.lib.TBMCSystemChatEvent
import buttondevteam.lib.chat.{Command2, CommandClass}
import buttondevteam.lib.player.{ChromaGamerBase, TBMCPlayer}

View file

@ -1,7 +1,8 @@
package buttondevteam.discordplugin.mcchat
import buttondevteam.discordplugin.commands.{Command2DCSender, ICommand2DC}
import buttondevteam.discordplugin.{DPUtils, DiscordPlayer, DiscordPlugin}
import buttondevteam.discordplugin.mcchat.sender.DiscordPlayer
import buttondevteam.discordplugin.{DPUtils, DiscordPlugin}
import buttondevteam.lib.chat.{Command2, CommandClass}
import buttondevteam.lib.player.ChromaGamerBase
import discord4j.core.`object`.entity.channel.PrivateChannel

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin.mcchat
import buttondevteam.core.component.channel.{Channel, ChatRoom}
import buttondevteam.discordplugin.DiscordConnectedPlayer
import buttondevteam.discordplugin.mcchat.sender.DiscordConnectedPlayer
import buttondevteam.lib.TBMCSystemChatEvent
import discord4j.common.util.Snowflake
import discord4j.core.`object`.entity.User

View file

@ -3,7 +3,8 @@ package buttondevteam.discordplugin.mcchat
import buttondevteam.core.ComponentManager
import buttondevteam.discordplugin.*
import buttondevteam.discordplugin.DPUtils.SpecExtensions
import buttondevteam.discordplugin.playerfaker.{VanillaCommandListener, VanillaCommandListener14, VanillaCommandListener15}
import buttondevteam.discordplugin.mcchat.playerfaker.{VanillaCommandListener, VanillaCommandListener14, VanillaCommandListener15}
import buttondevteam.discordplugin.mcchat.sender.{DiscordPlayer, DiscordSender, DiscordSenderBase}
import buttondevteam.lib.*
import buttondevteam.lib.chat.{ChatMessage, TBMCChatAPI}
import buttondevteam.lib.player.TBMCPlayer

View file

@ -2,7 +2,8 @@ package buttondevteam.discordplugin.mcchat
import buttondevteam.core.ComponentManager
import buttondevteam.discordplugin.mcchat.MCChatUtils.LastMsgData
import buttondevteam.discordplugin.{DiscordConnectedPlayer, DiscordPlayer, DiscordPlugin, DiscordSenderBase}
import buttondevteam.discordplugin.mcchat.sender.{DiscordConnectedPlayer, DiscordPlayer, DiscordSenderBase}
import buttondevteam.discordplugin.DiscordPlugin
import buttondevteam.lib.player.TBMCPlayer
import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.{MessageChannel, PrivateChannel}

View file

@ -6,6 +6,7 @@ import buttondevteam.discordplugin.ChannelconBroadcast.ChannelconBroadcast
import buttondevteam.discordplugin.DPUtils.SpecExtensions
import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule
import buttondevteam.discordplugin.mcchat.MCChatCustom.CustomLMD
import buttondevteam.discordplugin.mcchat.sender.{DiscordConnectedPlayer, DiscordPlayerSender, DiscordSender, DiscordSenderBase}
import buttondevteam.lib.{TBMCCoreAPI, TBMCSystemChatEvent}
import com.google.common.collect.Sets
import discord4j.common.util.Snowflake

View file

@ -2,6 +2,7 @@ package buttondevteam.discordplugin.mcchat
import buttondevteam.discordplugin.*
import buttondevteam.discordplugin.DPUtils.{FluxExtensions, MonoExtensions}
import buttondevteam.discordplugin.mcchat.sender.{DiscordConnectedPlayer, DiscordPlayer, DiscordPlayerSender}
import buttondevteam.lib.TBMCSystemChatEvent
import buttondevteam.lib.player.{TBMCPlayer, TBMCPlayerBase, TBMCYEEHAWEvent}
import discord4j.common.util.Snowflake
@ -107,8 +108,10 @@ class MCListener(val module: MinecraftChatModule) extends Listener {
@EventHandler def onChatSystemMessage(event: TBMCSystemChatEvent): Unit =
MCChatUtils.forAllowedMCChat(MCChatUtils.send(event.getMessage), event).subscribe()
@EventHandler def onBroadcastMessage(event: BroadcastMessageEvent): Unit =
@EventHandler def onBroadcastMessage(event: BroadcastMessageEvent): Unit = {
module.broadcastedMessages += ((event.getMessage, System.nanoTime()))
MCChatUtils.forCustomAndAllMCChat(MCChatUtils.send(event.getMessage), ChannelconBroadcast.BROADCAST, hookmsg = false).subscribe()
}
@EventHandler def onYEEHAW(event: TBMCYEEHAWEvent): Unit = { //TODO: Inherit from the chat event base to have channel support
val name = event.getSender match {

View file

@ -2,10 +2,11 @@ package buttondevteam.discordplugin.mcchat
import buttondevteam.core.component.channel.Channel
import buttondevteam.discordplugin.DPUtils.{MonoExtensions, SpecExtensions}
import buttondevteam.discordplugin.playerfaker.ServerWatcher
import buttondevteam.discordplugin.playerfaker.perm.LPInjector
import buttondevteam.discordplugin.mcchat.playerfaker.ServerWatcher
import buttondevteam.discordplugin.mcchat.playerfaker.perm.LPInjector
import buttondevteam.discordplugin.mcchat.sender.DiscordConnectedPlayer
import buttondevteam.discordplugin.util.DPState
import buttondevteam.discordplugin.{ChannelconBroadcast, DPUtils, DiscordConnectedPlayer, DiscordPlugin}
import buttondevteam.discordplugin.{ChannelconBroadcast, DPUtils, DiscordPlugin}
import buttondevteam.lib.architecture.{Component, ConfigData, ReadOnlyConfigData}
import buttondevteam.lib.{TBMCCoreAPI, TBMCSystemChatEvent}
import com.google.common.collect.Lists
@ -18,6 +19,7 @@ import reactor.core.scala.publisher.SMono
import java.util
import java.util.stream.Collectors
import java.util.{Objects, UUID}
import scala.collection.mutable
import scala.jdk.CollectionConverters.IterableHasAsScala
/**
@ -100,6 +102,8 @@ class MinecraftChatModule extends Component[DiscordPlugin] {
final private val mcChatCommand = new MCChatCommand(this)
final private val channelconCommand = new ChannelconCommand(this)
val broadcastedMessages: mutable.Map[String, Long] = mutable.Map()
override protected def enable(): Unit = {
if (DPUtils.disableIfConfigErrorRes(this, chatChannel, chatChannelMono)) return ()
listener = new MCChatListener(this)

View file

@ -1,4 +1,4 @@
package buttondevteam.discordplugin.playerfaker
package buttondevteam.discordplugin.mcchat.playerfaker
import org.mockito.MockedConstruction
import org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker

View file

@ -1,4 +1,4 @@
package buttondevteam.discordplugin.playerfaker;
package buttondevteam.discordplugin.mcchat.playerfaker;
import org.bukkit.Location;
import org.bukkit.Material;

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin.playerfaker
package buttondevteam.discordplugin.mcchat.playerfaker
import buttondevteam.discordplugin.DiscordConnectedPlayer
import buttondevteam.discordplugin.mcchat.MCChatUtils
import buttondevteam.discordplugin.mcchat.sender.DiscordConnectedPlayer
import com.destroystokyo.paper.profile.CraftPlayerProfile
import net.bytebuddy.implementation.bind.annotation.IgnoreForBinding
import org.bukkit.entity.Player

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin.playerfaker
package buttondevteam.discordplugin.mcchat.playerfaker
import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import buttondevteam.discordplugin.{DiscordSenderBase, IMCPlayer}
import buttondevteam.discordplugin.mcchat.sender.{DiscordSenderBase, IMCPlayer}
import buttondevteam.lib.TBMCCoreAPI
import org.bukkit.Bukkit
import org.bukkit.entity.Player

View file

@ -1,6 +1,6 @@
package buttondevteam.discordplugin.playerfaker
package buttondevteam.discordplugin.mcchat.playerfaker
import buttondevteam.discordplugin.{DiscordSenderBase, IMCPlayer}
import buttondevteam.discordplugin.mcchat.sender.{DiscordSenderBase, IMCPlayer}
import net.minecraft.server.v1_12_R1.*
import org.bukkit.Bukkit
import org.bukkit.craftbukkit.v1_12_R1.command.VanillaCommandWrapper

View file

@ -1,6 +1,6 @@
package buttondevteam.discordplugin.playerfaker
package buttondevteam.discordplugin.mcchat.playerfaker
import buttondevteam.discordplugin.{DiscordSenderBase, IMCPlayer}
import buttondevteam.discordplugin.mcchat.sender.{DiscordSenderBase, IMCPlayer}
import net.minecraft.server.v1_14_R1.*
import org.bukkit.Bukkit
import org.bukkit.command.CommandSender

View file

@ -1,6 +1,6 @@
package buttondevteam.discordplugin.playerfaker
package buttondevteam.discordplugin.mcchat.playerfaker
import buttondevteam.discordplugin.{DiscordSenderBase, IMCPlayer}
import buttondevteam.discordplugin.mcchat.sender.{DiscordSenderBase, IMCPlayer}
import org.bukkit.Bukkit
import org.bukkit.command.{CommandSender, SimpleCommandMap}
import org.bukkit.entity.Player

View file

@ -1,4 +1,4 @@
package buttondevteam.discordplugin.playerfaker.perm;
package buttondevteam.discordplugin.mcchat.playerfaker.perm;
import org.bukkit.event.Listener;

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin
package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import buttondevteam.discordplugin.playerfaker.{DiscordInventory, VCMDWrapper}
import buttondevteam.discordplugin.mcchat.playerfaker.{DiscordInventory, VCMDWrapper}
import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel
import org.bukkit.*

View file

@ -1,4 +1,4 @@
package buttondevteam.discordplugin
package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.mcchat.MCChatPrivate
import buttondevteam.lib.player.{ChromaGamerBase, UserClass}

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin
package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import buttondevteam.discordplugin.playerfaker.VCMDWrapper
import buttondevteam.discordplugin.mcchat.playerfaker.VCMDWrapper
import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel
import org.bukkit.entity.Player

View file

@ -1,5 +1,6 @@
package buttondevteam.discordplugin
package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.DiscordPlugin
import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel
import org.bukkit.command.CommandSender

View file

@ -1,5 +1,6 @@
package buttondevteam.discordplugin
package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.{DPUtils, DiscordPlugin}
import buttondevteam.lib.TBMCCoreAPI
import buttondevteam.lib.player.ChromaGamerBase
import discord4j.core.`object`.entity.User

View file

@ -0,0 +1,8 @@
package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.mcchat.playerfaker.VCMDWrapper
import org.bukkit.entity.Player
trait IMCPlayer[T] extends Player {
def getVanillaCmdListener: VCMDWrapper
}

View file

@ -1,9 +1,10 @@
package buttondevteam.discordplugin.mccommands
import buttondevteam.discordplugin.commands.{ConnectCommand, VersionCommand}
import buttondevteam.discordplugin.mcchat.sender.{DiscordPlayer, DiscordSenderBase}
import buttondevteam.discordplugin.mcchat.{MCChatUtils, MinecraftChatModule}
import buttondevteam.discordplugin.util.DPState
import buttondevteam.discordplugin.{DPUtils, DiscordPlayer, DiscordPlugin, DiscordSenderBase}
import buttondevteam.discordplugin.{DPUtils, DiscordPlugin}
import buttondevteam.lib.chat.{Command2, CommandClass, ICommand2MC}
import buttondevteam.lib.player.{ChromaGamerBase, TBMCPlayer, TBMCPlayerBase}
import discord4j.core.`object`.ExtendedInvite