Skip to content

Commit

Permalink
Added EventsModule
Browse files Browse the repository at this point in the history
  • Loading branch information
EazyFTW committed Oct 3, 2020
1 parent de66574 commit 80d3c2d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/me/TechsCode/TechDiscordBot/logs/ServerLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ public class ServerLogs {

private static final long CHANNEL_ID = 761382066633572373L;

public static boolean log(String msg) {
return sendChannel("Log", msg, null);
}

public static boolean log(String title, String msg) {
return sendChannel(title, msg, null);
}

public static boolean log(String msg) {
return sendChannel("Log", msg, null);
public static boolean log(TechEmbedBuilder embed) {
return sendChannel(embed);
}

public static boolean error(Exception ex) {
Expand All @@ -27,6 +31,16 @@ public static boolean error(String error) {
return sendChannel("Error", "```" + error + "```", new Color(178,34,34));
}

private static boolean sendChannel(TechEmbedBuilder embed) {
try {
embed.send(Objects.requireNonNull(TechDiscordBot.getJDA().getTextChannelById(CHANNEL_ID)));

return true;
} catch (Exception ex) {
return false;
}
}

private static boolean sendChannel(String title, String msg, Color color) {
try {
new TechEmbedBuilder(title)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package me.TechsCode.TechDiscordBot.module.modules;

import me.TechsCode.TechDiscordBot.TechDiscordBot;
import me.TechsCode.TechDiscordBot.logs.ServerLogs;
import me.TechsCode.TechDiscordBot.module.Module;
import me.TechsCode.TechDiscordBot.objects.Requirement;
import me.TechsCode.TechDiscordBot.util.TechEmbedBuilder;
import net.dv8tion.jda.api.events.guild.GuildBanEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.hooks.SubscribeEvent;

public class EventsModule extends Module {

public EventsModule(TechDiscordBot bot) {
super(bot);
}

@Override
public void onEnable() {

}

@SubscribeEvent
public void memberJoin(GuildMemberJoinEvent e) {
ServerLogs.log(
new TechEmbedBuilder("Member Joined!")
.success()
.setText("Welcome " + e.getMember().getAsMention() + "(" + e.getUser().getName() + "#" + e.getUser().getDiscriminator() + ", " + e.getUser().getId() + ")")
.setThumbnail(e.getMember().getUser().getAvatarUrl())
);
}

@SubscribeEvent
public void memberLeave(GuildMemberRemoveEvent e) {
ServerLogs.log(
new TechEmbedBuilder("Member Left!")
.error()
.setText(e.getUser().getAsMention() + "(" + e.getUser().getName() + "#" + e.getUser().getDiscriminator() + ", " + e.getUser().getId() + ")")
.setThumbnail(e.getUser().getAvatarUrl())
);
}

@SubscribeEvent
public void memberBan(GuildBanEvent e) {
ServerLogs.log(
new TechEmbedBuilder("Member Banned!")
.error()
.setText("Don't say goodbye to " + e.getUser().getAsMention() + "(" + e.getUser().getName() + "#" + e.getUser().getDiscriminator() + ", " + e.getUser().getId() + ")")
.setThumbnail(e.getUser().getAvatarUrl())
);
}

@Override
public void onDisable() {}

@Override
public String getName() {
return "Events";
}

@Override
public Requirement[] getRequirements() {
return new Requirement[0];
}
}

0 comments on commit 80d3c2d

Please sign in to comment.