Search in sources :

Example 1 with SubscribeEvent

use of net.dv8tion.jda.core.hooks.SubscribeEvent 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)

Example 2 with SubscribeEvent

use of net.dv8tion.jda.core.hooks.SubscribeEvent in project Ardent by adamint.

the class Join method onJoin.

@SubscribeEvent
public void onJoin(GuildJoinEvent event) {
    Guild guild = event.getGuild();
    Shard shard = GuildUtils.getShard(guild);
    Cursor<GuildModel> guilds = r.db("data").table("guilds").filter(r.hashMap("guild_id", guild.getId())).run(connection);
    if (!guilds.hasNext()) {
        TextChannel channel = guild.getPublicChannel();
        channel.sendMessage(welcomeText).queue();
        r.db("data").table("guilds").insert(r.hashMap("guild_id", guild.getId()).with("language", "english").with("prefix", "/").with("role_permissions", new ArrayList<>())).run(connection);
        String prefix = "/";
        shard.botPrefixData.set(guild, prefix);
        botJoinEvents.add(Instant.now());
        Status.commandsByGuild.put(guild.getId(), 0);
        shard.musicManagers.put(Long.parseLong(guild.getId()), new GuildMusicManager(shard.playerManager, null));
        Ardent.cleverbots.put(guild.getId(), shard.cleverBot.createSession());
        Ardent.sentAnnouncement.put(guild.getId(), false);
        Status.commandsByGuild.put(guild.getId(), 0);
        shard.executorService.schedule(() -> {
            guild.getOwner().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage("Thanks for adding Ardent. If you have questions or something isn't working, join over 300 people on our" + " support server @ https://discordapp.com/invite/rfGSxNA").queue());
        }, 3, TimeUnit.SECONDS);
    }
}
Also used : GuildModel(tk.ardentbot.rethink.models.GuildModel) GuildMusicManager(tk.ardentbot.commands.music.GuildMusicManager) Shard(tk.ardentbot.main.Shard) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Example 3 with SubscribeEvent

use of net.dv8tion.jda.core.hooks.SubscribeEvent in project Ardent by adamint.

the class OnMessage method onEvent.

@SubscribeEvent
public void onEvent(Event event) {
    Shard shard = GuildUtils.getShard(event.getJDA());
    shard.setLAST_EVENT(System.currentTimeMillis());
}
Also used : Shard(tk.ardentbot.main.Shard) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Example 4 with SubscribeEvent

use of net.dv8tion.jda.core.hooks.SubscribeEvent in project Ardent by adamint.

the class Leave method onLeave.

@SubscribeEvent
public void onLeave(GuildLeaveEvent event) {
    botLeaveEvents.add(Instant.now());
    Guild guild = event.getGuild();
    Shard shard = GuildUtils.getShard(guild);
    String id = guild.getId();
    Ardent.cleverbots.remove(id);
    shard.botPrefixData.remove(guild);
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) Shard(tk.ardentbot.main.Shard) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Example 5 with SubscribeEvent

use of net.dv8tion.jda.core.hooks.SubscribeEvent in project Ardent by adamint.

the class Leave method onUserLeave.

@SubscribeEvent
public void onUserLeave(GuildMemberLeaveEvent event) throws SQLException {
    userLeaveEvents.add(Instant.now());
    Guild guild = event.getGuild();
    Member left = event.getMember();
    Triplet<String, String, String> automessageSettings = Automessage.getMessagesAndChannel(guild);
    String channelId = automessageSettings.getA();
    String leave = automessageSettings.getC();
    if (channelId != null && leave != null) {
        TextChannel channel = guild.getTextChannelById(channelId);
        if (channel != null) {
            try {
                leave = leave.replace("{user}", left.getUser().getName()).replace("{servername}", guild.getName()).replace("{amtusers}", String.valueOf(guild.getMembers().size()));
                channel.sendMessage(leave).queue();
            } catch (PermissionException ex) {
            }
        }
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Aggregations

SubscribeEvent (net.dv8tion.jda.core.hooks.SubscribeEvent)6 Shard (tk.ardentbot.main.Shard)4 Guild (net.dv8tion.jda.core.entities.Guild)3 Member (net.dv8tion.jda.core.entities.Member)2 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)2 GuildModel (tk.ardentbot.rethink.models.GuildModel)2 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 DefaultRole (tk.ardentbot.commands.administration.DefaultRole)1 GuildMusicManager (tk.ardentbot.commands.music.GuildMusicManager)1 BotException (tk.ardentbot.core.misc.logging.BotException)1 AdvertisingInfraction (tk.ardentbot.rethink.models.AdvertisingInfraction)1 AntiAdvertisingSettings (tk.ardentbot.rethink.models.AntiAdvertisingSettings)1 Rankable (tk.ardentbot.rethink.models.Rankable)1