Search in sources :

Example 1 with Rankable

use of tk.ardentbot.rethink.models.Rankable in project Ardent by adamint.

the class Join method onJoinUser.

@SubscribeEvent
public void onJoinUser(GuildMemberJoinEvent event) throws SQLException {
    userJoinEvents.add(Instant.now());
    Member joined = event.getMember();
    User joinedUser = joined.getUser();
    Guild guild = event.getGuild();
    Role role = DefaultRole.getDefaultRole(guild);
    if (role != null) {
        try {
            guild.getController().addRolesToMember(event.getMember(), role).queue();
        } catch (PermissionException ex) {
        }
    }
    Triplet<String, String, String> automessageSettings = Automessage.getMessagesAndChannel(guild);
    String channelId = automessageSettings.getA();
    String welcome = automessageSettings.getB();
    if (channelId != null && welcome != null) {
        TextChannel channel = guild.getTextChannelById(channelId);
        if (channel != null) {
            try {
                welcome = welcome.replace("{user}", joinedUser.getAsMention()).replace("{servername}", guild.getName()).replace("{amtusers}", String.valueOf(guild.getMembers().size()));
                channel.sendMessage(welcome).queue();
            } catch (PermissionException ex) {
            }
        }
    }
    GuildModel guildModel = BaseCommand.asPojo(r.table("guilds").get(guild.getId()).run(connection), GuildModel.class);
    guildModel.role_permissions.forEach(rolePermission -> {
        Rankable rankable = rolePermission.getRankable();
        if (rankable != null && rankable.getStartsOnServerJoin()) {
            rankable.getQueued().put(joinedUser.getId(), Instant.now().getEpochSecond());
        }
    });
}
Also used : DefaultRole(tk.ardentbot.commands.administration.DefaultRole) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildModel(tk.ardentbot.rethink.models.GuildModel) Rankable(tk.ardentbot.rethink.models.Rankable) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Aggregations

PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)1 SubscribeEvent (net.dv8tion.jda.core.hooks.SubscribeEvent)1 DefaultRole (tk.ardentbot.commands.administration.DefaultRole)1 GuildModel (tk.ardentbot.rethink.models.GuildModel)1 Rankable (tk.ardentbot.rethink.models.Rankable)1