Added 5 minute Member role to NewMember workflow
This commit is contained in:
parent
19b2eef56b
commit
567a6585ae
@ -63,6 +63,9 @@ public class BotConfig {
|
||||
@ConfigurationOption
|
||||
public static String HYDRIX_ROLE = "hydrix role id here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String MEMBER_ROLE = "member role id here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String IMGUR_ID = "imgur_id_here";
|
||||
|
||||
|
@ -7,22 +7,32 @@ package dev.salmonllama.fsbot.listeners;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.database.controllers.ServerConfigController;
|
||||
import dev.salmonllama.fsbot.utilities.AddMemberRole;
|
||||
import org.javacord.api.event.server.member.ServerMemberJoinEvent;
|
||||
import org.javacord.api.listener.server.member.ServerMemberJoinListener;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NewMemberListener implements ServerMemberJoinListener {
|
||||
|
||||
ServerMemberJoinEvent event;
|
||||
|
||||
public void onServerMemberJoin(ServerMemberJoinEvent event) {
|
||||
this.event = event;
|
||||
|
||||
if (!event.getServer().getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
// Only active in the Fashionscape server, currently.
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Use the ServerConfig to retrieve the welcome channel as well.
|
||||
// Send the welcome message in the welcome channel
|
||||
event.getApi().getServerTextChannelById(BotConfig.WELCOME_CHANNEL).ifPresent( // Get the Welcome Channel
|
||||
channel -> ServerConfigController.get(event.getServer().getIdAsString()).thenAcceptAsync( // Fetch the server config, if set.
|
||||
possibleConfig -> possibleConfig.ifPresent( // If config exists
|
||||
config -> channel.sendMessage(String.format(config.getWelcomeMessage(), event.getUser().getMentionTag()))))); // Send the welcome message
|
||||
|
||||
// Add the Member role after 5 minutes
|
||||
var roleAdder = new AddMemberRole(event);
|
||||
event.getApi().getThreadPool().getScheduler().schedule(roleAdder, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package dev.salmonllama.fsbot.utilities;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import org.javacord.api.event.server.member.ServerMemberJoinEvent;
|
||||
|
||||
public class AddMemberRole implements Runnable{
|
||||
|
||||
ServerMemberJoinEvent event;
|
||||
|
||||
public AddMemberRole(ServerMemberJoinEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
event.getApi().getRoleById(BotConfig.MEMBER_ROLE).ifPresent(role -> role.addUser(event.getUser()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user