From be604d1e10b6b3d2fc62ce219f8945aecb14038c Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 1 Oct 2022 16:10:40 -0400 Subject: [PATCH] Remove some old + generally outdated stuff --- build.gradle.kts | 2 +- .../helpbot/bot/HelpBotInstance.java | 11 +- .../impl/other/fun/SamQuotesCommand.java | 468 +----------------- .../impl/other/mod/ChannelMuteCommand.java | 2 +- .../impl/other/mod/DiscussionMuteCommand.java | 103 ---- .../command/impl/other/mod/UnmuteCommand.java | 10 +- .../stats/individualized/HistoryCommand.java | 18 +- .../sys/tasks/impl/MuteExpireTask.java | 25 +- 8 files changed, 30 insertions(+), 609 deletions(-) delete mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java diff --git a/build.gradle.kts b/build.gradle.kts index 7bd7392a..5129b40c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ repositories { } dependencies { - implementation("net.dv8tion:JDA:4.3.0_305") { + implementation("net.dv8tion:JDA:4.4.0_350") { exclude(module = "opus-java") } diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index b55eeaa2..380d2007 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -54,7 +54,7 @@ public static void initialize() throws LoginException { new FetchDataCommand(), new InfoCommand(), new EvalCommand(), - new GarfieldCommand(), + // new GarfieldCommand(), - Dead new HelpCommand(), new RestartCommand(), new ActionDumpCommand(), @@ -74,10 +74,10 @@ public static void initialize() throws LoginException { new MutedCommand(), new UnmuteCommand(), new VerifyCommand(), - new PollCommand(), + // new PollCommand(), - Unused new IdeaCommand(), new StoreCommand(), - new ChannelMuteCommand(), + // new ChannelMuteCommand(), - not finished // statsbot new StatsCommand(), new SupportBadCommand(), @@ -103,7 +103,7 @@ public static void initialize() throws LoginException { new QueueCommand(), new WhoHelpedCommand(), new HelpedByCommand(), - new NamesCommand(), + // new NamesCommand(), - Dead new PlayerJoinGraphCommand(), //new CpCommand(), //new CpRequirementsCommand(), @@ -121,11 +121,10 @@ public static void initialize() throws LoginException { new ExcuseStaffCommand(), new ExcusedStaffCommand(), new SupportBannedPlayersCommand(), - new DiscussionMuteCommand(), new NbsCommand(), new DailySessionsCommand(), new EightBallCommand(), - new OcrCommand(), + // new OcrCommand(), - Dead new JoinsCommand(), new TagCommand(), new PurgeCommand() diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java index 5345536e..8bfc9488 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java @@ -35,18 +35,7 @@ public String getName() { public HelpContext getHelpContext() { return new HelpContext() .description("Gets a quote from Sam the Man.") - .category(CommandCategory.OTHER) - .addArgument( - new HelpContextArgument() - .name("get"), - new HelpContextArgument() - .name("submit (beginning word)"), - new HelpContextArgument() - .name("generate"), - new HelpContextArgument() - .name("reload"), - new HelpContextArgument() - .name("count")); + .category(CommandCategory.OTHER); } @Override @@ -56,459 +45,20 @@ public Permission getPermission() { @Override public void run(CommandEvent event) { + String[] strings = ExternalFiles.SAM_DIR.list(); - if (event.getArgument("action") == null) { + File file = new File(ExternalFiles.SAM_DIR, strings[random.nextInt(strings.length)]); + EmbedBuilder builder = new EmbedBuilder(); + builder.setTitle("Sam Quote"); + builder.setImage("attachment://quote.png"); + builder.setColor(new Color(87, 177, 71)); - String[] strings = ExternalFiles.SAM_DIR.list(); - File file = new File(ExternalFiles.SAM_DIR, strings[random.nextInt(strings.length)]); - EmbedBuilder builder = new EmbedBuilder(); - builder.setTitle("Sam Quote"); - builder.setImage("attachment://quote.png"); - builder.setColor(new Color(87, 177, 71)); - - event.getChannel().sendMessageEmbeds(builder.build()).addFile(file, "quote.png").queue(); - - } else if (event.getArgument("action").equals("submit")) { - - String[] message = event.getMessage().getContentRaw().split("/"); - - if(message.length != 7 || message[5] == null || message[6] == null || message[5].length() != 18 || message[6].length() != 18) { - - PresetBuilder error = new PresetBuilder(); - - error.withPreset( - new InformativeReply(InformativeReplyType.ERROR, "This is not a samquote!") - ); - - event.reply(error); - - return; - } - - long channelID = Long.parseLong(message[5]); - long messageID = Long.parseLong(message[6]); - - event.getGuild().getTextChannelById(channelID).retrieveMessageById(messageID).queue((messageText) -> { - - if(messageText.getAuthor().getIdLong() == 132092551782989824L) { - - try { - - BufferedImage samPfp = ImageIO.read(ExternalFiles.SAMMAN); - - String text = " " + messageText.getContentRaw().replaceAll("[^a-zA-Z0-9 ]", ""); - - int pfpWidth = samPfp.getWidth() * 10; - - //crop pfp into a circle - - BufferedImage circleBuffer = new BufferedImage(pfpWidth, pfpWidth, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2 = circleBuffer.createGraphics(); - - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - g2.setClip(new Ellipse2D.Float(0, 0, pfpWidth, pfpWidth)); - g2.drawImage(samPfp, 0, 0, pfpWidth, pfpWidth, null); - - //convert text into image - - BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - - Graphics2D g2d = img.createGraphics(); - - Font font = new Font("Whitney", Font.PLAIN, 140); - g2d.setFont(font); - FontMetrics fm = g2d.getFontMetrics(); - - int width = fm.stringWidth(text); - int height = fm.getHeight() * 2; - - g2d.dispose(); - - img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - - g2d = img.createGraphics(); - - g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); - g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - - g2d.setFont(font); - g2d.setColor(Color.WHITE); - g2d.drawString(text, 0, fm.getAscent() * 2.2f); - - g2d.dispose(); - - //convert SamMan_ into image - - BufferedImage img2 = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - - Graphics2D g2d2 = img2.createGraphics(); - - Font font2 = new Font("Whitney", Font.BOLD, 140); - g2d2.setFont(font2); - FontMetrics fm2 = g2d2.getFontMetrics(); - - int width2 = fm2.stringWidth(" SamMan_"); - int height2 = fm2.getHeight(); - - g2d2.dispose(); - - img2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_ARGB); - - g2d2 = img2.createGraphics(); - - g2d2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); - g2d2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); - g2d2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); - g2d2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - g2d2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g2d2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g2d2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - - g2d2.setFont(font); - Color nameColor = new Color(45, 102, 212); - g2d2.setColor(nameColor); - g2d2.drawString(" SamMan_", 0, fm2.getAscent()); - - g2d2.dispose(); - - //create background image - - BufferedImage combined = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, img.getHeight() + 10, BufferedImage.TYPE_INT_ARGB); - - Graphics g = combined.getGraphics(); - - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - Color bgColor = new Color(54,57,63); - - BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 30, height + 30, BufferedImage.TYPE_INT_ARGB); - Graphics2D bgg = bg.createGraphics(); - bgg.setPaint (bgColor); - bgg.fillRect (0, 0, bg.getWidth(), bg.getHeight()); - bgg.dispose(); - - //combine images - - g.drawImage(bg, 0, 0, bgColor, null); - g.drawImage(img, 5, 5, bgColor, null); - g.drawImage(img2, 5, 5, bgColor, null); - g.drawImage(circleBuffer, 5, 5, height, height, bgColor, null); - - //save image - - File imageFile = new File(ExternalFiles.SAM_DIR, messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", "") + ".png"); - ImageIO.write(combined, "PNG", imageFile); - - PresetBuilder success = new PresetBuilder(); - - success.withPreset( - new InformativeReply(InformativeReplyType.SUCCESS, "Your SamQuote has been added!") - ); - - event.reply(success); - - addSamquote(messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", "")); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } else { - - PresetBuilder error = new PresetBuilder(); - - error.withPreset( - new InformativeReply(InformativeReplyType.ERROR, "This is not a samquote!") - ); - - event.reply(error); - - } - - }); - } else if (event.getArgument("action").equals("generate")) { - - File file = new File("samquotes.txt"); - - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(file)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - ArrayList startingTexts = new ArrayList<>(); - - String line = null; - while (true) { - try { - if ((line = br.readLine()) == null) break; - } catch (IOException e) { - e.printStackTrace(); - } - - startingTexts.add(line.split(" ")[0]); - } - - 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++) { - - if (word == null || word.equals(".")) break; - string += word + " "; - try { - word = getNextWord(word); - } catch (IOException e) { - e.printStackTrace(); - } - } - - BufferedImage samPfp = null; - try { - samPfp = ImageIO.read(ExternalFiles.SAMMAN); - } catch (IOException e) { - e.printStackTrace(); - } - - String text = " " + string; - - int pfpWidth = samPfp.getWidth() * 10; - - //crop pfp into a circle - - BufferedImage circleBuffer = new BufferedImage(pfpWidth, pfpWidth, BufferedImage.TYPE_INT_ARGB); - - Graphics2D g2 = circleBuffer.createGraphics(); - - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - g2.setClip(new Ellipse2D.Float(0, 0, pfpWidth, pfpWidth)); - g2.drawImage(samPfp, 0, 0, pfpWidth, pfpWidth, null); - - //convert text into image - - BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - - Graphics2D g2d = img.createGraphics(); - - Font font = new Font("Whitney", Font.PLAIN, 140); - g2d.setFont(font); - FontMetrics fm = g2d.getFontMetrics(); - - int width = fm.stringWidth(text); - int height = fm.getHeight() * 2; - - g2d.dispose(); - - img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - - g2d = img.createGraphics(); - - g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); - g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - - g2d.setFont(font); - g2d.setColor(Color.WHITE); - g2d.drawString(text, 0, fm.getAscent() * 2.2f); - - g2d.dispose(); - - //convert SamMan_ into image - - BufferedImage img2 = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - - Graphics2D g2d2 = img2.createGraphics(); - - Font font2 = new Font("Whitney", Font.BOLD, 140); - g2d2.setFont(font2); - FontMetrics fm2 = g2d2.getFontMetrics(); - - int width2 = fm2.stringWidth(" SamMan_"); - int height2 = fm2.getHeight(); - - g2d2.dispose(); - - img2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_ARGB); - - g2d2 = img2.createGraphics(); - - g2d2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); - g2d2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); - g2d2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); - g2d2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - g2d2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g2d2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g2d2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - - g2d2.setFont(font); - - double colorChance = Math.random(); - - - Color nameColor; - - if (colorChance < 0.1) { - - nameColor = new Color(255, 153, 227); - - } else if (colorChance < 0.3) { - - nameColor = new Color(255, 225, 76); - - } else if (colorChance < 0.6) { - - nameColor = new Color(35, 255, 38); - - } else { - - nameColor = new Color(45, 102, 212); - } - - g2d2.setColor(nameColor); - g2d2.drawString(" SamMan_", 0, fm2.getAscent()); - - g2d2.dispose(); - - //create background image - - BufferedImage combined = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, img.getHeight() + 10, BufferedImage.TYPE_INT_ARGB); - - Graphics g = combined.getGraphics(); - - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - Color bgColor = new Color(54,57,63); - - BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 30, height + 30, BufferedImage.TYPE_INT_ARGB); - Graphics2D bgg = bg.createGraphics(); - bgg.setPaint (bgColor); - bgg.fillRect (0, 0, bg.getWidth(), bg.getHeight()); - bgg.dispose(); - - //combine images - - g.drawImage(bg, 0, 0, bgColor, null); - g.drawImage(img, 5, 5, bgColor, null); - g.drawImage(img2, 5, 5, bgColor, null); - g.drawImage(circleBuffer, 5, 5, height, height, bgColor, null); - - File samQuote = new File(ExternalFiles.OTHER_CACHE_DIR, "quote.png"); - try { - ImageIO.write(combined, "PNG", samQuote); - } catch (IOException e) { - e.printStackTrace(); - } - EmbedBuilder builder = new EmbedBuilder(); - builder.setTitle("Sam Quote"); - builder.setImage("attachment://quote.png"); - builder.setColor(new Color(87, 177, 71)); - - event.getChannel().sendMessageEmbeds(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().sendMessageEmbeds(builder.build()).queue(); - - } else { - - String[] strings = ExternalFiles.SAM_DIR.list(); - File file = new File(ExternalFiles.SAM_DIR, strings[random.nextInt(strings.length)]); - EmbedBuilder builder = new EmbedBuilder(); - builder.setTitle("Sam Quote"); - builder.setImage("attachment://quote.png"); - builder.setColor(new Color(87, 177, 71)); - - event.getChannel().sendMessageEmbeds(builder.build()).addFile(file, "quote.png").queue(); - - } - + event.getChannel().sendMessageEmbeds(builder.build()).addFile(file, "quote.png").queue(); } @Override public ArgumentSet compileArguments() { - return new ArgumentSet() - .addArgument("action", - 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(); - } + return new ArgumentSet(); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java index 33d90d2d..96491723 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java @@ -89,7 +89,7 @@ public void run(CommandEvent event) { textChannel.putPermissionOverride(member).deny(net.dv8tion.jda.api.Permission.MESSAGE_ADD_REACTION, net.dv8tion.jda.api.Permission.MESSAGE_WRITE).queue(); }); - HelpBotInstance.getScheduler().schedule(new MuteExpireTask(user, finalDuration, false)); + HelpBotInstance.getScheduler().schedule(new MuteExpireTask(user, finalDuration)); event.reply(builder); }, (error) -> { builder.withPreset( diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java deleted file mode 100644 index 610af367..00000000 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/DiscussionMuteCommand.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.diamondfire.helpbot.bot.command.impl.other.mod; - -import com.diamondfire.helpbot.bot.HelpBotInstance; -import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; -import com.diamondfire.helpbot.bot.command.argument.impl.types.*; -import com.diamondfire.helpbot.bot.command.help.*; -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.*; -import com.diamondfire.helpbot.bot.events.CommandEvent; -import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; -import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; -import com.diamondfire.helpbot.sys.tasks.impl.MuteExpireTask; -import com.diamondfire.helpbot.util.*; -import net.dv8tion.jda.api.entities.*; - -import java.time.*; -import java.time.temporal.TemporalAdjusters; -import java.util.Date; - -public class DiscussionMuteCommand extends Command { - - public static final long DISCUSSION_CHANNEL = HelpBotInstance.getConfig().getDiscussionChannel(); - - @Override - public String getName() { - return "discussionmute"; - } - - @Override - public String[] getAliases() { - return new String[]{"weeklymute", "weekmute", "discmute"}; - } - - @Override - public HelpContext getHelpContext() { - return new HelpContext() - .description("Mutes a player from discussion till the next Monday 6PM EST.") - .category(CommandCategory.OTHER) - .addArgument( - new HelpContextArgument() - .name("user"), - new HelpContextArgument() - .name("duration") - ); - } - - @Override - protected ArgumentSet compileArguments() { - LocalDate nextMonday = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.MONDAY)); - - return new ArgumentSet() - .addArgument("user", - new DiscordUserArgument()) - .addArgument("duration", - new SingleArgumentContainer<>(new TimeOffsetArgument()).optional(DateUtil.toDate(nextMonday))); - } - - @Override - public Permission getPermission() { - return Permission.MODERATION; - } - - @Override - public void run(CommandEvent event) { - PresetBuilder builder = new PresetBuilder(); - long user = event.getArgument("user"); - Date duration = event.getArgument("duration"); - long timeLeft = duration.toInstant().minusSeconds(Instant.now().getEpochSecond()).toEpochMilli(); - - event.getGuild().retrieveMemberById(user).queue((msg) -> { - new DatabaseQuery() - .query(new BasicQuery("INSERT INTO owen.muted_members (member,muted_by,muted_at,muted_till,reason) VALUES (?,?,CURRENT_TIMESTAMP(),?,'Weekly Discussion Mute')", (statement) -> { - statement.setLong(1, user); - statement.setLong(2, event.getAuthor().getIdLong()); - statement.setTimestamp(3, DateUtil.toTimeStamp(duration)); - - })) - .compile(); - - builder.withPreset( - new InformativeReply(InformativeReplyType.SUCCESS, "Muted!", String.format("Player will be muted for ``%s``.", FormatUtil.formatMilliTime(timeLeft))) - ); - Guild guild = event.getGuild(); - TextChannel channel = guild.getTextChannelById(DISCUSSION_CHANNEL); - guild.retrieveMemberById(user).queue((member) -> { - channel.putPermissionOverride(member).deny(net.dv8tion.jda.api.Permission.MESSAGE_ADD_REACTION, net.dv8tion.jda.api.Permission.MESSAGE_WRITE).queue(); - }); - - HelpBotInstance.getScheduler().schedule(new MuteExpireTask(user, duration, true)); - event.reply(builder); - }, (error) -> { - builder.withPreset( - new InformativeReply(InformativeReplyType.ERROR, "Discord user was not found!") - ); - - event.reply(builder); - }); - - } -} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java index fa2fc488..935f2a3e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java @@ -71,16 +71,8 @@ public void run(CommandEvent event) { } else { Guild guild = event.getGuild(); - ResultSet set = result.getResult(); - boolean special = "Weekly Discussion Mute".equals(set.getString("reason")); - if (special) { - TextChannel channel = guild.getTextChannelById(DiscussionMuteCommand.DISCUSSION_CHANNEL); - channel.getPermissionOverride(member).delete().queue(); - - } else { - guild.removeRoleFromMember(member, guild.getRoleById(MuteCommand.ROLE_ID)).queue(); - } + guild.removeRoleFromMember(member, guild.getRoleById(MuteCommand.ROLE_ID)).queue(); new DatabaseQuery() .query(new BasicQuery("UPDATE owen.muted_members SET handled = true WHERE member = ?", (statement) -> statement.setLong(1, member.getIdLong()))) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java index 6a1e5cac..c9219821 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java @@ -114,18 +114,18 @@ protected void execute(CommandEvent event, Player player) { warningReq = 6 - warnings; } - if (duration != null) { - embed.addField("Tempban", String.format("\u26A0 If you receive **%s** more active %s, you will receive a **%s** tempban!", warningReq, StringUtil.sCheck("warning", warningReq), duration), false); - } +// if (duration != null) { +// embed.addField("Tempban", String.format("\u26A0 If you receive **%s** more active %s, you will receive a **%s** tempban!", warningReq, StringUtil.sCheck("warning", warningReq), duration), false); +// } } else if (punishments.size() == 0) { embed.setDescription("No punishments here, keep up the good work!"); } - - if (yearlyWarnings > 10) { - embed.setColor(Color.RED); - embed.addField("Tempban", String.format("\u26A0 If you receive **%s** more %s this year, you will receive a **45** day tempban!", 20 - yearlyWarnings, StringUtil.sCheck("warning", 20 - yearlyWarnings)), false); - } +// +// if (yearlyWarnings > 10) { +// embed.setColor(Color.RED); +// embed.addField("Tempban", String.format("\u26A0 If you receive **%s** more %s this year, you will receive a **45** day tempban!", 20 - yearlyWarnings, StringUtil.sCheck("warning", 20 - yearlyWarnings)), false); +// } msgs.add(privateChannel.sendMessageEmbeds(embed.build())); } @@ -145,7 +145,7 @@ protected void execute(CommandEvent event, Player player) { EmbedUtil.addFields(presetBuilder, punishmentStrings, "", "", true); if (punishmentStrings.size() == 0) { } else if (presetBuilder.isValidLength()) { - msgs.add(privateChannel.sendMessage(presetBuilder.build())); + msgs.add(privateChannel.sendMessageEmbeds(presetBuilder.build())); } else { try { File sendFile = ExternalFileUtil.generateFile("history.txt"); diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java index 4ba55a70..bd71dbaa 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java @@ -15,18 +15,10 @@ public class MuteExpireTask implements OneTimeTask { private final long ms; private final long member; - private final boolean discussionMute; public MuteExpireTask(long member, Date date) { this.ms = Duration.between(Instant.now(), date.toInstant()).toMillis(); this.member = member; - this.discussionMute = false; - } - - public MuteExpireTask(long member, Date date, boolean discussionMute) { - this.ms = Duration.between(Instant.now(), date.toInstant()).toMillis(); - this.member = member; - this.discussionMute = discussionMute; } @Override @@ -37,16 +29,8 @@ public long getExecution() { @Override public void run() { Guild guild = HelpBotInstance.getJda().getGuildById(HelpBotInstance.DF_GUILD); - - if (discussionMute) { - TextChannel channel = guild.getTextChannelById(DiscussionMuteCommand.DISCUSSION_CHANNEL); - guild.retrieveMemberById(member).queue((member) -> { - channel.getPermissionOverride(member).delete().queue(); - }); - - } else { - guild.removeRoleFromMember(member, guild.getRoleById(MuteCommand.ROLE_ID)).queue(); - } + + guild.removeRoleFromMember(member, guild.getRoleById(MuteCommand.ROLE_ID)).queue(); new DatabaseQuery() .query(new BasicQuery("UPDATE owen.muted_members SET handled = true WHERE member = ?", (statement) -> statement.setLong(1, member))) @@ -62,9 +46,8 @@ public static void prepare() { for (ResultSet set : result) { Timestamp date = set.getTimestamp("muted_till"); long member = set.getLong("member"); - boolean special = "Weekly Discussion Mute".equals(set.getString("reason")); - - HelpBotInstance.getScheduler().schedule(new MuteExpireTask(member, date, special)); + + HelpBotInstance.getScheduler().schedule(new MuteExpireTask(member, date)); } }); }