better version of the imposter format + some music stuff

This commit is contained in:
Chayapak 2023-09-24 08:52:51 +07:00
parent 7bfa7d2e75
commit 52aa236a63
2 changed files with 29 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
import com.google.common.hash.Hashing;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerEntry;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
@ -15,17 +16,37 @@ import java.util.List;
public class FormatCheckerPlugin extends ChatPlugin.Listener {
private final Bot bot;
private int totalFormat = 0;
public FormatCheckerPlugin (Bot bot) {
this.bot = bot;
bot.chat.addListener(this);
bot.players.addListener(new PlayersPlugin.Listener() {
@Override
public void playerJoined(PlayerEntry target) {
reset(target);
}
@Override
public void playerLeft(PlayerEntry target) {
reset(target);
}
});
}
private void reset (PlayerEntry entry) {
if (!entry.profile.getName().equals(bot.config.ownerName)) return;
totalFormat = 0;
}
@Override
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
if (!isImposterFormat) return;
bot.chat.tellraw(Component.text("Possible fake ChomeNS custom chat (this can be false-positive)").color(NamedTextColor.GRAY).style(Style.style(TextDecoration.ITALIC)));
bot.chat.tellraw(Component.text("Possible fake ChomeNS custom chat").style(Style.style(TextDecoration.ITALIC)).color(NamedTextColor.GRAY));
}
public boolean isImposterFormat (Component component) {
@ -56,16 +77,16 @@ public class FormatCheckerPlugin extends ChatPlugin.Listener {
if (!(userHash instanceof TextComponent userHashComponent)) return true;
final long time = System.currentTimeMillis() / 10_000;
final String key = bot.config.imposterFormatChecker.key;
final String hash = Hashing.sha256()
// very pro hash input
.hashString(key + key + time + time, StandardCharsets.UTF_8)
.hashString(key + totalFormat, StandardCharsets.UTF_8)
.toString()
.substring(0, 8);
totalFormat++;
return !hash.equals(userHashComponent.content());
}
}

View file

@ -70,6 +70,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
}
public void loadSong (Path location) {
if (songQueue.size() > 100) return;
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot);
bot.chat.tellraw(
@ -85,6 +87,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
}
public void loadSong (URL location) {
if (songQueue.size() > 100) return;
limit++;
if (limit > bot.config.music.urlRatelimit.limit) {