-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made some adjustments to commandhandler
Finished expansioncommand Added paginations Added help command added expansion list command Added set prefix command Added ecloud status command
- Loading branch information
1 parent
9403986
commit a85b366
Showing
14 changed files
with
507 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.gradle/ | ||
.idea/ | ||
src/test | ||
build/ | ||
build/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package at.helpch.papibot.commands; | ||
|
||
import at.helpch.papibot.core.framework.Command; | ||
import at.helpch.papibot.core.utils.mysql.ServerUtils; | ||
import net.dv8tion.jda.core.EmbedBuilder; | ||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
// ------------------------------ | ||
// Copyright (c) PiggyPiglet 2018 | ||
// https://www.piggypiglet.me | ||
// ------------------------------ | ||
public final class HelpCommand extends Command { | ||
public HelpCommand() { | ||
super("help"); | ||
} | ||
|
||
@Override | ||
protected void execute(GuildMessageReceivedEvent e, String[] args) { | ||
String prefix = "**" + ServerUtils.getPrefix(e.getGuild().getIdLong()) + " "; | ||
|
||
e.getChannel().sendMessage(new EmbedBuilder() | ||
.setTitle("PlaceholderAPI Bot Help Menu", "https://github.com/help-chat/PlaceholderAPI-Discord-Bot") | ||
.setThumbnail(e.getJDA().getSelfUser().getEffectiveAvatarUrl()) | ||
.setDescription( | ||
prefix + "help** - This menu.\n" + | ||
prefix + "list** - Expansion list.\n" + | ||
prefix + "<expansion name>** - Get placeholders for a specific expansion.\n" + | ||
prefix + "status** - Get the current status of the eCloud.\n" + | ||
prefix + "prefix <prefix>** - Admin command to change the bot's prefix for this specific guild.") | ||
.addField("Support: ", "Having trouble with PlaceholderAPI or any other plugin? Don't hesitate to ask for help in our help chat, https://helpch.at/discord", false) | ||
.setTimestamp(ZonedDateTime.now()) | ||
.build()).queue(s -> s.delete().queueAfter(1, TimeUnit.MINUTES)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package at.helpch.papibot.commands; | ||
|
||
import at.helpch.papibot.core.framework.Command; | ||
import at.helpch.papibot.core.handlers.misc.PaginationHandler; | ||
import at.helpch.papibot.core.objects.paginations.PaginationBuilder; | ||
import at.helpch.papibot.core.objects.paginations.PaginationPage; | ||
import com.google.gson.Gson; | ||
import com.google.gson.internal.LinkedTreeMap; | ||
import com.google.inject.Inject; | ||
import net.dv8tion.jda.core.EmbedBuilder; | ||
import net.dv8tion.jda.core.entities.MessageEmbed; | ||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.stream.Stream; | ||
|
||
// ------------------------------ | ||
// Copyright (c) PiggyPiglet 2018 | ||
// https://www.piggypiglet.me | ||
// ------------------------------ | ||
public final class ListCommand extends Command { | ||
@Inject private Gson gson; | ||
@Inject private PaginationHandler paginationHandler; | ||
|
||
public ListCommand() { | ||
super("list"); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
protected void execute(GuildMessageReceivedEvent e, String[] args) { | ||
HttpClient client = HttpClientBuilder.create().build(); | ||
HttpGet get = new HttpGet("https://api.extendedclip.com/"); | ||
List<String> keys = new ArrayList<>(); | ||
|
||
try { | ||
HttpResponse response = client.execute(get); | ||
keys.addAll(gson.fromJson(EntityUtils.toString(response.getEntity()), LinkedTreeMap.class).keySet()); | ||
} catch (Exception ex) { | ||
e.getChannel().sendMessage(e.getAuthor().getAsMention() + "The eCloud is currently non responsive, please report this to staff in https://helpch.at/discord").queue(); | ||
} | ||
|
||
keys = Arrays.asList(String.join("\n", keys).replaceAll("((.*\\s*\\n\\s*){25})", "$1-SEPARATOR-\n").split("-SEPARATOR-")); | ||
String[] title = new String[] {"Expansions in the eCloud", "https://api.extendedclip.com/all"}; | ||
|
||
if (keys.size() == 1) { | ||
e.getChannel().sendMessage(new EmbedBuilder() | ||
.setTitle(title[0], title[1]) | ||
.addField("Expansions: ", keys.get(0), false) | ||
.setTimestamp(ZonedDateTime.now()) | ||
.build()).queue(s -> s.delete().queueAfter(5, TimeUnit.MINUTES)); | ||
} else { | ||
List<String> unicodes = new ArrayList<>(); | ||
|
||
Stream.of( | ||
"1\u20E3", "2\u20E3", "3\u20E3", "4\u20E3", "5\u20E3", "6\u20E3", "7\u20E3", "8\u20E3", "9\u20E3" | ||
).forEach(unicodes::add); | ||
|
||
AtomicInteger i = new AtomicInteger(0); | ||
PaginationBuilder paginationBuilder = new PaginationBuilder(); | ||
|
||
keys.forEach(someKeys -> { | ||
EmbedBuilder embed = new EmbedBuilder() | ||
.setTitle(title[0], title[1]) | ||
.setTimestamp(ZonedDateTime.now()); | ||
|
||
PaginationPage page = new PaginationPage(embed.addField(new MessageEmbed.Field("Placeholders:", someKeys, false)).build(), unicodes.get(i.getAndIncrement())); | ||
paginationBuilder.addPages(page); | ||
}); | ||
|
||
paginationBuilder.build(e.getChannel(), paginationHandler); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/at/helpch/papibot/commands/PrefixCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package at.helpch.papibot.commands; | ||
|
||
import at.helpch.papibot.core.framework.Command; | ||
import at.helpch.papibot.core.utils.mysql.ServerUtils; | ||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
// ------------------------------ | ||
// Copyright (c) PiggyPiglet 2018 | ||
// https://www.piggypiglet.me | ||
// ------------------------------ | ||
public final class PrefixCommand extends Command { | ||
public PrefixCommand() { | ||
super("prefix"); | ||
} | ||
|
||
@Override | ||
protected void execute(GuildMessageReceivedEvent e, String[] args) { | ||
if (e.getMember() == e.getGuild().getOwner() || e.getAuthor().getIdLong() == 181675431362035712L) { | ||
if (args.length >= 1) { | ||
ServerUtils.setPrefix(e.getGuild().getIdLong(), args[0]); | ||
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " :white_check_mark: **Prefix successfully set to `" + args[0] + "`.**").queue(s -> s.delete().queueAfter(15, TimeUnit.SECONDS)); | ||
} else { | ||
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " :warning: **Please supply the prefix you want to set.**").queue(s -> s.delete().queueAfter(30, TimeUnit.SECONDS)); | ||
} | ||
} else { | ||
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " :warning: **Only the server owner can use this command.**").queue(s -> s.delete().queueAfter(30, TimeUnit.SECONDS)); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/at/helpch/papibot/commands/StatusCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package at.helpch.papibot.commands; | ||
|
||
import at.helpch.papibot.core.framework.Command; | ||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; | ||
|
||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
// ------------------------------ | ||
// Copyright (c) PiggyPiglet 2018 | ||
// https://www.piggypiglet.me | ||
// ------------------------------ | ||
public final class StatusCommand extends Command { | ||
public StatusCommand() { | ||
super("status"); | ||
} | ||
|
||
@Override | ||
protected void execute(GuildMessageReceivedEvent e, String[] args) { | ||
try { | ||
HttpURLConnection con = (HttpURLConnection) new URL("https://api.extendedclip.com/").openConnection(); | ||
|
||
if (con.getResponseCode() != HttpURLConnection.HTTP_OK) { | ||
e.getChannel().sendMessage(e.getAuthor().getAsMention() + ":warning: **The eCloud is currently non responsive, please report this to staff in https://helpch.at/discord**").queue(s -> s.delete().queueAfter(45, TimeUnit.SECONDS)); | ||
} else { | ||
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " :white_check_mark: **The eCloud is up and responsive.**").queue(s -> s.delete().queueAfter(15, TimeUnit.SECONDS)); | ||
} | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.