use of sx.blah.discord.api.events.EventSubscriber 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 sx.blah.discord.api.events.EventSubscriber 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 sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.
the class CreatorHandler method creatorCommands.
@EventSubscriber
public void creatorCommands(MessageReceivedEvent event) {
if (event.getAuthor().getLongID() != Globals.creatorID)
return;
List<Command> commands;
CommandObject command = new CommandObject(event.getMessage());
if (event.getChannel().isPrivate()) {
commands = new ArrayList<>(Globals.getCreatorCommands(true));
} else {
commands = new ArrayList<>(Globals.getCreatorCommands(false));
}
String message = event.getMessage().getContent();
for (Command c : commands) {
if (c.isCall(message, command)) {
String args = c.getArgs(message, command);
RequestHandler.sendMessage(c.execute(args, command), command.channel.get());
MessageHandler.handleLogging(command, c, args);
return;
}
}
}
use of sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.
the class CreatorHandler method restart.
@EventSubscriber
public void restart(MessageReceivedEvent event) {
CommandObject command = new CommandObject(event.getMessage());
Restart restart = new Restart();
if (restart.isCall(event.getMessage().getContent(), command)) {
List<Long> auth = new LinkedList<>();
try {
List<String> toParse = FileHandler.readFromFile(Constants.FILE_AUTH_TO_RESTART);
auth.addAll(toParse.stream().map(Long::parseUnsignedLong).collect(Collectors.toList()));
} catch (NumberFormatException e) {
// do nothing
}
auth.add(Globals.creatorID);
if (auth.contains(event.getAuthor().getLongID())) {
restart.execute("", command);
return;
}
}
}
use of sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.
the class GuildCreateListener method onGuildCreateEvent.
@EventSubscriber
public void onGuildCreateEvent(GuildCreateEvent event) {
IGuild guild = event.getGuild();
long guildID = guild.getLongID();
logger.debug("Starting Loading process for Guild with ID: " + guildID);
if (new File(Utility.getDirectory(guildID)).exists()) {
PatchHandler.guildPatches(guild);
}
FileHandler.createDirectory(Utility.getDirectory(guildID));
FileHandler.createDirectory(Utility.getDirectory(guildID, true));
FileHandler.createDirectory(Utility.getGuildImageDir(guildID));
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_INFO));
GuildObject guildObject = new GuildObject(guild);
Globals.initGuild(guildObject);
logger.info("Finished Loading Guild With ID: " + guildID);
}
Aggregations