use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.
the class SetupWizard method execute.
@Override
public String execute(String args, CommandObject command) {
if (SetupHandler.isRunningSetup(command.guild)) {
return "> Setup is already running for this guild. I can't run it twice!";
}
// user can only run setup for one guild at a time
UserObject user = command.user;
for (GuildObject guildObject : Globals.getGuilds()) {
if (guildObject.config.setupUser == user.longID) {
return "> You're running setup for a different guild. I can't do more than one at a time.";
}
}
// Handle Setup beginning
String message = "Hi! I'm " + command.client.bot.displayName + " and I'm here to help you get your server set up.\n" + "This guide will walk you through a bunch of commands and things you can do to make your server exactly the way you want it.\n\n" + "You can navigate forwards and backwards in this setup with **" + new SetupBack().getUsage(command) + "** and **" + new SetupNext().getUsage(command) + "**";
if (command.user.sendDm(message) == null) {
return "> **ERROR**: I wasn't able to send you a DM! Check your server privacy settings!";
}
// send first setup stage response
SetupHandler.setSetupStage(command, SetupStage.SETUP_MODULES);
return "> Check your DMs for more instructions.";
}
use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.
the class LoggingHandler method doRoleUpdateLog.
public static void doRoleUpdateLog(UserRoleUpdateEvent event) {
IGuild guild = event.getGuild();
GuildObject content = Globals.getGuildContent(guild.getLongID());
if (!content.config.moduleLogging)
return;
if (content.config.userRoleLogging) {
ArrayList<String> oldRoles = new ArrayList<>();
ArrayList<String> newRoles = new ArrayList<>();
oldRoles.addAll(event.getOldRoles().stream().filter(r -> !r.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
newRoles.addAll(event.getNewRoles().stream().filter(r -> !r.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
StringBuilder oldRoleList = new StringBuilder();
StringBuilder newRoleList = new StringBuilder();
for (String r : oldRoles) {
oldRoleList.append(r + ", ");
}
for (String r : newRoles) {
newRoleList.append(r + ", ");
}
String prefix = "> **@" + event.getUser().getName() + "#" + event.getUser().getDiscriminator() + "'s** Role have been Updated.";
Utility.sendLog(prefix + "\nOld Roles: " + Utility.listFormatter(oldRoles, true) + "\nNew Roles: " + Utility.listFormatter(newRoles, true), content, false);
}
}
use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.
the class LoggingHandler method doChannelUpdateLog.
public static void doChannelUpdateLog(ChannelUpdateEvent event) {
GuildObject content = Globals.getGuildContent(event.getGuild().getLongID());
if (event.getNewChannel() instanceof IVoiceChannel) {
// TODO: 26/03/2018 Add support for voice Channels.
return;
}
if (!content.config.moduleLogging)
return;
if (content.config.channelLogging) {
if (!event.getOldChannel().getName().equalsIgnoreCase(event.getNewChannel().getName())) {
String log = "> Channel " + event.getNewChannel().mention() + "'s name was changed.\nOld name : #" + event.getOldChannel().getName() + ".";
Utility.sendLog(log, content, false);
} else if ((event.getOldChannel().getTopic() == null || event.getOldChannel().getTopic().isEmpty()) && (event.getNewChannel().getTopic() == null || event.getNewChannel().getTopic().isEmpty())) {
// do nothing
} else if ((event.getOldChannel().getTopic() == null || event.getOldChannel().getTopic().isEmpty()) && (event.getNewChannel().getTopic() != null || !event.getNewChannel().getTopic().isEmpty())) {
StringBuilder log = new StringBuilder("> Channel " + event.getNewChannel().mention() + "'s Channel topic was added.\n");
log.append("**New Topic**: " + event.getNewChannel().getTopic());
Utility.sendLog(log.toString(), content, false);
} else if ((event.getOldChannel().getTopic() != null || !event.getOldChannel().getTopic().isEmpty()) && (event.getNewChannel().getTopic() == null || event.getNewChannel().getTopic().isEmpty())) {
StringBuilder log = new StringBuilder("> Channel " + event.getNewChannel().mention() + "'s Channel topic was removed.\n");
log.append("**Old Topic**: " + event.getOldChannel().getTopic());
Utility.sendLog(log.toString(), content, false);
} else if (!event.getOldChannel().getTopic().equalsIgnoreCase(event.getNewChannel().getTopic())) {
StringBuilder log = new StringBuilder("> Channel " + event.getNewChannel().mention() + "'s Channel topic was changed.");
log.append("\n**Old Topic**: " + event.getOldChannel().getTopic());
log.append("\n**New Topic**: " + event.getNewChannel().getTopic());
Utility.sendLog(log.toString(), content, false);
}
}
}
use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.
the class LoggingHandler method doBanLog.
public static void doBanLog(UserBanEvent event) {
IGuild guild = event.getGuild();
GuildObject guildObject = Globals.getGuildContent(guild.getLongID());
if (!guildObject.config.banLogging || !GuildHandler.testForPerms(Client.getClient().getOurUser(), guild, Permissions.VIEW_AUDIT_LOG))
return;
StringHandler output = new StringHandler("> **@%s#%s** was banned");
output.setContent(String.format(output.toString(), event.getUser().getName(), event.getUser().getDiscriminator()));
// get recent bans
List<TargetedEntry> recentBans = event.getGuild().getAuditLog(ActionType.MEMBER_BAN_ADD).getEntriesByTarget(event.getUser().getLongID());
if (recentBans.size() == 0)
return;
// and sort them. last entry is most recent.
recentBans.sort(Comparator.comparingLong(o -> DiscordUtils.getSnowflakeTimeFromID(o.getLongID()).toEpochMilli()));
AuditLogEntry lastBan = recentBans.get(recentBans.size() - 1);
output.appendFormatted(" by **@%s#%s**", lastBan.getResponsibleUser().getName(), lastBan.getResponsibleUser().getDiscriminator());
String reason = lastBan.getReason().isPresent() ? lastBan.getReason().get() : "No reason provided";
output.appendFormatted(" with reason `%s`", reason);
Utility.sendLog(output.toString(), guildObject, true);
}
use of com.github.vaerys.masterobjects.GuildObject in project DiscordSailv2 by Vaerys-Dawn.
the class LoggingHandler method doKickLog.
/**
* Handler for logging Kicks.
*
* @param guild the Guild the user left.
* @param user the User that left the server.
*/
private static void doKickLog(IGuild guild, IUser user) {
IUser botUser = Client.getClient().getOurUser();
// test if the bot has auditLog perms
if (!GuildHandler.testForPerms(botUser, guild, Permissions.VIEW_AUDIT_LOG))
return;
// getTimestamp
long timeStamp = Instant.now().atZone(ZoneOffset.UTC).toEpochSecond() * 1000;
// build Message
StringHandler kickLog = new StringHandler("**@%s#%d** has been **Kicked** by **@%s#%d**");
// do some checks to make sure the user was in fact kicked
List<TargetedEntry> kicksLog = guild.getAuditLog(ActionType.MEMBER_KICK).getEntriesByTarget(user.getLongID());
if (kicksLog.size() == 0)
return;
// sort kickLog and get latest entry
kicksLog.sort(Comparator.comparingLong(o -> DiscordUtils.getSnowflakeTimeFromID(o.getLongID()).toEpochMilli()));
AuditLogEntry lastKick = kicksLog.get(kicksLog.size() - 1);
// get the latest entry's timestamp
long lastKickTime = DiscordUtils.getSnowflakeTimeFromID(lastKick.getLongID()).toEpochMilli();
// get user responsible
IUser responsible = lastKick.getResponsibleUser();
// Check if timestamp is within fifteen seconds either way, lastKick is valid.
long timeDiff = Math.abs(timeStamp - lastKickTime);
if (timeDiff > 15000)
return;
// format and send message
kickLog.format(user.getName(), user.getDiscriminator(), responsible.getName(), responsible.getName());
if (lastKick.getReason().isPresent()) {
kickLog.appendFormatted(" with reason `%s`", lastKick.getReason().get());
}
// send log
GuildObject content = Globals.getGuildContent(guild.getLongID());
Utility.sendLog(kickLog.toString(), content, true);
}
Aggregations