better version of the imposter format + some music stuff
This commit is contained in:
parent
7bfa7d2e75
commit
52aa236a63
2 changed files with 29 additions and 4 deletions
|
@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
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.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.TranslatableComponent;
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
|
@ -15,17 +16,37 @@ import java.util.List;
|
||||||
public class FormatCheckerPlugin extends ChatPlugin.Listener {
|
public class FormatCheckerPlugin extends ChatPlugin.Listener {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
|
private int totalFormat = 0;
|
||||||
|
|
||||||
public FormatCheckerPlugin (Bot bot) {
|
public FormatCheckerPlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
bot.chat.addListener(this);
|
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
|
@Override
|
||||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||||
if (!isImposterFormat) return;
|
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) {
|
public boolean isImposterFormat (Component component) {
|
||||||
|
@ -56,16 +77,16 @@ public class FormatCheckerPlugin extends ChatPlugin.Listener {
|
||||||
|
|
||||||
if (!(userHash instanceof TextComponent userHashComponent)) return true;
|
if (!(userHash instanceof TextComponent userHashComponent)) return true;
|
||||||
|
|
||||||
final long time = System.currentTimeMillis() / 10_000;
|
|
||||||
|
|
||||||
final String key = bot.config.imposterFormatChecker.key;
|
final String key = bot.config.imposterFormatChecker.key;
|
||||||
|
|
||||||
final String hash = Hashing.sha256()
|
final String hash = Hashing.sha256()
|
||||||
// very pro hash input
|
// very pro hash input
|
||||||
.hashString(key + key + time + time, StandardCharsets.UTF_8)
|
.hashString(key + totalFormat, StandardCharsets.UTF_8)
|
||||||
.toString()
|
.toString()
|
||||||
.substring(0, 8);
|
.substring(0, 8);
|
||||||
|
|
||||||
|
totalFormat++;
|
||||||
|
|
||||||
return !hash.equals(userHashComponent.content());
|
return !hash.equals(userHashComponent.content());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadSong (Path location) {
|
public void loadSong (Path location) {
|
||||||
|
if (songQueue.size() > 100) return;
|
||||||
|
|
||||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot);
|
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot);
|
||||||
|
|
||||||
bot.chat.tellraw(
|
bot.chat.tellraw(
|
||||||
|
@ -85,6 +87,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadSong (URL location) {
|
public void loadSong (URL location) {
|
||||||
|
if (songQueue.size() > 100) return;
|
||||||
|
|
||||||
limit++;
|
limit++;
|
||||||
|
|
||||||
if (limit > bot.config.music.urlRatelimit.limit) {
|
if (limit > bot.config.music.urlRatelimit.limit) {
|
||||||
|
|
Loading…
Reference in a new issue