use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class ModerationOptions method onRegistry.
@Subscribe
public void onRegistry(OptionRegistryEvent e) {
registerOption("localblacklist:add", "Local Blacklist add", "Adds someone to the local blacklist.\n" + "You need to mention the user. You can mention multiple users.\n" + "**Example:** `~>opts localblacklist add @user1 @user2`", "Adds someone to the local blacklist.", (event, args) -> {
List<User> mentioned = event.getMessage().getMentionedUsers();
if (mentioned.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally blacklist.**").queue();
return;
}
if (mentioned.contains(event.getAuthor())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Why are you trying to blacklist yourself?...").queue();
return;
}
Guild guild = event.getGuild();
if (mentioned.stream().anyMatch(u -> CommandPermission.ADMIN.test(guild.getMember(u)))) {
event.getChannel().sendMessage(EmoteReference.ERROR + "One (or more) of the users you're trying to blacklist are admins or Bot Commanders!").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(guild);
GuildData guildData = dbGuild.getData();
List<String> toBlackList = mentioned.stream().map(ISnowflake::getId).collect(Collectors.toList());
String blacklisted = mentioned.stream().map(user -> user.getName() + "#" + user.getDiscriminator()).collect(Collectors.joining(","));
guildData.getDisabledUsers().addAll(toBlackList);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Locally blacklisted users: **" + blacklisted + "**").queue();
});
registerOption("localblacklist:remove", "Local Blacklist remove", "Removes someone from the local blacklist.\n" + "You need to mention the user. You can mention multiple users.\n" + "**Example:** `~>opts localblacklist remove @user1 @user2`", "Removes someone from the local blacklist.", (event, args) -> {
List<User> mentioned = event.getMessage().getMentionedUsers();
if (mentioned.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally blacklist.**").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
List<String> toUnBlackList = mentioned.stream().map(ISnowflake::getId).collect(Collectors.toList());
String unBlackListed = mentioned.stream().map(user -> user.getName() + "#" + user.getDiscriminator()).collect(Collectors.joining(","));
guildData.getDisabledUsers().removeAll(toUnBlackList);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Locally unblacklisted users: **" + unBlackListed + "**").queue();
});
// region logs
// region enable
registerOption("logs:enable", "Enable logs", "Enables logs. You need to use the channel name.\n" + "**Example:** `~>opts logs enable mod-logs`", "Enables logs.", (event, args) -> {
if (args.length < 1) {
onHelp(event);
return;
}
String logChannel = args[0];
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
Consumer<TextChannel> consumer = textChannel -> {
guildData.setGuildLogChannel(textChannel.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(String.format(EmoteReference.MEGA + "Message logging has been enabled with parameters -> ``Channel #%s (%s)``", textChannel.getName(), textChannel.getId())).queue();
};
TextChannel channel = Utils.findChannelSelect(event, logChannel, consumer);
if (channel != null) {
consumer.accept(channel);
}
});
registerOption("logs:exclude", "Exclude log channel.", "Excludes a channel from logging. You need to use the channel name, *not* the mention.\n" + "**Example:** `~>opts logs exclude staff`", "Excludes a channel from logging.", (event, args) -> {
if (args.length == 0) {
onHelp(event);
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
if (args[0].equals("clearchannels")) {
guildData.getLogExcludedChannels().clear();
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Cleared log exceptions!").queue();
return;
}
if (args[0].equals("remove")) {
if (args.length < 2) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Incorrect argument length.").queue();
return;
}
String channel = args[1];
List<TextChannel> channels = event.getGuild().getTextChannelsByName(channel, true);
if (channels.size() == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a channel with that name!").queue();
} else if (channels.size() == 1) {
TextChannel ch = channels.get(0);
guildData.getLogExcludedChannels().remove(ch.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Removed logs exception on channel: " + ch.getAsMention()).queue();
} else {
DiscordUtils.selectList(event, channels, ch -> String.format("%s (ID: %s)", ch.getName(), ch.getId()), s -> ((SimpleCommand) optsCmd).baseEmbed(event, "Select the Channel:").setDescription(s).build(), ch -> {
guildData.getLogExcludedChannels().remove(ch.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Removed logs exception on channel: " + ch.getAsMention()).queue();
});
}
return;
}
String channel = args[0];
List<TextChannel> channels = event.getGuild().getTextChannelsByName(channel, true);
if (channels.size() == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a channel with that name!").queue();
} else if (channels.size() == 1) {
TextChannel ch = channels.get(0);
guildData.getLogExcludedChannels().add(ch.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Added logs exception on channel: " + ch.getAsMention()).queue();
} else {
DiscordUtils.selectList(event, channels, ch -> String.format("%s (ID: %s)", ch.getName(), ch.getId()), s -> ((SimpleCommand) optsCmd).baseEmbed(event, "Select the Channel:").setDescription(s).build(), ch -> {
guildData.getLogExcludedChannels().add(ch.getId());
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.OK + "Added logs exception on channel: " + ch.getAsMention()).queue();
});
}
});
// endregion
// region disable
registerOption("logs:disable", "Disable logs", "Disables logs.\n" + "**Example:** `~>opts logs disable`", "Disables logs.", (event) -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setGuildLogChannel(null);
dbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.MEGA + "Message logging has been disabled.").queue();
});
// endregion
// endregion
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class UtilsCmds method weather.
@Subscribe
public void weather(CommandRegistry registry) {
registry.register("weather", new SimpleCommand(Category.UTILS) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (content.isEmpty()) {
onError(event);
return;
}
EmbedBuilder embed = new EmbedBuilder();
try {
long start = System.currentTimeMillis();
WeatherData data = GsonDataManager.GSON_PRETTY.fromJson(Utils.wgetResty(String.format("http://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s", URLEncoder.encode(content, "UTF-8"), MantaroData.config().get().weatherAppId), event), WeatherData.class);
String countryCode = data.getSys().country;
String status = data.getWeather().get(0).main;
Double temp = data.getMain().getTemp();
double pressure = data.getMain().getPressure();
int humidity = data.getMain().getHumidity();
Double ws = data.getWind().speed;
int cloudiness = data.getClouds().all;
Double finalTemperatureCelsius = temp - 273.15;
Double finalTemperatureFahrenheit = temp * 9 / 5 - 459.67;
Double finalWindSpeedMetric = ws * 3.6;
Double finalWindSpeedImperial = ws / 0.447046;
long end = System.currentTimeMillis() - start;
embed.setColor(Color.CYAN).setTitle(":flag_" + countryCode.toLowerCase() + ":" + " Forecast information for " + content, null).setDescription(status + " (" + cloudiness + "% clouds)").addField(":thermometer: Temperature", String.format("%d°C | %d°F", finalTemperatureCelsius.intValue(), finalTemperatureFahrenheit.intValue()), true).addField(":droplet: Humidity", humidity + "%", true).addBlankField(true).addField(":wind_blowing_face: Wind Speed", String.format("%dkm/h | %dmph", finalWindSpeedMetric.intValue(), finalWindSpeedImperial.intValue()), true).addField("Pressure", pressure + "hPA", true).addBlankField(true).setFooter("Information provided by OpenWeatherMap (Process time: " + end + "ms)", null);
event.getChannel().sendMessage(embed.build()).queue();
} catch (NullPointerException npe) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Error while fetching results. (Not found?)").queue();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Error while fetching results. (Not found?)").queue();
log.warn("Exception caught while trying to fetch weather data, maybe the API changed something?", e);
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Weather command").setDescription("This command retrieves information from OpenWeatherMap. Used to check **forecast information.**").addField("Usage", "`~>weather <city>,<countrycode>` - **Retrieves the forecast information for the given location.**", false).addField("Parameters", "`city` - **Your city name, e.g. New York, **\n" + "`countrycode` - **(OPTIONAL) The abbreviation for your country, for example US (USA) or MX (Mexico).**", false).addField("Example", "`~>weather New York, US`", false).build();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class CurrencyCmds method inventory.
@Subscribe
public void inventory(CommandRegistry cr) {
cr.register("inventory", new SimpleCommand(Category.CURRENCY) {
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
Map<String, Optional<String>> t = StringUtils.parse(args);
content = Utils.replaceArguments(t, content, "brief", "calculate");
Member member = Utils.findMember(event, event.getMember(), content);
if (member == null)
return;
Player player = MantaroData.db().getPlayer(member);
if (t.containsKey("brief")) {
event.getChannel().sendMessage(String.format("**%s's inventory:** %s", member.getEffectiveName(), ItemStack.toString(player.getInventory().asList()))).queue();
return;
}
if (t.containsKey("calculate")) {
long all = player.getInventory().asList().stream().filter(item -> item.getItem().isSellable()).mapToLong(value -> (long) (value.getItem().getValue() * value.getAmount() * 0.9d)).sum();
event.getChannel().sendMessage(String.format("%sYou will get **%d credits** if you sell all of your items!", EmoteReference.DIAMOND, all)).queue();
return;
}
EmbedBuilder builder = baseEmbed(event, member.getEffectiveName() + "'s Inventory", member.getUser().getEffectiveAvatarUrl());
List<ItemStack> list = player.getInventory().asList();
List<MessageEmbed.Field> fields = new LinkedList<>();
if (list.isEmpty())
builder.setDescription("There is only dust here.");
else
player.getInventory().asList().forEach(stack -> {
long buyValue = stack.getItem().isBuyable() ? stack.getItem().getValue() : 0;
long sellValue = stack.getItem().isSellable() ? (long) (stack.getItem().getValue() * 0.9) : 0;
fields.add(new MessageEmbed.Field(stack.getItem().getEmoji() + " " + stack.getItem().getName() + " x " + stack.getAmount(), String.format("**Price**: \uD83D\uDCE5 %d \uD83D\uDCE4 %d\n%s", buyValue, sellValue, stack.getItem().getDesc()), false));
});
List<List<MessageEmbed.Field>> splitFields = DiscordUtils.divideFields(18, fields);
boolean hasReactionPerms = event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION);
if (hasReactionPerms) {
DiscordUtils.list(event, 45, false, builder, splitFields);
} else {
DiscordUtils.listText(event, 45, false, builder, splitFields);
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Inventory command").setDescription("**Shows your current inventory.**\n" + "You can use `~>inventory -brief` to get a mobile friendly version.\n" + "Use `~>inventory -calculate` to see how much you'd get if you sell every sellable item on your inventory!").build();
}
});
cr.registerAlias("inventory", "inv");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class DebugCmds method ping.
@Subscribe
public void ping(CommandRegistry cr) {
final RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 5, true);
final Random r = new Random();
final String[] pingQuotes = { "W-Was I fast enough?", "What are you doing?", "W-What are you looking at?!", "Huh.", "Did I do well?", "What do you think?", "Does this happen often?", "Am I performing p-properly?", "<3", "*pats*", "Pong.", "Pang.", "Pung.", "Peng.", "Ping-pong? Yay!", "U-Uh... h-hi" };
cr.register("ping", new SimpleCommand(Category.INFO) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
return;
long start = System.currentTimeMillis();
event.getChannel().sendTyping().queue(v -> {
long ping = System.currentTimeMillis() - start;
event.getChannel().sendMessage(EmoteReference.MEGA + "*" + pingQuotes[r.nextInt(pingQuotes.length)] + "* - My ping: " + ping + " ms (" + ratePing(ping) + ") `Websocket:" + event.getJDA().getPing() + "ms`").queue();
TextChannelGround.of(event).dropItemWithChance(5, 5);
});
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Ping Command").setDescription("**Plays Ping-Pong with Discord and prints out the result.**").build();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class FunCmds method ratewaifu.
@Subscribe
public void ratewaifu(CommandRegistry cr) {
cr.register("ratewaifu", new SimpleCommand(Category.FUN) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Give me a waifu to rate!").queue();
return;
}
int waifuRate = content.replaceAll("\\s+", " ").replaceAll("<@!?(\\d+)>", "<@$1>").chars().sum() % 101;
if (content.equalsIgnoreCase("mantaro"))
waifuRate = 100;
new MessageBuilder().setContent(String.format("%sI rate %s with a **%d/100**", EmoteReference.THINKING, content, waifuRate)).stripMentions(event.getGuild(), Message.MentionType.EVERYONE, Message.MentionType.HERE).sendTo(event.getChannel()).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Rate your waifu").setDescription("**Just rates your waifu from zero to 100. Results may vary.**").build();
}
});
cr.registerAlias("ratewaifu", "rw");
}
Aggregations