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());
}
});
}
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);
}
}
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());
}
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);
}
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) {
}
}
}
}
Aggregations