use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class WarningsCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("stats")) {
Map.Entry<String, List<String>> highestEntry = Collections.max(guild.getWarningsMap().entrySet(), Comparator.comparingInt(entry -> entry.getValue().size()));
User mostWarned = GuildUtils.getUser(highestEntry.getKey(), guild.getGuildId(), true);
channel.sendMessage(new EmbedBuilder().setTitle("Warning stats", null).addField("Total Warnings", String.valueOf(guild.getWarningsMap().values().stream().mapToLong(List::size).sum()), true).addField("Users warned", String.valueOf(guild.getWarningsMap().size()), true).addField("Most warned user", MessageUtils.getTag(mostWarned) + " - " + highestEntry.getValue().size() + " warnings", true).setColor(Color.CYAN).build()).queue();
} else {
User user = GuildUtils.getUser(args[0]);
if (user == null) {
MessageUtils.sendErrorMessage("That user could not be found!!", channel);
return;
}
StringBuilder sb = new StringBuilder();
List<String> tmp = guild.getUserWarnings(user);
List<String> warnings = tmp.subList(Math.max(tmp.size() - 5, 0), tmp.size());
int i = 1;
for (String warning : warnings) {
sb.append(i).append(". ").append(warning.substring(0, Math.min(725, warning.length()))).append(warning.length() > 725 ? "..." : "").append("\n");
i++;
}
EmbedBuilder eb = new EmbedBuilder().setTitle("Warnings for " + user.getName()).addField("Warning count", String.valueOf(tmp.size()), true).addField("Last 5 warnings", "```md\n" + sb.toString().trim() + "\n```", false).setColor(Color.CYAN);
channel.sendMessage(eb.build()).queue();
}
} else {
MessageUtils.sendUsage(this, channel, sender, args);
}
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class Events method handleCommand.
private void handleCommand(GuildMessageReceivedEvent event, Command cmd, String[] args) {
Metrics.commandsReceived.labels(cmd.getClass().getSimpleName()).inc();
GuildWrapper guild = flareBot.getManager().getGuild(event.getGuild().getId());
if (cmd.getType().isInternal()) {
if (GeneralUtils.canRunInternalCommand(cmd.getType(), event.getAuthor())) {
dispatchCommand(cmd, args, event, guild);
return;
} else {
GeneralUtils.sendImage("https://flarebot.stream/img/trap.jpg", "trap.jpg", event.getAuthor());
Constants.logEG("It's a trap", cmd, guild.getGuild(), event.getAuthor());
return;
}
}
if (guild.hasBetaAccess()) {
if ((guild.getSettings().getChannelBlacklist().contains(event.getChannel().getIdLong()) || guild.getSettings().getUserBlacklist().contains(event.getAuthor().getIdLong())) && !guild.getPermissions().hasPermission(event.getMember(), stream.flarebot.flarebot.permissions.Permission.BLACKLIST_BYPASS))
return;
}
if (guild.isBlocked() && System.currentTimeMillis() > guild.getUnBlockTime() && guild.getUnBlockTime() != -1)
guild.revokeBlock();
handleSpamDetection(event, guild);
if (guild.isBlocked() && !(cmd.getType() == CommandType.SECRET))
return;
if (handleMissingPermission(cmd, event))
return;
if (!guild.hasBetaAccess() && cmd.isBetaTesterCommand()) {
if (flareBot.isTestBot())
LOGGER.error("Guild " + event.getGuild().getId() + " tried to use the beta command '" + cmd.getCommand() + "'!");
return;
}
if (FlareBot.UPDATING.get()) {
event.getChannel().sendMessage("**Currently updating!**").queue();
return;
}
if (flareBot.getManager().isCommandDisabled(cmd.getCommand())) {
MessageUtils.sendErrorMessage(flareBot.getManager().getDisabledCommandReason(cmd.getCommand()), event.getChannel(), event.getAuthor());
return;
}
// Internal stuff
if (event.getGuild().getIdLong() == Constants.OFFICIAL_GUILD && !handleOfficialGuildStuff(event, cmd))
return;
dispatchCommand(cmd, args, event, guild);
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class PlayerListener method onTrackEnd.
@Override
public void onTrackEnd(AudioPlayer aplayer, AudioTrack atrack, AudioTrackEndReason reason) {
GuildWrapper wrapper = FlareBotManager.instance().getGuild(player.getGuildId());
// No song on next
if (player.getPlaylist().isEmpty()) {
FlareBotManager.instance().getLastActive().put(Long.parseLong(player.getGuildId()), System.currentTimeMillis());
}
VoteUtil.remove(SkipCommand.getSkipUUID(), wrapper.getGuild());
if (wrapper.isSongnickEnabled()) {
if (GuildUtils.canChangeNick(player.getGuildId())) {
Guild c = wrapper.getGuild();
if (c == null) {
wrapper.setSongnick(false);
} else {
if (player.getPlaylist().isEmpty())
c.getController().setNickname(c.getSelfMember(), null).queue();
}
} else {
if (!GuildUtils.canChangeNick(player.getGuildId())) {
MessageUtils.sendPM(Getters.getGuildById(player.getGuildId()).getOwner().getUser(), "FlareBot can't change it's nickname so SongNick has been disabled!");
}
}
}
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class HelpCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length == 1) {
CommandType type;
try {
type = CommandType.valueOf(args[0].toUpperCase());
} catch (IllegalArgumentException ignored) {
channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
return;
}
if (GeneralUtils.canRunInternalCommand(type, sender)) {
List<String> pages = new ArrayList<>();
List<String> help = type.getCommands().stream().filter(cmd -> getPermissions(channel).hasPermission(member, cmd.getPermission())).map(command -> guild.getPrefix() + command.getCommand() + " - " + command.getDescription() + '\n').collect(Collectors.toList());
StringBuilder sb = new StringBuilder();
for (String s : help) {
if (sb.length() + s.length() > 1024) {
pages.add(sb.toString());
sb.setLength(0);
}
sb.append(s);
}
pages.add(sb.toString());
PagedEmbedBuilder<String> builder = new PagedEmbedBuilder<>(new PaginationList<>(pages));
builder.setTitle("***FlareBot " + type + " commands!***");
builder.setColor(Color.CYAN);
PaginationUtil.sendEmbedPagedMessage(builder.build(), 0, channel, sender, ButtonGroupConstants.HELP);
} else {
channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
}
} else {
sendCommands(channel.getGuild(), channel, sender);
}
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class Events method onGuildMemberJoin.
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
if (event.getMember().getUser().isBot() || event.getMember().getUser().isFake())
return;
PlayerCache cache = flareBot.getPlayerCache(event.getMember().getUser().getId());
cache.setLastSeen(LocalDateTime.now());
GuildWrapper wrapper = FlareBotManager.instance().getGuild(event.getGuild().getId());
if (wrapper == null)
return;
if (wrapper.isBlocked())
return;
if (flareBot.getManager().getGuild(event.getGuild().getId()).getWelcome() != null) {
Welcome welcome = wrapper.getWelcome();
if ((welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null) || welcome.isDmEnabled()) {
if (welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null && welcome.isGuildEnabled()) {
TextChannel channel = Getters.getChannelById(welcome.getChannelId());
if (channel == null || !channel.canTalk()) {
welcome.setGuildEnabled(false);
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Cannot send welcome messages in " + (channel == null ? welcome.getChannelId() : channel.getAsMention()) + " due to this, welcomes have been disabled!");
return;
}
if (welcome.isGuildEnabled()) {
String guildMsg = VariableUtils.parseVariables(welcome.getRandomGuildMessage(), wrapper, null, event.getUser());
// Deprecated values
guildMsg = guildMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
channel.sendMessage(guildMsg).queue();
if (guildMsg.contains("%user%") || guildMsg.contains("%guild%") || guildMsg.contains("%mention%")) {
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your guild welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
}
}
}
if (welcome.isDmEnabled()) {
// We can't DM other bots.
if (event.getMember().getUser().isBot())
return;
String dmMsg = VariableUtils.parseVariables(welcome.getRandomDmMessage(), wrapper, null, event.getUser());
// Deprecated values
dmMsg = dmMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
MessageUtils.sendPM(event.getMember().getUser(), dmMsg);
if (dmMsg.contains("%user%") || dmMsg.contains("%guild%") || dmMsg.contains("%mention%")) {
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your DM welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
}
}
} else
welcome.setGuildEnabled(false);
}
if (event.getMember().getUser().isBot())
return;
if (!wrapper.getAutoAssignRoles().isEmpty()) {
Set<String> autoAssignRoles = wrapper.getAutoAssignRoles();
List<Role> roles = new ArrayList<>();
for (String s : autoAssignRoles) {
Role role = event.getGuild().getRoleById(s);
if (role != null) {
roles.add(role);
} else
autoAssignRoles.remove(s);
}
try {
event.getGuild().getController().addRolesToMember(event.getMember(), roles).queue((n) -> {
}, e1 -> handle(e1, event, roles));
StringBuilder sb = new StringBuilder("```\n");
for (Role role : roles) {
sb.append(role.getName()).append(" (").append(role.getId()).append(")\n");
}
sb.append("```");
ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.FLAREBOT_AUTOASSIGN_ROLE, event.getUser(), new MessageEmbed.Field("Roles", sb.toString(), false));
} catch (Exception e1) {
handle(e1, event, roles);
}
}
}
Aggregations