use of tk.ardentbot.utils.javaAdditions.Triplet in project Ardent by adamint.
the class Command method dispatchInteractiveEvent.
private static boolean dispatchInteractiveEvent(OffsetDateTime creationTime, TextChannel channel, Message message, User user, Consumer<Message> function, int time, boolean sendMessage) {
final boolean[] success = { false };
Pair<String, Triplet<String, String, Consumer<Message>>> p = new Pair<>(channel.getId(), new Triplet<>(user.getId(), message.getId(), function));
InteractiveEvent e = GuildUtils.getShard(channel.getJDA()).interactiveEvent;
e.getMessageInteractivesQueue().add(p);
ex.schedule(() -> {
if (e.getMessageInteractivesQueue().contains(p)) {
e.getMessageInteractivesQueue().remove(p);
if (sendMessage) {
if (time >= 15) {
channel.sendMessage("Cancelled your interactive operation because you didn't respond within " + time + " seconds!").queue();
} else {
channel.sendMessage("Cancelled your reaction event because you didn't respond within **" + String.valueOf(time / 1000) + "** seconds").queue();
}
}
}
return success[0];
}, time, TimeUnit.SECONDS);
return success[0];
}
use of tk.ardentbot.utils.javaAdditions.Triplet in project Ardent by adamint.
the class Command method interactiveReaction.
public static void interactiveReaction(MessageChannel channel, Message message, User user, int seconds, Consumer<MessageReaction> function) {
Pair<String, Triplet<String, String, Consumer<MessageReaction>>> p = new Pair<>(channel.getId(), new Triplet<>(user.getId(), message.getId(), function));
InteractiveEvent e = GuildUtils.getShard(channel.getJDA()).interactiveEvent;
e.getReactionInteractivesQueue().add(p);
ex.schedule(() -> {
if (e.getReactionInteractivesQueue().contains(p)) {
e.getReactionInteractivesQueue().remove(p);
channel.sendMessage("Cancelled your reaction event because you didn't respond in time!").queue();
}
}, seconds, TimeUnit.SECONDS);
}
use of tk.ardentbot.utils.javaAdditions.Triplet in project Ardent by adamint.
the class Command method dispatchInteractiveEvent.
private static boolean dispatchInteractiveEvent(OffsetDateTime creationTime, TextChannel channel, Message message, Consumer<Message> function, int time, boolean sendMessage) {
final boolean[] success = { false };
Pair<String, Triplet<String, String, Consumer<Message>>> p = new Pair<>(channel.getId(), new Triplet<>(message.getAuthor().getId(), message.getId(), function));
InteractiveEvent e = GuildUtils.getShard(channel.getJDA()).interactiveEvent;
e.getMessageInteractivesQueue().add(p);
ex.schedule(() -> {
if (e.getMessageInteractivesQueue().contains(p)) {
e.getMessageInteractivesQueue().remove(p);
if (sendMessage) {
if (time >= 15) {
channel.sendMessage("Cancelled your interactive operation because you didn't respond within " + time + " seconds!").queue();
} else {
channel.sendMessage("Cancelled your reaction event because you didn't respond within **" + String.valueOf(time / 1000) + "** seconds").queue();
}
}
}
return success[0];
}, time, TimeUnit.SECONDS);
return success[0];
}
use of tk.ardentbot.utils.javaAdditions.Triplet in project Ardent by adamint.
the class Automessage method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Prompt the automessage setup", "setup", "setup") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
sendTranslatedMessage("Type **join** to set this server's join message, **leave** to set this server's leave message, or " + "**channel** to set the channel I'll send join & leave messages to", channel, user);
interactiveOperation(channel, message, selectType -> {
String type;
String content = selectType.getContent();
if (content.equalsIgnoreCase("join")) {
type = "join";
sendTranslatedMessage("Type the message you want to send below", channel, user);
} else if (content.equalsIgnoreCase("leave")) {
type = "leave";
sendTranslatedMessage("Type the message you want to send below", channel, user);
} else if (content.equalsIgnoreCase("channel")) {
type = "channel";
sendTranslatedMessage("Mention a channel to send the automessages to", channel, user);
} else {
sendTranslatedMessage("You specified an invalid category type! Please redo setup", channel, user);
return;
}
longInteractiveOperation(channel, message, 60, inputMessage -> {
try {
if (type.equals("channel")) {
List<TextChannel> mentionedChannels = inputMessage.getMentionedChannels();
if (mentionedChannels.size() > 0) {
TextChannel mentioned = mentionedChannels.get(0);
set(guild, mentioned.getId(), 0);
sendTranslatedMessage("Successfully set {0} as the automessage sending channel".replace("{0}", mentioned.getAsMention()), channel, user);
} else
sendTranslatedMessage("You needed to mention a channel!", channel, user);
} else {
String toPut = inputMessage.getRawContent();
if (type.equals("join")) {
set(guild, toPut, 1);
sendTranslatedMessage("Successfully set {0} as the join message".replace("{0}", toPut), channel, user);
} else {
set(guild, toPut, 2);
sendTranslatedMessage("Successfully set {0} as the leave message".replace("{0}", toPut), channel, user);
}
String textChannel = getMessagesAndChannel(guild).getA();
if (textChannel == null || guild.getTextChannelById(textChannel) == null) {
sendTranslatedMessage("Warning: you need a set a channel to send messages to, or else nothing " + "will happen", channel, user);
}
}
} catch (Exception e) {
new BotException(e);
}
});
});
}
});
subcommands.add(new Subcommand("View special arguments you can add to your messages", "arguments") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
sendTranslatedMessage("The available arguments are listed here:\n" + "{user}: mentions the user involved\n" + "{servername}: replaced with the name of your server\n" + "{amtusers}: replaced with the amount of users in your server", channel, user);
}
});
subcommands.add(new Subcommand("Remove a setting", "remove", "remove") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
if (args.length == 2) {
sendTranslatedMessage("Type **/automessage remove join** to remove this server's join message, **/automessage " + "remove leave** to remove this server's " + "leave message, or **/automessage remove channel** to remove the set channel", channel, user);
} else {
String type = args[2];
Triplet<String, String, String> settings = getMessagesAndChannel(guild);
if (type.equalsIgnoreCase("channel")) {
if (settings.getA() == null) {
sendTranslatedMessage("There isn't a channel set!", channel, user);
} else {
remove(guild, 0);
sendTranslatedMessage("Successfully removed the automessage channel", channel, user);
}
} else if (type.equalsIgnoreCase("join")) {
if (settings.getB() == null) {
sendTranslatedMessage("There's no welcome message set!", channel, user);
} else {
remove(guild, 1);
sendTranslatedMessage("Successfully removed the welcome message", channel, user);
}
} else if (type.equalsIgnoreCase("leave")) {
if (settings.getC() == null) {
sendTranslatedMessage("There's no goodbye message set!", channel, user);
} else {
remove(guild, 2);
sendTranslatedMessage("The goodbye message has been successfully removed", channel, user);
}
} else
sendTranslatedMessage("Cancelling removal, you specified an invalid category", channel, user);
}
} else
sendTranslatedMessage("You need the `Manage Server` permission to use this command", channel, user);
}
});
subcommands.add(new Subcommand("View the current automessage settings", "view", "view", "settings") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
Triplet<String, String, String> messages = getMessagesAndChannel(guild);
StringBuilder sb = new StringBuilder();
sb.append("**Automessage Settings**\n=============\n");
if (messages.getA() == null)
sb.append("There isn't a set automessage channel" + "\n\n");
else {
TextChannel textChannel = guild.getTextChannelById(messages.getA());
if (textChannel != null) {
sb.append("The set channel for messages is {0}".replace("{0}", textChannel.getName() + "\n\n"));
} else
sb.append("There isn't a set automessage channel" + "\n\n");
}
if (messages.getB() != null)
sb.append("The set join message is {0}".replace("{0}", messages.getB()) + "\n\n");
else
sb.append("There isn't a set join message" + "\n\n");
if (messages.getC() != null)
sb.append("The set join message is {0}".replace("{0}", messages.getC()) + "\n");
else
sb.append("There isn't a set goodbye message");
sendTranslatedMessage(sb.toString(), channel, user);
}
});
}
Aggregations