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 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 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 Rubicon by Rubicon-Bot.
the class CommandPortal method portalInfo.
private void portalInfo(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
String entry = RubiconBot.getMySQL().getGuildValue(parsedCommandInvocation.getGuild(), "portal");
TextChannel channel = parsedCommandInvocation.getTextChannel();
if (entry.equals("open")) {
Guild guild = RubiconBot.getJDA().getGuildById(RubiconBot.getMySQL().getPortalValue(parsedCommandInvocation.getGuild(), "partnerid"));
SafeMessage.sendMessage(channel, EmbedUtil.info("Connected to " + guild.getName(), "This server is currently connected to `" + guild.getName() + "`!").build(), 8);
} else if (entry.equals("waiting")) {
SafeMessage.sendMessage(channel, EmbedUtil.error("Portal is waitng", "The portal is currently waiting to be accepted by the other side").build(), 5);
} else if (entry.equals("closed")) {
SafeMessage.sendMessage(channel, EmbedUtil.error("Portal is closed", "The portal is currently closed").build(), 5);
}
}
use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.
the class PortalListener method onGuildMessageReceived.
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
if (!e.getAuthor().isBot()) {
if (e.getChannel().getId().equals(RubiconBot.getMySQL().getPortalValue(e.getGuild(), "channelid"))) {
String status = RubiconBot.getMySQL().getGuildValue(e.getGuild(), "portal");
if (status.contains("open")) {
TextChannel otherChannel = e.getJDA().getTextChannelById(RubiconBot.getMySQL().getPortalValue(e.getJDA().getGuildById(RubiconBot.getMySQL().getPortalValue(e.getGuild(), "partnerid")), "channelid"));
try {
Webhook webhook = null;
for (Webhook hook : otherChannel.getWebhooks().complete()) {
if (hook.getName().equals("rubicon-portal-hook")) {
webhook = hook;
break;
}
}
if (webhook == null) {
webhook = otherChannel.createWebhook("rubicon-portal-hook").complete();
}
WebhookClientBuilder clientBuilder = webhook.newClient();
WebhookClient client = clientBuilder.build();
WebhookMessageBuilder builder = new WebhookMessageBuilder();
builder.setContent(e.getMessage().getContentDisplay().replace("@here", "@ here").replace("@everyone", "@ everyone"));
builder.setAvatarUrl(e.getAuthor().getAvatarUrl());
builder.setUsername(e.getAuthor().getName());
WebhookMessage message = builder.build();
client.send(message);
client.close();
/*EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor(e.getAuthor().getName(), null, e.getAuthor().getEffectiveAvatarUrl());
builder.setDescription(e.getMessage().getContent());
otherChannel.sendMessage(builder.build()).queue();*/
} catch (NullPointerException fuck) {
fuck.printStackTrace();
}
}
}
}
}
Aggregations