use of net.dv8tion.jda.core.entities.TextChannel 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) {
}
}
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.
the class StuckVoiceConnection method run.
@Override
public void run() {
for (Shard shard : getShards()) {
for (Guild guild : shard.jda.getGuilds()) {
GuildMusicManager guildMusicManager = Music.getGuildAudioPlayer(guild, null, shard);
AudioPlayer player = guildMusicManager.player;
if (!player.isPaused() && guild.getAudioManager().getConnectedChannel() != null && guild.getAudioManager().getConnectedChannel().getMembers().size() > 1) {
AudioTrack playingTrack = player.getPlayingTrack();
if (playingTrack != null) {
long position = playingTrack.getPosition();
if (position == 0 || (position > 0 && !guild.getAudioManager().isConnected())) {
String textChannelId = voiceChannelsAtZeroDuration.get(guild.getId());
if (textChannelId == null) {
ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
TextChannel channel = ardentMusicManager.getChannel();
voiceChannelsAtZeroDuration.put(guild.getId(), channel.getId());
} else {
TextChannel channel = guild.getTextChannelById(textChannelId);
ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
if (ardentMusicManager != null) {
List<ArdentTrack> queue = ardentMusicManager.getQueueAsList();
shard.musicManagers.remove(Long.parseLong(guild.getId()));
GuildMusicManager manager = Music.getGuildAudioPlayer(guild, channel, shard);
for (ArdentTrack track : queue) {
manager.scheduler.manager.addToQueue(new ArdentTrack(track.getAuthor(), track.getAddedFrom(), track.getTrack().makeClone()));
}
} else
shard.musicManagers.remove(Long.parseLong(guild.getId()));
if (channel == null)
channel = guild.getPublicChannel();
try {
channel.sendMessage("I detected that my audio connection was stuck and reset my player. #BlameDiscord").queue();
} catch (Exception e) {
new BotException(e);
}
}
}
} else {
voiceChannelsAtZeroDuration.remove(guild.getId());
}
}
}
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.
the class TriviaChecker method check.
static void check(MessageReceivedEvent event) throws Exception {
if (event.isFromType(ChannelType.TEXT)) {
User user = event.getAuthor();
Guild guild = event.getGuild();
Shard shard = GuildUtils.getShard(guild);
TextChannel channel = event.getTextChannel();
for (Iterator<TriviaGame> iterator = Trivia.gamesInSession.iterator(); iterator.hasNext(); ) {
TriviaGame triviaGame = iterator.next();
if (triviaGame.getGuildId().equalsIgnoreCase(guild.getId()) && triviaGame.getTextChannelId().equalsIgnoreCase(channel.getId())) {
if (!triviaGame.isAnsweredCurrentQuestion()) {
if (triviaGame.isSolo() && !triviaGame.getCreator().equalsIgnoreCase(user.getId()))
return;
String content = event.getMessage().getContent();
if (triviaGame.getCurrentTriviaQuestion() != null) {
final boolean[] correct = { false };
triviaGame.getCurrentTriviaQuestion().getAnswers().forEach(a -> {
if (a.equalsIgnoreCase(content))
correct[0] = true;
});
if (correct[0]) {
triviaGame.addPoint(user);
shard.help.sendEditedTranslation("{0} got it right!", user, channel, user.getAsMention());
if (triviaGame.getRound() != triviaGame.getTotalRounds()) {
Trivia.dispatchRound(guild, channel, guild.getMemberById(triviaGame.getCreator()).getUser(), triviaGame, triviaGame.getEx());
} else
triviaGame.finish(shard, shard.help);
}
}
}
}
}
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.
the class GuildUtils method getChannelNames.
public static ArrayList<String> getChannelNames(ArrayList<String> ids, Guild guild) {
ArrayList<String> names = new ArrayList<>();
ids.forEach(id -> {
TextChannel channel = guild.getTextChannelById(id);
if (channel != null)
names.add(channel.getName());
});
return names;
}
Aggregations