use of tk.ardentbot.core.executor.Subcommand in project Ardent by adamint.
the class Prefix method setupSubcommands.
@Override
public void setupSubcommands() {
subcommands.add(new Subcommand("View the prefix of your server!", "view", "view") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
sendTranslatedMessage("The prefix for this server is **{0}**.".replace("{0}", GuildUtils.getPrefix(guild)), channel, user);
}
});
subcommands.add(new Subcommand("Change the prefix of your server.", "change", "change") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length > 2) {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
String newPrefix = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + "" + args[1] + " ", "").replace(" ", "");
if (newPrefix.length() == message.getRawContent().length()) {
newPrefix = message.getRawContent().replace("/" + args[0] + " " + args[1] + " ", "");
}
if (!newPrefix.contains(" ") && !newPrefix.contains("$")) {
GuildUtils.updatePrefix(newPrefix, guild);
r.db("data").table("guilds").filter(row -> row.g("guild_id").eq(guild.getId())).update(r.hashMap("prefix", newPrefix)).run(connection);
sendTranslatedMessage("Successfully updated the prefix, {0}!".replace("{0}", newPrefix), channel, user);
} else
sendTranslatedMessage("Your supplied prefix contained invalid characters!", channel, user);
} else {
sendTranslatedMessage("You need ```Manage Server``` permissions.", channel, user);
}
} else {
sendTranslatedMessage("You must include a prefix as your third argument!", channel, user);
}
}
});
}
use of tk.ardentbot.core.executor.Subcommand in project Ardent by adamint.
the class Restrict method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Prevent a user from using Ardent commands", "block @User", "block") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Member member = guild.getMember(user);
if (member.hasPermission(Permission.MANAGE_SERVER)) {
List<User> mentionedUsers = message.getMentionedUsers();
if (mentionedUsers.size() > 0) {
for (User mentioned : mentionedUsers) {
Member mentionedMember = guild.getMember(mentioned);
if (mentionedMember.hasPermission(member.getPermissions()) || mentionedMember.hasPermission(Permission.MANAGE_SERVER) || mentionedMember.getUser().getId().equalsIgnoreCase(guild.getSelfMember().getUser().getId())) {
sendTranslatedMessage("You cannot modify this user because they have the same or higher permissions than " + "you.", channel, user);
return;
}
EntityGuild entityGuild = EntityGuild.get(guild);
boolean isRestricted = entityGuild.isRestricted(mentioned);
if (isRestricted) {
sendTranslatedMessage("This user has already been blocked from using commands!", channel, user);
} else {
RestrictedUser restrictedUser = new RestrictedUser(mentioned.getId(), user.getId(), guild);
entityGuild.addRestricted(restrictedUser);
r.db("data").table("restricted").insert(r.json(gson.toJson(new RestrictedUserModel(guild.getId(), mentioned.getId(), user.getId())))).run(connection);
sendEditedTranslation("{1} has blocked {0} from sending commands", user, channel, mentioned.getName(), user.getName());
}
}
} else
sendTranslatedMessage("You need to mention one or more users", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
subcommands.add(new Subcommand("Allow a blocked user to run Ardent commands again", "unblock @User", "unblock") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
List<User> mentionedUsers = message.getMentionedUsers();
if (mentionedUsers.size() > 0) {
for (User mentioned : mentionedUsers) {
EntityGuild entityGuild = EntityGuild.get(guild);
boolean isRestricted = entityGuild.isRestricted(mentioned);
if (!isRestricted) {
sendEditedTranslation("{0} isn't restricted from sending commands!", user, channel, mentioned.getName());
} else {
entityGuild.removeRestricted(mentioned.getId());
r.db("data").table("restricted").filter(row -> row.g("user_id").eq(mentioned.getId()).and(row.g("guild_id").eq(guild.getId()))).delete().run(connection);
sendEditedTranslation("{0} unrestricted {1}, allowing them to use commands again", user, channel, mentioned.getName(), user.getName());
}
}
} else
sendTranslatedMessage("You need to mention one or more users", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
subcommands.add(new Subcommand("View all the users who have been blocked in your server", "view") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
EntityGuild entityGuild = EntityGuild.get(guild);
ArrayList<RestrictedUser> restrictedUsers = entityGuild.getRestrictedUsers();
String title = "Restricted users";
String restrictedBy = "restricted by";
StringBuilder response = new StringBuilder();
response.append("**" + title + "**");
if (restrictedUsers.size() == 0) {
response.append("\nNo one");
} else {
restrictedUsers.forEach(restrictedUser -> response.append("\n - " + guild.getMemberById(restrictedUser.getUserId()).getUser().getName() + ", " + restrictedBy + " " + guild.getMemberById(restrictedUser.getRestrictedById()).getUser().getName()));
}
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(title, getShard().url, guild.getSelfMember().getUser().getAvatarUrl());
builder.setDescription(response.toString());
sendEmbed(builder, channel, user);
}
});
}
use of tk.ardentbot.core.executor.Subcommand in project Ardent by adamint.
the class DefaultRole method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("View the current default role in this server", "view", "view") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
Role role = getDefaultRole(guild);
if (role == null) {
sendTranslatedMessage("There's no default role set up in this server!", channel, user);
} else {
String reply = "The set default role is {0}".replace("{0}", role.getName());
sendTranslatedMessage(reply, channel, user);
}
}
});
subcommands.add(new Subcommand("Remove the default role", "remove", "remove") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
Role role = getDefaultRole(guild);
if (role == null) {
sendTranslatedMessage("There's no default role set up in this server!", channel, user);
} else {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
removeDefaultRole(guild);
sendTranslatedMessage("Removed the set default role!", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
}
});
subcommands.add(new Subcommand("Set the default role", "set", "set") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (GuildUtils.hasManageServerPermission(guild.getMember(user))) {
String roleName = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + args[1] + " ", "");
List<Role> roles = guild.getRolesByName(roleName, true);
if (roles.size() == 0) {
sendTranslatedMessage("You need to type a role name!", channel, user);
} else {
Role role = roles.get(0);
setDefaultRole(role, guild);
sendTranslatedMessage("Successfully set the default role as " + role.getName() + "!", channel, user);
}
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
}
use of tk.ardentbot.core.executor.Subcommand in project Ardent by adamint.
the class NSFW method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Set whether people can send NSFW channels in all channels", "alloweverywhere [true/false]", "alloweverywhere") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
if (args.length == 3) {
try {
boolean allowEverywhere = Boolean.parseBoolean(args[2]);
getSettings(guild);
if (allowEverywhere)
sendTranslatedMessage("You can now use NSFW commands in all channels", channel, user);
else
sendTranslatedMessage("You can now use NSFW commands only in specified channels", channel, user);
r.table("nsfw_settings").get(guild.getId()).update(r.hashMap("global", allowEverywhere)).run(connection);
} catch (Exception e) {
sendTranslatedMessage("You need to specify true or false", channel, user);
}
} else
sendTranslatedMessage("Invalid arguments ¯\\_(ツ)_/¯", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
subcommands.add(new Subcommand("Set whether you need a role called NSFW to send NSFW commands", "neednsfwrole [true/false]", "neednsfwrole") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
if (args.length == 3) {
try {
boolean needs = Boolean.parseBoolean(args[2]);
getSettings(guild);
if (needs)
sendTranslatedMessage("You now need the NSFW role to send NSFW commands", channel, user);
else
sendTranslatedMessage("Anyone can now send NSFW commands", channel, user);
r.table("nsfw_settings").get(guild.getId()).update(r.hashMap("needNsfwRole", needs)).run(connection);
} catch (Exception e) {
sendTranslatedMessage("You need to specify true or false", channel, user);
}
} else
sendTranslatedMessage("Invalid arguments ¯\\_(ツ)_/¯", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
subcommands.add(new Subcommand("View the current NSFW settings for your server", "settings", "settings") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
String nsfwSettings = "NSFW Settings";
NSFWSettings settings = getSettings(guild);
EmbedBuilder embedBuilder = MessageUtils.getDefaultEmbed(user);
embedBuilder.setAuthor(nsfwSettings, getShard().url, getShard().bot.getAvatarUrl());
StringBuilder description = new StringBuilder();
description.append("**" + nsfwSettings + "**");
description.append("\n\nAble to use NSFW commands in all channels: " + settings.isGlobal());
description.append("\n\nNeed the NSFW role: " + settings.isNeedNsfwRole());
if (!settings.isGlobal()) {
description.append("\n\nCan only use these command in discord NSFFW channels");
}
embedBuilder.setDescription(description.toString());
sendEmbed(embedBuilder, channel, user);
}
});
}
use of tk.ardentbot.core.executor.Subcommand in project Ardent by adamint.
the class Trivia method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Start a new trivia game", "start", "start") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
for (TriviaGame triviaGame : gamesInSession) {
if (triviaGame.getGuildId().equalsIgnoreCase(guild.getId())) {
sendTranslatedMessage("There's already a game in session in this server!", channel, user);
return;
}
}
if (gamesSettingUp.contains(guild.getId())) {
sendTranslatedMessage("There's already a game in session in this server!", channel, user);
return;
}
gamesSettingUp.add(guild.getId());
sendTranslatedMessage("Do you want to play this solo? Type `yes` if so, or `no` if not", channel, user);
interactiveOperation(channel, message, (soloMessage) -> {
String content = soloMessage.getContent();
boolean solo;
solo = content.equalsIgnoreCase("yes");
TriviaGame currentGame = new TriviaGame(user, solo, (TextChannel) channel, 15);
gamesInSession.add(currentGame);
sendTranslatedMessage("The game is starting! Type your answers in this channel. You have **15** seconds to answer " + "each question.", channel, user);
commenceRounds(guild, (TextChannel) channel, user, currentGame);
gamesSettingUp.remove(guild.getId());
});
}
});
subcommands.add(new Subcommand("Stop a currently active trivia game", "stop", "stop") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
if (gamesInSession.stream().filter(game -> game.getGuildId().equals(guild.getId())).count() > 0 || gamesSettingUp.contains(guild.getId())) {
gamesSettingUp.remove(guild.getId());
gamesInSession.removeIf(g -> g.getGuildId().equals(guild.getId()));
sendTranslatedMessage("Stopped the trivia game in session.", channel, user);
} else {
sendTranslatedMessage("There isn't a trivia game running!", channel, user);
}
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
}
Aggregations