use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class TimerHandler method dailyMessageHandler.
private static void dailyMessageHandler(TimedEvent event) {
ZonedDateTime timeNow = ZonedDateTime.now(ZoneOffset.UTC);
DayOfWeek day = timeNow.getDayOfWeek();
logger.info("Running Daily tasks for " + day);
Random random = new Random();
for (GuildObject task : Globals.getGuilds()) {
GuildConfig guildconfig = task.config;
// do decay
GuildHandler.dailyTask(task);
// reset offenders
task.resetOffenders();
// getToggles general channel
IChannel generalChannel = task.getChannelByType(ChannelSetting.GENERAL);
// do daily messages
if (generalChannel != null && guildconfig.dailyMessage) {
DailyMessage finalMessage;
List<DailyMessage> messages;
if (event != null && event.doSpecialMessages() && event.getMessagesDay(day).size() != 0) {
messages = event.getMessagesDay(day);
} else {
messages = new ArrayList<>(Globals.getDailyMessages().getDailyMessages(day));
messages.add(Globals.getDailyMessage(day));
}
int randomMessage = random.nextInt(messages.size());
finalMessage = messages.get(randomMessage);
task.config.setLastDailyMessage(finalMessage);
CommandObject command = new CommandObject(task, generalChannel);
RequestHandler.sendMessage(finalMessage.getContents(command), generalChannel);
}
}
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class SettingsStage method stepText.
@Override
public void stepText(CommandObject command) {
StringHandler output = new StringHandler();
output.append("Next step is to pick which settings you want to use.\n").append("There's a lot of settings in modules, and those will be set there.\n").append("Here's a list of the settings that aren't tied to any specific module.\n");
// Get the settings and modules.
List<GuildToggle> globalToggles = ToggleInit.getToggles(false);
List<GuildToggle> modules = ToggleInit.getToggles(true);
// Sort settings
globalToggles.sort(Comparator.comparing(GuildToggle::name));
// Init additional vars
List<String> enabled = new ArrayList<>();
List<String> disabled = new ArrayList<>();
String format = "\t> **%s** - %s\n";
// skip debug mode after it's defaulted to off:
if (!new DebugMode().getDefault()) {
globalToggles.removeIf(t -> t.name() == SAILType.DEBUG_MODE);
}
// Filter toggles that are not part of modules.
List<SAILType> types = new LinkedList<>();
modules.forEach(t -> types.addAll(t.settings.stream().map(s -> s.name()).collect(Collectors.toList())));
ListIterator iterator = globalToggles.listIterator();
while (iterator.hasNext()) {
GuildToggle toggle = (GuildToggle) iterator.next();
if (types.contains(toggle.name())) {
// Is part of a module, remove from list
iterator.remove();
} else {
// is not, get extra information...
if (toggle.enabled(command.guild.config))
enabled.add(toggle.name().toString());
else
disabled.add(toggle.name().toString());
// append to list of things.
output.appendFormatted(format, toggle.name().toString(), toggle.shortDesc(command));
}
}
// Send message
output.append("\nYou can switch settings on and off with **" + Command.get(Toggle.class).getCommand(command) + "** and get more info on each setting with **" + Command.get(HelpSettings.class).getCommand(command) + "**.");
// Append additional enabled/disabled state info.
XEmbedBuilder embed = new XEmbedBuilder(command);
embed.withTitle("Global Settings");
embed.appendField("Enabled", "```" + Utility.listFormatter(enabled, true) + "```", false);
embed.appendField("Disabled", "```" + Utility.listFormatter(disabled, true) + "```", false);
RequestHandler.sendEmbedMessage(output.toString(), embed, command.channel);
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class AnnotationListener method onMessageReceivedEvent.
@EventSubscriber
public void onMessageReceivedEvent(MessageReceivedEvent event) {
if (!Globals.isReady)
return;
try {
if (event.getAuthor().isBot())
return;
CommandObject command = new CommandObject(event.getMessage());
// Set Console Response Channel.
if (command.user.get().equals(command.client.creator)) {
Globals.consoleMessageCID = command.channel.longID;
}
command.guild.handleWelcome(command);
// message and command handling
new MessageHandler(command.message.get().getContent(), command, event.getChannel().isPrivate());
} catch (Exception e) {
String errorPos = "";
for (StackTraceElement s : e.getStackTrace()) {
if (s.toString().contains("com.github.vaerys")) {
errorPos = s.toString();
break;
}
}
StringBuilder builder = new StringBuilder();
builder.append("> I caught an Error, Please send this Error message and the message that caused this error " + "to my **Direct Messages** so my developer can look at it and try to solve the issue.\n```\n");
builder.append(e.getClass().getName());
builder.append(": " + e.getMessage());
if (!errorPos.isEmpty()) {
builder.append("\n" + Constants.PREFIX_INDENT + "at " + errorPos);
}
builder.append("```");
RequestHandler.sendMessage(builder.toString(), event.getChannel());
Globals.addToLog(new LogObject("ERROR", "MESSAGE_HANDLER", event.getMessage().getContent(), event.getChannel().getLongID(), event.getAuthor().getLongID(), event.getMessageID(), event.getGuild().getLongID()));
Utility.sendStack(e);
}
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class AnnotationListener method onReactionAddEvent.
@EventSubscriber
public void onReactionAddEvent(ReactionAddEvent event) {
if (event.getUser().isBot()) {
return;
}
ReactionEmoji x = Utility.getReaction("x");
ReactionEmoji pin = Utility.getReaction(Constants.EMOJI_ADD_PIN);
ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
ReactionEmoji heart = Utility.getReaction(Constants.EMOJI_LIKE_PIN);
ReactionEmoji remove = Utility.getReaction(Constants.EMOJI_REMOVE_PIN);
ReactionEmoji emoji = event.getReaction().getEmoji();
if (emoji == null)
return;
IMessage message = event.getMessage();
if (message == null)
message = event.getChannel().getMessageByID(event.getMessageID());
CommandObject object = new CommandObject(message);
UserObject pinner = new UserObject(event.getUser(), object.guild);
UserObject owner = new UserObject(event.getAuthor(), object.guild);
// do only on server channels
if (!event.getChannel().isPrivate() && emoji.isUnicode()) {
// if is x and can bypass
if (emoji.equals(remove))
ArtHandler.unPin(object);
if (emoji.equals(x) && GuildHandler.testForPerms(object, Permissions.MANAGE_MESSAGES) && object.client.bot.longID == object.user.longID)
RequestHandler.deleteMessage(object.message);
// if is pushpin
if (emoji.equals(pin))
ArtHandler.pinMessage(object, pinner, owner);
// if is thumbsup or thumbs down and is creator.
if (emoji.equals(thumbsUp) || emoji.equals(thumbsDown))
QueueHandler.reactionAdded(object, event.getReaction());
// if is hear and is pinned then give xp
if (emoji.equals(heart))
ArtHandler.pinLiked(object, pinner, owner);
// do only within Direct messages
} else if (event.getChannel().isPrivate() && emoji.isUnicode()) {
// if anyone uses x
if (emoji.equals(x) && object.client.bot.longID == object.user.longID) {
RequestHandler.deleteMessage(message);
}
}
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class Utility method getUser.
public static UserObject getUser(CommandObject command, String args, boolean doContains, boolean hasProfile) {
if (args != null && !args.isEmpty()) {
IUser user = null;
IUser conUser = null;
String toTest;
if (args.split(" ").length != 1) {
toTest = escapeRegex(args);
} else {
toTest = escapeRegex(args).replace("_", "[_| ]");
}
List<IUser> guildUsers = command.guild.getUsers();
guildUsers.sort(Comparator.comparing(o -> o.getRolesForGuild(command.guild.get()).size()));
Collections.reverse(guildUsers);
for (IUser u : guildUsers) {
if (user != null) {
break;
}
try {
UserObject object = new UserObject(u, command.guild, true);
if (hasProfile) {
ProfileObject profile = object.getProfile(command.guild);
if (profile == null || profile.isEmpty())
continue;
}
if ((u.getName() + "#" + u.getDiscriminator()).matches("(?i)" + toTest)) {
user = u;
}
if (u.getName().matches("(?i)" + toTest) && user == null) {
user = u;
}
String displayName = u.getDisplayName(command.guild.get());
if (displayName.matches("(?i)" + toTest) && user == null) {
user = u;
}
if (doContains && conUser == null) {
if (u.getName().matches("(?i).*" + toTest + ".*")) {
conUser = u;
}
if (displayName.matches("(?i).*" + toTest + ".*") && conUser == null) {
conUser = u;
}
}
} catch (PatternSyntaxException e) {
// continue.
}
}
UserObject userObject = null;
try {
long uID = Long.parseLong(args);
return new UserObject(uID, command.guild);
} catch (NumberFormatException e) {
if (command.message.get().getMentions().size() > 0) {
user = command.message.get().getMentions().get(0);
}
}
if (user == null && doContains) {
user = conUser;
}
if (user != null) {
userObject = new UserObject(user, command.guild);
}
return userObject;
}
return null;
}
Aggregations