From 54cc20813638bceafa12da74f32f119731c433e3 Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Thu, 11 Feb 2021 15:37:03 -0600 Subject: [PATCH 001/104] big jere crazy --- .../command/impl/other/JerePicsCommand.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java new file mode 100644 index 00000000..795267cb --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java @@ -0,0 +1,61 @@ +package com.diamondfire.helpbot.bot.command.impl.other; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.help.CommandCategory; +import com.diamondfire.helpbot.bot.command.help.HelpContext; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import net.dv8tion.jda.api.EmbedBuilder; + +import java.awt.*; + +public class JerePicsCommand extends Command { + + @Override + public String getName() { + return "jerepic"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Very hot jeremaster pictures.") + .category(CommandCategory.OTHER); + + } + + @Override + protected ArgumentSet compileArguments() { + return new ArgumentSet(); + } + + @Override + public Permission getPermission() { + return Permission.USER; + } + + @Override + public void run(CommandEvent event) { + EmbedBuilder embed = new EmbedBuilder(); + embed.setColor(Color.RED); + embed.setTitle("Jere Pic"); + int rngIndex = (int) (Math.random() * links.length); + embed.setImage(links[rngIndex]); + event.getChannel().sendMessage(embed.build()).queue(); + + } + private static final String[] links = { + "https://imgur.com/cZZHMWY.png", + "https://imgur.com/BGcPKv8.png", + "https://imgur.com/seRPPR2.png", + "https://imgur.com/e0aHeLp.png", + "https://imgur.com/m6MjDbk.png", + "https://imgur.com/3yaNUzm.png", + "https://cdn.discordapp.com/attachments/180793115223916544/539188769480507426/unknown.png", + "https://cdn.discordapp.com/attachments/789266995672907818/809169563543273512/jeremaster.png", + "https://external-content.duckduckgo.com/iu/?reload=1613077331588&u=https://mc-heads.net/body/jeremaster/180.png" + }; + + +} From f29843e57a94b017874f6b6dbb7aa745d115663a Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Thu, 11 Feb 2021 15:38:46 -0600 Subject: [PATCH 002/104] Add files via upload crazy --- .../helpbot/bot/HelpBotInstance.java | 284 +++++++++--------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index f55c5e83..87edbf79 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -1,142 +1,142 @@ -package com.diamondfire.helpbot.bot; - -import com.diamondfire.helpbot.HelpBot; -import com.diamondfire.helpbot.bot.command.CommandHandler; -import com.diamondfire.helpbot.bot.command.impl.codeblock.*; -import com.diamondfire.helpbot.bot.command.impl.other.*; -import com.diamondfire.helpbot.bot.command.impl.stats.*; -import com.diamondfire.helpbot.bot.command.impl.stats.graph.*; -import com.diamondfire.helpbot.bot.command.impl.stats.individualized.*; -import com.diamondfire.helpbot.bot.command.impl.stats.plot.*; -import com.diamondfire.helpbot.bot.command.impl.stats.support.*; -import com.diamondfire.helpbot.bot.config.Config; -import com.diamondfire.helpbot.bot.events.*; -import com.diamondfire.helpbot.sys.tasks.TaskRegistry; -import net.dv8tion.jda.api.*; -import net.dv8tion.jda.api.entities.Activity; -import net.dv8tion.jda.api.requests.GatewayIntent; -import net.dv8tion.jda.api.utils.MemberCachePolicy; -import net.dv8tion.jda.api.utils.cache.CacheFlag; - -import javax.security.auth.login.LoginException; - -public class HelpBotInstance { - - private static final Config config = new Config(); - public static final long DF_GUILD = config.getGuild(); - public static final long LOG_CHANNEL = config.getLogChannel(); - private static final CommandHandler handler = new CommandHandler(); - - private static JDA jda; - private static final TaskRegistry loop = new TaskRegistry(); - - public static void initialize() throws LoginException { - - handler.register( - // codeblock commands - new CodeCommand(), - new RankCommand(), - new BlockCommand(), - new SearchCommand(), - new TagsCommand(), - // others - new MimicCommand(), - new FetchDataCommand(), - new InfoCommand(), - new EvalCommand(), - new GarfieldCommand(), - new HelpCommand(), - new RestartCommand(), - new ActionDumpCommand(), - new RawCommand(), - new SamQuotesCommand(), - new PolicyCommand(), - new SkinCommand(), - new DisableCommand(), - new EnableCommand(), - new DisableCommand(), - new ImageDumpCommand(), - new SoundListCommand(), - new QueryCommand(), - new RulesCommand(), - new BulkExecuteCommand(), - new PermUnlocksCommand(), - new MuteCommand(), - new MutedCommand(), - new UnmuteCommand(), - new VerifyCommand(), - // statsbot - new StatsCommand(), - new SupportBadCommand(), - new JoinBadCommand(), - new PlotCommand(), - new ProfileCommand(), - new ActivePlotsCommand(), - new TrendingPlotsCommand(), - new PlotsCommand(), - new CpTopCommand(), - new RetiredListCommand(), - new StaffListCommand(), - new SessionTopCommand(), - new LastJoinedCommand(), - new SupporteeStatsCommand(), - new NewPlayersCommand(), - new StatsGraphCommand(), - new NewJoinGraphCommand(), - new PlayersCommand(), - new BoostersCommand(), - new DiscordBoostersCommand(), - new TimeTopCommand(), - new QueueCommand(), - new WhoHelpedCommand(), - new HelpedByCommand(), - new NamesCommand(), - new PlayerJoinGraphCommand(), - new CpCommand(), - new CpRequirementsCommand(), - new VoteGivenLeaderboard(), - new PlotVoteGraphCommand(), - new JoinDataCommand(), - new TotalStatsCommand(), - new TokenTopCommand(), - new HistoryCommand(), - new UuidCommand(), - new PlotLocCommand(), - new FindSupporteeNamesCommand(), - new SessionsCommand(), - new SupporteeSessionsCommand(), - new ExcuseStaffCommand(), - new ExcusedStaffCommand(), - new SupportBannedPlayersCommand(), - new DiscussionMuteCommand() - ); - - JDABuilder builder = JDABuilder.createDefault(config.getToken()) - .enableIntents(GatewayIntent.GUILD_MEMBERS) - .setStatus(OnlineStatus.ONLINE) - .setMemberCachePolicy(MemberCachePolicy.NONE) - .setActivity(Activity.watching("for " + getConfig().getPrefix() + "help")) - .setGatewayEncoding(GatewayEncoding.ETF) - .disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.CLIENT_STATUS) - .addEventListeners(new MessageEvent(), new ReactionEvent(), new ReadyEvent(), new GuildJoinEvent()); - - jda = builder.build(); - handler.initialize(); - } - - public static JDA getJda() { - return jda; - } - - public static CommandHandler getHandler() { - return handler; - } - - public static Config getConfig() { - return config; - } - - public static TaskRegistry getScheduler() { - return loop; - } -} +package com.diamondfire.helpbot.bot; + +import com.diamondfire.helpbot.bot.command.CommandHandler; +import com.diamondfire.helpbot.bot.command.impl.codeblock.*; +import com.diamondfire.helpbot.bot.command.impl.other.*; +import com.diamondfire.helpbot.bot.command.impl.stats.*; +import com.diamondfire.helpbot.bot.command.impl.stats.graph.*; +import com.diamondfire.helpbot.bot.command.impl.stats.individualized.*; +import com.diamondfire.helpbot.bot.command.impl.stats.plot.*; +import com.diamondfire.helpbot.bot.command.impl.stats.support.*; +import com.diamondfire.helpbot.bot.config.Config; +import com.diamondfire.helpbot.bot.events.*; +import com.diamondfire.helpbot.sys.tasks.TaskRegistry; +import net.dv8tion.jda.api.*; +import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.requests.GatewayIntent; +import net.dv8tion.jda.api.utils.MemberCachePolicy; +import net.dv8tion.jda.api.utils.cache.CacheFlag; + +import javax.security.auth.login.LoginException; + +public class HelpBotInstance { + + private static final Config config = new Config(); + public static final long DF_GUILD = config.getGuild(); + public static final long LOG_CHANNEL = config.getLogChannel(); + private static final CommandHandler handler = new CommandHandler(); + + private static JDA jda; + private static final TaskRegistry loop = new TaskRegistry(); + + public static void initialize() throws LoginException { + + handler.register( + // codeblock commands + new CodeCommand(), + new RankCommand(), + new BlockCommand(), + new SearchCommand(), + new TagsCommand(), + // others + new MimicCommand(), + new FetchDataCommand(), + new InfoCommand(), + new EvalCommand(), + new GarfieldCommand(), + new HelpCommand(), + new RestartCommand(), + new ActionDumpCommand(), + new RawCommand(), + new SamQuotesCommand(), + new PolicyCommand(), + new SkinCommand(), + new DisableCommand(), + new EnableCommand(), + new DisableCommand(), + new ImageDumpCommand(), + new SoundListCommand(), + new QueryCommand(), + new RulesCommand(), + new BulkExecuteCommand(), + new PermUnlocksCommand(), + new MuteCommand(), + new MutedCommand(), + new UnmuteCommand(), + new VerifyCommand(), + // statsbot + new StatsCommand(), + new SupportBadCommand(), + new JoinBadCommand(), + new PlotCommand(), + new ProfileCommand(), + new ActivePlotsCommand(), + new TrendingPlotsCommand(), + new PlotsCommand(), + new CpTopCommand(), + new RetiredListCommand(), + new StaffListCommand(), + new SessionTopCommand(), + new LastJoinedCommand(), + new SupporteeStatsCommand(), + new NewPlayersCommand(), + new StatsGraphCommand(), + new NewJoinGraphCommand(), + new PlayersCommand(), + new BoostersCommand(), + new DiscordBoostersCommand(), + new TimeTopCommand(), + new QueueCommand(), + new WhoHelpedCommand(), + new HelpedByCommand(), + new NamesCommand(), + new PlayerJoinGraphCommand(), + new CpCommand(), + new CpRequirementsCommand(), + new VoteGivenLeaderboard(), + new PlotVoteGraphCommand(), + new JoinDataCommand(), + new TotalStatsCommand(), + new TokenTopCommand(), + new HistoryCommand(), + new UuidCommand(), + new PlotLocCommand(), + new FindSupporteeNamesCommand(), + new SessionsCommand(), + new SupporteeSessionsCommand(), + new ExcuseStaffCommand(), + new ExcusedStaffCommand(), + new SupportBannedPlayersCommand(), + new DiscussionMuteCommand(), + new JerePicsCommand() + ); + + JDABuilder builder = JDABuilder.createDefault(config.getToken()) + .enableIntents(GatewayIntent.GUILD_MEMBERS) + .setStatus(OnlineStatus.ONLINE) + .setMemberCachePolicy(MemberCachePolicy.NONE) + .setActivity(Activity.watching("for " + getConfig().getPrefix() + "help")) + .setGatewayEncoding(GatewayEncoding.ETF) + .disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.CLIENT_STATUS) + .addEventListeners(new MessageEvent(), new ReactionEvent(), new ReadyEvent(), new GuildJoinEvent()); + + jda = builder.build(); + handler.initialize(); + } + + public static JDA getJda() { + return jda; + } + + public static CommandHandler getHandler() { + return handler; + } + + public static Config getConfig() { + return config; + } + + public static TaskRegistry getScheduler() { + return loop; + } +} From 6f5073e211ef42e21ac74207c3e0e9035f77a32c Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Fri, 12 Feb 2021 10:44:23 -0600 Subject: [PATCH 003/104] Update JerePicsCommand.java --- .../helpbot/bot/command/impl/other/JerePicsCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java index 795267cb..c2fb60af 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java @@ -54,7 +54,9 @@ public void run(CommandEvent event) { "https://imgur.com/3yaNUzm.png", "https://cdn.discordapp.com/attachments/180793115223916544/539188769480507426/unknown.png", "https://cdn.discordapp.com/attachments/789266995672907818/809169563543273512/jeremaster.png", - "https://external-content.duckduckgo.com/iu/?reload=1613077331588&u=https://mc-heads.net/body/jeremaster/180.png" + "https://external-content.duckduckgo.com/iu/?reload=1613077331588&u=https://mc-heads.net/body/jeremaster/180.png", + "https://imgur.com/LFldK2p.png", + "https://imgur.com/aEq7voY.png" }; From fa687d78da28e08e90764b21ba62776f9c2e36a2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 13 Feb 2021 14:48:08 -0600 Subject: [PATCH 004/104] jere moment --- .../helpbot/bot/command/impl/other/JerePicsCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java index c2fb60af..838cf8e9 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java @@ -38,7 +38,7 @@ public Permission getPermission() { @Override public void run(CommandEvent event) { EmbedBuilder embed = new EmbedBuilder(); - embed.setColor(Color.RED); + embed.setColor(new Color(184,45,40)); embed.setTitle("Jere Pic"); int rngIndex = (int) (Math.random() * links.length); embed.setImage(links[rngIndex]); @@ -56,7 +56,8 @@ public void run(CommandEvent event) { "https://cdn.discordapp.com/attachments/789266995672907818/809169563543273512/jeremaster.png", "https://external-content.duckduckgo.com/iu/?reload=1613077331588&u=https://mc-heads.net/body/jeremaster/180.png", "https://imgur.com/LFldK2p.png", - "https://imgur.com/aEq7voY.png" + "https://imgur.com/aEq7voY.png", + "https://render.namemc.com/skin/3d/body.png?skin=8c8cd7a1a2c52ca4&model=classic&theta=180&phi=0&time=0&width=600&height=800" }; From a307a1b0489da69ba549e2abe84f861fc8af05d1 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 13 Feb 2021 14:59:50 -0600 Subject: [PATCH 005/104] nbs stuff --- .../helpbot/bot/HelpBotInstance.java | 3 +- .../bot/command/impl/other/NbsCommand.java | 122 ++++++++ .../helpbot/util/CompressionUtil.java | 46 +++ .../diamondfire/helpbot/util/NBSDecoder.java | 291 ++++++++++++++++++ .../helpbot/util/NBSToTemplate.java | 157 ++++++++++ .../helpbot/util/OutdatedNBSException.java | 4 + .../diamondfire/helpbot/util/SongData.java | 88 ++++++ 7 files changed, 710 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/SongData.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 87edbf79..d7f4c748 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -108,7 +108,8 @@ public static void initialize() throws LoginException { new ExcusedStaffCommand(), new SupportBannedPlayersCommand(), new DiscussionMuteCommand(), - new JerePicsCommand() + new JerePicsCommand(), + new NbsCommand() ); JDABuilder builder = JDABuilder.createDefault(config.getToken()) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java new file mode 100644 index 00000000..b46ccd71 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java @@ -0,0 +1,122 @@ +package com.diamondfire.helpbot.bot.command.impl.other; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.help.CommandCategory; +import com.diamondfire.helpbot.bot.command.help.HelpContext; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.util.*; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.TextChannel; + +import java.awt.*; +import java.io.*; +import java.net.*; +import java.nio.charset.StandardCharsets; + +import java.util.Scanner; +import java.util.concurrent.CompletableFuture; + +public class NbsCommand extends Command { + private static String generateLink(String templateData) throws IOException { + URL url = new URL("https://twv.vercel.app/v2/create"); + URLConnection con = url.openConnection(); + HttpURLConnection http = (HttpURLConnection) con; + http.setRequestMethod("POST"); + http.setDoOutput(true); + byte[] out = templateData.getBytes(StandardCharsets.UTF_8); + int length = out.length; + + http.setFixedLengthStreamingMode(length); + http.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + http.setRequestProperty("Accept","application/json; charset=UTF-8"); + http.connect(); + try(OutputStream os = http.getOutputStream()) { + os.write(out); + } + Scanner s = new Scanner(http.getInputStream()).useDelimiter("\\A"); + String result = s.hasNext() ? s.next() : ""; + s.close(); + http.disconnect(); + + return result; + } + @Override + public String getName() { + return "nbs"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Generates Codeutils song function.") + .category(CommandCategory.OTHER); + + } + + @Override + protected ArgumentSet compileArguments() { return new ArgumentSet(); } + + @Override + public Permission getPermission() { return Permission.USER; } + + @Override + public void run(CommandEvent event) { + TextChannel channel = event.getChannel(); + if(event.getMessage().getAttachments().isEmpty()) { + EmbedBuilder warning = new EmbedBuilder() + .addField("Warning!","You need to attach an nbs file!",false) + .setColor(Color.RED); + event.getChannel().sendMessage(warning.build()).queue(); + return; + } + + EmbedBuilder errorEmbed = new EmbedBuilder() + .setColor(Color.RED) + .setTitle("An error occurred!"); + try { + File file = new File("input.nbs"); + CompletableFuture.runAsync(() -> { + CompletableFuture task = event.getMessage().getAttachments().get(0).downloadToFile(file); + while(!task.isDone()) { } + try { + SongData d = NBSDecoder.parse(file); + String code = new NBSToTemplate(d).convert(); + byte[] b64 = CompressionUtil.toBase64(CompressionUtil.toGZIP(code.getBytes(StandardCharsets.UTF_8))); + String exported = new String(b64); + String jsonInputString = String.format("{\"template\": \"%s\",\"temp\": true}",exported); + String result = generateLink(jsonInputString); + JsonObject json = new Gson().fromJson(result,JsonObject.class); + + EmbedBuilder embed = new EmbedBuilder() + .setColor(new Color(70,199,82)) + .setTitle("Function Generated!") + .setThumbnail("https://static.wikia.nocookie.net/minecraft/images/9/9b/Note_Block.png/revision/latest?cb=20190921170620") + .addField("Link(Expires in 2 mins):","https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString(),false) + .addField("Music Player:","https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40",false); + + + + channel.sendMessage(embed.build()).queue(); + System.out.println(exported); + } catch(OutdatedNBSException e) { + e.printStackTrace(); + channel.sendMessage(errorEmbed.build()).queue(); + } catch(IOException e) { + e.printStackTrace(); + channel.sendMessage(errorEmbed.build()).queue(); + } + + }); + } catch(Exception e) { + e.printStackTrace(); + channel.sendMessage(errorEmbed.build()).queue(); + } + + + } +} diff --git a/src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java b/src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java new file mode 100644 index 00000000..4e3de232 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java @@ -0,0 +1,46 @@ +package com.diamondfire.helpbot.util; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.zip.*; + +public class CompressionUtil { + + public static byte[] fromBase64(byte[] bytes) { + return Base64.getDecoder().decode(bytes); + } + + public static byte[] toBase64(byte[] bytes) { + return Base64.getEncoder().encode(bytes); + } + + public static byte[] fromGZIP(byte[] bytes) throws IOException { + if (bytes == null) { + return null; + } + + GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes)); + BufferedReader bf = new BufferedReader(new InputStreamReader(gis, StandardCharsets.UTF_8)); + StringBuilder outStr = new StringBuilder(); + String line; + while ((line = bf.readLine()) != null) { + outStr.append(line); + } + + return outStr.toString().getBytes(); + } + + public static byte[] toGZIP(byte[] bytes) throws IOException { + if (bytes == null) { + return null; + } + ByteArrayOutputStream obj = new ByteArrayOutputStream(); + GZIPOutputStream gzip = new GZIPOutputStream(obj); + gzip.write(bytes); + gzip.close(); + + return obj.toByteArray(); + } + +} diff --git a/src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java b/src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java new file mode 100644 index 00000000..0e2cbcc0 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java @@ -0,0 +1,291 @@ +package com.diamondfire.helpbot.util; +import java.io.*; +import java.math.BigDecimal; +//stolen from Codeutils + +public class NBSDecoder { + + public static SongData parse(File songFile) throws IOException, OutdatedNBSException { + try { + return parse(new FileInputStream(songFile), songFile); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } + + private static SongData parse(InputStream inputStream, File songFile) throws IOException, OutdatedNBSException { + String title = ""; + String author = ""; + String file = songFile.getName(); + float speed = 0f; + float actualSpeed = 0f; + short timeSignature = 4; + int loopTick = 0; + int loopCount = 0; + int vanillaInstruments = 9; + + StringBuilder stringBuilder = new StringBuilder(); + StringBuilder layerStringBuilder = new StringBuilder(); + + DataInputStream dataInputStream = new DataInputStream(inputStream); + short length = readShort(dataInputStream); + int nbsversion = 0; + if (length == 0) { + nbsversion = dataInputStream.readByte(); + vanillaInstruments = dataInputStream.readByte(); + if (nbsversion >= 3) { + length = readShort(dataInputStream); + } else if (nbsversion == 1 || nbsversion == 2) { + throw new OutdatedNBSException(); + } + } else { + // poop ChatUtil.sendMessage("§a§lHEY!§r Looks like you are using original Note Block Studio. I recommend you to use §bOpen Note Block Studio§r, which is an unofficial continuation of Note Block Studio!"); + } + short layers = readShort(dataInputStream); //song height + title = readString(dataInputStream); //title + author = readString(dataInputStream); //author + readString(dataInputStream); //original author + String description = readString(dataInputStream); //description + actualSpeed = readShort(dataInputStream); //speed + speed = actualSpeed / 100f; //speed + dataInputStream.readBoolean(); //autosave + dataInputStream.readByte(); //autosave duration + timeSignature = (short) dataInputStream.readByte(); //time signature + readInt(dataInputStream); //minutes spent + readInt(dataInputStream); //left clicks + readInt(dataInputStream); //right clicks + readInt(dataInputStream); //blocks added + readInt(dataInputStream); //nlocks removed + readString(dataInputStream); // mid or schematic filename + if (nbsversion >= 4) { + dataInputStream.readByte(); //loop on/off + loopCount = dataInputStream.readByte(); //loop count + loopTick = readShort(dataInputStream); //loop start tick + } + + short tick = -1; + String[][] addStringList = new String[layers][length + 1]; + int[][] instrumentList = new int[layers][length + 1]; + int[][] pitchList = new int[layers][length + 1]; + int[][] finepitchList = new int[layers][length + 1]; + int[][] velocityList = new int[layers][length + 1]; + int[][] panningList = new int[layers][length + 1]; + boolean[] columnExistence = new boolean[length + 1]; + boolean[][] noteExistence = new boolean[layers][length + 1]; + boolean firstNoted = false; + + while (true) { //Read notes + short t = readShort(dataInputStream); + if (t == 0) { + break; + } + tick += t; + + columnExistence[tick] = true; + + short layer = -1; + while (true) { + short jumpLayers = readShort(dataInputStream); + if (jumpLayers == 0) { + break; + } + layer += jumpLayers; + byte instrument = dataInputStream.readByte(); + byte note = dataInputStream.readByte(); + byte velocity = 100; + int panning = 100; + short finepitch = 0; + if (nbsversion >= 4) { + velocity = dataInputStream.readByte(); + panning = Byte.toUnsignedInt(dataInputStream.readByte()); + finepitch = readShort(dataInputStream); + } + + //System.out.println("==NOTE #" + debugNoteCount + "=="); + //System.out.println(" Tick: " + tick); + //System.out.println(" Instrument ID: " + instrument); + //System.out.println(" Jump to the next tick: " + tCopy); + //System.out.println(" Jump to the next layer: " + jumpLayers); + + instrumentList[layer][tick] = instrument; + pitchList[layer][tick] = note; + finepitchList[layer][tick] = finepitch; + velocityList[layer][tick] = velocity; + panningList[layer][tick] = panning; + noteExistence[layer][tick] = true; + } + } + + for (int i = 0; i < layers; i++) { //Read layer data + + String name = readString(dataInputStream); + + if (nbsversion >= 4) { + dataInputStream.readByte(); + } + + byte volume = dataInputStream.readByte(); + int panning = 100; + + if (nbsversion >= 2) { + panning = Byte.toUnsignedInt(dataInputStream.readByte()); + } + + for (int currentTick = 0; currentTick < length + 1; currentTick++) { + boolean noteExists = noteExistence[i][currentTick]; + if (noteExists == true) { + + int noteVelocity = velocityList[i][currentTick]; + int notePanning = panningList[i][currentTick]; + + double averageVelocity = noteVelocity * (volume / 100d); + double averagePanning = (notePanning + panning) / 2d; + + double preFinalPanning = (averagePanning - 100) / 50; + + String finalVelocity = new BigDecimal(averageVelocity).setScale(3, BigDecimal.ROUND_FLOOR).stripTrailingZeros().toPlainString(); + String finalPanning = new BigDecimal(preFinalPanning).setScale(3, BigDecimal.ROUND_FLOOR).stripTrailingZeros().toPlainString(); + + //COOL DEBUG CODE STARTS FROM HERE + //System.out.println("Pre-Final Panning: " + preFinalPanning); + //System.out.println("Final Panning: " + finalPanning); + //COOL DEBUG CODE ENDS HERE + + String finalString; + if (preFinalPanning == 0) { + finalString = "," + finalVelocity; + } else { + finalString = "," + finalVelocity + "," + finalPanning; + } + addStringList[i][currentTick] = finalString; + } + } + + String finalLayerVolume = new BigDecimal(volume).setScale(3, BigDecimal.ROUND_FLOOR).stripTrailingZeros().toPlainString(); + String finalLayerPanning = new BigDecimal(panning).setScale(3, BigDecimal.ROUND_FLOOR).stripTrailingZeros().toPlainString(); + + layerStringBuilder.append("=" + finalLayerVolume + "," + finalLayerPanning); + } + + int customInstruments = 0; + customInstruments = dataInputStream.readByte(); + + int[] customPitchList = new int[customInstruments]; + + if (customInstruments >= 1) { + for (int i = 0; i < customInstruments; i++) { + int instrumentOffset = vanillaInstruments + customInstruments; + int instrumentPitch = 0; + + readString(dataInputStream); //Instrument name + readString(dataInputStream); //Sound file + + instrumentPitch = dataInputStream.readByte(); //Sound pitch + + customPitchList[i] = instrumentPitch; + + dataInputStream.readByte(); //Press key + } + } + + //EPIC DEBUG CODE STARTS FROM HERE + //System.out.println("List length: " + jumpTickList.size()); + //System.out.println("Array length: " + jumpTickArray.length); + //EPIC DEBUG CODE ENDS HERE + + dataInputStream.close(); + + for (int currentTick = 0; currentTick < length + 1; currentTick++) { + boolean columnExists = columnExistence[currentTick]; + if (columnExists == true) { + StringBuilder columnStringBuilder = new StringBuilder(); + if (!firstNoted) { + columnStringBuilder.append(currentTick + 1); + firstNoted = true; + } else { + columnStringBuilder.append("=" + (currentTick + 1)); + } + boolean firstAppend = true; + for (int i = 0; i < layers; i++) { + boolean noteExists = noteExistence[i][currentTick]; + if (noteExists == true) { + String laterNoteString = addStringList[i][currentTick]; + + int noteInstrument = instrumentList[i][currentTick]; + int noteKey = pitchList[i][currentTick]; + int noteFinePitch = finepitchList[i][currentTick]; + int noteKeyOffset = 0; + + //ANOTHER EPIC DEBUG CODE STARTS FROM HERE + //System.out.println("Note ID: " + noteID); + //ANOTHER EPIC DEBUG CODE ENDS HERE + + if (noteInstrument >= vanillaInstruments) { + int instrumentId = noteInstrument - vanillaInstruments; + noteKeyOffset = customPitchList[instrumentId] - 45; + } + if (firstAppend == true) { + columnStringBuilder.append(":" + (noteInstrument + 1) + "," + getMinecraftPitch(noteKey + (double) noteFinePitch / 100d, noteKeyOffset) + laterNoteString); + firstAppend = false; + } else { + columnStringBuilder.append(";" + (noteInstrument + 1) + "," + getMinecraftPitch(noteKey + (double) noteFinePitch / 100d, noteKeyOffset) + laterNoteString); + } + } + } + stringBuilder.append(columnStringBuilder.toString()); + } + } + + //YET ANOTHER EPIC DEBUG CODE STARTS FROM HERE + //System.out.println("Note Data: " + stringBuilder.toString()); + //System.out.println("Layer Data: " + layerStringBuilder.toString()); + //YET ANOTHER EPIC DEBUG CODE ENDS HERE + + return new SongData(title, author, speed, (int) ((Math.ceil((length + 1) / timeSignature) + 1) * timeSignature), stringBuilder.toString(), file, layerStringBuilder.toString(), (loopTick + 1), loopCount, customInstruments); + } + + private static short readShort(DataInputStream dataInputStream) throws IOException { + int byte1 = dataInputStream.readUnsignedByte(); + int byte2 = dataInputStream.readUnsignedByte(); + return (short) (byte1 + (byte2 << 8)); + } + + private static int readInt(DataInputStream dataInputStream) throws IOException { + int byte1 = dataInputStream.readUnsignedByte(); + int byte2 = dataInputStream.readUnsignedByte(); + int byte3 = dataInputStream.readUnsignedByte(); + int byte4 = dataInputStream.readUnsignedByte(); + return (byte1 + (byte2 << 8) + (byte3 << 16) + (byte4 << 24)); + } + + private static String readString(DataInputStream dataInputStream) throws IOException { + int length = readInt(dataInputStream); + StringBuilder builder = new StringBuilder(length); + for (; length > 0; --length) { + char c = (char) dataInputStream.readByte(); + if (c == (char) 0x0D) { + c = ' '; + } + builder.append(c); + } + return builder.toString(); + } + + private static int getMinecraftPitch(double key, double offset) { + + if (key < 33) key -= 9; + else if (key > 57) key -= 57; + else key -= 33; + + key += offset; + + double finalValue = (0.5 * (Math.pow(2, (key / 12)))) * 1000; + + return (int) finalValue; + } + + public SongData parse(InputStream inputStream) throws IOException, OutdatedNBSException { + return parse(inputStream, null); + } +} diff --git a/src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java b/src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java new file mode 100644 index 00000000..a5359dc9 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java @@ -0,0 +1,157 @@ +package com.diamondfire.helpbot.util; +import java.math.BigDecimal; +// stolen from Codeutils + + +public class NBSToTemplate { + + private static final String SONG_PARSER_VERSION = "4"; + private static final String SONG_NBS_FORMAT_VERSION = "4"; + + String song; + String name; + String author; + String filename; + String layers; + String version; + float speed; + int length; + int loopTick; + int loopCount; + int customInstrumentCount; + boolean multipleChests = false; + + public NBSToTemplate(SongData song) { + + this.version = "v" + SONG_PARSER_VERSION + "-nbs" + SONG_NBS_FORMAT_VERSION; + + this.song = song.getNotes(); + this.author = song.getAuthor(); + this.name = song.getName(); + this.filename = song.getFileName(); + this.layers = song.getLayers(); + this.length = song.getLength(); + this.speed = song.getSpeed(); + this.loopTick = song.getLoopTick(); + this.loopCount = song.getLoopCount(); + this.customInstrumentCount = song.getCustomInstrumentCount(); + } + + public String convert() { + String[] songData = song.split("="); + StringBuilder currentNotes = new StringBuilder(); + StringBuilder code = new StringBuilder(); + StringBuilder currentBlock = new StringBuilder(); + StringBuilder instList = new StringBuilder(); + + String songTempo = new BigDecimal(this.speed).stripTrailingZeros().toPlainString(); + + if (name.length() == 0) { + if (filename.indexOf(".") > 0) { + name = filename.substring(0, filename.lastIndexOf(".")); + } else { + name = filename; + } + } + if (author.length() == 0) author = "N/A"; + + code.append(String.format("{\"id\":\"block\",\"block\":\"func\",\"args\":{\"items\":[{\"item\":{\"id\":\"bl_tag\",\"data\":{\"option\":\"False\",\"tag\":\"Is Hidden\",\"action\":\"dynamic\",\"block\":\"func\"}},\"slot\":26}]},\"data\":\"%s\"},", name)); + + int slot = 1; + int chestCount = 1; + boolean chestInited = false; + int noteCount = 0; + boolean finalNote = false; + + for (int i = 0; i < songData.length; i++) { + boolean closeChest = false; + if (slot == 1) { + if (!chestInited) { + chestInited = true; + currentBlock.append("{\"id\":\"block\",\"block\":\"set_var\",\"args\":{\"items\":[{\"item\":{\"id\":\"var\",\"data\":{\"name\":\"notes\",\"scope\":\"local\"}},\"slot\":0}"); + } + } + + if (slot >= 27) { + closeChest = true; + } + + if (!closeChest) { + String currentNote = songData[i]; + String revertString = currentNotes.toString(); + + if (noteCount == 0) { + currentNotes.append(currentNote); + } else { + currentNotes.append("=" + currentNote); + } + noteCount++; + + if (currentNotes.length() > 1930) { + currentNotes = new StringBuilder(revertString); + currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes.toString(), slot)); + currentNotes.setLength(0); + noteCount = 0; + finalNote = true; + i -= 1; + slot++; + } + + if (i >= songData.length - 1) { + if (!finalNote) { + currentBlock.append(String.format(",{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":%d}", currentNotes.toString(), slot)); + currentNotes.setLength(0); + } + closeChest = true; + } + finalNote = false; + } + if (closeChest) { + String varActionType; + if (chestCount == 1) { + varActionType = "CreateList"; + } else { + varActionType = "AppendValue"; + } + + currentBlock.append(String.format("]},\"action\":\"%s\"},", varActionType)); + code.append(currentBlock.toString()); + currentBlock.setLength(0); + currentNotes.setLength(0); + + chestInited = false; + noteCount = 0; + finalNote = false; + chestCount++; + closeChest = false; + slot = 1; + } + } + + //CreateList: instrumentNames + if (customInstrumentCount == 0) { + code.append("{\"id\":\"block\",\"block\":\"set_var\",\"args\":{\"items\":[{\"item\":{\"id\":\"var\",\"data\":{\"name\":\"instrumentNames\",\"scope\":\"local\"}},\"slot\":0},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Harp\"}},\"slot\":1},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bass\"}},\"slot\":2},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bass Drum\"}},\"slot\":3},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Snare Drum\"}},\"slot\":4},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Click\"}},\"slot\":5},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Guitar\"}},\"slot\":6},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Flute\"}},\"slot\":7},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bell\"}},\"slot\":8},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Chime\"}},\"slot\":9},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Xylophone\"}},\"slot\":10},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Iron Xylophone\"}},\"slot\":11},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Cow Bell\"}},\"slot\":12},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Didgeridoo\"}},\"slot\":13},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bit\"}},\"slot\":14},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Banjo\"}},\"slot\":15},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Pling\"}},\"slot\":16}]},\"action\":\"CreateList\"},"); + } else { + instList.append("{\"id\":\"block\",\"block\":\"set_var\",\"args\":{\"items\":[{\"item\":{\"id\":\"var\",\"data\":{\"name\":\"instrumentNames\",\"scope\":\"local\"}},\"slot\":0},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Harp\"}},\"slot\":1},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bass\"}},\"slot\":2},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bass Drum\"}},\"slot\":3},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Snare Drum\"}},\"slot\":4},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Click\"}},\"slot\":5},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Guitar\"}},\"slot\":6},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Flute\"}},\"slot\":7},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bell\"}},\"slot\":8},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Chime\"}},\"slot\":9},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Xylophone\"}},\"slot\":10},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Iron Xylophone\"}},\"slot\":11},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Cow Bell\"}},\"slot\":12},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Didgeridoo\"}},\"slot\":13},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Bit\"}},\"slot\":14},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Banjo\"}},\"slot\":15},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"Pling\"}},\"slot\":16},"); + + int currentSlot; + + currentSlot = 17; + for (int currentInstID = 1; currentInstID <= customInstrumentCount; currentInstID++) { + if (currentInstID == customInstrumentCount) { + instList.append(String.format("{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"\"}},\"slot\":%d}", currentInstID, currentSlot)); + } else { + instList.append(String.format("{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"\"}},\"slot\":%d},", currentInstID, currentSlot)); + } + currentSlot++; + } + instList.append("]},\"action\":\"CreateList\"},"); + code.append(instList.toString()); + } + + //CreateList: songData + code.append(String.format("{\"id\":\"block\",\"block\":\"set_var\",\"args\":{\"items\":[{\"item\":{\"id\":\"var\",\"data\":{\"name\":\"songData\",\"scope\":\"local\"}},\"slot\":0},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":1},{\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":2},{\"item\":{\"id\":\"num\",\"data\":{\"name\":\"%s\"}},\"slot\":3}, {\"item\":{\"id\":\"num\",\"data\":{\"name\":\"%d\"}},\"slot\":4}, {\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":5}, {\"item\":{\"id\":\"txt\",\"data\":{\"name\":\"%s\"}},\"slot\":6},{\"item\":{\"id\":\"num\",\"data\":{\"name\":\"%d\"}},\"slot\":7},{\"item\":{\"id\":\"num\",\"data\":{\"name\":\"%d\"}},\"slot\":8}]},\"action\":\"CreateList\"}", name, author, songTempo, length, layers, version, loopTick, loopCount)); + + return "{\"blocks\": [" + code + "]}"; + } +} diff --git a/src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java b/src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java new file mode 100644 index 00000000..24314b2d --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java @@ -0,0 +1,4 @@ +package com.diamondfire.helpbot.util; + +public class OutdatedNBSException extends Exception{ +} diff --git a/src/main/java/com/diamondfire/helpbot/util/SongData.java b/src/main/java/com/diamondfire/helpbot/util/SongData.java new file mode 100644 index 00000000..194ee0fd --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/SongData.java @@ -0,0 +1,88 @@ +package com.diamondfire.helpbot.util; +// stole from codeutils lol +public class SongData { + + String name; + String author; + float speed; + int length; + String fileName; + String notes; + String layers; + int loopTick; + int loopCount; + int customInstrumentCount; + + public SongData(String name, String author, float speed, int length, String notes, String fileName, String layers, int loopTick, int loopCount, int customInstrumentCount) { + this.name = name; + this.author = author; + this.speed = speed; + this.length = length; + this.notes = notes; + this.fileName = fileName; + this.layers = layers; + this.loopTick = loopTick; + this.loopCount = loopCount; + this.customInstrumentCount = customInstrumentCount; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public float getSpeed() { + return speed; + } + + public void setSpeed(float speed) { + this.speed = speed; + } + + public int getLength() { + return length; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getLayers() { + return layers; + } + + public int getLoopTick() { + return loopTick; + } + + public int getLoopCount() { + return loopCount; + } + + public int getCustomInstrumentCount() { + return customInstrumentCount; + } +} \ No newline at end of file From 60ec0cfc3985bd612e86f25ced3fa0a5fda1d713 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 13 Feb 2021 15:11:19 -0600 Subject: [PATCH 006/104] nbs stuff --- input.nbs | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 input.nbs diff --git a/input.nbs b/input.nbs new file mode 100644 index 00000000..e69de29b From b90f5d546f9f0c6c61d2a9c40fa55b0b118ab488 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 13 Feb 2021 20:13:08 -0600 Subject: [PATCH 007/104] nbs things --- src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index d7f4c748..364ae7b1 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -108,7 +108,6 @@ public static void initialize() throws LoginException { new ExcusedStaffCommand(), new SupportBannedPlayersCommand(), new DiscussionMuteCommand(), - new JerePicsCommand(), new NbsCommand() ); From 8242dea84c43b5da36425b82b7be8cc1622bbe18 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 13 Feb 2021 20:14:08 -0600 Subject: [PATCH 008/104] nbs things --- .../helpbot/util/OutdatedNBSException.java | 4 --- .../util/{ => nbs}/CompressionUtil.java | 3 +- .../helpbot/util/{ => nbs}/NBSDecoder.java | 32 ++++++------------- .../helpbot/util/{ => nbs}/NBSToTemplate.java | 6 ++-- .../util/nbs/OutdatedNBSException.java | 4 +++ .../helpbot/util/{ => nbs}/SongData.java | 4 +-- 6 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java rename src/main/java/com/diamondfire/helpbot/util/{ => nbs}/CompressionUtil.java (92%) rename src/main/java/com/diamondfire/helpbot/util/{ => nbs}/NBSDecoder.java (87%) rename src/main/java/com/diamondfire/helpbot/util/{ => nbs}/NBSToTemplate.java (98%) create mode 100644 src/main/java/com/diamondfire/helpbot/util/nbs/OutdatedNBSException.java rename src/main/java/com/diamondfire/helpbot/util/{ => nbs}/SongData.java (94%) diff --git a/src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java b/src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java deleted file mode 100644 index 24314b2d..00000000 --- a/src/main/java/com/diamondfire/helpbot/util/OutdatedNBSException.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.diamondfire.helpbot.util; - -public class OutdatedNBSException extends Exception{ -} diff --git a/src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java b/src/main/java/com/diamondfire/helpbot/util/nbs/CompressionUtil.java similarity index 92% rename from src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java rename to src/main/java/com/diamondfire/helpbot/util/nbs/CompressionUtil.java index 4e3de232..76feef15 100644 --- a/src/main/java/com/diamondfire/helpbot/util/CompressionUtil.java +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/CompressionUtil.java @@ -1,9 +1,10 @@ -package com.diamondfire.helpbot.util; +package com.diamondfire.helpbot.util.nbs; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.zip.*; +//from https://github.com/CodeUtilities/CodeUtilities public class CompressionUtil { diff --git a/src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java similarity index 87% rename from src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java rename to src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java index 0e2cbcc0..a38628cf 100644 --- a/src/main/java/com/diamondfire/helpbot/util/NBSDecoder.java +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSDecoder.java @@ -1,7 +1,8 @@ -package com.diamondfire.helpbot.util; +package com.diamondfire.helpbot.util.nbs; + import java.io.*; import java.math.BigDecimal; -//stolen from Codeutils +//from https://github.com/CodeUtilities/CodeUtilities public class NBSDecoder { @@ -40,7 +41,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE throw new OutdatedNBSException(); } } else { - // poop ChatUtil.sendMessage("§a§lHEY!§r Looks like you are using original Note Block Studio. I recommend you to use §bOpen Note Block Studio§r, which is an unofficial continuation of Note Block Studio!"); + } short layers = readShort(dataInputStream); //song height title = readString(dataInputStream); //title @@ -102,11 +103,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE finepitch = readShort(dataInputStream); } - //System.out.println("==NOTE #" + debugNoteCount + "=="); - //System.out.println(" Tick: " + tick); - //System.out.println(" Instrument ID: " + instrument); - //System.out.println(" Jump to the next tick: " + tCopy); - //System.out.println(" Jump to the next layer: " + jumpLayers); + instrumentList[layer][tick] = instrument; pitchList[layer][tick] = note; @@ -147,10 +144,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE String finalVelocity = new BigDecimal(averageVelocity).setScale(3, BigDecimal.ROUND_FLOOR).stripTrailingZeros().toPlainString(); String finalPanning = new BigDecimal(preFinalPanning).setScale(3, BigDecimal.ROUND_FLOOR).stripTrailingZeros().toPlainString(); - //COOL DEBUG CODE STARTS FROM HERE - //System.out.println("Pre-Final Panning: " + preFinalPanning); - //System.out.println("Final Panning: " + finalPanning); - //COOL DEBUG CODE ENDS HERE + String finalString; if (preFinalPanning == 0) { @@ -189,10 +183,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE } } - //EPIC DEBUG CODE STARTS FROM HERE - //System.out.println("List length: " + jumpTickList.size()); - //System.out.println("Array length: " + jumpTickArray.length); - //EPIC DEBUG CODE ENDS HERE + dataInputStream.close(); @@ -217,9 +208,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE int noteFinePitch = finepitchList[i][currentTick]; int noteKeyOffset = 0; - //ANOTHER EPIC DEBUG CODE STARTS FROM HERE - //System.out.println("Note ID: " + noteID); - //ANOTHER EPIC DEBUG CODE ENDS HERE + if (noteInstrument >= vanillaInstruments) { int instrumentId = noteInstrument - vanillaInstruments; @@ -237,10 +226,7 @@ private static SongData parse(InputStream inputStream, File songFile) throws IOE } } - //YET ANOTHER EPIC DEBUG CODE STARTS FROM HERE - //System.out.println("Note Data: " + stringBuilder.toString()); - //System.out.println("Layer Data: " + layerStringBuilder.toString()); - //YET ANOTHER EPIC DEBUG CODE ENDS HERE + return new SongData(title, author, speed, (int) ((Math.ceil((length + 1) / timeSignature) + 1) * timeSignature), stringBuilder.toString(), file, layerStringBuilder.toString(), (loopTick + 1), loopCount, customInstruments); } diff --git a/src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java similarity index 98% rename from src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java rename to src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java index a5359dc9..6eee3ec0 100644 --- a/src/main/java/com/diamondfire/helpbot/util/NBSToTemplate.java +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/NBSToTemplate.java @@ -1,6 +1,8 @@ -package com.diamondfire.helpbot.util; +package com.diamondfire.helpbot.util.nbs; + import java.math.BigDecimal; -// stolen from Codeutils +// from https://github.com/CodeUtilities/CodeUtilities + public class NBSToTemplate { diff --git a/src/main/java/com/diamondfire/helpbot/util/nbs/OutdatedNBSException.java b/src/main/java/com/diamondfire/helpbot/util/nbs/OutdatedNBSException.java new file mode 100644 index 00000000..1c4245c8 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/OutdatedNBSException.java @@ -0,0 +1,4 @@ +package com.diamondfire.helpbot.util.nbs; +//from https://github.com/CodeUtilities/CodeUtilities +public class OutdatedNBSException extends Exception{ +} diff --git a/src/main/java/com/diamondfire/helpbot/util/SongData.java b/src/main/java/com/diamondfire/helpbot/util/nbs/SongData.java similarity index 94% rename from src/main/java/com/diamondfire/helpbot/util/SongData.java rename to src/main/java/com/diamondfire/helpbot/util/nbs/SongData.java index 194ee0fd..ad939a07 100644 --- a/src/main/java/com/diamondfire/helpbot/util/SongData.java +++ b/src/main/java/com/diamondfire/helpbot/util/nbs/SongData.java @@ -1,5 +1,5 @@ -package com.diamondfire.helpbot.util; -// stole from codeutils lol +package com.diamondfire.helpbot.util.nbs; +// from https://github.com/CodeUtilities/CodeUtilities public class SongData { String name; From 997957250a21af5e952525e3f17864933ae4f5ba Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 13 Feb 2021 20:16:19 -0600 Subject: [PATCH 009/104] nbs things --- .../bot/command/impl/other/NbsCommand.java | 83 +++++++++---------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java index b46ccd71..a5601a6c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java @@ -6,7 +6,7 @@ import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; -import com.diamondfire.helpbot.util.*; +import com.diamondfire.helpbot.util.nbs.*; import com.google.gson.Gson; import com.google.gson.JsonObject; import net.dv8tion.jda.api.EmbedBuilder; @@ -22,29 +22,7 @@ import java.util.concurrent.CompletableFuture; public class NbsCommand extends Command { - private static String generateLink(String templateData) throws IOException { - URL url = new URL("https://twv.vercel.app/v2/create"); - URLConnection con = url.openConnection(); - HttpURLConnection http = (HttpURLConnection) con; - http.setRequestMethod("POST"); - http.setDoOutput(true); - byte[] out = templateData.getBytes(StandardCharsets.UTF_8); - int length = out.length; - - http.setFixedLengthStreamingMode(length); - http.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); - http.setRequestProperty("Accept","application/json; charset=UTF-8"); - http.connect(); - try(OutputStream os = http.getOutputStream()) { - os.write(out); - } - Scanner s = new Scanner(http.getInputStream()).useDelimiter("\\A"); - String result = s.hasNext() ? s.next() : ""; - s.close(); - http.disconnect(); - return result; - } @Override public String getName() { return "nbs"; @@ -53,9 +31,8 @@ public String getName() { @Override public HelpContext getHelpContext() { return new HelpContext() - .description("Generates Codeutils song function.") + .description("Generates a Codeutils song function.") .category(CommandCategory.OTHER); - } @Override @@ -67,42 +44,41 @@ public HelpContext getHelpContext() { @Override public void run(CommandEvent event) { TextChannel channel = event.getChannel(); + EmbedBuilder warning = new EmbedBuilder() + .addField("Warning!","You need to attach an nbs file!",false) + .setColor(Color.RED); if(event.getMessage().getAttachments().isEmpty()) { - EmbedBuilder warning = new EmbedBuilder() - .addField("Warning!","You need to attach an nbs file!",false) - .setColor(Color.RED); - event.getChannel().sendMessage(warning.build()).queue(); + channel.sendMessage(warning.build()).queue(); + return; + } + Message.Attachment attachment = event.getMessage().getAttachments().get(0); + if(!attachment.getFileExtension().equals("nbs")) { + channel.sendMessage(warning.build()).queue(); return; } - EmbedBuilder errorEmbed = new EmbedBuilder() .setColor(Color.RED) .setTitle("An error occurred!"); try { File file = new File("input.nbs"); + System.out.println(event.getMessage().getAttachments().get(0).getFileExtension()); CompletableFuture.runAsync(() -> { - CompletableFuture task = event.getMessage().getAttachments().get(0).downloadToFile(file); + CompletableFuture task = attachment.downloadToFile(file); while(!task.isDone()) { } try { - SongData d = NBSDecoder.parse(file); - String code = new NBSToTemplate(d).convert(); + String code = new NBSToTemplate(NBSDecoder.parse(file)).convert(); byte[] b64 = CompressionUtil.toBase64(CompressionUtil.toGZIP(code.getBytes(StandardCharsets.UTF_8))); - String exported = new String(b64); - String jsonInputString = String.format("{\"template\": \"%s\",\"temp\": true}",exported); - String result = generateLink(jsonInputString); - JsonObject json = new Gson().fromJson(result,JsonObject.class); + String jsonInputString = String.format("{\"template\": \"%s\",\"temp\": true}",new String(b64)); + JsonObject json = new Gson().fromJson(generateLink(jsonInputString),JsonObject.class); EmbedBuilder embed = new EmbedBuilder() .setColor(new Color(70,199,82)) .setTitle("Function Generated!") .setThumbnail("https://static.wikia.nocookie.net/minecraft/images/9/9b/Note_Block.png/revision/latest?cb=20190921170620") - .addField("Link(Expires in 2 mins):","https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString(),false) - .addField("Music Player:","https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40",false); - - + .addField("Link: *Expires in 2 mins*","https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString(),false) + .addField("Info:","Click the link shown above and click the button in the bottom left corner to copy the give command for the template. You will need this function to play songs: https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40",false); channel.sendMessage(embed.build()).queue(); - System.out.println(exported); } catch(OutdatedNBSException e) { e.printStackTrace(); channel.sendMessage(errorEmbed.build()).queue(); @@ -110,13 +86,34 @@ public void run(CommandEvent event) { e.printStackTrace(); channel.sendMessage(errorEmbed.build()).queue(); } - }); } catch(Exception e) { e.printStackTrace(); channel.sendMessage(errorEmbed.build()).queue(); } + } + private static String generateLink(String templateData) throws IOException { + URL url = new URL("https://twv.vercel.app/v2/create"); + URLConnection con = url.openConnection(); + HttpURLConnection http = (HttpURLConnection) con; + http.setRequestMethod("POST"); + http.setDoOutput(true); + byte[] out = templateData.getBytes(StandardCharsets.UTF_8); + int length = out.length; + http.setFixedLengthStreamingMode(length); + http.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + http.setRequestProperty("Accept","application/json; charset=UTF-8"); + http.connect(); + try(OutputStream os = http.getOutputStream()) { + os.write(out); + } + Scanner s = new Scanner(http.getInputStream()).useDelimiter("\\A"); + String result = s.hasNext() ? s.next() : ""; + s.close(); + http.disconnect(); + + return result; } } From 62c1c8e829bd8a8f4eeb6c2482562f1cfd6295e1 Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Sat, 13 Feb 2021 20:20:44 -0600 Subject: [PATCH 010/104] Delete JerePicsCommand.java --- .../command/impl/other/JerePicsCommand.java | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java deleted file mode 100644 index 838cf8e9..00000000 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/JerePicsCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.diamondfire.helpbot.bot.command.impl.other; - -import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.help.CommandCategory; -import com.diamondfire.helpbot.bot.command.help.HelpContext; -import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; -import com.diamondfire.helpbot.bot.events.CommandEvent; -import net.dv8tion.jda.api.EmbedBuilder; - -import java.awt.*; - -public class JerePicsCommand extends Command { - - @Override - public String getName() { - return "jerepic"; - } - - @Override - public HelpContext getHelpContext() { - return new HelpContext() - .description("Very hot jeremaster pictures.") - .category(CommandCategory.OTHER); - - } - - @Override - protected ArgumentSet compileArguments() { - return new ArgumentSet(); - } - - @Override - public Permission getPermission() { - return Permission.USER; - } - - @Override - public void run(CommandEvent event) { - EmbedBuilder embed = new EmbedBuilder(); - embed.setColor(new Color(184,45,40)); - embed.setTitle("Jere Pic"); - int rngIndex = (int) (Math.random() * links.length); - embed.setImage(links[rngIndex]); - event.getChannel().sendMessage(embed.build()).queue(); - - } - private static final String[] links = { - "https://imgur.com/cZZHMWY.png", - "https://imgur.com/BGcPKv8.png", - "https://imgur.com/seRPPR2.png", - "https://imgur.com/e0aHeLp.png", - "https://imgur.com/m6MjDbk.png", - "https://imgur.com/3yaNUzm.png", - "https://cdn.discordapp.com/attachments/180793115223916544/539188769480507426/unknown.png", - "https://cdn.discordapp.com/attachments/789266995672907818/809169563543273512/jeremaster.png", - "https://external-content.duckduckgo.com/iu/?reload=1613077331588&u=https://mc-heads.net/body/jeremaster/180.png", - "https://imgur.com/LFldK2p.png", - "https://imgur.com/aEq7voY.png", - "https://render.namemc.com/skin/3d/body.png?skin=8c8cd7a1a2c52ca4&model=classic&theta=180&phi=0&time=0&width=600&height=800" - }; - - -} From cd7af5a9695fcfdb59150d5d54e07ea20723bc5f Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Sun, 14 Feb 2021 09:37:29 -0600 Subject: [PATCH 011/104] Update HelpBotInstance.java --- src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 364ae7b1..d43be811 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -64,6 +64,7 @@ public static void initialize() throws LoginException { new MutedCommand(), new UnmuteCommand(), new VerifyCommand(), + new PollCommand(), // statsbot new StatsCommand(), new SupportBadCommand(), From 696835825c95b66b87eefaeee80839dfcbc241a6 Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Mon, 15 Feb 2021 18:24:33 -0600 Subject: [PATCH 012/104] Update HelpBotInstance.java --- .../java/com/diamondfire/helpbot/bot/HelpBotInstance.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 699b064a..c5f761c5 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -1,6 +1,5 @@ package com.diamondfire.helpbot.bot; -import com.diamondfire.helpbot.HelpBot; import com.diamondfire.helpbot.bot.command.CommandHandler; import com.diamondfire.helpbot.bot.command.impl.codeblock.*; import com.diamondfire.helpbot.bot.command.impl.other.*; @@ -110,7 +109,8 @@ public static void initialize() throws LoginException { new ExcusedStaffCommand(), new SupportBannedPlayersCommand(), new DiscussionMuteCommand(), - new NbsCommand() + new NbsCommand(), + new DailySessionsCommand() ); JDABuilder builder = JDABuilder.createDefault(config.getToken()) @@ -141,4 +141,4 @@ public static Config getConfig() { public static TaskRegistry getScheduler() { return loop; } -} \ No newline at end of file +} From 7bf5b5d4a9e17a714091185e0023c53b6e6fe17e Mon Sep 17 00:00:00 2001 From: ProjectDF <61924259+ProjectDF@users.noreply.github.com> Date: Mon, 15 Feb 2021 18:25:19 -0600 Subject: [PATCH 013/104] Update NbsCommand.java --- .../bot/command/impl/other/NbsCommand.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java index a5601a6c..ecf23771 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java @@ -5,6 +5,9 @@ import com.diamondfire.helpbot.bot.command.help.HelpContext; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.InformativeReply; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.InformativeReplyType; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.nbs.*; import com.google.gson.Gson; @@ -44,16 +47,15 @@ public HelpContext getHelpContext() { @Override public void run(CommandEvent event) { TextChannel channel = event.getChannel(); - EmbedBuilder warning = new EmbedBuilder() - .addField("Warning!","You need to attach an nbs file!",false) - .setColor(Color.RED); + PresetBuilder preset = new PresetBuilder(); + preset.withPreset(new InformativeReply(InformativeReplyType.ERROR,"You need to attach an nbs file!")); if(event.getMessage().getAttachments().isEmpty()) { - channel.sendMessage(warning.build()).queue(); + event.reply(preset); return; } Message.Attachment attachment = event.getMessage().getAttachments().get(0); if(!attachment.getFileExtension().equals("nbs")) { - channel.sendMessage(warning.build()).queue(); + event.reply(preset); return; } EmbedBuilder errorEmbed = new EmbedBuilder() @@ -75,8 +77,8 @@ public void run(CommandEvent event) { .setColor(new Color(70,199,82)) .setTitle("Function Generated!") .setThumbnail("https://static.wikia.nocookie.net/minecraft/images/9/9b/Note_Block.png/revision/latest?cb=20190921170620") - .addField("Link: *Expires in 2 mins*","https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString(),false) - .addField("Info:","Click the link shown above and click the button in the bottom left corner to copy the give command for the template. You will need this function to play songs: https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40",false); + .addField("Link: __Expires in 2 mins__","[Function Link](https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString() + ")",false) + .addField("Info:","Click the link shown above and click the button in the bottom left corner to copy the give command for the template. You will need [this function](https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40) to play songs.",false); channel.sendMessage(embed.build()).queue(); } catch(OutdatedNBSException e) { From 98a976c3f27424b72493357721a087be6927c914 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 19 Apr 2021 16:21:32 -0500 Subject: [PATCH 014/104] Update to nbs command --- .../bot/command/impl/other/NbsCommand.java | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java index ecf23771..5da1bebe 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/NbsCommand.java @@ -22,79 +22,74 @@ import java.nio.charset.StandardCharsets; import java.util.Scanner; -import java.util.concurrent.CompletableFuture; public class NbsCommand extends Command { - + @Override public String getName() { return "nbs"; } - + @Override public HelpContext getHelpContext() { return new HelpContext() .description("Generates a Codeutils song function.") .category(CommandCategory.OTHER); } - + @Override protected ArgumentSet compileArguments() { return new ArgumentSet(); } - + @Override public Permission getPermission() { return Permission.USER; } - + @Override public void run(CommandEvent event) { TextChannel channel = event.getChannel(); - PresetBuilder preset = new PresetBuilder(); - preset.withPreset(new InformativeReply(InformativeReplyType.ERROR,"You need to attach an nbs file!")); + PresetBuilder nbsPreset = new PresetBuilder() + .withPreset(new InformativeReply(InformativeReplyType.ERROR,"You need to attach an nbs file!")); + PresetBuilder error = new PresetBuilder() + .withPreset(new InformativeReply(InformativeReplyType.ERROR,"Something went wrong while processing/generating!")); + if(event.getMessage().getAttachments().isEmpty()) { - event.reply(preset); + event.reply(nbsPreset); return; } Message.Attachment attachment = event.getMessage().getAttachments().get(0); if(!attachment.getFileExtension().equals("nbs")) { - event.reply(preset); + event.reply(nbsPreset); return; } - EmbedBuilder errorEmbed = new EmbedBuilder() - .setColor(Color.RED) - .setTitle("An error occurred!"); + try { File file = new File("input.nbs"); - System.out.println(event.getMessage().getAttachments().get(0).getFileExtension()); - CompletableFuture.runAsync(() -> { - CompletableFuture task = attachment.downloadToFile(file); - while(!task.isDone()) { } + attachment.downloadToFile(file).thenAccept((downloadedFile) -> { try { String code = new NBSToTemplate(NBSDecoder.parse(file)).convert(); byte[] b64 = CompressionUtil.toBase64(CompressionUtil.toGZIP(code.getBytes(StandardCharsets.UTF_8))); - String jsonInputString = String.format("{\"template\": \"%s\",\"temp\": true}",new String(b64)); - JsonObject json = new Gson().fromJson(generateLink(jsonInputString),JsonObject.class); - + String templateJson = String.format("{\"template\": \"%s\",\"temp\": true}",new String(b64)); + JsonObject json = new Gson().fromJson(generateLink(templateJson),JsonObject.class); + EmbedBuilder embed = new EmbedBuilder() - .setColor(new Color(70,199,82)) - .setTitle("Function Generated!") - .setThumbnail("https://static.wikia.nocookie.net/minecraft/images/9/9b/Note_Block.png/revision/latest?cb=20190921170620") - .addField("Link: __Expires in 2 mins__","[Function Link](https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString() + ")",false) - .addField("Info:","Click the link shown above and click the button in the bottom left corner to copy the give command for the template. You will need [this function](https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40) to play songs.",false); - + .setColor(new Color(70,199,82)) + .setTitle("Template Generated!") + .setThumbnail("https://static.wikia.nocookie.net/minecraft/images/9/9b/Note_Block.png/revision/latest?cb=20190921170620") + .addField("Link: __Expires in 2 minutes__","[Template Link](https://derpystuff.gitlab.io/code/l?link=" + json.get("link").getAsString() + ")",false) + .addField("Info:","Click the link shown above and click the button in the bottom left corner to copy the give command for the template. You will need [this function](https://derpystuff.gitlab.io/code/l?link=7cf5d91c35bbde31c28567d8d8945c40) to play songs.",false); + channel.sendMessage(embed.build()).queue(); - } catch(OutdatedNBSException e) { - e.printStackTrace(); - channel.sendMessage(errorEmbed.build()).queue(); - } catch(IOException e) { + } catch(OutdatedNBSException | IOException e) { e.printStackTrace(); - channel.sendMessage(errorEmbed.build()).queue(); + event.reply(error); } }); } catch(Exception e) { e.printStackTrace(); - channel.sendMessage(errorEmbed.build()).queue(); + event.reply(error); } - + } + private static String generateLink(String templateData) throws IOException { URL url = new URL("https://twv.vercel.app/v2/create"); URLConnection con = url.openConnection(); @@ -103,7 +98,6 @@ private static String generateLink(String templateData) throws IOException { http.setDoOutput(true); byte[] out = templateData.getBytes(StandardCharsets.UTF_8); int length = out.length; - http.setFixedLengthStreamingMode(length); http.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); http.setRequestProperty("Accept","application/json; charset=UTF-8"); @@ -115,7 +109,7 @@ private static String generateLink(String templateData) throws IOException { String result = s.hasNext() ? s.next() : ""; s.close(); http.disconnect(); - + return result; } } From 2f1b84bf6dd0781d138fd9eebea7e7eb35a48647 Mon Sep 17 00:00:00 2001 From: Ymerald <72456735+Ymerald@users.noreply.github.com> Date: Mon, 3 May 2021 07:12:44 -0700 Subject: [PATCH 015/104] ?samquote submit update + ?samquote reload (#39) --- .../command/impl/other/SamQuotesCommand.java | 85 +++++++++++++++++-- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java index 2dfd60f6..a262587b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java @@ -10,7 +10,6 @@ import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; -import com.diamondfire.helpbot.util.IOUtil; import net.dv8tion.jda.api.EmbedBuilder; import javax.imageio.ImageIO; @@ -18,10 +17,9 @@ import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import java.io.*; -import java.net.URL; import java.util.*; -import static com.diamondfire.helpbot.util.textgen.CacheData.CacheData; //use this if you want to add more data to ai sam +import static com.diamondfire.helpbot.util.textgen.CacheData.CacheData; import static com.diamondfire.helpbot.util.textgen.MarkovManipulation.getNextWord; public class SamQuotesCommand extends Command { @@ -42,9 +40,13 @@ public HelpContext getHelpContext() { new HelpContextArgument() .name("get"), new HelpContextArgument() - .name("submit"), + .name("submit (beginning word)"), new HelpContextArgument() - .name("generate")); + .name("generate"), + new HelpContextArgument() + .name("reload"), + new HelpContextArgument() + .name("count")); } @Override @@ -211,6 +213,8 @@ public void run(CommandEvent event) { ); event.reply(success); + + addSamquote(messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", "")); } catch (IOException e) { @@ -255,8 +259,28 @@ public void run(CommandEvent event) { startingTexts.add(line.split(" ")[0]); } - String word = startingTexts.get((int) Math.rint(Math.random() * startingTexts.size())); + String word; + if (event.getMessage().getContentRaw().split(" ").length == 2) { + + word = startingTexts.get((int) Math.rint(Math.random() * startingTexts.size())); + } else { + + if (startingTexts.contains(event.getMessage().getContentRaw().split(" ")[2])) { + + word = event.getMessage().getContentRaw().split(" ")[2]; + + } else { + + PresetBuilder error = new PresetBuilder(); + + error.withPreset( + new InformativeReply(InformativeReplyType.ERROR, "Sam has never started a message with this word before!") + ); + + return; + } + } String string = ""; for (int i = 0; i < 50; i++) { @@ -418,6 +442,25 @@ public void run(CommandEvent event) { event.getChannel().sendMessage(builder.build()).addFile(samQuote, "quote.png").queue(); + } else if (event.getArgument("action").equals("reload")) { + + try { + CacheData(); + } catch (IOException e) { + e.printStackTrace(); + } + + } else if (event.getArgument("action").equals("count")) { + + String[] strings = ExternalFiles.SAM_DIR.list(); + + EmbedBuilder builder = new EmbedBuilder(); + builder.setTitle("Total Sam Quotes:"); + builder.setDescription("" + strings.length); + builder.setColor(new Color(87, 177, 71)); + + event.getChannel().sendMessage(builder.build()).queue(); + } else { String[] strings = ExternalFiles.SAM_DIR.list(); @@ -437,7 +480,35 @@ public void run(CommandEvent event) { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("action", - new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit", "generate", "get")).optional(null)); + new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit", "generate", "get", "reload", "count")).optional(null)); + } + + private void addSamquote(String samquote) { + + try { + + File file = new File("samquotes.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + + String line; + String newFile = ""; + + while ((line = br.readLine()) != null) { + + if (line != samquote) { newFile += line + "\n"; } + } + + newFile += samquote; + + FileWriter fileWriter = new FileWriter("samquotes.txt"); + fileWriter.write(newFile); + fileWriter.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } } } From dddaeb03b30433e5c8362219d2f643fa80e360a4 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Fri, 28 May 2021 11:57:59 -0400 Subject: [PATCH 016/104] initial button stuff --- build.gradle | 2 +- .../helpbot/bot/HelpBotInstance.java | 7 +- .../argument/impl/parsing/ArgumentStack.java | 2 + .../codeblock/AbstractSingleQueryCommand.java | 54 ++++----- .../bot/command/impl/other/HelpCommand.java | 2 +- .../bot/command/impl/other/OcrCommand.java | 109 ++++++++++++++++++ .../bot/command/impl/other/RulesCommand.java | 2 +- .../bot/command/impl/other/VerifyCommand.java | 5 + .../command/impl/stats/JoinDataCommand.java | 10 +- .../command/impl/stats/NewPlayersCommand.java | 7 +- .../bot/command/impl/stats/QueueCommand.java | 5 +- .../impl/stats/RetiredListCommand.java | 2 +- .../command/impl/stats/StaffListCommand.java | 2 +- .../helpbot/bot/config/Config.java | 4 + .../helpbot/bot/events/ButtonEvent.java | 14 +++ .../helpbot/bot/events/GuildJoinEvent.java | 1 - .../helpbot/bot/events/MessageEvent.java | 4 +- .../helpbot/bot/events/ReactionEvent.java | 37 ------ .../sys/graph/generators/GraphGenerators.java | 8 +- .../sys/interaction/button/ButtonHandler.java | 59 ++++++++++ .../sys/message/acceptors/FilterAcceptor.java | 2 +- .../sys/message/acceptors/VerifyAcceptor.java | 72 ++++++++++++ .../sys/multiselector/MultiSelector.java | 57 +++++++++ .../multiselector/MultiSelectorBuilder.java | 2 +- .../multiselector/MultiSelectorPage.java | 2 +- .../sys/reactions/impl/ReactionHandler.java | 91 --------------- .../reactions/impl/ReactionRespondEvent.java | 22 ---- .../sys/reactions/impl/ReactionWait.java | 50 -------- .../multiselector/MultiSelector.java | 68 ----------- .../helpbot/sys/rolereact/ReactRole.java | 3 +- .../sys/rolereact/RoleReactListener.java | 95 +++++---------- .../diamondfire/helpbot/util/EmbedUtil.java | 4 + .../diamondfire/helpbot/util/StringUtil.java | 8 ++ .../util/TemporaryRunnableStorage.java | 89 ++++++++++++++ .../com/diamondfire/helpbot/util/Util.java | 23 ++++ 35 files changed, 528 insertions(+), 396 deletions(-) create mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/OcrCommand.java create mode 100644 src/main/java/com/diamondfire/helpbot/bot/events/ButtonEvent.java delete mode 100644 src/main/java/com/diamondfire/helpbot/bot/events/ReactionEvent.java create mode 100644 src/main/java/com/diamondfire/helpbot/sys/interaction/button/ButtonHandler.java create mode 100644 src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java create mode 100644 src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java rename src/main/java/com/diamondfire/helpbot/sys/{reactions => }/multiselector/MultiSelectorBuilder.java (96%) rename src/main/java/com/diamondfire/helpbot/sys/{reactions => }/multiselector/MultiSelectorPage.java (94%) delete mode 100644 src/main/java/com/diamondfire/helpbot/sys/reactions/impl/ReactionHandler.java delete mode 100644 src/main/java/com/diamondfire/helpbot/sys/reactions/impl/ReactionRespondEvent.java delete mode 100644 src/main/java/com/diamondfire/helpbot/sys/reactions/impl/ReactionWait.java delete mode 100644 src/main/java/com/diamondfire/helpbot/sys/reactions/multiselector/MultiSelector.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/TemporaryRunnableStorage.java diff --git a/build.gradle b/build.gradle index 9a837368..b7735700 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ repositories { } dependencies { - implementation ('net.dv8tion:JDA:4.2.0_207') { + implementation ('com.github.DV8FromTheWorld:JDA:5885efcc40d4087b93e142e84fb9aeb11d388dd1') { exclude module: 'opus-java' } implementation 'ch.qos.logback:logback-classic:1.2.3' diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 79584d35..56ce7ee4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -66,7 +66,7 @@ public static void initialize() throws LoginException { new VerifyCommand(), new PollCommand(), new IdeaCommand(), - new ChannelMuteCommand(), + //new ChannelMuteCommand(), // statsbot new StatsCommand(), new SupportBadCommand(), @@ -114,6 +114,7 @@ public static void initialize() throws LoginException { new NbsCommand(), new DailySessionsCommand(), new EightBallCommand(), + new OcrCommand(), new JoinsCommand() ); @@ -124,7 +125,7 @@ public static void initialize() throws LoginException { .setActivity(Activity.watching("for " + getConfig().getPrefix() + "help")) .setGatewayEncoding(GatewayEncoding.ETF) .disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.CLIENT_STATUS) - .addEventListeners(new MessageEvent(), new ReactionEvent(), new ReadyEvent(), new GuildJoinEvent()); + .addEventListeners(new MessageEvent(), new ReadyEvent(), new GuildJoinEvent(), new ButtonEvent()); jda = builder.build(); handler.initialize(); @@ -145,4 +146,4 @@ public static Config getConfig() { public static TaskRegistry getScheduler() { return loop; } -} +} \ No newline at end of file diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ArgumentStack.java b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ArgumentStack.java index ba357885..261ad737 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ArgumentStack.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ArgumentStack.java @@ -11,6 +11,8 @@ public class ArgumentStack { public ArgumentStack(List> args, Collection rawArgs) { this.stack = new RawArgumentStack(new ArrayDeque<>(rawArgs)); this.args = new ArrayDeque<>(args); + + stack.stack.removeIf(String::isEmpty); } public RawArgumentStack getRawArguments() { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java index ce6c27ed..c94e6b72 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java @@ -1,5 +1,6 @@ package com.diamondfire.helpbot.bot.command.impl.codeblock; +import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; import com.diamondfire.helpbot.bot.command.impl.Command; @@ -9,9 +10,11 @@ import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.df.codeinfo.viewables.BasicReaction; -import com.diamondfire.helpbot.sys.reactions.impl.ReactionHandler; +import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler; import com.diamondfire.helpbot.util.*; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.interactions.ActionRow; +import net.dv8tion.jda.api.interactions.button.Button; import java.util.*; import java.util.function.BiConsumer; @@ -24,11 +27,10 @@ public static void sendMultipleMessage(List actions, TextChannel cha // This here is to determine if all the duplicate types are the same. If not, we need to make sure that we filter those out first.. CodeObject referenceData = actions.get(0); Class classReference = referenceData.getClass(); - Map emojis = new HashMap<>(); PresetBuilder preset = new PresetBuilder(); preset.withPreset( new InformativeReply(InformativeReplyType.INFO, "Duplicate Objects Detected!", - "What you are searching for contains a duplicate entry, please react accordingly so I can figure out what you are looking for.") + "What you are searching for contains a duplicate entry. Let's narrow down your search.") ); boolean isSameType = true; @@ -39,42 +41,34 @@ public static void sendMultipleMessage(List actions, TextChannel cha } } //If they are the same type, use the dupe emojis for that certain action type. + Map buttonMap = new HashMap<>(); + List