├── settings.gradle.kts ├── src └── main │ ├── resources │ ├── star.png │ └── logback.xml │ └── java │ └── com │ └── diamondfire │ └── helpbot │ ├── bot │ ├── command │ │ ├── impl │ │ │ ├── SubCommand.java │ │ │ ├── stats │ │ │ │ ├── plot │ │ │ │ │ ├── Plot.java │ │ │ │ │ └── PlotSize.java │ │ │ │ ├── graph │ │ │ │ │ ├── AbstractGraphCommand.java │ │ │ │ │ ├── NewJoinGraphCommand.java │ │ │ │ │ └── PlayerJoinGraphCommand.java │ │ │ │ ├── individualized │ │ │ │ │ ├── UuidCommand.java │ │ │ │ │ └── SkinCommand.java │ │ │ │ ├── support │ │ │ │ │ ├── SessionsCommand.java │ │ │ │ │ └── SupporteeSessionsCommand.java │ │ │ │ ├── metrics │ │ │ │ │ └── JoinsCommand.java │ │ │ │ ├── CpRequirementsCommand.java │ │ │ │ └── AbstractPlayerUUIDCommand.java │ │ │ ├── Command.java │ │ │ ├── other │ │ │ │ ├── dumps │ │ │ │ │ ├── SoundListCommand.java │ │ │ │ │ └── ActionDumpCommand.java │ │ │ │ ├── tag │ │ │ │ │ ├── TagCommand.java │ │ │ │ │ └── ListTagsSubCommand.java │ │ │ │ ├── util │ │ │ │ │ ├── MimicCommand.java │ │ │ │ │ └── AbstractFileListCommand.java │ │ │ │ ├── dev │ │ │ │ │ └── RestartCommand.java │ │ │ │ └── fun │ │ │ │ │ └── GarfieldCommand.java │ │ │ ├── SubCommandHolder.java │ │ │ └── codeblock │ │ │ │ ├── SearchCommand.java │ │ │ │ └── RawCommand.java │ │ ├── disable │ │ │ ├── CommandDisableFlag.java │ │ │ └── DisableCommandHandler.java │ │ ├── executor │ │ │ └── checks │ │ │ │ ├── CommandCheckFailure.java │ │ │ │ ├── CommandCheck.java │ │ │ │ ├── MutedCheck.java │ │ │ │ ├── DisabledCheck.java │ │ │ │ ├── PermissionCheck.java │ │ │ │ └── CommandLog.java │ │ ├── reply │ │ │ ├── feature │ │ │ │ ├── ReplyPreset.java │ │ │ │ ├── informative │ │ │ │ │ ├── InformativeReplyType.java │ │ │ │ │ └── InformativeReply.java │ │ │ │ └── MinecraftUserPreset.java │ │ │ ├── PresetBuilder.java │ │ │ └── ReplyHandler.java │ │ ├── argument │ │ │ ├── impl │ │ │ │ ├── types │ │ │ │ │ ├── minecraft │ │ │ │ │ │ ├── Player.java │ │ │ │ │ │ ├── MojangPlayerUUIDArgument.java │ │ │ │ │ │ └── DFPlayerArgument.java │ │ │ │ │ ├── StringArgument.java │ │ │ │ │ ├── LongArgument.java │ │ │ │ │ ├── EndlessStringArgument.java │ │ │ │ │ ├── DateOffsetArgument.java │ │ │ │ │ ├── IntegerArgument.java │ │ │ │ │ ├── AbstractSimpleValueArgument.java │ │ │ │ │ ├── Argument.java │ │ │ │ │ ├── TimeOffsetArgument.java │ │ │ │ │ ├── DateArgument.java │ │ │ │ │ ├── ClampedIntegerArgument.java │ │ │ │ │ ├── SubCommandArgument.java │ │ │ │ │ ├── DiscordUserArgument.java │ │ │ │ │ ├── QuoteStringArgument.java │ │ │ │ │ ├── Enum │ │ │ │ │ │ ├── TagProperty.java │ │ │ │ │ │ └── EnumArgument.java │ │ │ │ │ └── DefinedObjectArgument.java │ │ │ │ └── parsing │ │ │ │ │ ├── exceptions │ │ │ │ │ ├── MissingArgumentException.java │ │ │ │ │ ├── MalformedArgumentException.java │ │ │ │ │ └── ArgumentException.java │ │ │ │ │ ├── types │ │ │ │ │ ├── SingleContainer.java │ │ │ │ │ ├── MultiArgumentContainer.java │ │ │ │ │ ├── SingleArgumentContainer.java │ │ │ │ │ ├── MessageArgument.java │ │ │ │ │ ├── AlternateArgumentContainer.java │ │ │ │ │ └── ArgumentContainer.java │ │ │ │ │ ├── ParsedArgument.java │ │ │ │ │ ├── ArgumentNode.java │ │ │ │ │ ├── ParsedArgumentSet.java │ │ │ │ │ ├── parser │ │ │ │ │ ├── AlternateArgumentParser.java │ │ │ │ │ ├── SingleArgumentParser.java │ │ │ │ │ └── MultiArgumentParser.java │ │ │ │ │ └── ArgumentStack.java │ │ │ └── ArgumentSet.java │ │ ├── help │ │ │ ├── HelpContextArgument.java │ │ │ ├── HelpContext.java │ │ │ └── CommandCategory.java │ │ ├── permissions │ │ │ ├── PermissionHandler.java │ │ │ └── Permission.java │ │ └── CommandHandler.java │ ├── events │ │ ├── ButtonEvent.java │ │ ├── GuildJoinEvent.java │ │ ├── ReadyEvent.java │ │ ├── MessageEditEvent.java │ │ ├── MessageEvent.java │ │ ├── PostChannelEvent.java │ │ ├── ChannelUpdatedNameEvent.java │ │ └── ChannelCreatedEvent.java │ └── restart │ │ └── RestartHandler.java │ ├── df │ ├── punishments │ │ ├── PunishmentType.java │ │ └── fetcher │ │ │ └── providers │ │ │ ├── PunishmentProvider.java │ │ │ ├── types │ │ │ ├── BanProvider.java │ │ │ ├── KickProvider.java │ │ │ ├── MuteProvider.java │ │ │ └── WarnProvider.java │ │ │ ├── StaticPunishmentProvider.java │ │ │ └── RemovablePunishmentProvider.java │ ├── creator │ │ ├── requirements │ │ │ ├── RequirementProvider.java │ │ │ ├── StaticRequirementProvider.java │ │ │ └── DynamicRequirementProvider.java │ │ └── CreatorLevel.java │ ├── ranks │ │ ├── RankBranch.java │ │ └── RankUtil.java │ └── codeinfo │ │ ├── viewables │ │ ├── embeds │ │ │ ├── SimpleIconBuilder.java │ │ │ ├── GameValueEmbedBuilder.java │ │ │ └── CodeBlockEmbedBuilder.java │ │ ├── BasicReaction.java │ │ └── constants │ │ │ ├── DataTypes.java │ │ │ └── CodeBlockEnum.java │ │ └── codedatabase │ │ └── db │ │ └── datatypes │ │ ├── SoundData.java │ │ ├── PotionData.java │ │ ├── ParticleData.java │ │ ├── CodeObject.java │ │ ├── GameValueData.java │ │ ├── CodeBlockData.java │ │ └── ActionData.java │ ├── sys │ ├── tasks │ │ ├── OneTimeTask.java │ │ ├── impl │ │ │ ├── CodeDatabaseTask.java │ │ │ ├── NameUpdateTask.java │ │ │ ├── RefreshCreditsTask.java │ │ │ ├── GraphChannelTask.java │ │ │ ├── SupporterClassTask.java │ │ │ └── VIPStarTask.java │ │ ├── LoopingTask.java │ │ ├── MidnightTask.java │ │ └── TaskRegistry.java │ ├── graph │ │ ├── impl │ │ │ ├── Graph.java │ │ │ └── BoxGraph.java │ │ ├── generators │ │ │ ├── GraphGenerator.java │ │ │ ├── context │ │ │ │ ├── SupportGraphContext.java │ │ │ │ └── TimeGraphContext.java │ │ │ ├── GraphGenerators.java │ │ │ ├── TimeMode.java │ │ │ └── QueryGraphGenerator.java │ │ └── graphable │ │ │ ├── StringEntry.java │ │ │ ├── NumberEntry.java │ │ │ ├── TimeStampEntry.java │ │ │ ├── DateEntry.java │ │ │ └── GraphableEntry.java │ ├── message │ │ ├── acceptors │ │ │ ├── MessageAcceptor.java │ │ │ ├── FilterAcceptor.java │ │ │ ├── CommandAcceptor.java │ │ │ └── TagAcceptor.java │ │ └── filter │ │ │ ├── ChatFilter.java │ │ │ ├── ChatFilters.java │ │ │ └── FilterData.java │ ├── tag │ │ └── exceptions │ │ │ ├── TagException.java │ │ │ ├── TagAlreadyExistsException.java │ │ │ └── TagDoesNotExistException.java │ ├── database │ │ ├── impl │ │ │ ├── queries │ │ │ │ ├── QueryResultProvider.java │ │ │ │ └── BasicQuery.java │ │ │ ├── DatabaseQuery.java │ │ │ └── result │ │ │ │ ├── DatabaseFuture.java │ │ │ │ └── DatabaseResult.java │ │ └── ConnectionProvider.java │ ├── externalfile │ │ ├── ExternalFileUtil.java │ │ ├── ExternalFileBuilder.java │ │ └── ExternalFiles.java │ ├── multiselector │ │ ├── MultiSelectorPage.java │ │ ├── MultiSelectorBuilder.java │ │ └── MultiSelector.java │ └── rolereact │ │ └── ReactRole.java │ ├── util │ ├── nbs │ │ ├── OutdatedNBSException.java │ │ ├── CompressionUtil.java │ │ └── SongData.java │ ├── serializer │ │ ├── Serializer.java │ │ └── TagSerializer.java │ ├── DateUtil.java │ ├── WebUtil.java │ ├── textgen │ │ └── CacheData.java │ ├── StarUtil.java │ └── PlainComponentSerializer.java │ └── HelpBot.java ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .github └── workflows │ └── gradle.yml └── README.md /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "DFHelpBot" 2 | 3 | -------------------------------------------------------------------------------- /src/main/resources/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MCDiamondFire/HelpBot/HEAD/src/main/resources/star.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | gradle 4 | build 5 | /src/main/resources/swear_filter.json 6 | 7 | *.json 8 | *.txt 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MCDiamondFire/HelpBot/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl; 2 | 3 | public abstract class SubCommand extends Command { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/PunishmentType.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments; 2 | 3 | public enum PunishmentType { 4 | WARN, 5 | KICK, 6 | MUTE, 7 | BAN 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/OneTimeTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks; 2 | 3 | public interface OneTimeTask extends Runnable { 4 | 5 | long getExecution(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/disable/CommandDisableFlag.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.disable; 2 | 3 | // Marks that this command cannot be disabled. 4 | public interface CommandDisableFlag { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/CommandCheckFailure.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.executor.checks; 2 | 3 | public class CommandCheckFailure extends RuntimeException { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/creator/requirements/RequirementProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.creator.requirements; 2 | 3 | public interface RequirementProvider { 4 | 5 | int getRequirement(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/nbs/OutdatedNBSException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util.nbs; 2 | //from https://github.com/CodeUtilities/CodeUtilities 3 | public class OutdatedNBSException extends Exception{ 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/impl/Graph.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.impl; 2 | 3 | 4 | import java.awt.*; 5 | 6 | public interface Graph { 7 | 8 | void paintGraph(Graphics2D graphics); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/generators/GraphGenerator.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.generators; 2 | 3 | import java.io.File; 4 | 5 | public interface GraphGenerator { 6 | 7 | File createGraph(T context); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/acceptors/MessageAcceptor.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.acceptors; 2 | 3 | import net.dv8tion.jda.api.entities.Message; 4 | 5 | public interface MessageAcceptor { 6 | 7 | boolean accept(Message message); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/ReplyPreset.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.reply.feature; 2 | 3 | import net.dv8tion.jda.api.EmbedBuilder; 4 | 5 | public interface ReplyPreset { 6 | 7 | void applyFeature(EmbedBuilder builder); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tag/exceptions/TagException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tag.exceptions; 2 | 3 | public class TagException extends Exception { 4 | 5 | public TagException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tag/exceptions/TagAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tag.exceptions; 2 | 3 | public class TagAlreadyExistsException extends Exception { 4 | 5 | public TagAlreadyExistsException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tag/exceptions/TagDoesNotExistException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tag.exceptions; 2 | 3 | public class TagDoesNotExistException extends TagException { 4 | 5 | public TagDoesNotExistException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/Player.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft; 2 | 3 | import java.util.UUID; 4 | 5 | public record Player(String name, UUID uuid) { 6 | 7 | public String uuidString() { 8 | return uuid.toString(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/database/impl/queries/QueryResultProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.database.impl.queries; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import java.sql.*; 6 | 7 | public interface QueryResultProvider { 8 | 9 | ResultSet execute(@NotNull Connection connection) throws SQLException; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/MissingArgumentException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions; 2 | 3 | public class MissingArgumentException extends ArgumentException { 4 | 5 | public MissingArgumentException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/MalformedArgumentException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions; 2 | 3 | public class MalformedArgumentException extends ArgumentException { 4 | 5 | public MalformedArgumentException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/graphable/StringEntry.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.graphable; 2 | 3 | public class StringEntry extends GraphableEntry { 4 | 5 | public StringEntry(String entry) { 6 | super(entry); 7 | } 8 | 9 | @Override 10 | public String toString() { 11 | return getEntry(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/filter/ChatFilter.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.filter; 2 | 3 | public abstract class ChatFilter { 4 | 5 | final boolean filter(FilterData data) { 6 | return filterString(data.getSimplifiedMessage(), data); 7 | } 8 | 9 | public abstract boolean filterString(String message, FilterData data); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/graphable/NumberEntry.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.graphable; 2 | 3 | public class NumberEntry extends GraphableEntry { 4 | 5 | public NumberEntry(Integer entry) { 6 | super(entry); 7 | } 8 | 9 | @Override 10 | public String toString() { 11 | return getEntry().toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} %-15.-15logger{0} %-6level %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/impl/CodeDatabaseTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks.impl; 2 | 3 | import com.diamondfire.helpbot.bot.command.impl.other.dev.FetchDataCommand; 4 | import com.diamondfire.helpbot.sys.tasks.MidnightTask; 5 | 6 | public class CodeDatabaseTask implements MidnightTask { 7 | 8 | @Override 9 | public void run() { 10 | new FetchDataCommand().setup(RESPONSE_CHANNEL); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/acceptors/FilterAcceptor.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.acceptors; 2 | 3 | import com.diamondfire.helpbot.sys.message.filter.ChatFilters; 4 | import net.dv8tion.jda.api.entities.Message; 5 | 6 | public class FilterAcceptor implements MessageAcceptor { 7 | 8 | @Override 9 | public boolean accept(Message message) { 10 | return !ChatFilters.filterMessage(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/serializer/Serializer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util.serializer; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | /** 6 | * Interface for serializer classes. 7 | * 8 | * @param Serialized value 9 | * @param Deserialized value 10 | */ 11 | public interface Serializer { 12 | 13 | S serialize(@NotNull D toSerialize); 14 | 15 | D deserialize(@NotNull S toDeserialize); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/StringArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.events.CommandEvent; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public class StringArgument extends AbstractSimpleValueArgument { 7 | 8 | @Override 9 | public String parse(@NotNull String msg, CommandEvent event) { 10 | return msg; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/Plot.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.plot; 2 | 3 | import java.time.LocalDate; 4 | 5 | public record Plot(int id, String handle, String description, String name, String ownerName, int node, 6 | PlotSize plotSize, String tags, int immunityLevel, LocalDate activeTime, boolean whitelisted, 7 | int playerCount, int votes, int xMin, int zMin, String icon) { 8 | 9 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/CommandCheck.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.executor.checks; 2 | 3 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | 6 | // Command checks are run before a command is executed. 7 | public interface CommandCheck { 8 | 9 | boolean check(CommandEvent event); 10 | 11 | void buildMessage(CommandEvent event, PresetBuilder builder); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/graphable/TimeStampEntry.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.graphable; 2 | 3 | import java.sql.Timestamp; 4 | 5 | public class TimeStampEntry extends GraphableEntry { 6 | 7 | public TimeStampEntry(Timestamp entry) { 8 | super(entry); 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | Timestamp timestamp = getEntry(); 14 | return timestamp.toString(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/LoopingTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; 5 | 6 | public interface LoopingTask extends Runnable { 7 | 8 | TextChannel RESPONSE_CHANNEL = HelpBotInstance.getJda().getTextChannelById(HelpBotInstance.LOG_CHANNEL); 9 | 10 | long getInitialStart(); 11 | 12 | long getNextLoop(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/creator/requirements/StaticRequirementProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.creator.requirements; 2 | 3 | public class StaticRequirementProvider implements RequirementProvider { 4 | 5 | private final int requirement; 6 | 7 | public StaticRequirementProvider(int requirement) { 8 | this.requirement = requirement; 9 | } 10 | 11 | @Override 12 | public int getRequirement() { 13 | return requirement; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/graphable/DateEntry.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.graphable; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | public class DateEntry extends GraphableEntry { 7 | 8 | public DateEntry(Date entry) { 9 | super(entry); 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | Date date = getEntry(); 15 | return new SimpleDateFormat("dd/MM/yy").format(date); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotSize.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.plot; 2 | 3 | enum PlotSize { 4 | BASIC(51), 5 | LARGE(101), 6 | MASSIVE(301), 7 | MEGA(1001); 8 | 9 | private final int size; 10 | 11 | PlotSize(int size) { 12 | this.size = size; 13 | } 14 | 15 | public static PlotSize fromID(int id) { 16 | return PlotSize.values()[id]; 17 | } 18 | 19 | public int getSize() { 20 | return size; 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/PunishmentProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers; 2 | 3 | import com.diamondfire.helpbot.df.punishments.*; 4 | import org.intellij.lang.annotations.Language; 5 | 6 | import java.sql.*; 7 | 8 | public interface PunishmentProvider { 9 | 10 | Punishment getPunishment(ResultSet data) throws SQLException; 11 | 12 | @Language("SQL") 13 | String getQuery(); 14 | 15 | PunishmentType getType(); 16 | 17 | String getDBTable(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/ranks/RankBranch.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.ranks; 2 | 3 | import java.util.*; 4 | 5 | public enum RankBranch { 6 | DONOR, 7 | RETIREMENT, 8 | BUILDER, 9 | YOUTUBER, 10 | SUPPORT, 11 | MODERATION, 12 | ADMINISTRATION; 13 | 14 | public static final Map databaseMap = new HashMap<>(); 15 | 16 | static { 17 | for (RankBranch branch : values()) { 18 | databaseMap.put(branch.toString(), branch); 19 | } 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/SingleContainer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 4 | 5 | public abstract class SingleContainer extends ArgumentContainer { 6 | 7 | private final Argument argument; 8 | 9 | public SingleContainer(Argument argument) { 10 | this.argument = argument; 11 | } 12 | 13 | public Argument getArgument() { 14 | return argument; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/generators/context/SupportGraphContext.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.generators.context; 2 | 3 | import com.diamondfire.helpbot.sys.graph.generators.TimeMode; 4 | 5 | public class SupportGraphContext extends TimeGraphContext { 6 | 7 | private final String support; 8 | 9 | public SupportGraphContext(TimeMode mode, int num, String support) { 10 | super(mode, num); 11 | this.support = support; 12 | } 13 | 14 | public String getSupport() { 15 | return support; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/ButtonEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler; 4 | import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; 5 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | public class ButtonEvent extends ListenerAdapter { 9 | 10 | @Override 11 | public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { 12 | ButtonHandler.handleEvent(event); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/SimpleIconBuilder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.viewables.embeds; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; 4 | import net.dv8tion.jda.api.EmbedBuilder; 5 | 6 | public class SimpleIconBuilder implements IconEmbedBuilder { 7 | 8 | @Override 9 | public EmbedBuilder buildDataEmbed(CodeObject data) { 10 | EmbedBuilder builder = new EmbedBuilder(); 11 | generateInfo(data, builder); 12 | 13 | return builder; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/LongArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public class LongArgument extends AbstractSimpleValueArgument{ 8 | 9 | @Override 10 | protected Long parse(@NotNull String argument, CommandEvent event) throws ArgumentException { 11 | return Long.parseLong(argument); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/types/BanProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers.types; 2 | 3 | import com.diamondfire.helpbot.df.punishments.PunishmentType; 4 | import com.diamondfire.helpbot.df.punishments.fetcher.providers.RemovablePunishmentProvider; 5 | 6 | public class BanProvider extends RemovablePunishmentProvider { 7 | 8 | @Override 9 | public PunishmentType getType() { 10 | return PunishmentType.BAN; 11 | } 12 | 13 | @Override 14 | public String getDBTable() { 15 | return "bans"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/types/KickProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers.types; 2 | 3 | import com.diamondfire.helpbot.df.punishments.PunishmentType; 4 | import com.diamondfire.helpbot.df.punishments.fetcher.providers.StaticPunishmentProvider; 5 | 6 | public class KickProvider extends StaticPunishmentProvider { 7 | 8 | @Override 9 | public PunishmentType getType() { 10 | return PunishmentType.KICK; 11 | } 12 | 13 | @Override 14 | public String getDBTable() { 15 | return "kicks"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/HelpBot.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.changelog.CodeDifferenceHandler; 5 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; 6 | 7 | import javax.security.auth.login.LoginException; 8 | 9 | public class HelpBot { 10 | 11 | public static void main(String[] args) throws LoginException { 12 | CodeDatabase.initialize(); 13 | HelpBotInstance.initialize(); 14 | CodeDifferenceHandler.refresh(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/types/MuteProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers.types; 2 | 3 | import com.diamondfire.helpbot.df.punishments.PunishmentType; 4 | import com.diamondfire.helpbot.df.punishments.fetcher.providers.RemovablePunishmentProvider; 5 | 6 | public class MuteProvider extends RemovablePunishmentProvider { 7 | 8 | @Override 9 | public PunishmentType getType() { 10 | return PunishmentType.MUTE; 11 | } 12 | 13 | @Override 14 | public String getDBTable() { 15 | return "mutes"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/types/WarnProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers.types; 2 | 3 | import com.diamondfire.helpbot.df.punishments.PunishmentType; 4 | import com.diamondfire.helpbot.df.punishments.fetcher.providers.RemovablePunishmentProvider; 5 | 6 | public class WarnProvider extends RemovablePunishmentProvider { 7 | 8 | @Override 9 | public PunishmentType getType() { 10 | return PunishmentType.WARN; 11 | } 12 | 13 | @Override 14 | public String getDBTable() { 15 | return "warnings"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/generators/context/TimeGraphContext.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.generators.context; 2 | 3 | import com.diamondfire.helpbot.sys.graph.generators.TimeMode; 4 | 5 | public class TimeGraphContext { 6 | 7 | private final TimeMode mode; 8 | private final int num; 9 | 10 | public TimeGraphContext(TimeMode mode, int num) { 11 | this.mode = mode; 12 | this.num = num; 13 | } 14 | 15 | public TimeMode getMode() { 16 | return mode; 17 | } 18 | 19 | public int getNum() { 20 | return num; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ParsedArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing; 2 | 3 | 4 | // Parsed arguments are simply just their identifier and their value. (Finalized and parsed) 5 | public class ParsedArgument { 6 | 7 | String argumentIdentifier; 8 | T argument; 9 | 10 | public ParsedArgument(String argumentIdentifier, T argument) { 11 | this.argument = argument; 12 | this.argumentIdentifier = argumentIdentifier; 13 | } 14 | 15 | public T getValue() { 16 | return argument; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.externalfile; 2 | 3 | import java.io.*; 4 | 5 | public class ExternalFileUtil { 6 | 7 | public static File generateFile(String name) throws IOException { 8 | File file = new File(ExternalFiles.OTHER_CACHE_DIR, name); 9 | if (file.exists()) { 10 | file.delete(); 11 | } 12 | 13 | file.createNewFile(); 14 | return file; 15 | } 16 | 17 | public static File getFile(String name) { 18 | return new File(ExternalFiles.OTHER_CACHE_DIR, name); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/EndlessStringArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.Deque; 8 | 9 | public class EndlessStringArgument implements Argument { 10 | 11 | @Override 12 | public String parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { 13 | return String.join(" ", args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/reply/PresetBuilder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.reply; 2 | 3 | import com.diamondfire.helpbot.bot.command.reply.feature.ReplyPreset; 4 | import net.dv8tion.jda.api.EmbedBuilder; 5 | 6 | public class PresetBuilder { 7 | 8 | private final EmbedBuilder builder = new EmbedBuilder(); 9 | 10 | public PresetBuilder withPreset(ReplyPreset... presets) { 11 | for (ReplyPreset preset : presets) { 12 | preset.applyFeature(builder); 13 | } 14 | return this; 15 | } 16 | 17 | public EmbedBuilder getEmbed() { 18 | return builder; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/SoundData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.DataTypes; 4 | import com.google.gson.JsonObject; 5 | 6 | 7 | public class SoundData extends CodeObject { 8 | 9 | public SoundData(JsonObject data) { 10 | super(data, data.get("sound").getAsString()); 11 | } 12 | 13 | public String getSound() { 14 | return data.get("sound").getAsString(); 15 | } 16 | 17 | @Override 18 | public DataTypes getEnum() { 19 | return DataTypes.SOUND; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/PotionData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.DataTypes; 4 | import com.google.gson.JsonObject; 5 | 6 | 7 | public class PotionData extends CodeObject { 8 | 9 | public PotionData(JsonObject data) { 10 | super(data, data.get("potion").getAsString()); 11 | } 12 | 13 | public String getPotion() { 14 | return data.get("potion").getAsString(); 15 | } 16 | 17 | @Override 18 | public DataTypes getEnum() { 19 | return DataTypes.POTION; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/ParticleData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.DataTypes; 4 | import com.google.gson.JsonObject; 5 | 6 | public class ParticleData extends CodeObject { 7 | 8 | public ParticleData(JsonObject data) { 9 | super(data, data.get("particle").getAsString()); 10 | } 11 | 12 | public String getParticle() { 13 | return data.get("particle").getAsString(); 14 | } 15 | 16 | @Override 17 | public DataTypes getEnum() { 18 | return DataTypes.PARTICLE; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateOffsetArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import java.util.Calendar; 4 | 5 | public class DateOffsetArgument extends AbstractOffsetArgument { 6 | 7 | public DateOffsetArgument() { 8 | super(); 9 | } 10 | 11 | @Override 12 | protected Duration[] getDurations() { 13 | return new Duration[]{ 14 | new Duration(Calendar.DAY_OF_MONTH, 'd'), 15 | new Duration(Calendar.DAY_OF_WEEK, 'w'), 16 | new Duration(Calendar.MONTH, 'm'), 17 | new Duration(Calendar.YEAR, 'y'), 18 | }; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/help/HelpContextArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.help; 2 | 3 | public class HelpContextArgument { 4 | 5 | String argumentName = null; 6 | boolean isOptional = false; 7 | 8 | public HelpContextArgument name(String argumentName) { 9 | this.argumentName = argumentName; 10 | return this; 11 | } 12 | 13 | public HelpContextArgument optional() { 14 | isOptional = true; 15 | return this; 16 | } 17 | 18 | public String getArgumentName() { 19 | return argumentName; 20 | } 21 | 22 | public boolean isOptional() { 23 | return isOptional; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/MultiArgumentContainer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser.MultiArgumentParser; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 5 | 6 | public class MultiArgumentContainer extends SingleContainer { 7 | 8 | public MultiArgumentContainer(Argument argument) { 9 | super(argument); 10 | } 11 | 12 | @SuppressWarnings("unchecked") 13 | @Override 14 | public MultiArgumentParser getParser() { 15 | return new MultiArgumentParser<>(this); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 21 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 21 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | - name: Build with Gradle 26 | run: ./gradlew build 27 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/SingleArgumentContainer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser.SingleArgumentParser; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 5 | 6 | public class SingleArgumentContainer extends SingleContainer { 7 | 8 | public SingleArgumentContainer(Argument argument) { 9 | super(argument); 10 | } 11 | 12 | @SuppressWarnings("unchecked") 13 | @Override 14 | public SingleArgumentParser getParser() { 15 | return new SingleArgumentParser<>(this); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/MessageArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.Deque; 9 | 10 | public class MessageArgument implements Argument { 11 | 12 | @Override 13 | public String parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { 14 | return String.join(" ", args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/MutedCheck.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.executor.checks; 2 | 3 | import com.diamondfire.helpbot.bot.command.impl.other.mod.MuteCommand; 4 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | 7 | public class MutedCheck implements CommandCheck { 8 | 9 | @Override 10 | public boolean check(CommandEvent event) { 11 | return !event.getMember().getRoles().contains(event.getGuild().getRoleById(MuteCommand.ROLE_ID)); 12 | } 13 | 14 | @Override 15 | public void buildMessage(CommandEvent event, PresetBuilder builder) { 16 | throw new CommandCheckFailure(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/IntegerArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public class IntegerArgument extends AbstractSimpleValueArgument { 8 | 9 | @Override 10 | public Integer parse(@NotNull String msg, CommandEvent event) throws ArgumentException { 11 | try { 12 | return Integer.parseInt(msg); 13 | } catch (NumberFormatException exception) { 14 | throw new MalformedArgumentException("Invalid number provided"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/impl/NameUpdateTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks.impl; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.tasks.LoopingTask; 5 | import com.diamondfire.helpbot.util.Util; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | public class NameUpdateTask implements LoopingTask { 10 | 11 | @Override 12 | public long getInitialStart() { 13 | return 0; 14 | } 15 | 16 | @Override 17 | public long getNextLoop() { 18 | return TimeUnit.MINUTES.toMillis(10); 19 | } 20 | 21 | @Override 22 | public void run() { 23 | Util.updateGuild(HelpBotInstance.getJda().getGuildById(HelpBotInstance.DF_GUILD)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/AbstractSimpleValueArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.Deque; 8 | 9 | public abstract class AbstractSimpleValueArgument implements Argument { 10 | 11 | @Override 12 | public T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { 13 | return parse(args.pop(), event); 14 | } 15 | 16 | protected abstract T parse(@NotNull String argument, CommandEvent event) throws ArgumentException; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Argument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | 4 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.Deque; 9 | 10 | /** 11 | * Arguments simply parse a given value and can remove it from the stack if they process it correctly. 12 | * This means an argument can actually use more than one argument if they want! 13 | * 14 | * @param parsed value type 15 | */ 16 | public interface Argument { 17 | 18 | T parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/TimeOffsetArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import java.util.Calendar; 4 | 5 | public class TimeOffsetArgument extends AbstractOffsetArgument { 6 | 7 | public TimeOffsetArgument() { 8 | super(); 9 | } 10 | 11 | public TimeOffsetArgument(boolean reverse) { 12 | super(reverse); 13 | } 14 | 15 | @Override 16 | protected Duration[] getDurations() { 17 | return new Duration[]{ 18 | new Duration(Calendar.SECOND, 's'), 19 | new Duration(Calendar.MINUTE, 'm'), 20 | new Duration(Calendar.HOUR, 'h'), 21 | new Duration(Calendar.DATE, 'd'), 22 | }; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/informative/InformativeReplyType.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.reply.feature.informative; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | import java.awt.*; 6 | 7 | public enum InformativeReplyType { 8 | SUCCESS("Success!", new Color(46, 204, 113)), 9 | INFO("Notice!", null), 10 | ERROR("Error!", new Color(231, 76, 60)); 11 | 12 | private final String title; 13 | private final Color color; 14 | 15 | InformativeReplyType(@Nullable String title, @Nullable Color color) { 16 | this.title = title; 17 | this.color = color; 18 | } 19 | 20 | public String getTitle() { 21 | return title; 22 | } 23 | 24 | public Color getColor() { 25 | return color; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/database/ConnectionProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.database; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.config.Config; 5 | import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; 6 | 7 | import java.sql.*; 8 | 9 | public class ConnectionProvider { 10 | 11 | private static final MysqlDataSource source = new MysqlDataSource(); 12 | 13 | static { 14 | Config config = HelpBotInstance.getConfig(); 15 | source.setUrl(config.getDBUrl()); 16 | source.setUser(config.getDBUser()); 17 | source.setPassword(config.getDBPassword()); 18 | } 19 | 20 | public static Connection getConnection() throws SQLException { 21 | return source.getConnection(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/MidnightTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks; 2 | 3 | import java.time.*; 4 | import java.util.TimeZone; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public interface MidnightTask extends LoopingTask { 8 | 9 | @Override 10 | default long getInitialStart() { 11 | LocalDateTime now = LocalDateTime.now(TimeZone.getTimeZone("EST").toZoneId()); 12 | LocalDateTime nextRun = now.withHour(22).withMinute(0).withSecond(0); 13 | if (now.compareTo(nextRun) > 0) { 14 | nextRun = nextRun.plusDays(1); 15 | } 16 | 17 | return Duration.between(now, nextRun).toMillis(); 18 | } 19 | 20 | @Override 21 | default long getNextLoop() { 22 | return TimeUnit.DAYS.toMillis(1); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ArgumentNode.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.ArgumentContainer; 4 | 5 | // An argument node contains an identifier and a container. 6 | public class ArgumentNode { 7 | 8 | private final String identifier; 9 | private final ArgumentContainer container; 10 | 11 | public ArgumentNode(String identifier, ArgumentContainer container) { 12 | this.identifier = identifier; 13 | this.container = container; 14 | } 15 | 16 | public String getIdentifier() { 17 | return identifier; 18 | } 19 | 20 | public ArgumentContainer getContainer() { 21 | return container; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.tasks.impl.MuteExpireTask; 5 | import com.diamondfire.helpbot.util.Util; 6 | import net.dv8tion.jda.api.entities.Member; 7 | import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; 8 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 9 | 10 | public class GuildJoinEvent extends ListenerAdapter { 11 | 12 | @Override 13 | public void onGuildMemberJoin(GuildMemberJoinEvent event) { 14 | if (event.getGuild().getIdLong() == HelpBotInstance.DF_GUILD) { 15 | Member member = event.getMember(); 16 | Util.updateMember(member); 17 | MuteExpireTask.handle(member); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/ReadyEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.restart.RestartHandler; 5 | import com.diamondfire.helpbot.sys.report.ReportListener; 6 | import com.diamondfire.helpbot.sys.rolereact.RoleReactListener; 7 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public class ReadyEvent extends ListenerAdapter { 11 | 12 | @Override 13 | public void onReady(@NotNull net.dv8tion.jda.api.events.session.ReadyEvent event) { 14 | RestartHandler.recover(event.getJDA()); 15 | HelpBotInstance.getScheduler().initialize(); 16 | 17 | event.getJDA().addEventListener(new RoleReactListener(), new ReportListener()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/MessageEditEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.sys.message.acceptors.*; 4 | import net.dv8tion.jda.api.entities.Message; 5 | import net.dv8tion.jda.api.events.message.MessageUpdateEvent; 6 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 7 | 8 | public class MessageEditEvent extends ListenerAdapter { 9 | 10 | private static final MessageAcceptor[] acceptors = { 11 | new FilterAcceptor(), 12 | }; 13 | 14 | @Override 15 | public void onMessageUpdate(MessageUpdateEvent event) { 16 | Message message = event.getMessage(); 17 | for (MessageAcceptor acceptor : acceptors) { 18 | if (acceptor.accept(message)) { 19 | break; 20 | } 21 | } 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ParsedArgumentSet.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing; 2 | 3 | import java.util.*; 4 | 5 | public class ParsedArgumentSet { 6 | 7 | private final Map> arguments = new HashMap<>(); 8 | 9 | public ParsedArgumentSet(Map> finalizedArguments) throws IllegalArgumentException { 10 | for (Map.Entry> argument : finalizedArguments.entrySet()) { 11 | arguments.put(argument.getKey(), argument.getValue()); 12 | } 13 | } 14 | 15 | public Map getArguments() { 16 | return arguments; 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | public T getArgument(String code) { 21 | return (T) arguments.get(code).getValue(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/filter/ChatFilters.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.filter; 2 | 3 | 4 | import com.diamondfire.helpbot.sys.message.filter.filters.SwearFilter; 5 | import net.dv8tion.jda.api.entities.Message; 6 | 7 | public final class ChatFilters { 8 | 9 | private static final ChatFilter[] chatFilters = new ChatFilter[]{ 10 | new SwearFilter() 11 | }; 12 | 13 | public static boolean filterMessage(Message message) { 14 | FilterData filterData = new FilterData(message); 15 | 16 | for (ChatFilter filter : chatFilters) { 17 | boolean filterResult = filter.filter(filterData); 18 | if (filterResult) { 19 | message.delete().queue(); 20 | return false; 21 | } 22 | } 23 | 24 | return true; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/CodeObject.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.DataTypes; 4 | import com.google.gson.JsonObject; 5 | 6 | public abstract class CodeObject { 7 | 8 | protected final JsonObject data; 9 | protected final String name; 10 | 11 | public CodeObject(JsonObject data, String name) { 12 | this.data = data; 13 | this.name = name; 14 | } 15 | 16 | public DisplayIcon getItem() { 17 | return new DisplayIcon(data.get("icon").getAsJsonObject()); 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public abstract DataTypes getEnum(); 25 | 26 | public JsonObject getJson() { 27 | return data; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/GameValueData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.DataTypes; 4 | import com.diamondfire.helpbot.util.Util; 5 | import com.google.gson.JsonObject; 6 | 7 | public class GameValueData extends CodeObject { 8 | 9 | public GameValueData(JsonObject data) { 10 | super(data, new DisplayIcon(data.get("icon").getAsJsonObject()).getItemName()); 11 | } 12 | 13 | public String[] getAliases() { 14 | return Util.fromJsonArray(data.get("aliases").getAsJsonArray()); 15 | } 16 | 17 | public String getCategory() { 18 | return data.get("category").getAsString(); 19 | } 20 | 21 | @Override 22 | public DataTypes getEnum() { 23 | return DataTypes.GAME_VALUE; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/AlternateArgumentContainer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser.AlternateArgumentParser; 4 | 5 | public class AlternateArgumentContainer extends ArgumentContainer { 6 | 7 | private final ArgumentContainer[] argumentContainers; 8 | 9 | public AlternateArgumentContainer(ArgumentContainer... argumentContainers) { 10 | this.argumentContainers = argumentContainers; 11 | } 12 | 13 | @SuppressWarnings("unchecked") 14 | @Override 15 | public AlternateArgumentParser getParser() { 16 | return new AlternateArgumentParser<>(this); 17 | } 18 | 19 | public ArgumentContainer[] getAlternatives() { 20 | return argumentContainers; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/filter/FilterData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.filter; 2 | 3 | 4 | import net.dv8tion.jda.api.entities.Message; 5 | 6 | public class FilterData { 7 | 8 | private final Message message; 9 | private final String simplifiedMessage; 10 | 11 | public FilterData(Message message) { 12 | this.message = message; 13 | this.simplifiedMessage = simplifyString(message.getContentDisplay()); 14 | } 15 | 16 | public Message getMessage() { 17 | return message; 18 | } 19 | 20 | public String getSimplifiedMessage() { 21 | return simplifiedMessage; 22 | } 23 | 24 | private static String simplifyString(String string) { 25 | string = string.toLowerCase(); 26 | string = string.replace("'", ""); 27 | string = string.replaceAll(" +", " ").trim(); 28 | 29 | return string; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/acceptors/CommandAcceptor.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.acceptors; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.command.CommandHandler; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import net.dv8tion.jda.api.entities.Message; 7 | 8 | public class CommandAcceptor implements MessageAcceptor { 9 | 10 | @Override 11 | public boolean accept(Message message) { 12 | if (message.getContentDisplay().startsWith(HelpBotInstance.getConfig().getPrefix()) && !message.getAuthor().isBot()) { 13 | CommandEvent event = new CommandEvent(message); 14 | if (event.getCommand() == null) { 15 | return false; 16 | } 17 | 18 | CommandHandler.getInstance().run(event); 19 | return true; 20 | } 21 | 22 | return false; 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/types/ArgumentContainer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser.ArgumentParser; 4 | 5 | 6 | // Argument containers provide essential information for the argument. 7 | // These give a parser. 8 | public abstract class ArgumentContainer { 9 | 10 | private T defaultValue; 11 | private boolean isOptional; 12 | 13 | public abstract

> P getParser(); 14 | 15 | public ArgumentContainer optional(T defaultValue) { 16 | this.defaultValue = defaultValue; 17 | this.isOptional = true; 18 | return this; 19 | } 20 | 21 | public boolean isOptional() { 22 | return isOptional; 23 | } 24 | 25 | public T getDefaultValue() { 26 | return defaultValue; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/DisabledCheck.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.executor.checks; 2 | 3 | import com.diamondfire.helpbot.bot.command.CommandHandler; 4 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 5 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 6 | import com.diamondfire.helpbot.bot.events.CommandEvent; 7 | 8 | public class DisabledCheck implements CommandCheck { 9 | @Override 10 | public boolean check(CommandEvent event) { 11 | return !CommandHandler.getInstance().getDisabledHandler().isDisabled(event.getCommand()); 12 | } 13 | 14 | @Override 15 | public void buildMessage(CommandEvent event, PresetBuilder builder) { 16 | builder.withPreset( 17 | new InformativeReply(InformativeReplyType.ERROR, "Disabled!", "This command has been disabled until further notice.") 18 | ); 19 | 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.sys.message.acceptors.*; 4 | import net.dv8tion.jda.api.entities.Message; 5 | import net.dv8tion.jda.api.events.message.*; 6 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | public class MessageEvent extends ListenerAdapter { 10 | 11 | private static final MessageAcceptor[] acceptors = { 12 | new FilterAcceptor(), 13 | new CommandAcceptor(), 14 | new TagAcceptor(), 15 | new VerifyAcceptor() 16 | }; 17 | 18 | @Override 19 | public void onMessageReceived(@NotNull MessageReceivedEvent event) { 20 | Message message = event.getMessage(); 21 | for (MessageAcceptor acceptor : acceptors) { 22 | if (acceptor.accept(message)) { 23 | break; 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/permissions/PermissionHandler.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.permissions; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import net.dv8tion.jda.api.entities.Member; 5 | 6 | import java.util.Comparator; 7 | 8 | public class PermissionHandler { 9 | 10 | 11 | public static Permission getPermission(Member member) { 12 | // Return user if guild isn't df guild. 13 | if (member.getGuild().getIdLong() != HelpBotInstance.DF_GUILD) { 14 | return Permission.USER; 15 | } 16 | 17 | //Calculates the highest permission that the member has access to. 18 | Permission perm = member.getRoles().stream() 19 | .map((role) -> Permission.fromRole(role.getIdLong())) 20 | .max(Comparator.comparingInt(Permission::getPermissionLevel)) 21 | .orElse(Permission.USER); 22 | 23 | return perm; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/GameValueEmbedBuilder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.viewables.embeds; 2 | 3 | 4 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.*; 5 | import net.dv8tion.jda.api.EmbedBuilder; 6 | 7 | import java.awt.*; 8 | 9 | public class GameValueEmbedBuilder implements IconEmbedBuilder { 10 | 11 | @Override 12 | public EmbedBuilder buildDataEmbed(GameValueData data) { 13 | DisplayIcon item = data.getItem(); 14 | EmbedBuilder builder = new EmbedBuilder(); 15 | 16 | generateInfo(data, builder); 17 | builder.addField("Returns Value", 18 | String.format("**%s** - ", ParamConverter.getTypeFromString(item.getReturnType()).getText()) 19 | + String.join(" ", item.getReturnDescription()), 20 | false); 21 | 22 | builder.setColor(Color.decode("#E6C78C")); 23 | return builder; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/graphable/GraphableEntry.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.graphable; 2 | 3 | import java.util.Objects; 4 | 5 | // Graphable Entries are displayed at bottom, and the amount of entries that are the same are calculated 6 | // and put onto the graph. 7 | public abstract class GraphableEntry { 8 | 9 | private final T entry; 10 | 11 | public GraphableEntry(T entry) { 12 | this.entry = entry; 13 | } 14 | 15 | public T getEntry() { 16 | return entry; 17 | } 18 | 19 | @Override 20 | public abstract String toString(); 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) return true; 25 | if (o == null || getClass() != o.getClass()) return false; 26 | GraphableEntry that = (GraphableEntry) o; 27 | return Objects.equals(entry, that.entry); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return Objects.hash(entry); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeBlockEmbedBuilder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.viewables.embeds; 2 | 3 | 4 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.*; 5 | import com.diamondfire.helpbot.util.StringUtil; 6 | import net.dv8tion.jda.api.EmbedBuilder; 7 | 8 | public class CodeBlockEmbedBuilder implements IconEmbedBuilder { 9 | 10 | @Override 11 | public EmbedBuilder buildDataEmbed(CodeBlockData data) { 12 | EmbedBuilder builder = new EmbedBuilder(); 13 | builder.setColor(data.getCodeblockEnum().getColor()); 14 | generateInfo(data, builder); 15 | 16 | ActionData associatedAction = data.getAssociatedAction(); 17 | if (associatedAction != null) { 18 | int tagLength = associatedAction.getTags().length; 19 | if (tagLength != 0) { 20 | builder.setFooter(tagLength + StringUtil.sCheck(" Tag", tagLength)); 21 | } 22 | 23 | } 24 | 25 | return builder; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/MinecraftUserPreset.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.reply.feature; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; 4 | import com.diamondfire.helpbot.util.Util; 5 | import net.dv8tion.jda.api.EmbedBuilder; 6 | 7 | public class MinecraftUserPreset implements ReplyPreset { 8 | 9 | private final String uuid; 10 | private final String player; 11 | 12 | public MinecraftUserPreset(Player player) { 13 | this.player = player.name(); 14 | this.uuid = player.uuidString(); 15 | } 16 | 17 | public MinecraftUserPreset(String player) { 18 | this.player = player; 19 | this.uuid = null; 20 | } 21 | 22 | public MinecraftUserPreset(String player, String uuid) { 23 | this.player = player; 24 | this.uuid = uuid; 25 | } 26 | 27 | @Override 28 | public void applyFeature(EmbedBuilder builder) { 29 | builder.setAuthor(player, null, Util.getPlayerHead(uuid == null ? player : uuid)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/database/impl/DatabaseQuery.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.database.impl; 2 | 3 | import com.diamondfire.helpbot.sys.database.ConnectionProvider; 4 | import com.diamondfire.helpbot.sys.database.impl.queries.QueryResultProvider; 5 | import com.diamondfire.helpbot.sys.database.impl.result.*; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.sql.*; 9 | 10 | public class DatabaseQuery { 11 | 12 | private QueryResultProvider queryProvider = null; 13 | 14 | public DatabaseQuery query(@NotNull QueryResultProvider queryProvider) { 15 | this.queryProvider = queryProvider; 16 | return this; 17 | } 18 | 19 | public DatabaseFuture compile() { 20 | try { 21 | Connection connection = ConnectionProvider.getConnection(); 22 | return new DatabaseFuture(connection, new DatabaseResult(queryProvider.execute(connection))); 23 | } catch (SQLException e) { 24 | throw new IllegalStateException("Failed to execute SQL !" + e.getMessage()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/impl/RefreshCreditsTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks.impl; 2 | 3 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 4 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 5 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 6 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 7 | import com.diamondfire.helpbot.sys.tasks.MidnightTask; 8 | 9 | public class RefreshCreditsTask implements MidnightTask { 10 | 11 | @Override 12 | public void run() { 13 | PresetBuilder preset = new PresetBuilder(); 14 | preset.withPreset(new InformativeReply(InformativeReplyType.INFO, "Credit log db has been updated")); 15 | RESPONSE_CHANNEL.sendMessageEmbeds(preset.getEmbed().build()).queue(); 16 | 17 | new DatabaseQuery() 18 | .query(new BasicQuery("INSERT INTO owen.creator_rankings_log(uuid, points, `rank`, date) " + 19 | "SELECT uuid, points, cur_rank, CURRENT_DATE() FROM creator_rankings WHERE points > 4990;")).compile(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/creator/requirements/DynamicRequirementProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.creator.requirements; 2 | 3 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 4 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 5 | import com.diamondfire.helpbot.sys.database.impl.result.DatabaseResult; 6 | 7 | import java.sql.SQLException; 8 | 9 | public class DynamicRequirementProvider implements RequirementProvider { 10 | 11 | private final String identifier; 12 | 13 | public DynamicRequirementProvider(String identifier) { 14 | this.identifier = identifier; 15 | } 16 | 17 | @Override 18 | public int getRequirement() { 19 | DatabaseResult result = new DatabaseQuery() 20 | .query(new BasicQuery("SELECT req FROM creator_req WHERE tier = ?", (statement) -> statement.setString(1, identifier))) 21 | .compile().get(); 22 | 23 | try { 24 | return result.getResult().getInt("req"); 25 | } catch (SQLException ignored) { 26 | return 0; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DateArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.text.*; 8 | import java.util.Date; 9 | 10 | public class DateArgument extends AbstractSimpleValueArgument { 11 | 12 | public final SimpleDateFormat format; 13 | 14 | public DateArgument() { 15 | this.format = new SimpleDateFormat("MM/dd/yy"); 16 | } 17 | 18 | public DateArgument(String format) { 19 | this.format = new SimpleDateFormat(format); 20 | } 21 | 22 | @Override 23 | public Date parse(@NotNull String msg, CommandEvent event) throws ArgumentException { 24 | try { 25 | return format.parse(msg); 26 | } catch (ParseException parseException) { 27 | throw new MalformedArgumentException("Invalid date provided, this date argument's format is " + format.toPattern()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/StaticPunishmentProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers; 2 | 3 | import com.diamondfire.helpbot.df.punishments.Punishment; 4 | 5 | import java.sql.*; 6 | 7 | public abstract class StaticPunishmentProvider implements PunishmentProvider { 8 | 9 | @Override 10 | public Punishment getPunishment(ResultSet data) throws SQLException { 11 | return new Punishment(getType(), data.getString("uuid"), data.getString("reason"), 12 | data.getString("banned_by_uuid"), data.getString("banned_by_name"), 13 | data.getTimestamp("time"), data.getTimestamp("until"), 14 | data.getBoolean("silent"), data.getBoolean("active"), 15 | null, null, null); 16 | } 17 | 18 | @Override 19 | public String getQuery() { 20 | return "SELECT uuid, reason, banned_by_uuid, banned_by_name, FROM_UNIXTIME(time / 1000) AS time, FROM_UNIXTIME(until / 1000) AS until, silent, active " + 21 | "FROM litebans." + getDBTable() + " WHERE uuid = ? ORDER BY time DESC;"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/ClampedIntegerArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import com.diamondfire.helpbot.util.Util; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | public class ClampedIntegerArgument extends IntegerArgument { 9 | 10 | final int min; 11 | final int max; 12 | 13 | public ClampedIntegerArgument(int min) { 14 | this.min = min; 15 | this.max = Integer.MAX_VALUE; 16 | } 17 | 18 | public ClampedIntegerArgument(int min, int max) { 19 | this.min = min; 20 | this.max = max; 21 | } 22 | 23 | @Override 24 | public Integer parse(@NotNull String msg, CommandEvent event) throws ArgumentException { 25 | int num = super.parse(msg, event); 26 | 27 | if (num <= max && num >= min) { 28 | return num; 29 | } else { 30 | return Util.clamp(num, min, max); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks.impl; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.graph.generators.*; 5 | import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; 6 | import com.diamondfire.helpbot.sys.tasks.MidnightTask; 7 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; 8 | import net.dv8tion.jda.api.utils.FileUpload; 9 | 10 | public class GraphChannelTask implements MidnightTask { 11 | 12 | @Override 13 | public void run() { 14 | TextChannel channel = HelpBotInstance.getJda().getTextChannelById(736019542882517062L); 15 | channel.getHistoryFromBeginning(50).queue(messageHistory -> channel.purgeMessages(messageHistory.getRetrievedHistory())); 16 | 17 | TimeGraphContext context = new TimeGraphContext(TimeMode.DAILY, 14); 18 | channel.sendFiles(FileUpload.fromData(GraphGenerators.NEW_PLAYERS.createGraph(context))).queue(); 19 | channel.sendFiles(FileUpload.fromData(GraphGenerators.UNIQUE_JOINS.createGraph(context))).queue(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/SubCommandArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 4 | import com.diamondfire.helpbot.bot.command.impl.*; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.Arrays; 9 | import java.util.stream.Collectors; 10 | 11 | public class SubCommandArgument extends AbstractSimpleValueArgument { 12 | 13 | @Override 14 | public SubCommand parse(@NotNull String msg, CommandEvent event) throws ArgumentException { 15 | try { 16 | return Arrays.stream(((SubCommandHolder) event.getCommand()).getSubCommands()) 17 | .filter(s -> s.getName().equals(msg)).collect(Collectors.toList()).get(0); 18 | } catch (IndexOutOfBoundsException e) { 19 | throw new MalformedArgumentException( 20 | "Not a valid subcommand. Choose from " + event.getCommand().getHelpContext().getArguments().get(0).getArgumentName()); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/DiscordUserArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.MalformedArgumentException; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import net.dv8tion.jda.api.utils.MiscUtil; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.regex.*; 9 | 10 | public class DiscordUserArgument extends AbstractSimpleValueArgument { 11 | 12 | private final Pattern pattern = Pattern.compile("<@!?(\\d+)>"); 13 | 14 | @Override 15 | public Long parse(@NotNull String msg, CommandEvent event) throws MalformedArgumentException { 16 | 17 | try { 18 | return Long.parseLong(msg); 19 | } catch (NumberFormatException ignored) { 20 | } 21 | 22 | Matcher matcher = pattern.matcher(msg); 23 | if (matcher.find()) { 24 | return MiscUtil.parseSnowflake(matcher.group(1)); 25 | } 26 | throw new MalformedArgumentException("Bad user argument provided, must either be a ping or an id."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/DateUtil.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util; 2 | 3 | import java.sql.Timestamp; 4 | import java.time.*; 5 | import java.util.*; 6 | 7 | @SuppressWarnings("deprecation") 8 | public class DateUtil { 9 | 10 | public static Date toDate(java.sql.Date sqlDate) { 11 | return new Date(sqlDate.getDay(), sqlDate.getMonth(), sqlDate.getYear()); 12 | } 13 | 14 | public static Date toDate(long milli) { 15 | return new Date(milli); 16 | } 17 | 18 | public static Date toDate(LocalDate date) { 19 | Calendar calendar = Calendar.getInstance(); 20 | calendar.set(date.getYear(), date.getMonthValue() - 1, date.getDayOfMonth()); 21 | 22 | return calendar.getTime(); 23 | } 24 | 25 | public static java.sql.Date toSqlDate(Date date) { 26 | return new java.sql.Date(date.toInstant().toEpochMilli()); 27 | } 28 | 29 | public static java.sql.Date toSqlDate(Instant instant) { 30 | return new java.sql.Date(instant.toEpochMilli()); 31 | } 32 | 33 | public static Timestamp toTimeStamp(Date date) { 34 | return new Timestamp(date.getTime()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/WebUtil.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonParser; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.net.URL; 10 | import java.nio.charset.Charset; 11 | 12 | public class WebUtil { 13 | 14 | public static String getString(String urlToRead, Charset charset) throws IOException { 15 | URL url = new URL(urlToRead); 16 | BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), charset)); 17 | StringBuilder builder = new StringBuilder(); 18 | String line; 19 | 20 | while ((line = in.readLine()) != null) { 21 | builder.append("\n").append(line); 22 | } 23 | in.close(); 24 | return builder.toString(); 25 | } 26 | 27 | public static String getString(String urlToRead) throws IOException { 28 | return getString(urlToRead, Charset.defaultCharset()); 29 | } 30 | 31 | public static JsonElement getJson(String url) throws IOException { 32 | return JsonParser.parseString(getString(url)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util.textgen; 2 | 3 | import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; 4 | 5 | import java.io.*; 6 | import java.util.*; 7 | 8 | import static com.diamondfire.helpbot.util.textgen.MarkovManipulation.addWord; 9 | 10 | public class CacheData { 11 | 12 | public static void cacheData() throws IOException { 13 | 14 | File file = ExternalFiles.SAM_QUOTES; 15 | BufferedReader br = new BufferedReader(new FileReader(file)); 16 | 17 | FileWriter fileWriter = new FileWriter("markov.txt"); 18 | fileWriter.write(""); 19 | fileWriter.close(); 20 | 21 | String line; 22 | while ((line = br.readLine()) != null) { 23 | 24 | List splitLine = Arrays.asList(line.split(" ")); 25 | for (int i = 0; i < splitLine.size(); i++) { 26 | 27 | if (i == splitLine.size() - 1) { 28 | addWord(splitLine.get(i), "."); 29 | } else { 30 | addWord(splitLine.get(i), splitLine.get(i + 1)); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/PermissionCheck.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.executor.checks; 2 | 3 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 4 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 5 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 6 | import com.diamondfire.helpbot.bot.events.CommandEvent; 7 | 8 | public class PermissionCheck implements CommandCheck { 9 | 10 | @Override 11 | public boolean check(CommandEvent event) { 12 | return event.getCommand().getPermission().hasPermission(event.getMember()) 13 | || Permission.getOverrides(event.getCommand()).contains(event.getAuthor().getIdLong()); 14 | } 15 | 16 | @Override 17 | public void buildMessage(CommandEvent event, PresetBuilder builder) { 18 | builder.withPreset( 19 | new InformativeReply(InformativeReplyType.ERROR, "No Permission!", "Sorry, you do not have permission to use this command. Commands that you are able to use are listed in ?help.") 20 | ); 21 | builder.getEmbed().setFooter("Permission Required: " + event.getCommand().getPermission().name()); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/ArgumentSet.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument; 2 | 3 | 4 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.ArgumentNode; 5 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; 6 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 7 | import org.jetbrains.annotations.*; 8 | 9 | import java.util.*; 10 | 11 | public class ArgumentSet { 12 | 13 | private final List> arguments = new ArrayList<>(); 14 | 15 | //Convenience method 16 | @Contract("_,_ -> this") 17 | public ArgumentSet addArgument(@NotNull String name, @NotNull Argument argument) { 18 | arguments.add(new ArgumentNode<>(name, new SingleArgumentContainer<>(argument))); 19 | return this; 20 | } 21 | 22 | @Contract("_,_ -> this") 23 | public ArgumentSet addArgument(@NotNull String name, @NotNull ArgumentContainer argument) { 24 | arguments.add(new ArgumentNode<>(name, argument)); 25 | return this; 26 | } 27 | 28 | 29 | @Contract(pure = true) 30 | public List> getArguments() { 31 | return arguments; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/Command.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.help.HelpContext; 5 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 6 | import com.diamondfire.helpbot.bot.events.CommandEvent; 7 | 8 | public abstract class Command { 9 | 10 | private ArgumentSet set = null; 11 | 12 | public abstract String getName(); 13 | 14 | public boolean cacheArgumentSet() { 15 | return true; 16 | } 17 | 18 | public String[] getAliases() { 19 | return new String[0]; 20 | } 21 | 22 | public abstract HelpContext getHelpContext(); 23 | 24 | protected abstract ArgumentSet compileArguments(); 25 | 26 | public ArgumentSet getArguments() { 27 | if (cacheArgumentSet()) { 28 | if (set == null) { 29 | set = compileArguments(); 30 | } 31 | return set; 32 | } else { 33 | return compileArguments(); 34 | } 35 | } 36 | 37 | public abstract Permission getPermission(); 38 | 39 | public abstract void run(CommandEvent event); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/reply/feature/informative/InformativeReply.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.reply.feature.informative; 2 | 3 | import com.diamondfire.helpbot.bot.command.reply.feature.ReplyPreset; 4 | import net.dv8tion.jda.api.EmbedBuilder; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.awt.*; 8 | 9 | public class InformativeReply implements ReplyPreset { 10 | 11 | final String title; 12 | final String description; 13 | final Color color; 14 | 15 | public InformativeReply(InformativeReplyType type, String description) { 16 | this.color = type.getColor(); 17 | this.description = description; 18 | this.title = type.getTitle(); 19 | } 20 | 21 | public InformativeReply(InformativeReplyType type, String title, @Nullable String description) { 22 | this.color = type.getColor(); 23 | this.description = description; 24 | this.title = title; 25 | } 26 | 27 | 28 | @Override 29 | public void applyFeature(EmbedBuilder builder) { 30 | builder.setTitle(title); 31 | if (description != null) { 32 | builder.setDescription(description); 33 | } 34 | builder.setColor(color); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/BasicReaction.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.viewables; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import net.dv8tion.jda.api.entities.*; 5 | import net.dv8tion.jda.api.entities.emoji.*; 6 | import net.dv8tion.jda.api.requests.RestAction; 7 | 8 | public class BasicReaction { 9 | 10 | private final Emoji emoji; 11 | 12 | public BasicReaction(Emoji emoji) { 13 | this.emoji = emoji; 14 | } 15 | 16 | 17 | 18 | public String getUnicode() { 19 | if (emoji.getType() != Emoji.Type.UNICODE) { 20 | throw new IllegalStateException("Emoji is not a unicode char!"); 21 | } 22 | 23 | return emoji.getName(); 24 | } 25 | 26 | public CustomEmoji getEmote() { 27 | if (emoji.getType() != Emoji.Type.CUSTOM) { 28 | throw new IllegalStateException("Emoji is not a unicode char!"); 29 | } 30 | 31 | return (CustomEmoji) emoji; 32 | } 33 | 34 | public RestAction react(Message message) { 35 | return message.addReaction(emoji); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return this.emoji.getFormatted(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/externalfile/ExternalFileBuilder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.externalfile; 2 | 3 | import java.io.File; 4 | 5 | public class ExternalFileBuilder { 6 | 7 | String fileName; 8 | String fileType = "unk"; 9 | boolean directory = false; 10 | 11 | public ExternalFileBuilder setName(String fileName) { 12 | this.fileName = fileName; 13 | return this; 14 | } 15 | 16 | public ExternalFileBuilder setFileType(String fileType) { 17 | this.fileType = fileType; 18 | return this; 19 | } 20 | 21 | public ExternalFileBuilder isDirectory(boolean directory) { 22 | this.directory = directory; 23 | return this; 24 | } 25 | 26 | public File buildFile() { 27 | File file = new File(fileName + (directory ? "" : "." + fileType)); 28 | try { 29 | if (!file.exists()) { 30 | if (directory) { 31 | file.mkdir(); 32 | } else { 33 | file.createNewFile(); 34 | } 35 | 36 | } 37 | 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | return file; 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/AlternateArgumentParser.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.*; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 5 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*; 6 | import com.diamondfire.helpbot.bot.events.CommandEvent; 7 | 8 | public class AlternateArgumentParser extends ArgumentParser, A> { 9 | 10 | public AlternateArgumentParser(AlternateArgumentContainer container) { 11 | super(container); 12 | } 13 | 14 | @Override 15 | public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException { 16 | for (ArgumentContainer container : getContainer().getAlternatives()) { 17 | try { 18 | return new ParsedArgument<>(identifier, container.getParser().parse(identifier, args, event).getValue()); 19 | } catch (ArgumentException ignored) { 20 | } 21 | } 22 | 23 | throw new MissingArgumentException("No valid arguments were provided."); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/help/HelpContext.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.help; 2 | 3 | import java.util.*; 4 | 5 | public class HelpContext { 6 | 7 | final List arguments = new ArrayList<>(); 8 | String description = null; 9 | CommandCategory commandCategory = null; 10 | 11 | public HelpContext description(String description) { 12 | this.description = description; 13 | return this; 14 | } 15 | 16 | public HelpContext category(CommandCategory commandCategory) { 17 | this.commandCategory = commandCategory; 18 | return this; 19 | } 20 | 21 | public HelpContext addArgument(HelpContextArgument argument) { 22 | arguments.add(argument); 23 | return this; 24 | } 25 | 26 | public HelpContext addArgument(HelpContextArgument... argument) { 27 | arguments.addAll(Arrays.asList(argument)); 28 | return this; 29 | } 30 | 31 | public String getDescription() { 32 | return description; 33 | } 34 | 35 | public CommandCategory getCommandCategory() { 36 | return commandCategory; 37 | } 38 | 39 | public List getArguments() { 40 | return arguments; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/StarUtil.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util; 2 | 3 | import javax.imageio.ImageIO; 4 | import java.awt.*; 5 | import java.awt.image.BufferedImage; 6 | import java.io.*; 7 | 8 | /** 9 | * Creates a coloured star to be used as a role icon. 10 | */ 11 | public class StarUtil { 12 | 13 | private static final BufferedImage STAR; 14 | private static final int SIZE = 64; 15 | 16 | static { 17 | // Load the star from the resources. 18 | InputStream inputStream = StarUtil.class.getResourceAsStream("/star.png"); 19 | 20 | try { 21 | assert inputStream != null; 22 | STAR = ImageIO.read(inputStream); 23 | }catch (IOException e) { 24 | throw new RuntimeException(e); 25 | } 26 | } 27 | 28 | public static BufferedImage create(Color color) { 29 | BufferedImage bufferedImage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB); 30 | Graphics2D g2d = bufferedImage.createGraphics(); 31 | 32 | g2d.drawImage(STAR, 0, 0, null); 33 | g2d.setComposite(AlphaComposite.SrcAtop); 34 | g2d.setColor(color); 35 | g2d.fillRect(0, 0, SIZE, SIZE); 36 | g2d.dispose(); 37 | return bufferedImage; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/punishments/fetcher/providers/RemovablePunishmentProvider.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.punishments.fetcher.providers; 2 | 3 | import com.diamondfire.helpbot.df.punishments.Punishment; 4 | 5 | import java.sql.*; 6 | 7 | public abstract class RemovablePunishmentProvider implements PunishmentProvider { 8 | 9 | @Override 10 | public Punishment getPunishment(ResultSet data) throws SQLException { 11 | return new Punishment(getType(), data.getString("uuid"), data.getString("reason"), 12 | data.getString("banned_by_uuid"), data.getString("banned_by_name"), 13 | data.getTimestamp("time"), data.getTimestamp("until"), data.getBoolean("silent"), 14 | data.getBoolean("active"), data.getString("removed_by_uuid"), 15 | data.getString("removed_by_name"), data.getTimestamp("removed_by_date")); 16 | } 17 | 18 | 19 | @Override 20 | public String getQuery() { 21 | return "SELECT uuid, reason, banned_by_uuid, banned_by_name, FROM_UNIXTIME(time / 1000) AS time, FROM_UNIXTIME(until / 1000) AS until, silent, active, " + 22 | "removed_by_uuid, removed_by_name, removed_by_date " + 23 | "FROM litebans." + getDBTable() + " WHERE uuid = ? ORDER BY time DESC;"; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/generators/GraphGenerators.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.generators; 2 | 3 | public interface GraphGenerators { 4 | 5 | QueryGraphGenerator UNIQUE_JOINS = new QueryGraphGenerator("unique player joins", "" + 6 | "SELECT time, COUNT(*) AS count " + 7 | "FROM (SELECT DISTINCT uuid, DATE_FORMAT(time, ?) AS time" + 8 | " FROM player_join_log" + 9 | " WHERE time > (((NOW() - INTERVAL ? HOUR) - INTERVAL MINUTE(NOW()) MINUTE) - INTERVAL SECOND(NOW()) SECOND) - INTERVAL HOUR(NOW()) HOUR" + 10 | " AND uuid NOT IN (SELECT uuid FROM litebans.bans WHERE active = 1 AND until = -1)) a " + 11 | "GROUP BY time"); 12 | 13 | QueryGraphGenerator NEW_PLAYERS = new QueryGraphGenerator("new player joins", "" + 14 | "SELECT time, COUNT(*) AS count " + 15 | "FROM (SELECT DISTINCT uuid, DATE_FORMAT(join_date, ?) AS time" + 16 | " FROM players" + 17 | " WHERE join_date > (((NOW() - INTERVAL ? HOUR) - INTERVAL MINUTE(NOW()) MINUTE) - INTERVAL SECOND(NOW()) SECOND) - INTERVAL HOUR(NOW()) HOUR" + 18 | " AND uuid NOT IN (SELECT uuid FROM litebans.bans WHERE active = 1 AND until = -1)) a " + 19 | "GROUP BY time"); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/SoundListCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.dumps; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.bot.command.impl.other.util.AbstractFileListCommand; 5 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 6 | import com.diamondfire.helpbot.bot.events.CommandEvent; 7 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; 8 | 9 | public class SoundListCommand extends AbstractFileListCommand { 10 | 11 | @Override 12 | public String getName() { 13 | return "sounds"; 14 | } 15 | 16 | @Override 17 | public String[] getAliases() { 18 | return new String[]{"soundlist"}; 19 | } 20 | 21 | @Override 22 | public HelpContext getHelpContext() { 23 | return new HelpContext() 24 | .description("Generates a file that contains all sounds.") 25 | .category(CommandCategory.OTHER); 26 | } 27 | 28 | @Override 29 | public Permission getPermission() { 30 | return Permission.USER; 31 | } 32 | 33 | @Override 34 | public void run(CommandEvent event) { 35 | super.generate(event, CodeDatabase.getRegistry(CodeDatabase.SOUNDS)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/CodeBlockData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.*; 4 | import com.google.gson.JsonObject; 5 | 6 | public class CodeBlockData extends CodeObject { 7 | 8 | private ActionData associatedAction; 9 | 10 | public CodeBlockData(JsonObject data) { 11 | super(data, data.get("name").getAsString()); 12 | } 13 | 14 | public String getName() { 15 | return data.get("name").getAsString(); 16 | } 17 | 18 | public String getIdentifier() { 19 | return data.get("identifier").getAsString(); 20 | } 21 | 22 | @Override 23 | public DisplayIcon getItem() { 24 | return new DisplayIcon(data.get("item").getAsJsonObject()); 25 | } 26 | 27 | public void assignAction(ActionData data) { 28 | associatedAction = data; 29 | } 30 | 31 | public ActionData getAssociatedAction() { 32 | return associatedAction; 33 | } 34 | 35 | public CodeBlockEnum getCodeblockEnum() { 36 | return CodeBlockEnum.getFromID(getIdentifier()); 37 | } 38 | 39 | @Override 40 | public DataTypes getEnum() { 41 | return DataTypes.CODEBLOCK; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/help/CommandCategory.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.help; 2 | 3 | public enum CommandCategory { 4 | 5 | PLAYER_STATS("Player Statistics", "These commands are made to be able to quickly search information on a player", "\uD83D\uDC64"), 6 | GENERAL_STATS("General Statistics", "These commands are made to be able to quickly search information on a plot or how many people are online a node.", "\uD83D\uDCCB"), 7 | SUPPORT("Support", "These commands are support related and are intended for staff use.", "\uD83D\uDD16"), 8 | CODE_BLOCK("Coding Help", "These commands are made to help you find things in dev mode.", "\uD83D\uDDA5"), 9 | OTHER("Other", "These commands are just random commands.", "\uD83E\uDDE9"); 10 | 11 | private final String name; 12 | private final String description; 13 | private final String emoji; 14 | 15 | CommandCategory(String name, String description, String emoji) { 16 | this.name = name; 17 | this.description = description; 18 | this.emoji = emoji; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public String getDescription() { 26 | return description; 27 | } 28 | 29 | public String getEmoji() { 30 | return emoji; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/SubCommandHolder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.command.CommandHandler; 5 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 6 | import com.diamondfire.helpbot.bot.command.argument.impl.types.SubCommandArgument; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | 9 | import java.util.*; 10 | 11 | public abstract class SubCommandHolder extends Command { 12 | 13 | @Override 14 | public ArgumentSet compileArguments() { 15 | return new ArgumentSet().addArgument( 16 | "subcommand", new SubCommandArgument() 17 | ); 18 | } 19 | 20 | @Override 21 | public void run(CommandEvent event) { 22 | SubCommand subcommand = event.getArgument("subcommand"); 23 | event.setCommand(subcommand); 24 | 25 | String[] rawArgs = event.getRawArgs(); 26 | rawArgs[0] = rawArgs[0].substring(HelpBotInstance.getConfig().getPrefix().length()); 27 | 28 | List args = new ArrayList<>(Arrays.asList(rawArgs)); 29 | args.remove(1); 30 | 31 | CommandHandler.getInstance().run(event, args.toArray(String[]::new)); 32 | } 33 | 34 | public abstract SubCommand[] getSubCommands(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/SingleArgumentParser.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.*; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 5 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; 6 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | 9 | import java.util.Deque; 10 | 11 | public class SingleArgumentParser extends ArgumentParser, A> { 12 | 13 | 14 | public SingleArgumentParser(SingleArgumentContainer container) { 15 | super(container); 16 | } 17 | 18 | @Override 19 | public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException { 20 | Deque rawArgs = args.popStack(); 21 | Argument arg = getContainer().getArgument(); 22 | 23 | if (rawArgs.peek() == null) { 24 | throw new MissingArgumentException("Expected an argument, but got nothing."); 25 | } 26 | 27 | return new ParsedArgument<>(identifier, arg.parseValue(rawArgs, event)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/exceptions/ArgumentException.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.command.impl.*; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import com.diamondfire.helpbot.util.FormatUtil; 7 | 8 | public class ArgumentException extends Exception { 9 | 10 | private String message; 11 | 12 | public ArgumentException(String message) { 13 | super(message); 14 | this.message = message; 15 | } 16 | 17 | public String getEmbedMessage() { 18 | return message; 19 | } 20 | 21 | public void setContext(Command command, int pos, CommandEvent event) { 22 | String[] args = FormatUtil.getArgumentDisplay(command.getHelpContext()); 23 | args[pos] = "**" + args[pos] + "**"; 24 | String argMessage = FormatUtil.displayCommand(command) + " " + String.join(" ", args); 25 | 26 | if (command instanceof SubCommand) { 27 | String prefix = HelpBotInstance.getConfig().getPrefix(); 28 | 29 | argMessage = event.getRawArgs()[0] + " " + argMessage.substring(prefix.length()); 30 | } 31 | 32 | message = argMessage + "\n\n" + getMessage(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.message.acceptors; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.tag.*; 5 | import com.diamondfire.helpbot.sys.tag.exceptions.TagDoesNotExistException; 6 | import net.dv8tion.jda.api.entities.Message; 7 | 8 | import java.io.IOException; 9 | 10 | public class TagAcceptor implements MessageAcceptor { 11 | 12 | @Override 13 | public boolean accept(Message message) { 14 | if (message.getContentDisplay().startsWith(HelpBotInstance.getConfig().getPrefix()) && 15 | !message.getAuthor().isBot()) { 16 | 17 | String parsedText = message.getContentStripped() 18 | .substring(HelpBotInstance.getConfig().getPrefix().length()) 19 | .replaceFirst(" .*$", ""); 20 | 21 | try { 22 | // Get Tag and send response 23 | TagHandler.getTag(parsedText) 24 | .sendResponse(message.getChannel().asGuildMessageChannel(), message.getAuthor()); 25 | 26 | } catch (TagDoesNotExistException | IOException ignored) { 27 | return false; 28 | } 29 | 30 | return true; 31 | } 32 | 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/ranks/RankUtil.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.ranks; 2 | 3 | import java.sql.*; 4 | import java.util.*; 5 | 6 | public class RankUtil { 7 | 8 | public static Rank[] getRanks(ResultSet set) { 9 | List ranks = new ArrayList<>(); 10 | try { 11 | ResultSetMetaData metaData = set.getMetaData(); 12 | for (int i = 1; i <= metaData.getColumnCount(); i++) { 13 | RankBranch branch = RankBranch.databaseMap.get(metaData.getColumnName(i).toUpperCase()); 14 | if (branch == null) { 15 | continue; 16 | } 17 | int num = set.getInt(i); 18 | 19 | Rank rank = Rank.fromBranch(branch, num); 20 | if (rank != null) { 21 | ranks.add(rank); 22 | } 23 | 24 | } 25 | 26 | } catch (SQLException ignored) { 27 | } 28 | 29 | return ranks.toArray(Rank[]::new); 30 | } 31 | 32 | public static Rank getHighRank(ResultSet set) { 33 | return getHighRank(getRanks(set)); 34 | } 35 | 36 | public static Rank getHighRank(Rank[] ranks) { 37 | if (ranks.length == 0) { 38 | return null; 39 | } 40 | 41 | return ranks[ranks.length - 1]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/PostChannelEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.util.SolvedPostManager; 4 | import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; 5 | import net.dv8tion.jda.api.entities.channel.forums.ForumTag; 6 | import net.dv8tion.jda.api.events.channel.update.*; 7 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 8 | 9 | import java.util.Optional; 10 | 11 | public class PostChannelEvent extends ListenerAdapter { 12 | 13 | @Override 14 | public void onChannelUpdateAppliedTags(ChannelUpdateAppliedTagsEvent event) { 15 | Optional optionalChannel = SolvedPostManager.getHelpPost(event.getChannel()); 16 | if (optionalChannel.isEmpty()) { 17 | return; 18 | } 19 | ThreadChannel threadChannel = optionalChannel.get(); 20 | 21 | Optional optionalTag = SolvedPostManager.getSolvedTag(threadChannel); 22 | if (optionalTag.isEmpty()) { 23 | return; 24 | } 25 | ForumTag solvedTag = optionalTag.get(); 26 | 27 | if (event.getAddedTags().contains(solvedTag)) { 28 | SolvedPostManager.addSolved(threadChannel); 29 | } else if (event.getRemovedTags().contains(solvedTag)) { 30 | SolvedPostManager.removeSolved(threadChannel); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/generators/TimeMode.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.generators; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.function.Function; 5 | 6 | public enum TimeMode { 7 | 8 | HOURLY("Hourly", "%m-%d-%Hh", (num) -> num), 9 | DAILY("Daily", "%y-%m-%d", (num) -> (int) TimeUnit.DAYS.toHours(num)), 10 | WEEKLY("Weekly", "%y-%m-%v", (num) -> (int) TimeUnit.DAYS.toHours(num * 7L)), 11 | MONTHLY("Monthly", "%y-%m", (num) -> (int) TimeUnit.DAYS.toHours(num * 30L)), 12 | YEARLY("Yearly", "%y", (num) -> (int) TimeUnit.DAYS.toHours(num * 365L)), 13 | ; 14 | 15 | private final String mode; 16 | private final String dateFormat; 17 | 18 | private final Function unitConversion; 19 | 20 | TimeMode(String mode, String dateFormat, Function unitConversion) { 21 | this.mode = mode; 22 | this.dateFormat = dateFormat; 23 | this.unitConversion = unitConversion; 24 | } 25 | 26 | public String getMode() { 27 | return mode; 28 | } 29 | 30 | public String getDateFormat() { 31 | return dateFormat; 32 | } 33 | 34 | public Function getUnitConversion() { 35 | return unitConversion; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return mode; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelectorPage.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.multiselector; 2 | 3 | import net.dv8tion.jda.api.EmbedBuilder; 4 | 5 | public class MultiSelectorPage { 6 | 7 | private final String name; 8 | private final EmbedBuilder page; 9 | private final boolean hidden; 10 | private final String customEmote; 11 | 12 | public MultiSelectorPage(String name, EmbedBuilder page) { 13 | this.name = name; 14 | this.page = page; 15 | this.hidden = false; 16 | this.customEmote = null; 17 | } 18 | 19 | public MultiSelectorPage(String name, EmbedBuilder page, boolean hidden) { 20 | this.name = name; 21 | this.page = page; 22 | this.hidden = hidden; 23 | this.customEmote = null; 24 | } 25 | 26 | public MultiSelectorPage(String name, EmbedBuilder page, String customEmote, boolean hidden) { 27 | this.name = name; 28 | this.page = page; 29 | this.hidden = hidden; 30 | this.customEmote = customEmote; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public EmbedBuilder getPage() { 38 | return page; 39 | } 40 | 41 | public boolean isHidden() { 42 | return hidden; 43 | } 44 | 45 | public String getCustomEmote() { 46 | return customEmote; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/ArgumentStack.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing; 2 | 3 | import java.util.*; 4 | 5 | // ArgumentStacks contain a bunch of argument nodes and raw arguments. 6 | public class ArgumentStack { 7 | 8 | private final RawArgumentStack stack; 9 | private final Deque> args; 10 | 11 | public ArgumentStack(List> args, Collection rawArgs) { 12 | this.stack = new RawArgumentStack(new ArrayDeque<>(rawArgs)); 13 | this.args = new ArrayDeque<>(args); 14 | 15 | stack.stack.removeIf(String::isEmpty); 16 | } 17 | 18 | public RawArgumentStack getRawArguments() { 19 | return stack; 20 | } 21 | 22 | public Deque> getArguments() { 23 | return args; 24 | } 25 | 26 | public static class RawArgumentStack { 27 | 28 | private Deque stack; 29 | private Deque currentStack; 30 | 31 | public RawArgumentStack(Deque stack) { 32 | this.stack = stack; 33 | } 34 | 35 | public Deque popStack() { 36 | return currentStack = new ArrayDeque<>(stack); 37 | } 38 | 39 | public Deque pushStack() { 40 | return stack = currentStack; 41 | } 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/serializer/TagSerializer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util.serializer; 2 | 3 | import com.diamondfire.helpbot.sys.tag.Tag; 4 | import com.google.gson.JsonObject; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public class TagSerializer implements Serializer { 8 | 9 | private static final TagSerializer instance = new TagSerializer(); 10 | 11 | public static TagSerializer getInstance() { 12 | return instance; 13 | } 14 | 15 | @Override 16 | public JsonObject serialize(@NotNull Tag tag) { 17 | JsonObject json = new JsonObject(); 18 | 19 | json.addProperty("activator", tag.getActivator()); 20 | json.addProperty("title", tag.getTitle()); 21 | json.addProperty("response", tag.getResponse()); 22 | json.addProperty("authorId", tag.getAuthorId()); 23 | json.addProperty("image", tag.getImage()); 24 | 25 | return json; 26 | } 27 | 28 | @Override 29 | public Tag deserialize(@NotNull JsonObject toDeserialize) { 30 | return new Tag( 31 | toDeserialize.get("activator").getAsString(), 32 | toDeserialize.get("title").getAsString(), 33 | toDeserialize.get("response").getAsString(), 34 | toDeserialize.get("authorId").getAsLong(), 35 | toDeserialize.get("image").getAsString() 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/DataTypes.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.viewables.constants; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; 4 | import com.diamondfire.helpbot.df.codeinfo.viewables.embeds.*; 5 | 6 | public enum DataTypes { 7 | CODEBLOCK("Codeblock", 688643535842705408L, new CodeBlockEmbedBuilder()), 8 | ACTION("Codeblock Action", 688643679686230066L, new CodeActionEmbedBuilder()), 9 | GAME_VALUE("Game Value", 789274945850441728L, new GameValueEmbedBuilder()), 10 | POTION("Potion", 789274945162575912L, new SimpleIconBuilder()), 11 | PARTICLE("Particle Effect", 789274944730824796L, new SimpleIconBuilder()), 12 | SOUND("Sound Effect", 789274945187479563L, new SimpleIconBuilder()); 13 | 14 | private final String name; 15 | private final long emoji; 16 | private final IconEmbedBuilder embedBuilder; 17 | 18 | DataTypes(String name, long emoji, IconEmbedBuilder builder) { 19 | this.name = name; 20 | this.emoji = emoji; 21 | this.embedBuilder = builder; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public long getEmoji() { 29 | return emoji; 30 | } 31 | 32 | public IconEmbedBuilder getEmbedBuilder() { 33 | return (IconEmbedBuilder) embedBuilder; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/executor/checks/CommandLog.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.executor.checks; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 7 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 8 | 9 | public class CommandLog implements CommandCheck { 10 | 11 | @Override 12 | public boolean check(CommandEvent event) { 13 | if (!HelpBotInstance.getConfig().isDevBot()) { 14 | new Thread(() -> { 15 | new DatabaseQuery() 16 | .query(new BasicQuery("INSERT INTO owen.cmd_log (user, command, alias, channel, time) VALUES (?,?,?,?,CURRENT_TIMESTAMP())", (statement) -> { 17 | statement.setLong(1, event.getMember().getIdLong()); 18 | statement.setString(2, event.getCommand().getName()); 19 | statement.setString(3, event.getAliasUsed()); 20 | statement.setLong(4, event.getChannel().getIdLong()); 21 | })).compile(); 22 | 23 | }).start(); 24 | } 25 | return true; 26 | } 27 | 28 | @Override 29 | public void buildMessage(CommandEvent event, PresetBuilder builder) { 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.dumps; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.help.*; 5 | import com.diamondfire.helpbot.bot.command.impl.Command; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; 9 | import net.dv8tion.jda.api.utils.FileUpload; 10 | 11 | public class ActionDumpCommand extends Command { 12 | 13 | @Override 14 | public String getName() { 15 | return "actiondump"; 16 | } 17 | 18 | @Override 19 | public HelpContext getHelpContext() { 20 | return new HelpContext() 21 | .description("Provides over the action dump file. This file provides a dump of all the data HelpBot uses. This is automatically updated every 24 hours.") 22 | .category(CommandCategory.OTHER); 23 | } 24 | 25 | @Override 26 | public ArgumentSet compileArguments() { 27 | return new ArgumentSet(); 28 | } 29 | 30 | @Override 31 | public Permission getPermission() { 32 | return Permission.USER; 33 | } 34 | 35 | @Override 36 | public void run(CommandEvent event) { 37 | event.getChannel().sendFiles(FileUpload.fromData(ExternalFiles.DB)).queue(); 38 | } 39 | 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/MojangPlayerUUIDArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import com.diamondfire.helpbot.util.*; 7 | import com.google.gson.JsonObject; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.io.IOException; 11 | import java.util.UUID; 12 | 13 | // TODO: Player 14 | public class MojangPlayerUUIDArgument extends AbstractSimpleValueArgument { 15 | 16 | @Override 17 | protected UUID parse(@NotNull String argument, CommandEvent event) throws ArgumentException { 18 | if (argument.length() > 16) { 19 | return Util.toUuid(argument); 20 | } else { 21 | JsonObject responseObject = null; 22 | 23 | try { 24 | responseObject = WebUtil.getJson("https://api.mojang.com/users/profiles/minecraft/" + argument).getAsJsonObject(); 25 | } catch (IOException e) { 26 | e.printStackTrace(); 27 | } 28 | 29 | if (responseObject.has("id")) { 30 | return Util.toUuid(responseObject.get("id").getAsString()); 31 | } else { 32 | return null; 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.graph; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.*; 5 | import com.diamondfire.helpbot.bot.command.impl.Command; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | import com.diamondfire.helpbot.sys.graph.generators.*; 9 | import net.dv8tion.jda.api.utils.FileUpload; 10 | 11 | public abstract class AbstractGraphCommand extends Command { 12 | 13 | @Override 14 | public ArgumentSet compileArguments() { 15 | return new ArgumentSet() 16 | .addArgument("mode", 17 | new DefinedObjectArgument<>(TimeMode.values())) 18 | .addArgument("amount", 19 | new ClampedIntegerArgument(1, 99999999)); 20 | } 21 | 22 | @Override 23 | public Permission getPermission() { 24 | return Permission.USER; 25 | } 26 | 27 | @Override 28 | public void run(CommandEvent event) { 29 | T context = createContext(event); 30 | 31 | event.getChannel().sendFiles(FileUpload.fromData(getGraphGenerator().createGraph(context))).queue(); 32 | } 33 | 34 | public abstract GraphGenerator getGraphGenerator(); 35 | 36 | public abstract T createContext(CommandEvent event); 37 | 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/TaskRegistry.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.tasks.impl.*; 5 | 6 | import java.util.concurrent.*; 7 | 8 | public class TaskRegistry { 9 | 10 | private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5); 11 | 12 | public void initialize() { 13 | if (HelpBotInstance.getConfig().isDevBot()) return; 14 | 15 | register( 16 | //new CodeDatabaseTask(), 17 | new GraphChannelTask(), 18 | //new RefreshCreditsTask(), 19 | new SupporterClassTask(), 20 | new NameUpdateTask(), 21 | new VIPStarTask() 22 | ); 23 | 24 | SupportUnexcuseTask.prepare(); 25 | MuteExpireTask.prepare(); 26 | } 27 | 28 | private void register(LoopingTask... tasks) { 29 | for (LoopingTask task : tasks) { 30 | scheduledExecutorService.scheduleAtFixedRate(task, 31 | task.getInitialStart(), 32 | task.getNextLoop(), 33 | TimeUnit.MILLISECONDS); 34 | } 35 | } 36 | 37 | public void schedule(Runnable runnable, long timeMs) { 38 | scheduledExecutorService.schedule(runnable, timeMs, TimeUnit.MILLISECONDS); 39 | } 40 | 41 | public void schedule(OneTimeTask task) { 42 | schedule(task, task.getExecution()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/nbs/CompressionUtil.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util.nbs; 2 | 3 | import java.io.*; 4 | import java.nio.charset.StandardCharsets; 5 | import java.util.Base64; 6 | import java.util.zip.*; 7 | //from https://github.com/CodeUtilities/CodeUtilities 8 | 9 | public class CompressionUtil { 10 | 11 | public static byte[] fromBase64(byte[] bytes) { 12 | return Base64.getDecoder().decode(bytes); 13 | } 14 | 15 | public static byte[] toBase64(byte[] bytes) { 16 | return Base64.getEncoder().encode(bytes); 17 | } 18 | 19 | public static byte[] fromGZIP(byte[] bytes) throws IOException { 20 | if (bytes == null) { 21 | return null; 22 | } 23 | 24 | GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes)); 25 | BufferedReader bf = new BufferedReader(new InputStreamReader(gis, StandardCharsets.UTF_8)); 26 | StringBuilder outStr = new StringBuilder(); 27 | String line; 28 | while ((line = bf.readLine()) != null) { 29 | outStr.append(line); 30 | } 31 | 32 | return outStr.toString().getBytes(); 33 | } 34 | 35 | public static byte[] toGZIP(byte[] bytes) throws IOException { 36 | if (bytes == null) { 37 | return null; 38 | } 39 | ByteArrayOutputStream obj = new ByteArrayOutputStream(); 40 | GZIPOutputStream gzip = new GZIPOutputStream(obj); 41 | gzip.write(bytes); 42 | gzip.close(); 43 | 44 | return obj.toByteArray(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/database/impl/result/DatabaseFuture.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.database.impl.result; 2 | 3 | import java.sql.*; 4 | import java.util.concurrent.CompletableFuture; 5 | 6 | public class DatabaseFuture { 7 | 8 | private final DatabaseResult result; 9 | private final Connection connection; 10 | 11 | public DatabaseFuture(Connection connection, DatabaseResult result) { 12 | this.connection = connection; 13 | this.result = result; 14 | } 15 | 16 | public void runAsync(DatabaseFutureRunnable action) { 17 | CompletableFuture.runAsync(() -> { 18 | run(action); 19 | }); 20 | } 21 | 22 | public void run(DatabaseFutureRunnable action) { 23 | try { 24 | action.run(result); 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | throw new RuntimeException(e); 28 | } finally { 29 | try { 30 | result.getResult().close(); 31 | connection.close(); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | } 37 | 38 | public CompletableFuture getFuture() { 39 | return CompletableFuture.completedFuture(result); 40 | } 41 | 42 | public DatabaseResult get() { 43 | return result; 44 | } 45 | 46 | public interface DatabaseFutureRunnable { 47 | 48 | void run(DatabaseResult resultSets) throws SQLException; 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/TagCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.tag; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.bot.command.impl.*; 5 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 6 | 7 | public class TagCommand extends SubCommandHolder { 8 | 9 | @Override 10 | public String getName() { 11 | return "tag"; 12 | } 13 | 14 | @Override 15 | public HelpContext getHelpContext() { 16 | return new HelpContext() 17 | .description(""" 18 | Controls custom command tags. Notes: 19 | - Edit: Use "none" for image to remove the image.""") 20 | .category(CommandCategory.OTHER) 21 | .addArgument( 22 | new HelpContextArgument() 23 | .name("add/edit/remove/list"), 24 | new HelpContextArgument() 25 | .name("...") 26 | .optional() 27 | ); 28 | } 29 | 30 | @Override 31 | public Permission getPermission() { 32 | return Permission.USER; 33 | } 34 | 35 | @Override 36 | public SubCommand[] getSubCommands() { 37 | return new SubCommand[]{ 38 | new AddTagSubCommand(), 39 | new EditTagSubCommand(), 40 | new RemoveTagSubCommand(), 41 | new ListTagsSubCommand() 42 | }; 43 | } 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/rolereact/ReactRole.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.rolereact; 2 | 3 | import java.util.*; 4 | 5 | public enum ReactRole { 6 | UPDATES("\uD83D\uDCDC", 761778773711519747L), 7 | EVENTS("\uD83D\uDCC5", 761779264345079848L), 8 | STREAMS("\uD83D\uDDA5", 761779390161223681L), 9 | PROMOTIONS("\uD83D\uDC64", 761779521937735711L), 10 | SALES("\uD83C\uDFF7", 761779623322320916L), 11 | APP_UPDATES("\uD83D\uDCD4", 770062219362435113L, "Staff Applications"), 12 | MEDIA("\uD83D\uDCF7", 821811669918416897L), 13 | POLLS("\uD83D\uDCCA", 995746459964166154L); 14 | 15 | private static final Map roleMap = new HashMap<>(); 16 | private final String emoji; 17 | private final long roleID; 18 | private final String override; 19 | 20 | static { 21 | for (ReactRole role : values()) { 22 | roleMap.put(role.getEmoji(), role); 23 | } 24 | } 25 | 26 | ReactRole(String emoji, long roleID) { 27 | this(emoji, roleID, null); 28 | } 29 | 30 | ReactRole(String emoji, long roleID, String override) { 31 | this.emoji = emoji; 32 | this.roleID = roleID; 33 | this.override = override; 34 | } 35 | 36 | public static ReactRole fromEmoji(String emoji) { 37 | return roleMap.get(emoji); 38 | } 39 | 40 | public long getRoleID() { 41 | return roleID; 42 | } 43 | 44 | public String getEmoji() { 45 | return emoji; 46 | } 47 | 48 | public String getOverride() { 49 | return override; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/NewJoinGraphCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.graph; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import com.diamondfire.helpbot.sys.graph.generators.*; 6 | import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; 7 | 8 | public class NewJoinGraphCommand extends AbstractGraphCommand { 9 | 10 | @Override 11 | public String getName() { 12 | return "joingraph"; 13 | } 14 | 15 | @Override 16 | public HelpContext getHelpContext() { 17 | return new HelpContext() 18 | .description("Generates a graph representing how many new players joined in a certain time frame.") 19 | .category(CommandCategory.GENERAL_STATS) 20 | .addArgument( 21 | new HelpContextArgument() 22 | .name("hourly|daily|amount|monthly|yearly"), 23 | new HelpContextArgument() 24 | .name("amount") 25 | ); 26 | } 27 | 28 | @Override 29 | public GraphGenerator getGraphGenerator() { 30 | return GraphGenerators.NEW_PLAYERS; 31 | } 32 | 33 | @Override 34 | public TimeGraphContext createContext(CommandEvent event) { 35 | TimeMode mode = event.getArgument("mode"); 36 | int amount = event.getArgument("amount"); 37 | 38 | return new TimeGraphContext(mode, amount); 39 | } 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/MimicCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.util; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MessageArgument; 5 | import com.diamondfire.helpbot.bot.command.help.*; 6 | import com.diamondfire.helpbot.bot.command.impl.Command; 7 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 8 | import com.diamondfire.helpbot.bot.events.CommandEvent; 9 | 10 | 11 | public class MimicCommand extends Command { 12 | 13 | @Override 14 | public String getName() { 15 | return "mimic"; 16 | } 17 | 18 | @Override 19 | public HelpContext getHelpContext() { 20 | return new HelpContext() 21 | .description("Removes your message and replaces it with its own.") 22 | .category(CommandCategory.OTHER) 23 | .addArgument( 24 | new HelpContextArgument().name("message") 25 | ); 26 | } 27 | 28 | @Override 29 | public ArgumentSet compileArguments() { 30 | return new ArgumentSet() 31 | .addArgument("msg", new MessageArgument()); 32 | } 33 | 34 | @Override 35 | public Permission getPermission() { 36 | return Permission.BOT_DEVELOPER; 37 | } 38 | 39 | @Override 40 | public void run(CommandEvent event) { 41 | String msg = event.getArgument("msg"); 42 | event.getMessage().delete().queue(); 43 | event.getChannel().sendMessage(msg).queue(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/PlayerJoinGraphCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.graph; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import com.diamondfire.helpbot.sys.graph.generators.*; 6 | import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; 7 | 8 | public class PlayerJoinGraphCommand extends AbstractGraphCommand { 9 | 10 | @Override 11 | public String getName() { 12 | return "playergraph"; 13 | } 14 | 15 | @Override 16 | public HelpContext getHelpContext() { 17 | return new HelpContext() 18 | .description("Generates a graph representing how many players joined in a certain time frame (unique).") 19 | .category(CommandCategory.GENERAL_STATS) 20 | .addArgument( 21 | new HelpContextArgument() 22 | .name("hourly|daily|weekly|monthly|yearly"), 23 | new HelpContextArgument() 24 | .name("amount") 25 | ); 26 | } 27 | 28 | @Override 29 | public GraphGenerator getGraphGenerator() { 30 | return GraphGenerators.UNIQUE_JOINS; 31 | } 32 | 33 | @Override 34 | public TimeGraphContext createContext(CommandEvent event) { 35 | TimeMode mode = event.getArgument("mode"); 36 | int amount = event.getArgument("amount"); 37 | 38 | return new TimeGraphContext(mode, amount); 39 | } 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/codedatabase/db/datatypes/ActionData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes; 2 | 3 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; 4 | import com.diamondfire.helpbot.df.codeinfo.viewables.constants.DataTypes; 5 | import com.diamondfire.helpbot.util.Util; 6 | import com.google.gson.JsonObject; 7 | 8 | import java.util.List; 9 | 10 | public class ActionData extends CodeObject { 11 | 12 | public ActionData(JsonObject data) { 13 | super(data, data.get("name").getAsString().trim()); 14 | } 15 | 16 | public String getName() { 17 | return data.get("name").getAsString().trim(); 18 | } 19 | 20 | public String getCodeblockName() { 21 | return data.get("codeblockName").getAsString(); 22 | } 23 | 24 | public CodeBlockTagData[] getTags() { 25 | return CodeBlockTagData.parseTags(data.get("tags").getAsJsonArray()); 26 | } 27 | 28 | public String[] getAliases() { 29 | return Util.fromJsonArray(data.get("aliases").getAsJsonArray()); 30 | } 31 | 32 | // Convenience method 33 | public CodeBlockData getCodeBlockData() { 34 | List codeBlocks = CodeDatabase.getRegistry(CodeDatabase.CODEBLOCKS); 35 | for (CodeBlockData data : codeBlocks) { 36 | if (data.getName().equals(getCodeblockName())) { 37 | return data; 38 | } 39 | } 40 | 41 | return null; 42 | } 43 | 44 | @Override 45 | public DataTypes getEnum() { 46 | return DataTypes.ACTION; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/UuidCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.individualized; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; 4 | import com.diamondfire.helpbot.bot.command.help.HelpContext; 5 | import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 8 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 9 | import com.diamondfire.helpbot.bot.events.CommandEvent; 10 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 11 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 12 | import com.diamondfire.helpbot.bot.command.help.HelpContextArgument; 13 | 14 | 15 | //Command exists for easy mobile copy and pasting 16 | public class UuidCommand extends AbstractPlayerUUIDCommand { 17 | 18 | @Override 19 | public String getName() { 20 | return "uuid"; 21 | } 22 | 23 | @Override 24 | public HelpContext getHelpContext() { 25 | return new HelpContext() 26 | .addArgument(new HelpContextArgument() 27 | .name("player name|uuid") 28 | .optional()); 29 | } 30 | 31 | @Override 32 | public Permission getPermission() { 33 | return Permission.USER; 34 | } 35 | 36 | @Override 37 | protected void execute(CommandEvent event, Player player) { 38 | event.getReplyHandler().reply(player.uuidString()); 39 | } 40 | 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/QuoteStringArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 4 | import com.diamondfire.helpbot.bot.events.CommandEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.*; 8 | 9 | public class QuoteStringArgument implements Argument { 10 | 11 | private static final String ERROR_MESSAGE = "Invalid quote, must start and end with `'` or `\"`."; 12 | 13 | @Override 14 | public String parseValue(@NotNull Deque args, CommandEvent event) throws ArgumentException { 15 | 16 | // Check if argument starts with quote 17 | if (!(args.element().startsWith("'") || args.peek().startsWith("\""))) { 18 | throw new MalformedArgumentException(ERROR_MESSAGE); 19 | } 20 | 21 | // Init variables 22 | List elements = new ArrayList<>(); 23 | String argument = args.poll(); 24 | elements.add(argument); 25 | 26 | // Repeat arguments until end is reached (exception) or an end quote is found 27 | while (!(argument.endsWith("'") || argument.endsWith("\""))) { 28 | argument = args.poll(); 29 | 30 | if (argument == null) { 31 | throw new MalformedArgumentException(ERROR_MESSAGE); 32 | } 33 | 34 | elements.add(argument); 35 | } 36 | 37 | // Join elements and remove quotes 38 | String result = String.join(" ", elements); 39 | return result.substring(1, result.length()-1); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/impl/SupporterClassTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks.impl; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.tasks.LoopingTask; 5 | import net.dv8tion.jda.api.entities.*; 6 | 7 | import java.util.List; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | public class SupporterClassTask implements LoopingTask { 11 | 12 | private static final long DISCORD_BOOSTER = 585528036070522894L; 13 | private static final long TWITCH_BOOSTER = 770098018510176256L; 14 | private static final long GENERAL_BOOST = 770103976506294303L; 15 | 16 | @Override 17 | public long getInitialStart() { 18 | return 0; 19 | } 20 | 21 | @Override 22 | public long getNextLoop() { 23 | return TimeUnit.HOURS.toMillis(1); 24 | } 25 | 26 | @Override 27 | public void run() { 28 | Guild guild = HelpBotInstance.getJda().getGuildById(HelpBotInstance.DF_GUILD); 29 | Role discord = guild.getRoleById(DISCORD_BOOSTER); 30 | Role twitch = guild.getRoleById(TWITCH_BOOSTER); 31 | Role generalBoost = guild.getRoleById(GENERAL_BOOST); 32 | 33 | guild.loadMembers((member) -> { 34 | List roles = member.getRoles(); 35 | if ((roles.contains(discord) || roles.contains(twitch)) && !roles.contains(generalBoost)) { 36 | guild.addRoleToMember(member, generalBoost).queue(); 37 | } else if (roles.contains(generalBoost) && !(roles.contains(discord) || roles.contains(twitch))) { 38 | guild.removeRoleFromMember(member, generalBoost).queue(); 39 | } 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SessionsCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.support; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 5 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 6 | 7 | import java.sql.ResultSet; 8 | import java.util.*; 9 | 10 | public class SessionsCommand extends AbstractSessionLogCommand { 11 | 12 | @Override 13 | public String getName() { 14 | return "sessions"; 15 | } 16 | 17 | @Override 18 | public HelpContext getHelpContext() { 19 | return new HelpContext() 20 | .description("Generates a file of all the sessions a support member has completed.") 21 | .category(CommandCategory.SUPPORT) 22 | .addArgument( 23 | new HelpContextArgument() 24 | .name("player|uuid") 25 | .optional() 26 | ); 27 | } 28 | 29 | @Override 30 | protected List getSessions(String player) { 31 | List sessions = new ArrayList<>(); 32 | new DatabaseQuery() 33 | .query(new BasicQuery("SELECT * FROM support_sessions WHERE staff = ? ORDER BY time", (statement) -> statement.setString(1, player))) 34 | .compile() 35 | .run((result) -> { 36 | for (ResultSet set : result) { 37 | sessions.add(new Session(set.getString("name"), set.getLong("duration"), set.getTimestamp("time"))); 38 | } 39 | }); 40 | return sessions; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/parsing/parser/MultiArgumentParser.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.parsing.parser; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.*; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 5 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MultiArgumentContainer; 6 | import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | 9 | import java.util.*; 10 | 11 | public class MultiArgumentParser extends ArgumentParser, A> { 12 | 13 | public MultiArgumentParser(MultiArgumentContainer container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public ParsedArgument parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException { 19 | Deque rawArgs = args.popStack(); 20 | List approvedArgumentValues = new ArrayList<>(); 21 | Argument arg = getContainer().getArgument(); 22 | int arguments = rawArgs.size(); 23 | 24 | for (int i = 0; i < arguments; i++) { 25 | try { 26 | approvedArgumentValues.add(arg.parseValue(rawArgs, event)); 27 | } catch (Exception e) { 28 | break; 29 | } 30 | } 31 | 32 | if (approvedArgumentValues.isEmpty()) { 33 | throw new MissingArgumentException("No valid arguments were provided."); 34 | } 35 | 36 | return new ParsedArgument<>(identifier, approvedArgumentValues); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/SupporteeSessionsCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.support; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 5 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 6 | 7 | import java.sql.ResultSet; 8 | import java.util.*; 9 | 10 | public class SupporteeSessionsCommand extends AbstractSessionLogCommand { 11 | 12 | @Override 13 | public String getName() { 14 | return "supporteesessions"; 15 | } 16 | 17 | @Override 18 | public HelpContext getHelpContext() { 19 | return new HelpContext() 20 | .description("Generates a file of all the sessions a supportee has completed.") 21 | .category(CommandCategory.SUPPORT) 22 | .addArgument( 23 | new HelpContextArgument() 24 | .name("player|uuid") 25 | .optional() 26 | ); 27 | } 28 | 29 | @Override 30 | protected List getSessions(String player) { 31 | List sessions = new ArrayList<>(); 32 | new DatabaseQuery() 33 | .query(new BasicQuery("SELECT * FROM support_sessions WHERE name = ? ORDER BY time", (statement) -> statement.setString(1, player))) 34 | .compile() 35 | .run((result) -> { 36 | for (ResultSet set : result) { 37 | sessions.add(new Session(set.getString("staff"), set.getLong("duration"), set.getTimestamp("time"))); 38 | } 39 | }); 40 | return sessions; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/RestartCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.dev; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.help.*; 5 | import com.diamondfire.helpbot.bot.command.impl.Command; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | import com.diamondfire.helpbot.bot.restart.RestartHandler; 9 | import net.dv8tion.jda.api.EmbedBuilder; 10 | 11 | public class RestartCommand extends Command { 12 | 13 | @Override 14 | public String getName() { 15 | return "restart"; 16 | } 17 | 18 | @Override 19 | public String[] getAliases() { 20 | return new String[]{"stop", "exit"}; 21 | } 22 | 23 | @Override 24 | public HelpContext getHelpContext() { 25 | return new HelpContext() 26 | .description("Restarts the bot.") 27 | .category(CommandCategory.OTHER); 28 | } 29 | 30 | @Override 31 | public ArgumentSet compileArguments() { 32 | return new ArgumentSet(); 33 | } 34 | 35 | @Override 36 | public Permission getPermission() { 37 | return Permission.BOT_DEVELOPER; 38 | } 39 | 40 | @Override 41 | public void run(CommandEvent event) { 42 | EmbedBuilder builder = new EmbedBuilder(); 43 | builder.setTitle("Restarting!"); 44 | builder.setDescription("This may take a moment"); 45 | 46 | event.getChannel().sendMessageEmbeds(builder.build()).queue((msg) -> { 47 | RestartHandler.logRestart(msg); 48 | System.exit(0); 49 | }); 50 | 51 | } 52 | 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/ChannelUpdatedNameEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.util.SolvedPostManager; 4 | import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; 5 | import net.dv8tion.jda.api.entities.channel.forums.ForumTag; 6 | import net.dv8tion.jda.api.events.channel.update.*; 7 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 8 | import org.jetbrains.annotations.*; 9 | 10 | import java.util.Optional; 11 | 12 | public class ChannelUpdatedNameEvent extends ListenerAdapter { 13 | 14 | @Override 15 | public void onChannelUpdateName(@NotNull ChannelUpdateNameEvent event) { 16 | Optional optionalChannel = SolvedPostManager.getHelpPost(event.getChannel()); 17 | if (optionalChannel.isEmpty()) { 18 | return; 19 | } 20 | ThreadChannel threadChannel = optionalChannel.get(); 21 | 22 | Optional optionalTag = SolvedPostManager.getSolvedTag(threadChannel); 23 | if (optionalTag.isEmpty() || event.getOldValue() == null || event.getNewValue() == null) { 24 | return; 25 | } 26 | ForumTag solvedTag = optionalTag.get(); 27 | 28 | if (event.getOldValue().startsWith("[SOLVED] ") && !event.getNewValue().startsWith("[SOLVED] ") && 29 | threadChannel.getAppliedTags().contains(solvedTag)) { 30 | 31 | SolvedPostManager.removeSolved(threadChannel); 32 | } 33 | else if (!event.getOldValue().startsWith("[SOLVED] ") && event.getNewValue().startsWith("[SOLVED] ") && 34 | !threadChannel.getAppliedTags().contains(solvedTag)) { 35 | 36 | SolvedPostManager.addSolved(threadChannel); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/database/impl/result/DatabaseResult.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.database.impl.result; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import java.sql.*; 6 | import java.util.Iterator; 7 | 8 | public class DatabaseResult implements Iterable { 9 | 10 | private final ResultSet set; 11 | 12 | public DatabaseResult(ResultSet set) { 13 | this.set = set; 14 | } 15 | 16 | public boolean isEmpty() { 17 | if (set == null) { 18 | return true; 19 | } 20 | 21 | try { 22 | if (!set.next()) { 23 | return true; 24 | } else { 25 | set.beforeFirst(); 26 | } 27 | } catch (SQLException ignored) { 28 | } 29 | 30 | return false; 31 | } 32 | 33 | public ResultSet getResult() { 34 | try { 35 | set.next(); 36 | } catch (SQLException ignored) { 37 | } 38 | 39 | return set; 40 | } 41 | 42 | @NotNull 43 | @Override 44 | public Iterator iterator() { 45 | ResultSet set = getResult(); 46 | try { 47 | set.beforeFirst(); 48 | } catch (SQLException e) { 49 | e.printStackTrace(); 50 | } 51 | return new Iterator<>() { 52 | @Override 53 | public boolean hasNext() { 54 | try { 55 | return set.next(); 56 | } catch (SQLException ignored) { 57 | return false; 58 | } 59 | } 60 | 61 | @Override 62 | public ResultSet next() { 63 | return set; 64 | } 65 | }; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/tasks/impl/VIPStarTask.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.tasks.impl; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.sys.tasks.LoopingTask; 5 | import com.diamondfire.helpbot.sys.vip.VIPRoleHandler; 6 | import net.dv8tion.jda.api.entities.Guild; 7 | import net.dv8tion.jda.api.entities.Member; 8 | import net.dv8tion.jda.api.entities.Role; 9 | 10 | import java.util.List; 11 | import java.util.Set; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public class VIPStarTask implements LoopingTask { 15 | 16 | @Override 17 | public long getInitialStart() { 18 | return 0; 19 | } 20 | 21 | @Override 22 | public long getNextLoop() { 23 | return TimeUnit.MINUTES.toMillis(30L); 24 | } 25 | 26 | @Override 27 | public void run() { 28 | Guild guild = HelpBotInstance.getJda().getGuildById(HelpBotInstance.DF_GUILD); 29 | Set vipIds = VIPRoleHandler.retrieveVIPs(); 30 | 31 | guild.loadMembers((member) -> { 32 | Role role = VIPRoleHandler.getRole(member.getColorRaw()); 33 | if (role == null) { 34 | return; 35 | } 36 | if (vipIds.contains(member.getIdLong()) && !member.getRoles().contains(role)) { 37 | guild.addRoleToMember(member, role) 38 | .reason("User has VIP Pass") 39 | .queue(); 40 | return; 41 | } 42 | if (!vipIds.contains(member.getIdLong()) && member.getRoles().contains(role)) { 43 | guild.removeRoleFromMember(member, role) 44 | .reason("User's VIP Pass has expired") 45 | .queue(); 46 | } 47 | }); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/restart/RestartHandler.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.restart; 2 | 3 | import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; 4 | import com.diamondfire.helpbot.util.FormatUtil; 5 | import net.dv8tion.jda.api.*; 6 | import net.dv8tion.jda.api.entities.Message; 7 | 8 | import java.io.*; 9 | import java.nio.file.Files; 10 | 11 | public class RestartHandler { 12 | 13 | public static void logRestart(Message restartMSG) { 14 | 15 | long msg = restartMSG.getIdLong(); 16 | long channel = restartMSG.getChannel().getIdLong(); 17 | 18 | try { 19 | File restart = ExternalFileUtil.generateFile("restart_cache"); 20 | try (FileWriter writer = new FileWriter(restart)) { 21 | writer.append(String.valueOf(msg)).append(":").append(String.valueOf(channel)).append(":").append(String.valueOf(System.currentTimeMillis())); 22 | } 23 | } catch (IOException ignored) { 24 | } 25 | 26 | } 27 | 28 | public static void recover(JDA jda) { 29 | try { 30 | File restart = ExternalFileUtil.getFile("restart_cache"); 31 | if (!restart.exists()) { 32 | return; 33 | } 34 | String[] restartMSG = Files.readAllLines(restart.toPath()).get(0).split(":"); 35 | EmbedBuilder builder = new EmbedBuilder(); 36 | builder.setTitle("Restart Successful!"); 37 | builder.setDescription("Restarted in " + FormatUtil.formatMilliTime(System.currentTimeMillis() - Long.parseLong(restartMSG[2]))); 38 | 39 | jda.getTextChannelById(restartMSG[1]).editMessageEmbedsById(restartMSG[0], builder.build()).setReplace(true).queue(); 40 | restart.delete(); 41 | } catch (IOException | ArrayIndexOutOfBoundsException ignored) { 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/TagProperty.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types.Enum; 2 | 3 | import com.diamondfire.helpbot.sys.tag.Tag; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.util.function.BiConsumer; 7 | 8 | public enum TagProperty implements EnumArgument.InputEnum { 9 | 10 | ACTIVATOR("activator", true, Tag::setActivator), 11 | TITLE("title", true, Tag::setTitle), 12 | RESPONSE("response", true, Tag::setResponse), 13 | AUTHOR_ID("authorId", false, (tag, newValue) -> { 14 | throw new UnsupportedOperationException(); 15 | }), 16 | IMAGE("image", true, Tag::setImage) 17 | ; 18 | 19 | private final String name; 20 | private final boolean modifiable; 21 | private final BiConsumer modifier; 22 | 23 | TagProperty(String name, boolean modifiable, BiConsumer modifier) { 24 | this.name = name; 25 | this.modifiable = modifiable; 26 | this.modifier = modifier; 27 | } 28 | 29 | public static @NotNull TagProperty of(String property) { 30 | for (TagProperty tagProperty : TagProperty.values()) { 31 | if (tagProperty.getName().equals(property)) { 32 | return tagProperty; 33 | } 34 | } 35 | 36 | throw new IllegalArgumentException(); 37 | } 38 | 39 | @Override 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | @Override 45 | public boolean isHidden() { 46 | return !isModifiable(); 47 | } 48 | 49 | public boolean isModifiable() { 50 | return modifiable; 51 | } 52 | 53 | public void set(Tag tag, String newValue) { 54 | getModifier().accept(tag, newValue); 55 | } 56 | 57 | public BiConsumer getModifier() { 58 | return modifier; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/events/ChannelCreatedEvent.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.events; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import net.dv8tion.jda.api.entities.channel.ChannelType; 5 | import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; 6 | import net.dv8tion.jda.api.entities.channel.forums.ForumTag; 7 | import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; 8 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 9 | 10 | import java.util.ArrayList; 11 | 12 | public class ChannelCreatedEvent extends ListenerAdapter { 13 | 14 | @Override 15 | public void onChannelCreate(ChannelCreateEvent event) { 16 | // Limit to help forum. 17 | if ( 18 | event.getChannel().getType() != ChannelType.GUILD_PUBLIC_THREAD || 19 | event.getChannel().asThreadChannel().getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel() 20 | ) { 21 | return; 22 | } 23 | 24 | // Remove solved tag if post was created with it. 25 | ThreadChannel threadChannel = event.getChannel().asThreadChannel(); 26 | 27 | ForumTag solvedTag = threadChannel.getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag()); 28 | if (threadChannel.getAppliedTags().contains(solvedTag)) { 29 | ArrayList appliedTags = new ArrayList<>(threadChannel.getAppliedTags()); 30 | // Solved tag is the only tag, and we need at least one tag. 31 | // In this case, this will do nothing, however ?solved will still change post's the name, so it's fine. 32 | if (appliedTags.size() != 1) { 33 | appliedTags.remove(solvedTag); 34 | } 35 | threadChannel.getManager().setAppliedTags(appliedTags).queue(); 36 | } 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/PlainComponentSerializer.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util; 2 | 3 | import net.kyori.adventure.text.*; 4 | import net.kyori.adventure.text.serializer.ComponentSerializer; 5 | 6 | import java.util.function.Function; 7 | 8 | public class PlainComponentSerializer implements ComponentSerializer { 9 | 10 | /** 11 | * A component serializer for plain-based serialization and deserialization. 12 | */ 13 | public static final PlainComponentSerializer INSTANCE = new PlainComponentSerializer(); 14 | private final Function translatable; 15 | 16 | public PlainComponentSerializer() { 17 | this(component -> ""); 18 | } 19 | 20 | public PlainComponentSerializer(final Function translatable) { 21 | this.translatable = translatable; 22 | } 23 | 24 | @Override 25 | public TextComponent deserialize(final String input) { 26 | return Component.text(input); 27 | } 28 | 29 | @Override 30 | public String serialize(final Component component) { 31 | final StringBuilder sb = new StringBuilder(); 32 | this.serialize(sb, component); 33 | return sb.toString(); 34 | } 35 | 36 | public void serialize(final StringBuilder sb, final Component component) { 37 | if (component instanceof TextComponent) { 38 | sb.append(((TextComponent) component).content()); 39 | } else if (component instanceof TranslatableComponent) { 40 | sb.append(this.translatable.apply((TranslatableComponent) component)); 41 | } else { 42 | throw new IllegalArgumentException("Don't know how to turn " + component + " into a string"); 43 | } 44 | 45 | for (final Component child : component.children()) { 46 | this.serialize(sb, child); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/database/impl/queries/BasicQuery.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.database.impl.queries; 2 | 3 | import com.mysql.jdbc.StatementImpl; 4 | import org.intellij.lang.annotations.Language; 5 | import org.jetbrains.annotations.*; 6 | 7 | import java.sql.*; 8 | 9 | public class BasicQuery implements QueryResultProvider { 10 | 11 | private final String query; 12 | private final PreparedStatementProvider provider; 13 | 14 | public BasicQuery(@NotNull @Language("SQL") String query) { 15 | this.query = query; 16 | this.provider = null; 17 | } 18 | 19 | public BasicQuery(@NotNull @Language("SQL") String query, @Nullable PreparedStatementProvider provider) { 20 | this.query = query; 21 | this.provider = provider; 22 | } 23 | 24 | @Override 25 | public ResultSet execute(@NotNull Connection connection) throws SQLException { 26 | PreparedStatement statement = connection.prepareStatement(query); 27 | statement.setQueryTimeout(10); 28 | 29 | if (provider != null) { 30 | provider.prepare(statement); 31 | } 32 | 33 | if (statement.execute()) { 34 | ResultSet set = statement.getResultSet(); 35 | try { 36 | // Close prepared statement but not the resultsets. Very weird I have to do this... 37 | StatementImpl.class.getDeclaredMethod("realClose", boolean.class, boolean.class).invoke(statement, true, false); 38 | } catch (Exception ignored) { 39 | } 40 | 41 | return set; 42 | } else { 43 | statement.close(); 44 | connection.close(); 45 | return null; 46 | } 47 | } 48 | 49 | public interface PreparedStatementProvider { 50 | 51 | void prepare(@NotNull PreparedStatement statement) throws SQLException; 52 | 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/SearchCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.codeblock; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; 7 | 8 | import java.util.*; 9 | 10 | 11 | public class SearchCommand extends AbstractMultiQueryCommand { 12 | 13 | @Override 14 | public String getName() { 15 | return "search"; 16 | } 17 | 18 | @Override 19 | public String[] getAliases() { 20 | return new String[]{"find"}; 21 | } 22 | 23 | @Override 24 | public HelpContext getHelpContext() { 25 | return new HelpContext() 26 | .description("Tries to find a list of possible actions/game values based on the given arguments.") 27 | .category(CommandCategory.CODE_BLOCK) 28 | .addArgument( 29 | new HelpContextArgument() 30 | .name("name") 31 | ); 32 | } 33 | 34 | @Override 35 | public Permission getPermission() { 36 | return Permission.USER; 37 | } 38 | 39 | @Override 40 | protected List filterData(List data, CommandEvent event) { 41 | ArrayList list = new ArrayList<>(); 42 | String args = event.getArgument("name"); 43 | args = args.toLowerCase(); 44 | 45 | for (CodeObject simpleData : data) { 46 | String dataName = simpleData.getName(); 47 | String itemName = simpleData.getItem().getItemName(); 48 | 49 | if (itemName.toLowerCase().contains(args) || dataName.toLowerCase().contains(args)) { 50 | list.add(dataName); 51 | } 52 | 53 | } 54 | return list; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/graph/generators/QueryGraphGenerator.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.graph.generators; 2 | 3 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 4 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 5 | import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; 6 | import com.diamondfire.helpbot.sys.graph.graphable.*; 7 | import com.diamondfire.helpbot.sys.graph.impl.ChartGraphBuilder; 8 | import org.intellij.lang.annotations.Language; 9 | 10 | import java.io.File; 11 | import java.sql.ResultSet; 12 | import java.util.*; 13 | 14 | public class QueryGraphGenerator implements GraphGenerator { 15 | 16 | private final String title; 17 | @Language("SQL") 18 | private final String query; 19 | 20 | public QueryGraphGenerator(String title, @Language("SQL") String query) { 21 | this.title = title; 22 | this.query = query; 23 | } 24 | 25 | @Override 26 | public File createGraph(TimeGraphContext context) { 27 | Map, Integer> entries = new LinkedHashMap<>(); 28 | ChartGraphBuilder builder = new ChartGraphBuilder(); 29 | TimeMode timeMode = context.getMode(); 30 | 31 | new DatabaseQuery() 32 | .query(new BasicQuery(query, statement -> { 33 | statement.setString(1, timeMode.getDateFormat()); 34 | statement.setInt(2, timeMode.getUnitConversion().apply(context.getNum())); 35 | })) 36 | .compile() 37 | .run((result) -> { 38 | for (ResultSet set : result) { 39 | entries.put(new StringEntry(set.getString("time")), set.getInt("count")); 40 | } 41 | 42 | builder.setGraphName(timeMode.getMode() + " " + title); 43 | }); 44 | 45 | return builder.createGraph(entries); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.codeinfo.viewables.constants; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import net.dv8tion.jda.api.entities.emoji.*; 5 | 6 | import java.awt.*; 7 | import java.util.Map; 8 | import java.util.stream.*; 9 | 10 | public enum CodeBlockEnum { 11 | PLAYER_EVENT("event", "3DE0E5"), 12 | ENTITY_EVENT("entity_event", "F5CC28"), 13 | FUNCTION("func", "1C3890"), 14 | PROCESS("process", "16DD61"), 15 | // Conditionals 16 | IF_PLAYER("if_player", "AF8F55"), 17 | IF_ENTITY("if_entity", "9A5643"), 18 | IF_GAME("if_game", "440507"), 19 | IF_VARIABLE("if_var", "261E3D"), 20 | ELSE("else", "D5DA94"), 21 | // Game Manipulators 22 | PLAYER_ACTION("player_action", "616161"), 23 | ENTITY_ACTION("entity_action", "728552"), 24 | GAME_ACTION("game_action", "511515"), 25 | // Code Manipulators 26 | SELECT_OBJECT("select_obj", "A472A2"), 27 | SET_VARIABLE("set_var", "E0E0E0"), 28 | CONTROL("control", "151515"), 29 | REPEAT("repeat", "5EA496"), 30 | // Line Starters 31 | CALL_FUNC("call_func", "1C3890"), 32 | START_PROCESS("start_process", "16DD61"); 33 | 34 | private static final Map identifiers = Stream.of(CodeBlockEnum.values()).collect(Collectors.toMap(CodeBlockEnum::getID, p -> p)); 35 | private final String ID; 36 | private final String color; 37 | 38 | CodeBlockEnum(String ID, String color) { 39 | this.ID = ID; 40 | this.color = color; 41 | } 42 | 43 | public static CodeBlockEnum getFromID(String id) { 44 | return identifiers.getOrDefault(id, CodeBlockEnum.CONTROL); 45 | } 46 | 47 | public Color getColor() { 48 | return Color.decode("#" + color); 49 | } 50 | 51 | public String getID() { 52 | return ID; 53 | } 54 | 55 | 56 | public CustomEmoji getEmoji() { 57 | return HelpBotInstance.getJda().getEmojisByName(getID(), true).get(0); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.util; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.impl.Command; 5 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 6 | import com.diamondfire.helpbot.bot.events.CommandEvent; 7 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; 8 | import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; 9 | import net.dv8tion.jda.api.EmbedBuilder; 10 | import net.dv8tion.jda.api.utils.FileUpload; 11 | 12 | import java.io.*; 13 | import java.util.*; 14 | 15 | public abstract class AbstractFileListCommand extends Command { 16 | 17 | @Override 18 | public ArgumentSet compileArguments() { 19 | return new ArgumentSet(); 20 | } 21 | 22 | @Override 23 | public Permission getPermission() { 24 | return Permission.USER; 25 | } 26 | 27 | protected void generate(CommandEvent event, List data) { 28 | File file; 29 | try { 30 | file = ExternalFileUtil.generateFile(data.get(0).getEnum().getName().toLowerCase().replace(" ", "-") + "-list.txt"); 31 | try (BufferedWriter writer = new BufferedWriter(new FileWriter(file.getPath(), true))) { 32 | List names = new ArrayList<>(); 33 | for (CodeObject item : data) { 34 | names.add(item.getItem().getItemName()); 35 | } 36 | 37 | writer.append(String.join("|", names)); 38 | } 39 | 40 | } catch (IOException e) { 41 | EmbedBuilder builder = new EmbedBuilder(); 42 | builder.setTitle("Could not generate file!"); 43 | event.getChannel().sendMessageEmbeds(builder.build()).queue(); 44 | return; 45 | } 46 | 47 | event.getChannel().sendMessage("File Generated").addFiles(FileUpload.fromData(file)).queue(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/Enum/EnumArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types.Enum; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.EnumSet; 9 | import java.util.stream.Collectors; 10 | 11 | public class EnumArgument & EnumArgument.InputEnum> extends AbstractSimpleValueArgument { 12 | 13 | private EnumSet associatedEnum; 14 | 15 | public EnumArgument setEnum(Class anEnum) { 16 | associatedEnum = EnumSet.allOf(anEnum); 17 | return this; 18 | } 19 | 20 | @Override 21 | protected E parse(@NotNull String argument, CommandEvent event) throws ArgumentException { 22 | for (E enumValue : associatedEnum) { 23 | if (argument.equals(enumValue.getName())) { 24 | return enumValue; 25 | } 26 | } 27 | 28 | throw new MalformedArgumentException("This is not a valid option! Choose from: " + getFormattedOptions()); 29 | } 30 | 31 | private String getFormattedOptions() { 32 | return getFormattedOptions(associatedEnum); 33 | } 34 | 35 | public static & InputEnum> String getFormattedOptions(@NotNull Class anEnum) { 36 | return getFormattedOptions(EnumSet.allOf(anEnum)); 37 | } 38 | 39 | public static String getFormattedOptions(@NotNull EnumSet anEnum) { 40 | return "`" + 41 | anEnum.stream() 42 | .filter(e -> !e.isHidden()) 43 | .map(InputEnum::getName) 44 | .collect(Collectors.joining("` `")) 45 | + "`"; 46 | } 47 | 48 | protected interface InputEnum { 49 | 50 | String getName(); 51 | 52 | boolean isHidden(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.metrics; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.help.*; 5 | import com.diamondfire.helpbot.bot.command.impl.Command; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.events.CommandEvent; 8 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 9 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 10 | import com.diamondfire.helpbot.util.FormatUtil; 11 | import net.dv8tion.jda.api.EmbedBuilder; 12 | 13 | public class JoinsCommand extends Command { 14 | 15 | @Override 16 | public String getName() { return "joins"; } 17 | 18 | @Override 19 | public HelpContext getHelpContext() { 20 | return new HelpContext() 21 | .description("Shows the total amount of unique players that have joined DiamondFire before.") 22 | .category(CommandCategory.GENERAL_STATS); 23 | } 24 | 25 | @Override 26 | public ArgumentSet compileArguments() { return new ArgumentSet(); } 27 | 28 | @Override 29 | public Permission getPermission() { return Permission.USER; } 30 | 31 | @Override 32 | public void run(CommandEvent event) { 33 | EmbedBuilder builder = new EmbedBuilder(); 34 | 35 | builder.setTitle("Total Joins"); 36 | 37 | // gets the total amount of players that have joined before 38 | new DatabaseQuery() 39 | .query(new BasicQuery("SELECT COUNT(uuid) AS count FROM ranks")) 40 | .compile() 41 | .run((result) -> { 42 | String count = FormatUtil.formatNumber(result.getResult().getInt("count")); 43 | builder.setDescription(String.format("A total of %s players have joined DiamondFire before!", count)); 44 | }); 45 | 46 | event.getChannel().sendMessageEmbeds(builder.build()).queue(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/argument/impl/types/minecraft/DFPlayerArgument.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*; 4 | import com.diamondfire.helpbot.bot.command.argument.impl.types.AbstractSimpleValueArgument; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; 7 | import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; 8 | import com.diamondfire.helpbot.sys.database.impl.result.DatabaseResult; 9 | import org.jetbrains.annotations.*; 10 | 11 | import java.sql.ResultSet; 12 | import java.util.UUID; 13 | 14 | public class DFPlayerArgument extends AbstractSimpleValueArgument { 15 | 16 | public static @Nullable Player fetchPlayer(String argument) { 17 | DatabaseResult result = new DatabaseQuery() 18 | .query(new BasicQuery("SELECT * FROM players WHERE players.name = ? OR players.uuid = ? LIMIT 1;", (statement) -> { 19 | statement.setString(1, argument); 20 | statement.setString(2, argument); 21 | })) 22 | .compile() 23 | .get(); 24 | 25 | if (result.isEmpty()) { 26 | return null; 27 | } 28 | 29 | try { 30 | ResultSet set = result.getResult(); 31 | 32 | UUID uuid = UUID.fromString(set.getString("uuid")); 33 | String playerName = set.getString("name"); 34 | 35 | return new Player(playerName, uuid); 36 | } catch (Exception e) { 37 | throw new RuntimeException(e); 38 | } 39 | } 40 | 41 | @Override 42 | protected Player parse(@NotNull String argument, CommandEvent event) throws ArgumentException { 43 | Player player = fetchPlayer(argument); 44 | if (player == null) { 45 | throw new MalformedArgumentException("Player has not joined DiamondFire before, or does not exist."); 46 | } 47 | 48 | return player; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/disable/DisableCommandHandler.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.disable; 2 | 3 | import com.diamondfire.helpbot.bot.command.CommandHandler; 4 | import com.diamondfire.helpbot.bot.command.impl.Command; 5 | import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; 6 | 7 | import java.io.*; 8 | import java.nio.file.*; 9 | import java.util.*; 10 | 11 | public class DisableCommandHandler { 12 | 13 | private final List disabledCommands = new ArrayList<>(); 14 | private static final File FILE = ExternalFiles.DISABLED_COMMANDS; 15 | 16 | public boolean isDisabled(Command command) { 17 | return disabledCommands.contains(command.getName()); 18 | } 19 | 20 | public void initialize() { 21 | try { 22 | List lines = Files.readAllLines(FILE.toPath()); 23 | for (String cmd : lines) { 24 | disable(CommandHandler.getCommand(cmd)); 25 | } 26 | 27 | } catch (IOException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | 32 | public void save() { 33 | String string = String.join("\n", disabledCommands); 34 | try { 35 | FILE.delete(); 36 | FILE.createNewFile(); 37 | Files.write(FILE.toPath(), string.getBytes(), StandardOpenOption.WRITE); 38 | 39 | } catch (IOException e) { 40 | e.printStackTrace(); 41 | } 42 | 43 | } 44 | 45 | public void enable(Command command) { 46 | disabledCommands.remove(command.getName()); 47 | save(); 48 | } 49 | 50 | public void disable(Command command) { 51 | if (command == null) { 52 | return; 53 | } 54 | // Prevents tricky people using eval. 55 | if (command instanceof CommandDisableFlag) { 56 | return; 57 | } 58 | 59 | disabledCommands.add(command.getName()); 60 | save(); 61 | } 62 | 63 | 64 | public List getDisabledCommands() { 65 | return disabledCommands; 66 | } 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelectorBuilder.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.multiselector; 2 | 3 | import net.dv8tion.jda.api.EmbedBuilder; 4 | import org.jetbrains.annotations.Contract; 5 | 6 | import java.util.*; 7 | 8 | public class MultiSelectorBuilder { 9 | 10 | private final ArrayList pages = new ArrayList<>(10); 11 | private long channel; 12 | private long userID; 13 | 14 | @Contract("_, -> this") 15 | public MultiSelectorBuilder setUser(long userID) { 16 | this.userID = userID; 17 | return this; 18 | } 19 | 20 | @Contract("_, -> this") 21 | public MultiSelectorBuilder setChannel(long channel) { 22 | this.channel = channel; 23 | return this; 24 | } 25 | 26 | @Contract("_,_, -> this") 27 | public MultiSelectorBuilder addPage(String name, EmbedBuilder EmbedBuilder) { 28 | pages.add(new MultiSelectorPage(name, EmbedBuilder)); 29 | return this; 30 | } 31 | 32 | @Contract("_,_,_ -> this") 33 | public MultiSelectorBuilder addPage(String name, EmbedBuilder EmbedBuilder, String customEmote) { 34 | pages.add(new MultiSelectorPage(name, EmbedBuilder, customEmote, false)); 35 | return this; 36 | } 37 | 38 | @Contract("_,_,_, -> this") 39 | public MultiSelectorBuilder addPage(String name, EmbedBuilder EmbedBuilder, boolean hidden) { 40 | pages.add(new MultiSelectorPage(name, EmbedBuilder, hidden)); 41 | return this; 42 | } 43 | 44 | @Contract("_,_,_,_, -> this") 45 | public MultiSelectorBuilder addPage(String name, EmbedBuilder EmbedBuilder, String customEmote, boolean hidden) { 46 | pages.add(new MultiSelectorPage(name, EmbedBuilder, customEmote, hidden)); 47 | return this; 48 | } 49 | 50 | @Contract("-> this") 51 | public MultiSelectorBuilder orderPages() { 52 | pages.sort(Comparator.comparing(MultiSelectorPage::getName)); 53 | return this; 54 | } 55 | 56 | public MultiSelector build() { 57 | return new MultiSelector(channel, userID, pages); 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.reply; 2 | 3 | import net.dv8tion.jda.api.EmbedBuilder; 4 | import net.dv8tion.jda.api.entities.*; 5 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; 6 | import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; 7 | import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; 8 | import net.dv8tion.jda.api.requests.RestAction; 9 | import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; 10 | import net.dv8tion.jda.api.utils.messages.MessageRequest; 11 | 12 | public class ReplyHandler { 13 | 14 | private final GuildMessageChannel channel; 15 | 16 | public ReplyHandler(GuildMessageChannel channel) { 17 | this.channel = channel; 18 | } 19 | 20 | public GuildMessageChannel getChannel() { 21 | return channel; 22 | } 23 | 24 | public void reply(String content) { 25 | textReply(content, getChannel()).queue(); 26 | } 27 | 28 | public void reply(PresetBuilder preset) { 29 | reply(preset, getChannel()); 30 | } 31 | 32 | public void reply(PresetBuilder preset, MessageChannel channel) { 33 | reply(preset.getEmbed(), channel); 34 | } 35 | 36 | public void reply(EmbedBuilder builder) { 37 | embedReply(builder, getChannel()).queue(); 38 | } 39 | 40 | public void reply(EmbedBuilder builder, MessageChannel channel) { 41 | embedReply(builder, channel).queue(); 42 | } 43 | 44 | public MessageCreateAction replyA(PresetBuilder preset) { 45 | return replyA(preset, getChannel()); 46 | } 47 | 48 | public MessageCreateAction replyA(PresetBuilder preset, MessageChannel channel) { 49 | return embedReply(preset.getEmbed(), channel); 50 | } 51 | 52 | public MessageCreateAction embedReply(EmbedBuilder embed, MessageChannel channel) { 53 | return channel.sendMessageEmbeds(embed.build()); 54 | } 55 | 56 | public MessageCreateAction textReply(String msg, MessageChannel channel) { 57 | return channel.sendMessage(msg); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/util/nbs/SongData.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.util.nbs; 2 | // from https://github.com/CodeUtilities/CodeUtilities 3 | public class SongData { 4 | 5 | String name; 6 | String author; 7 | float speed; 8 | int length; 9 | String fileName; 10 | String notes; 11 | String layers; 12 | int loopTick; 13 | int loopCount; 14 | int customInstrumentCount; 15 | 16 | public SongData(String name, String author, float speed, int length, String notes, String fileName, String layers, int loopTick, int loopCount, int customInstrumentCount) { 17 | this.name = name; 18 | this.author = author; 19 | this.speed = speed; 20 | this.length = length; 21 | this.notes = notes; 22 | this.fileName = fileName; 23 | this.layers = layers; 24 | this.loopTick = loopTick; 25 | this.loopCount = loopCount; 26 | this.customInstrumentCount = customInstrumentCount; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getAuthor() { 38 | return author; 39 | } 40 | 41 | public void setAuthor(String author) { 42 | this.author = author; 43 | } 44 | 45 | public float getSpeed() { 46 | return speed; 47 | } 48 | 49 | public void setSpeed(float speed) { 50 | this.speed = speed; 51 | } 52 | 53 | public int getLength() { 54 | return length; 55 | } 56 | 57 | public String getNotes() { 58 | return notes; 59 | } 60 | 61 | public void setNotes(String notes) { 62 | this.notes = notes; 63 | } 64 | 65 | public String getFileName() { 66 | return fileName; 67 | } 68 | 69 | public void setFileName(String fileName) { 70 | this.fileName = fileName; 71 | } 72 | 73 | public String getLayers() { 74 | return layers; 75 | } 76 | 77 | public int getLoopTick() { 78 | return loopTick; 79 | } 80 | 81 | public int getLoopCount() { 82 | return loopCount; 83 | } 84 | 85 | public int getCustomInstrumentCount() { 86 | return customInstrumentCount; 87 | } 88 | } -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.codeblock; 2 | 3 | import com.diamondfire.helpbot.bot.command.help.*; 4 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 5 | import com.diamondfire.helpbot.bot.events.CommandEvent; 6 | import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; 7 | import com.diamondfire.helpbot.util.StringUtil; 8 | import com.google.gson.*; 9 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; 10 | import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; 11 | 12 | import java.util.function.BiConsumer; 13 | 14 | 15 | public class RawCommand extends AbstractSingleQueryCommand { 16 | 17 | private static void sendRawMessage(CodeObject data, GuildMessageChannel channel) { 18 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); 19 | String json = gson.toJson(data.getJson()); 20 | 21 | for (String part : StringUtil.splitBy(json, 1950)) { 22 | channel.sendMessage(String.format("```%s```", part)).queue(); 23 | } 24 | 25 | } 26 | 27 | @Override 28 | public String getName() { 29 | return "rawcode"; 30 | } 31 | 32 | @Override 33 | public String[] getAliases() { 34 | return new String[]{"coderaw"}; 35 | } 36 | 37 | @Override 38 | public HelpContext getHelpContext() { 39 | return new HelpContext() 40 | .description("Gets raw data of a codeblock/action/game value. (Anything within simpledata class)") 41 | .category(CommandCategory.CODE_BLOCK) 42 | .addArgument( 43 | new HelpContextArgument() 44 | .name("codeblock|action|game value") 45 | ); 46 | } 47 | 48 | @Override 49 | public Permission getPermission() { 50 | return Permission.BOT_DEVELOPER; 51 | } 52 | 53 | @Override 54 | public void run(CommandEvent event) { 55 | super.run(event); 56 | } 57 | 58 | @Override 59 | public BiConsumer onDataReceived() { 60 | return RawCommand::sendRawMessage; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/SkinCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats.individualized; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.impl.types.minecraft.Player; 4 | import com.diamondfire.helpbot.bot.command.help.*; 5 | import com.diamondfire.helpbot.bot.command.impl.stats.AbstractPlayerUUIDCommand; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 8 | import com.diamondfire.helpbot.bot.command.reply.feature.MinecraftUserPreset; 9 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 10 | import com.diamondfire.helpbot.bot.events.CommandEvent; 11 | import net.dv8tion.jda.api.EmbedBuilder; 12 | 13 | 14 | public class SkinCommand extends AbstractPlayerUUIDCommand { 15 | 16 | @Override 17 | public String getName() { 18 | return "skin"; 19 | } 20 | 21 | @Override 22 | public HelpContext getHelpContext() { 23 | return new HelpContext() 24 | .description("Gets a user's player skin.") 25 | .category(CommandCategory.PLAYER_STATS) 26 | .addArgument( 27 | new HelpContextArgument() 28 | .name("player|uuid") 29 | .optional() 30 | ); 31 | } 32 | 33 | @Override 34 | public Permission getPermission() { 35 | return Permission.USER; 36 | } 37 | 38 | @Override 39 | protected void execute(CommandEvent event, Player player) { 40 | PresetBuilder preset = new PresetBuilder() 41 | .withPreset( 42 | new InformativeReply(InformativeReplyType.INFO, String.format("%s's Skin", player.name()), null), 43 | new MinecraftUserPreset(player) 44 | ); 45 | 46 | //Discord didn't want to preview the skin, why? I don't know.. 47 | EmbedBuilder embed = preset.getEmbed(); 48 | embed.setImage("https://external-content.duckduckgo.com/iu/?reload=" + System.currentTimeMillis() + "&u=" + "https://mc-heads.net/body/" + player.name() + "/180"); 49 | event.reply(preset); 50 | } 51 | 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/permissions/Permission.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.permissions; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.command.impl.Command; 5 | import net.dv8tion.jda.api.entities.Member; 6 | 7 | import java.util.*; 8 | import java.util.stream.Collectors; 9 | 10 | public enum Permission { 11 | DEVELOPER(999), 12 | BOT_DEVELOPER(998), 13 | // Ask DragonSlasher, not me. 14 | ADMINISTRATOR(666), 15 | MODERATION(5), 16 | SR_HELPER(4), 17 | SUPPORT(3), 18 | RETIRED_SUPPORT(2), 19 | USER(1); 20 | 21 | private static final HashMap roleMap = new HashMap<>(); 22 | private static final HashMap> overrides = new HashMap<>(); 23 | 24 | static { 25 | for (Permission perm : values()) { 26 | roleMap.put(perm.getRole(), perm); 27 | } 28 | } 29 | 30 | private final long role; 31 | private final int permissionLevel; 32 | 33 | Permission(int permissionLevel) { 34 | this.role = HelpBotInstance.getConfig().getPermissionRoleMap().get(this.name()); 35 | this.permissionLevel = permissionLevel; 36 | } 37 | 38 | public static Permission fromRole(long roleID) { 39 | Permission perm = roleMap.get(roleID); 40 | if (perm == null) { 41 | return USER; 42 | } 43 | return perm; 44 | } 45 | 46 | public Permission setOverrides(Command command, Long... userIds) { 47 | overrides.put(command, Arrays.stream(userIds).collect(Collectors.toSet())); 48 | return this; 49 | } 50 | 51 | public static Set getOverrides(Command command) { 52 | return Objects.requireNonNullElse(overrides.get(command), new HashSet<>()); 53 | } 54 | 55 | public long getRole() { 56 | return role; 57 | } 58 | 59 | public int getPermissionLevel() { 60 | return permissionLevel; 61 | } 62 | 63 | public boolean hasPermission(Member member) { 64 | return hasPermission(PermissionHandler.getPermission(member)); 65 | } 66 | 67 | public boolean hasPermission(Permission permission) { 68 | return getPermissionLevel() <= permission.getPermissionLevel(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/CpRequirementsCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.stats; 2 | 3 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 4 | import com.diamondfire.helpbot.bot.command.help.*; 5 | import com.diamondfire.helpbot.bot.command.impl.Command; 6 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 7 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 8 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 9 | import com.diamondfire.helpbot.bot.events.CommandEvent; 10 | import com.diamondfire.helpbot.df.creator.CreatorLevel; 11 | import com.diamondfire.helpbot.util.FormatUtil; 12 | import net.dv8tion.jda.api.EmbedBuilder; 13 | 14 | 15 | public class CpRequirementsCommand extends Command { 16 | 17 | @Override 18 | public String getName() { 19 | return "cprequirements"; 20 | } 21 | 22 | @Override 23 | public String[] getAliases() { 24 | return new String[]{"cpreq", "cpneeded", "creatorreq"}; 25 | } 26 | 27 | @Override 28 | public HelpContext getHelpContext() { 29 | return new HelpContext() 30 | .description("Gets the current CP level requirements.") 31 | .category(CommandCategory.GENERAL_STATS); 32 | } 33 | 34 | @Override 35 | public ArgumentSet compileArguments() { 36 | return new ArgumentSet(); 37 | } 38 | 39 | @Override 40 | public Permission getPermission() { 41 | return Permission.USER; 42 | } 43 | 44 | @Override 45 | public void run(CommandEvent event) { 46 | PresetBuilder preset = new PresetBuilder() 47 | .withPreset( 48 | new InformativeReply(InformativeReplyType.INFO, "CP Requirements", null) 49 | ); 50 | EmbedBuilder embed = preset.getEmbed(); 51 | embed.setFooter("*Level requirement is based on a top % of players."); 52 | for (CreatorLevel level : CreatorLevel.values()) { 53 | embed.addField(level.display(), "CP Required: " + FormatUtil.formatNumber(level.getRequirementProvider().getRequirement()), true); 54 | } 55 | 56 | // Even it out 57 | embed.addBlankField(true); 58 | event.reply(preset); 59 | } 60 | 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/bot/command/impl/other/tag/ListTagsSubCommand.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.bot.command.impl.other.tag; 2 | 3 | import com.diamondfire.helpbot.bot.HelpBotInstance; 4 | import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; 5 | import com.diamondfire.helpbot.bot.command.help.HelpContext; 6 | import com.diamondfire.helpbot.bot.command.impl.SubCommand; 7 | import com.diamondfire.helpbot.bot.command.permissions.Permission; 8 | import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; 9 | import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; 10 | import com.diamondfire.helpbot.bot.events.CommandEvent; 11 | import com.diamondfire.helpbot.sys.tag.*; 12 | 13 | import java.io.IOException; 14 | import java.util.*; 15 | import java.util.stream.Collectors; 16 | 17 | public class ListTagsSubCommand extends SubCommand { 18 | 19 | @Override 20 | public String getName() { 21 | return "list"; 22 | } 23 | 24 | @Override 25 | public HelpContext getHelpContext() { 26 | return new HelpContext(); 27 | } 28 | 29 | @Override 30 | protected ArgumentSet compileArguments() { 31 | return new ArgumentSet(); 32 | } 33 | 34 | @Override 35 | public Permission getPermission() { 36 | return Permission.USER; 37 | } 38 | 39 | @Override 40 | public void run(CommandEvent event) { 41 | String formattedTags = TagHandler.getTags().stream() 42 | .map(tag -> String.format("`%s`", tag.getActivator())) 43 | .collect(Collectors.joining(" ")); 44 | 45 | if (formattedTags.isEmpty()) { 46 | formattedTags = "*None*"; 47 | } 48 | 49 | event.reply(new PresetBuilder() 50 | .withPreset( 51 | new InformativeReply(InformativeReplyType.INFO, "Tags", 52 | String.format(""" 53 | A list of all custom command tags added. 54 | You can execute a tag using `%s`. 55 | 56 | %s""", 57 | HelpBotInstance.getConfig().getPrefix(), formattedTags)) 58 | )); 59 | 60 | } 61 | 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/df/creator/CreatorLevel.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.df.creator; 2 | 3 | import com.diamondfire.helpbot.df.creator.requirements.*; 4 | 5 | public enum CreatorLevel { 6 | SPARK("Spark", 734808957545349221L, new StaticRequirementProvider(0)), 7 | EMBER("Ember", 734808957738287114L, new StaticRequirementProvider(200)), 8 | BLAZE("Blaze", 734808957243097110L, new StaticRequirementProvider(1000)), 9 | INFERNO("Inferno", 734808957536960512L, new StaticRequirementProvider(3000)), 10 | QUARTZ("Quartz", 734808957604069416L, new StaticRequirementProvider(5000)), 11 | JADE("Jade", 734808957302079580L, new DynamicRequirementProvider("jade")), 12 | RUBY("Ruby", 734808957289496667L, new DynamicRequirementProvider("ruby")), 13 | DIAMOND("Diamond", 734808957490823228L, new DynamicRequirementProvider("diamond")); 14 | 15 | private final String name; 16 | private final long emoji; 17 | private final RequirementProvider requirementProvider; 18 | 19 | CreatorLevel(String name, long emoji, RequirementProvider requirementProvider) { 20 | this.name = name; 21 | this.emoji = emoji; 22 | this.requirementProvider = requirementProvider; 23 | } 24 | 25 | public static CreatorLevel getLevel(int level) { 26 | return values()[level]; 27 | } 28 | 29 | public static CreatorLevel getNextLevel(CreatorLevel level) { 30 | if (level == DIAMOND) return DIAMOND; 31 | 32 | CreatorLevel[] levels = values(); 33 | for (int i = 0; i < levels.length; i++) { 34 | if (levels[i] == level) { 35 | return levels[++i]; 36 | } 37 | } 38 | 39 | return null; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public RequirementProvider getRequirementProvider() { 47 | return requirementProvider; 48 | } 49 | 50 | public long getEmoji() { 51 | return emoji; 52 | } 53 | 54 | public String display() { 55 | return display(false); 56 | } 57 | 58 | public String display(boolean hideStar) { 59 | return String.format("<:%s:%s>", getName().toLowerCase(), getEmoji()) + " " + getName() + (requirementProvider instanceof DynamicRequirementProvider && !hideStar ? "*" : ""); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java: -------------------------------------------------------------------------------- 1 | package com.diamondfire.helpbot.sys.multiselector; 2 | 3 | import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler; 4 | import com.diamondfire.helpbot.util.Util; 5 | import net.dv8tion.jda.api.*; 6 | import net.dv8tion.jda.api.components.actionrow.ActionRow; 7 | import net.dv8tion.jda.api.components.buttons.Button; 8 | import net.dv8tion.jda.api.entities.emoji.Emoji; 9 | 10 | import java.util.*; 11 | 12 | public class MultiSelector { 13 | 14 | private final MultiSelectorPage[] pages; 15 | private final long channel; 16 | private final long user; 17 | 18 | public MultiSelector(long channel, long user, List pages) { 19 | this.pages = pages.toArray(new MultiSelectorPage[0]); 20 | this.channel = channel; 21 | this.user = user; 22 | } 23 | 24 | public void send(JDA jda) { 25 | for (MultiSelectorPage page : pages) { 26 | EmbedBuilder pageBuilder = page.getPage(); 27 | pageBuilder.setTitle(page.getName()); 28 | } 29 | 30 | Map pageMap = new HashMap<>(pages.length); 31 | List