use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class UtilsCmds method onPostLoad.
@Command
public static void onPostLoad(PostLoadEvent e) {
OptsCmd.registerOption("birthday:enable", (event, args) -> {
if (args.length < 2) {
OptsCmd.onHelp(event);
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
try {
String channel = args[0];
String role = args[1];
boolean isId = channel.matches("^[0-9]*$");
String channelId = isId ? channel : event.getGuild().getTextChannelsByName(channel, true).get(0).getId();
String roleId = event.getGuild().getRolesByName(role.replace(channelId, ""), true).get(0).getId();
guildData.setBirthdayChannel(channelId);
guildData.setBirthdayRole(roleId);
dbGuild.save();
event.getChannel().sendMessage(String.format(EmoteReference.MEGA + "Birthday logging enabled on this server with parameters -> " + "Channel: ``#%s (%s)`` and role: ``%s (%s)``", channel, channelId, role, roleId)).queue();
} catch (Exception ex) {
if (ex instanceof IndexOutOfBoundsException) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a channel or role!\n " + "**Remember, you don't have to mention neither the role or the channel, rather just type its " + "name, order is <channel> <role>, without the leading \"<>\".**").queue();
return;
}
event.getChannel().sendMessage(EmoteReference.ERROR + "You supplied invalid arguments for this command " + EmoteReference.SAD).queue();
OptsCmd.onHelp(event);
}
});
OptsCmd.registerOption("birthday:disable", (event) -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
guildData.setBirthdayChannel(null);
guildData.setBirthdayRole(null);
dbGuild.save();
event.getChannel().sendMessage(EmoteReference.MEGA + "Birthday logging has been disabled on this server").queue();
});
}
use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class ImageActionCmd method call.
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String random = random(images);
try {
if (mentions(event).isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention a user").queue();
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
MessageBuilder toSend = new MessageBuilder().append(String.format(format, mentions(event), event.getAuthor().getAsMention()));
if (!guildData.isNoMentionsAction() && swapNames) {
toSend = new MessageBuilder().append(String.format(format, event.getAuthor().getAsMention(), mentions(event)));
}
if (guildData.isNoMentionsAction() && swapNames) {
toSend = new MessageBuilder().append(String.format(format, "**" + noMentions(event) + "**", "**" + event.getMember().getEffectiveName() + "**"));
}
if (swapNames && guildData.isNoMentionsAction()) {
toSend = new MessageBuilder().append(String.format(format, "**" + event.getMember().getEffectiveName() + "**", "**" + noMentions(event) + "**"));
}
if (isLonely(event)) {
toSend = new MessageBuilder().append("**").append(lonelyLine).append("**");
}
event.getChannel().sendFile(CACHE.getInput(random), imageName, toSend.build()).queue();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I'd like to know what happened, but I couldn't send the image.").queue();
log.error("Error while performing Action Command ``" + name + "``. The image ``" + random + "`` threw an Exception.", e);
}
}
use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class MantaroListener method onUserLeave.
private void onUserLeave(GuildMemberLeaveEvent event) {
try {
String hour = df.format(new Date(System.currentTimeMillis()));
DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbg.getData();
String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
if (logChannel != null) {
TextChannel tc = event.getGuild().getTextChannelById(logChannel);
tc.sendMessage("`[" + hour + "]` " + "📣 `" + event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + "` just left `" + event.getGuild().getName() + "` `(User #" + event.getGuild().getMembers().size() + ")`").queue();
logTotal++;
}
String leaveChannel = MantaroData.db().getGuild(event.getGuild()).getData().getLogJoinLeaveChannel();
String leaveMessage = MantaroData.db().getGuild(event.getGuild()).getData().getLeaveMessage();
if (leaveChannel != null && leaveMessage != null) {
TextChannel tc = event.getGuild().getTextChannelById(leaveChannel);
if (leaveMessage.contains("$(")) {
Map<String, String> dynamicMap = new HashMap<>();
map("event", dynamicMap, event);
leaveMessage = dynamicResolve(leaveMessage, dynamicMap);
}
int c = leaveMessage.indexOf(':');
if (c != -1) {
String m = leaveMessage.substring(0, c);
String v = leaveMessage.substring(c + 1);
if (m.equals("embed")) {
EmbedJSON embed;
try {
embed = GsonDataManager.gson(false).fromJson('{' + v + '}', EmbedJSON.class);
} catch (Exception ignored) {
tc.sendMessage(EmoteReference.ERROR2 + "The string ``{" + v + "}`` isn't a valid JSON.").queue();
return;
}
tc.sendMessage(embed.gen(event)).queue();
return;
}
}
tc.sendMessage(leaveMessage).queue();
}
} catch (Exception e) {
}
}
use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class AudioRequester method loadSingle.
private void loadSingle(AudioTrack audioTrack, boolean silent) {
AudioTrackInfo trackInfo = audioTrack.getInfo();
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
String title = trackInfo.title;
long length = trackInfo.length;
long queueLimit = !Optional.ofNullable(dbGuild.getData().getMusicQueueSizeLimit()).isPresent() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit();
int fqSize = guildData.getMaxFairQueue();
if (getMusicManager().getTrackScheduler().getQueue().size() > queueLimit && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
if (!silent)
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Surpassed queue song limit!", title)).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
if (musicManager.getTrackScheduler().isStopped())
event.getGuild().getAudioManager().closeAudioConnection();
return;
}
if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 21 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
if (musicManager.getTrackScheduler().isStopped())
//do you?
event.getGuild().getAudioManager().closeAudioConnection();
return;
}
//Comparing if the URLs are the same to be 100% sure they're just not spamming the same url over and over again.
if (musicManager.getTrackScheduler().getQueue().stream().filter(track -> track.getInfo().uri.equals(audioTrack.getInfo().uri)).count() > fqSize) {
event.getChannel().sendMessage(EmoteReference.ERROR + String.format("**Surpassed fair queue level of %d (Too many songs which are exactly equal)**", fqSize + 1)).queue();
return;
}
musicManager.getTrackScheduler().queue(new AudioTrackContext(event.getAuthor(), event.getChannel(), audioTrack.getSourceManager() instanceof YoutubeAudioSourceManager ? "https://www.youtube.com/watch?v=" + audioTrack.getIdentifier() : trackUrl, audioTrack));
if (!silent) {
event.getChannel().sendMessage(String.format("📣 Added to queue -> **%s** **!(%s)**", title, AudioUtils.getLength(length))).queue();
}
}
use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class CommandRegistry method process.
public boolean process(GuildMessageReceivedEvent event, String cmdname, String content) {
Command cmd = commands.get(cmdname);
Config conf = MantaroData.config().get();
DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbg.getData();
if (cmd == null)
return false;
if (data.getDisabledCommands().contains(cmdname)) {
return false;
}
if (data.getChannelSpecificDisabledCommands().get(event.getChannel().getId()) != null && data.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).contains(cmdname)) {
return false;
}
if (data.getDisabledUsers().contains(event.getAuthor().getId())) {
return false;
}
if (MantaroData.db().getGuild(event.getGuild()).getData().getDisabledChannels().contains(event.getChannel().getId()) && cmd.category() != Category.MODERATION) {
return false;
}
if (MantaroData.config().get().isPremiumBot() && cmd.category() == Category.CURRENCY) {
return false;
}
if (data.getDisabledCategories().contains(cmd.category())) {
return false;
}
//If we are in the patreon bot, deny all requests from unknown guilds.
if (conf.isPremiumBot() && !conf.isOwner(event.getAuthor()) && !dbg.isPremium()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Seems like you're trying to use the Patreon bot when this guild is **not** marked as premium. " + "**If you think this is an error please contact Kodehawa#3457 or poke me on #donators in the support guild**").queue();
return false;
}
if (!cmd.permission().test(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.STOP + "You have no permissions to trigger this command").queue();
return false;
}
cmd.run(event, cmdname, content);
return true;
}
Aggregations