Skip to content

Commit ca0b5fb

Browse files
authored
Merge pull request #3 from MCDiamondFire/master
.
2 parents 87ffd42 + a92d6b9 commit ca0b5fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+988
-510
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
gradle
44
build
55
/src/main/resources/swear_filter.json
6+
7+
*.json
8+
*.png
9+
*.txt

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ HelpBot is created in **java 16** and there are no current rules in place for co
1212
something you are able to create a **fork** and submit a **pull request**.
1313

1414
Most pull requests are accepted, do not be afraid to make a change I promise I do not bite.
15+
Please give me time to review your PR however, as it takes a little bit for me to make sure that your PR is up to standards. Testing will help!
1516

1617
**Config File**
1718

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ tasks.withType(JavaCompile) {
3232
options.encoding = 'UTF-8'
3333
}
3434

35+
jar {
36+
manifest {
37+
attributes("Main-Class": "com.diamondfire.helpbot.HelpBot")
38+
}
39+
}
40+
3541
build {
3642
dependsOn {
3743
shadowJar

src/main/java/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static void initialize() throws LoginException {
4949
new SearchCommand(),
5050
new TagsCommand(),
5151
// others
52+
new CowsayCommand(),
5253
new MimicCommand(),
5354
new FetchDataCommand(),
5455
new InfoCommand(),
@@ -77,7 +78,7 @@ public static void initialize() throws LoginException {
7778
new PollCommand(),
7879
new IdeaCommand(),
7980
new StoreCommand(),
80-
//new ChannelMuteCommand(),
81+
new ChannelMuteCommand(),
8182
// statsbot
8283
new StatsCommand(),
8384
new SupportBadCommand(),
@@ -87,7 +88,7 @@ public static void initialize() throws LoginException {
8788
new ActivePlotsCommand(),
8889
new TrendingPlotsCommand(),
8990
new PlotsCommand(),
90-
new CpTopCommand(),
91+
//new CpTopCommand(),
9192
new RetiredListCommand(),
9293
new StaffListCommand(),
9394
new SessionTopCommand(),
@@ -105,8 +106,8 @@ public static void initialize() throws LoginException {
105106
new HelpedByCommand(),
106107
new NamesCommand(),
107108
new PlayerJoinGraphCommand(),
108-
new CpCommand(),
109-
new CpRequirementsCommand(),
109+
//new CpCommand(),
110+
//new CpRequirementsCommand(),
110111
new VoteGivenLeaderboard(),
111112
new PlotVoteGraphCommand(),
112113
new JoinDataCommand(),
@@ -159,4 +160,4 @@ public static Config getConfig() {
159160
public static TaskRegistry getScheduler() {
160161
return loop;
161162
}
162-
}
163+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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<String> {
10+
11+
@Override
12+
public String parseValue(@NotNull Deque<String> args, CommandEvent event) throws ArgumentException {
13+
return String.join(" ", args);
14+
}
15+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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<E extends Enum<E> & EnumArgument.InputEnum> extends AbstractSimpleValueArgument<E> {
12+
13+
private EnumSet<E> associatedEnum;
14+
15+
public EnumArgument<E> setEnum(Class<E> 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 <T extends Enum<T> & InputEnum> String getFormattedOptions(@NotNull Class<T> anEnum) {
36+
return getFormattedOptions(EnumSet.allOf(anEnum));
37+
}
38+
39+
public static String getFormattedOptions(@NotNull EnumSet<? extends InputEnum> 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+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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<Tag, String> modifier;
22+
23+
TagProperty(String name, boolean modifiable, BiConsumer<Tag, String> 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<Tag, String> getModifier() {
58+
return modifier;
59+
}
60+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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<String> {
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<String> 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<String> 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+
}

src/main/java/com/diamondfire/helpbot/bot/command/impl/other/StoreCommand.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.diamondfire.helpbot.util.WebUtil;
1111
import com.google.gson.*;
1212
import net.dv8tion.jda.api.EmbedBuilder;
13+
import net.dv8tion.jda.api.entities.Message;
1314

1415
import java.util.*;
1516

@@ -46,6 +47,9 @@ public Permission getPermission() {
4647
@Override
4748
public void run(CommandEvent event) {
4849
EmbedBuilder builder = new EmbedBuilder();
50+
builder.setTitle("<:diamondfire:867472383098486794> DiamondFire Store <:diamondfire:867472383098486794>", "https://store.mcdiamondfire.com/");
51+
builder.setDescription("Fetching store..");
52+
Message message = event.getChannel().sendMessageEmbeds(builder.build()).complete();
4953
try{
5054
JsonObject json = WebUtil.getJson("https://df.vatten.dev/store/").getAsJsonObject();
5155
builder.setTitle("<:diamondfire:867472383098486794> DiamondFire Store <:diamondfire:867472383098486794>", "https://store.mcdiamondfire.com/");
@@ -73,16 +77,16 @@ public void run(CommandEvent event) {
7377
}
7478
builder.addField(emotes.get(category.getKey()) + " " + category.getKey(), String.join("\n", fieldval) + "\n\u200b", false);
7579
}
76-
80+
7781
ArrayList<String> fieldval = new ArrayList<>();
7882
for(JsonElement purchase : json.getAsJsonArray("recent-purchases")) {
7983
fieldval.add(" **" + purchase.getAsJsonObject().get("player").getAsString() + "** bought **" + purchase.getAsJsonObject().get("item").getAsString() + "**");
8084
}
8185
builder.addField(":partying_face: Recent Purchases", String.join("\n", fieldval), false);
8286

83-
event.getChannel().sendMessageEmbeds(builder.build()).queue();
87+
message.editMessageEmbeds(builder.build()).queue();
8488
}catch(Exception e) {
85-
event.reply(new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR, "Failed to retrieve store items.")));
89+
message.editMessageEmbeds(new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR, "Failed to retrieve store items.")).getEmbed().build()).queue();
8690
}
8791
}
8892
}

0 commit comments

Comments
 (0)