Welcome and Join Role Prep, just need a settings command to configure it now.
This commit is contained in:
parent
12d3d1e486
commit
8e128979fc
|
@ -1,14 +1,22 @@
|
||||||
package moe.oko.Kiafumi.listener;
|
package moe.oko.Kiafumi.listener;
|
||||||
|
|
||||||
import moe.oko.Kiafumi.Kiafumi;
|
import moe.oko.Kiafumi.Kiafumi;
|
||||||
|
import moe.oko.Kiafumi.model.Server;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||||
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
|
||||||
import net.dv8tion.jda.api.events.user.update.GenericUserPresenceEvent;
|
import net.dv8tion.jda.api.events.user.update.GenericUserPresenceEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
@ -73,4 +81,48 @@ public class MainListener extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
|
||||||
|
Server server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
||||||
|
if(server.getJoinRole() != null) {
|
||||||
|
try {
|
||||||
|
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(server.getJoinRole())).queue();
|
||||||
|
} catch(Exception ex) {
|
||||||
|
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", role did not exist.**").queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(server.isWelcomeEnabled()) {
|
||||||
|
TextChannel textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
||||||
|
if(textChannel == null) {
|
||||||
|
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send welcome message, welcome channel doesn't exist.**").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Ok, now we proceed.
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder()
|
||||||
|
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
|
||||||
|
+ event.getMember().getId() + ")", null, event.getMember().getAvatarUrl()).setFooter("User Joined").setTimestamp(OffsetDateTime.now())
|
||||||
|
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated()).setColor(Color.GREEN);
|
||||||
|
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
|
||||||
|
Server server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
||||||
|
if(server.isWelcomeEnabled()) {
|
||||||
|
TextChannel textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
||||||
|
if(textChannel == null) {
|
||||||
|
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send leave message, welcome channel doesn't exist.**").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Ok, now we proceed.
|
||||||
|
DateTimeFormatter dTF = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder()
|
||||||
|
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
|
||||||
|
+ event.getMember().getId() + ")", null, event.getMember().getAvatarUrl()).setFooter("User Left").setTimestamp(OffsetDateTime.now())
|
||||||
|
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF)).setColor(Color.RED);
|
||||||
|
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,16 @@ public class Server {
|
||||||
*/
|
*/
|
||||||
public String getId() { return id; }
|
public String getId() { return id; }
|
||||||
|
|
||||||
|
public String getJoinRole() { return joinRole; }
|
||||||
|
|
||||||
|
public boolean isWelcomeEnabled() {
|
||||||
|
return welcomeEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWelcomeChannel() {
|
||||||
|
return welcomeChannel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the modification of the server file in memory
|
* Checks the modification of the server file in memory
|
||||||
* @return - whether the server settings have been modified
|
* @return - whether the server settings have been modified
|
||||||
|
|
Loading…
Reference in a new issue