0

Compare commits

...

11 Commits

Author SHA1 Message Date
93b41e99c8 Updated dependencies.
This is a massive commit incorporating 5 years' worth of upstream dependencies updates all at once, particularly with JDA. Several classpaths and APIs changed, requiring some rework. The bot is mostly functional as a result, but issues remain with reaction callbacks and playing audio from YouTube.
2024-06-02 17:51:12 -04:00
Logan Fick
87510448d4 Fixed search results getting added to queue on wrong thread. 2019-06-25 12:21:06 -04:00
Logan Fick
766b0d0ad5 Fixed handling of invalid emojis. 2019-06-25 10:27:14 -04:00
Logan Fick
fdb1c0b093 Moved many operations to single main thread. 2019-06-25 10:20:55 -04:00
Logan Fick
079c7ecc81 Fixed number related argument checks being too strict. 2019-06-05 13:05:53 -04:00
Logan Fick
b4ac0a90a9 Improved quality of method argument checks. 2019-06-05 09:24:36 -04:00
Logan Fick
e142437b1e Fixed playlist loader attempting to load incorrect track reference. 2019-06-04 14:39:35 -04:00
Logan Fick
edaac0c33a Made reaction timeout emoji only get added if message has registered callbacks. 2019-06-04 13:03:48 -04:00
Logan Fick
68ecf4acd1 Added missing bounds check to dice maximum range. 2019-05-31 18:17:22 -04:00
Logan Fick
1122bff7e2 Fixed issue where current loaded track information could become desynced. 2019-05-31 18:03:21 -04:00
Logan Fick
4eb972e1b0 Added command for generating random numbers. 2019-05-31 08:58:13 -04:00
56 changed files with 1049 additions and 1045 deletions

View File

@@ -1,27 +1,38 @@
buildscript {
repositories {
jcenter()
gradlePluginPortal()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
classpath 'com.github.johnrengelman:shadow:8.1.1'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
repositories {
jcenter()
mavenCentral()
maven {
name 'm2-dv8tion'
url 'https://m2.dv8tion.net/releases'
}
maven {
url 'https://m2.dv8tion.net/releases'
}
maven {
url 'https://jitpack.io'
}
}
dependencies {
implementation 'org.slf4j:slf4j-simple:1.7.26'
implementation 'org.slf4j:slf4j-simple:2.0.13'
implementation 'net.dv8tion:JDA:3.8.3_463'
implementation 'com.sedmelluq:lavaplayer:1.3.17'
implementation 'redis.clients:jedis:3.0.1'
implementation 'com.vdurmont:emoji-java:4.0.0'
implementation 'net.dv8tion:JDA:5.0.0-beta.24'
implementation 'dev.arbjerg:lavaplayer:2.1.1'
implementation 'redis.clients:jedis:5.1.3'
}
jar {

View File

@@ -1,5 +1,6 @@
#Wed May 29 18:53:59 EDT 2024
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME

View File

@@ -1,37 +1,34 @@
package dev.logal.logalbot;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import javax.security.auth.login.LoginException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dev.logal.logalbot.commands.administration.*;
import dev.logal.logalbot.commands.administration.Settings;
import dev.logal.logalbot.commands.administration.Whitelist;
import dev.logal.logalbot.commands.audio.*;
import dev.logal.logalbot.commands.fun.*;
import dev.logal.logalbot.commands.general.*;
import dev.logal.logalbot.commands.fun.Dice;
import dev.logal.logalbot.commands.fun.EightBall;
import dev.logal.logalbot.commands.general.About;
import dev.logal.logalbot.commands.general.Help;
import dev.logal.logalbot.events.*;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.CommandManager;
import dev.logal.logalbot.utils.DataManager;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Main {
import java.util.ArrayList;
import java.util.Collection;
public final class Main implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static final String token = System.getenv("TOKEN");
@@ -42,6 +39,11 @@ public final class Main {
}
public static final void main(final String[] arguments) {
MainThread.scheduleImmediately(new Main());
}
@Override
public final void run() {
logger.info("Beginning setup of LogalBot...");
logger.info("Verifying connection to Redis...");
@@ -62,15 +64,13 @@ public final class Main {
logger.info("Attempting to log into Discord...");
try {
final JDABuilder builder = new JDABuilder(AccountType.BOT);
final JDABuilder builder = JDABuilder.createDefault(token);
builder.enableIntents(GatewayIntent.GUILD_VOICE_STATES);
builder.enableIntents(GatewayIntent.MESSAGE_CONTENT);
builder.setAutoReconnect(true);
builder.setAudioEnabled(true);
builder.setToken(token);
builder.addEventListener(new GuildReady());
builder.addEventListeners(new GuildReady());
jda = builder.build().awaitReady();
} catch (final LoginException exception) {
logger.error("The token specified is not valid.");
System.exit(1);
} catch (final Throwable exception) {
logger.error("An error occurred while attempting to set up JDA!", exception);
System.exit(1);
@@ -80,15 +80,19 @@ public final class Main {
logger.info("Initializing...");
AudioUtil.initializePlayerManager();
jda.addEventListener(new GuildVoiceLeave());
jda.addEventListener(new GuildVoiceMove());
jda.addEventListener(new GuildMessageReactionAdd());
jda.addEventListener(new GuildVoiceUpdate());
jda.addEventListener(new MessageReactionAdd());
// General Commands
CommandManager.registerCommand("about", new About(), false);
CommandManager.registerCommand("help", new Help(), false);
// Fun Commands
CommandManager.registerCommand("dice", new Dice(), false);
CommandManager.registerCommandAlias("die", "dice");
CommandManager.registerCommandAlias("random", "dice");
CommandManager.registerCommandAlias("rng", "dice");
CommandManager.registerCommandAlias("roll", "dice");
CommandManager.registerCommand("8ball", new EightBall(), false);
// Audio Commands
@@ -135,7 +139,7 @@ public final class Main {
CommandManager.registerCommandAlias("conf", "settings");
logger.info("Everything seems to be ready! Enabling command listener...");
jda.addEventListener(new GuildMessageReceived());
jda.addEventListener(new MessageReceived());
logger.info("Initialization complete!");
}
}

View File

@@ -0,0 +1,55 @@
package dev.logal.logalbot;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import net.dv8tion.jda.internal.utils.Checks;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public final class MainThread {
private static final ScheduledExecutorService mainThread = Executors
.newSingleThreadScheduledExecutor(new MainThreadFactory());
public static final void scheduleImmediately(final Runnable task) {
Checks.notNull(task, "Task");
mainThread.schedule(task, 0, TimeUnit.MICROSECONDS);
}
public static final ScheduledFuture<?> scheduleLater(final Runnable task, final long delay, final TimeUnit unit) {
Checks.notNull(task, "Task");
Checks.notNegative(delay, "Delay");
Checks.notNull(unit, "Unit");
return mainThread.schedule(task, delay, unit);
}
public static final ScheduledFuture<?> scheduleRepeatedlyAtFixedRate(final Runnable task, final long initialDelay,
final long period, final TimeUnit unit) {
Checks.notNull(task, "Task");
Checks.notNegative(initialDelay, "Initial Delay");
Checks.notNegative(period, "Period");
Checks.notNull(unit, "Unit");
return mainThread.scheduleAtFixedRate(task, initialDelay, period, unit);
}
public static final ScheduledFuture<?> scheduleRepeatedlyWithFixedDelay(final Runnable task,
final long initialDelay, final long period, final TimeUnit unit) {
Checks.notNull(task, "Task");
Checks.notNegative(initialDelay, "Initial Delay");
Checks.notNegative(period, "Period");
Checks.notNull(unit, "Unit");
return mainThread.scheduleWithFixedDelay(task, initialDelay, period, unit);
}
}

View File

@@ -0,0 +1,24 @@
package dev.logal.logalbot;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import net.dv8tion.jda.internal.utils.Checks;
import java.util.concurrent.ThreadFactory;
public final class MainThreadFactory implements ThreadFactory {
@Override
public final Thread newThread(final Runnable runnable) {
Checks.notNull(runnable, "Runnable");
final Thread newThread = new Thread(runnable);
newThread.setName("Main Thread");
return newThread;
}
}

View File

@@ -1,24 +1,19 @@
package dev.logal.logalbot.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import net.dv8tion.jda.api.audio.AudioSendHandler;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.core.audio.AudioSendHandler;
import net.dv8tion.jda.core.utils.Checks;
import java.nio.ByteBuffer;
public final class AudioPlayerSendHandler implements AudioSendHandler {
private final AudioPlayer audioPlayer;
@@ -37,8 +32,8 @@ public final class AudioPlayerSendHandler implements AudioSendHandler {
}
@Override
public final byte[] provide20MsAudio() {
return lastFrame.getData();
public final ByteBuffer provide20MsAudio() {
return ByteBuffer.wrap(lastFrame.getData());
}
@Override

View File

@@ -1,23 +1,16 @@
package dev.logal.logalbot.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.internal.utils.Checks;
public final class RequestedTrack {
private final AudioTrack track;

View File

@@ -1,39 +1,33 @@
package dev.logal.logalbot.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.tasks.TrackAdditionTask;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.PermissionManager;
import dev.logal.logalbot.utils.TrackUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
public final class TrackLoadHandler implements AudioLoadResultHandler {
private final Logger logger = LoggerFactory.getLogger(TrackLoadHandler.class);
@@ -54,7 +48,8 @@ public final class TrackLoadHandler implements AudioLoadResultHandler {
Checks.notNull(track, "Track");
final CommandResponse response;
final TrackScheduler scheduler = AudioUtil.getTrackScheduler(this.channel.getGuild());
final Guild guild = this.channel.getGuild();
final TrackScheduler scheduler = AudioUtil.getTrackScheduler(guild);
final AudioTrackInfo info = track.getInfo();
if (info.isStream) {
@@ -83,7 +78,7 @@ public final class TrackLoadHandler implements AudioLoadResultHandler {
}
final RequestedTrack requestedTrack = new RequestedTrack(track, requester);
scheduler.addToQueue(requestedTrack);
MainThread.scheduleImmediately(new TrackAdditionTask(guild, requestedTrack));
response = new CommandResponse("notes",
this.requester.getAsMention() + " added the following track to the queue:");
response.attachEmbed(TrackUtil.trackInfoEmbed(requestedTrack));
@@ -95,7 +90,8 @@ public final class TrackLoadHandler implements AudioLoadResultHandler {
Checks.notNull(playlist, "Playlist");
CommandResponse response;
final TrackScheduler scheduler = AudioUtil.getTrackScheduler(this.channel.getGuild());
final Guild guild = this.channel.getGuild();
final TrackScheduler scheduler = AudioUtil.getTrackScheduler(guild);
final AudioTrack selectedTrack = playlist.getSelectedTrack();
final AudioTrack track;
@@ -127,7 +123,7 @@ public final class TrackLoadHandler implements AudioLoadResultHandler {
if ((info.length >= 60000 && info.length <= 900000) || PermissionManager.isWhitelisted(this.requester)) {
final RequestedTrack requestedTrack = new RequestedTrack(track, requester);
scheduler.addToQueue(requestedTrack);
MainThread.scheduleImmediately(new TrackAdditionTask(guild, requestedTrack));
response = new CommandResponse("notes",
this.requester.getAsMention() + " added the following track to the queue:");
response.attachEmbed(TrackUtil.trackInfoEmbed(requestedTrack));
@@ -141,20 +137,19 @@ public final class TrackLoadHandler implements AudioLoadResultHandler {
}
} else {
if (PermissionManager.isWhitelisted(this.requester)) {
final LinkedList<RequestedTrack> addedTracks = new LinkedList<>();
final LinkedList<RequestedTrack> tracksToAdd = new LinkedList<>();
int count = 0;
for (final AudioTrack playlistTrack : playlist.getTracks()) {
if (!scheduler.isQueueFull()) {
if (count++ != 250) {
if (!scheduler.isQueued(playlistTrack) && !playlistTrack.getInfo().isStream) {
final RequestedTrack requestedTrack = new RequestedTrack(track, requester);
scheduler.addToQueue(requestedTrack);
addedTracks.add(requestedTrack);
tracksToAdd.add(new RequestedTrack(playlistTrack, requester));
}
} else {
break;
}
}
if (addedTracks.size() == 0) {
if (tracksToAdd.size() == 0) {
response = new CommandResponse("x",
"Sorry " + this.requester.getAsMention()
+ ", but none of the tracks in that playlist could be added to the queue.")
@@ -162,9 +157,10 @@ public final class TrackLoadHandler implements AudioLoadResultHandler {
response.sendResponse(this.channel);
}
MainThread.scheduleImmediately(new TrackAdditionTask(guild, tracksToAdd));
response = new CommandResponse("notes",
this.requester.getAsMention() + " added the following tracks from a playlist to the queue:");
response.attachEmbed(TrackUtil.trackListInfoEmbed(addedTracks, false));
response.attachEmbed(TrackUtil.trackListInfoEmbed(tracksToAdd, false));
response.sendResponse(this.channel);
} else {
response = new CommandResponse("x",

View File

@@ -1,44 +1,34 @@
package dev.logal.logalbot.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.Collections;
import java.util.LinkedList;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.tasks.CloseAudioConnectionTask;
import dev.logal.logalbot.tasks.OpenAudioConnectionTask;
import dev.logal.logalbot.tasks.PlayNextTrackTask;
import dev.logal.logalbot.utils.*;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dev.logal.logalbot.tasks.IdleDisconnectTask;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.DataManager;
import dev.logal.logalbot.utils.PermissionManager;
import dev.logal.logalbot.utils.Scheduler;
import dev.logal.logalbot.utils.SkipTracker;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.utils.Checks;
import java.util.Collections;
import java.util.LinkedList;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public final class TrackScheduler extends AudioEventAdapter {
private static final Logger logger = LoggerFactory.getLogger(TrackScheduler.class);
@@ -46,7 +36,7 @@ public final class TrackScheduler extends AudioEventAdapter {
private final Guild guild;
private final LinkedList<RequestedTrack> queue = new LinkedList<>();
private boolean queueLocked = false;
private ScheduledFuture<?> idleLogoutTask;
private ScheduledFuture<?> closeAudioConnectionTask;
public TrackScheduler(final Guild guild) {
Checks.notNull(guild, "Guild");
@@ -71,16 +61,21 @@ public final class TrackScheduler extends AudioEventAdapter {
logger.info(user.getName() + " (" + user.getId() + ") added '" + track.getInfo().title + "' to the queue in "
+ this.guild.getName() + " (" + this.guild.getId() + ").");
if (!AudioUtil.isTrackLoaded(this.guild)) {
AudioUtil.openAudioConnection(VoiceChannelUtil.getVoiceChannelMemberIsConnectedTo(requester));
AudioUtil.playTrack(this.guild, requestedTrack);
} else {
this.queue.add(requestedTrack);
final VoiceChannel targetChannel = VoiceChannelUtil.getVoiceChannelMemberIsConnectedTo(requester);
if (!AudioUtil.isAudioConnectionOpen(this.guild)
|| targetChannel != AudioUtil.getVoiceChannelConnectedTo(this.guild)) {
MainThread.scheduleImmediately(
new OpenAudioConnectionTask(VoiceChannelUtil.getVoiceChannelMemberIsConnectedTo(requester)));
}
if (!AudioUtil.isTrackLoaded(this.guild) && this.queue.size() == 0) {
MainThread.scheduleImmediately(new PlayNextTrackTask(this.guild));
}
this.queue.add(requestedTrack);
}
public final void removeFromQueue(final int index) {
Checks.notNull(index, "Index");
Checks.notNegative(index, "Index");
logger.info("Track '" + queue.remove(index).getTrack().getInfo().title + "' has been removed from the queue in "
+ this.guild.getName() + " (" + this.guild.getId() + ").");
@@ -110,8 +105,6 @@ public final class TrackScheduler extends AudioEventAdapter {
}
public final void setQueueLocked(final boolean locked) {
Checks.notNull(locked, "Locked");
this.queueLocked = locked;
}
@@ -123,7 +116,13 @@ public final class TrackScheduler extends AudioEventAdapter {
Collections.shuffle(this.queue);
}
public final RequestedTrack popFromQueue() {
return this.queue.remove(0);
}
public final int occupiedSlotCount(Member member) {
Checks.notNull(member, "Member");
int count = 0;
for (RequestedTrack requestedTrack : this.queue) {
if (requestedTrack.getRequester().equals(member)) {
@@ -152,10 +151,10 @@ public final class TrackScheduler extends AudioEventAdapter {
logger.info("Track '" + track.getInfo().title + "' in " + this.guild.getName() + " (" + this.guild.getId()
+ ") has started.");
if (this.idleLogoutTask != null && !this.idleLogoutTask.isDone()) {
if (this.closeAudioConnectionTask != null && !this.closeAudioConnectionTask.isDone()) {
logger.info("A track has started in " + this.guild.getName() + " (" + this.guild.getId()
+ "). Cancelling scheduled disconnect.");
this.idleLogoutTask.cancel(true);
this.closeAudioConnectionTask.cancel(true);
}
SkipTracker.resetVotes(this.guild);
}
@@ -170,7 +169,7 @@ public final class TrackScheduler extends AudioEventAdapter {
logger.info("Track '" + track.getInfo().title + "' in " + this.guild.getName() + " (" + this.guild.getId()
+ ") has stopped.");
if ((endReason.mayStartNext || endReason == AudioTrackEndReason.STOPPED) && this.queue.size() >= 1) {
AudioUtil.playTrack(this.guild, this.queue.remove(0));
MainThread.scheduleImmediately(new PlayNextTrackTask(this.guild));
} else {
try {
AudioUtil.setVolume(this.guild, Integer.parseInt(DataManager.getGuildValue(guild, "defaultVolume")));
@@ -182,7 +181,8 @@ public final class TrackScheduler extends AudioEventAdapter {
final VoiceChannel currentChannel = AudioUtil.getVoiceChannelConnectedTo(this.guild);
logger.info("Disconnecting from " + currentChannel.getName() + " (" + currentChannel.getId() + ") in "
+ this.guild.getName() + " (" + this.guild.getId() + ") in 1 minute...");
this.idleLogoutTask = Scheduler.schedule(new IdleDisconnectTask(this.guild), 1, TimeUnit.MINUTES);
this.closeAudioConnectionTask = MainThread.scheduleLater(new CloseAudioConnectionTask(this.guild), 1,
TimeUnit.MINUTES);
}
SkipTracker.resetVotes(this.guild);
}

View File

@@ -1,21 +1,16 @@
package dev.logal.logalbot.commands;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
public interface Command {
CommandResponse execute(final String[] arguments, final Member executor, final TextChannel channel);

View File

@@ -1,37 +1,27 @@
package dev.logal.logalbot.commands;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.tasks.MessageDeleteTask;
import dev.logal.logalbot.tasks.ReactionCallbackExpireTask;
import dev.logal.logalbot.utils.ReactionCallbackManager;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.internal.utils.Checks;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.vdurmont.emoji.Emoji;
import com.vdurmont.emoji.EmojiManager;
import dev.logal.logalbot.tasks.MessageDeleteTask;
import dev.logal.logalbot.tasks.ReactionCallbackExpireTask;
import dev.logal.logalbot.utils.ReactionCallbackManager;
import dev.logal.logalbot.utils.Scheduler;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.utils.Checks;
public final class CommandResponse {
private final Emoji emoji;
@@ -44,10 +34,11 @@ public final class CommandResponse {
private TimeUnit deletionDelayUnit, expireDelayUnit;
public CommandResponse(final String emoji, final String response) {
Checks.notNull(emoji, "Emoji");
Checks.notNull(response, "Response");
Checks.notEmpty(emoji, "Emoji");
Checks.notEmpty(response, "Response");
this.emoji = EmojiManager.getForAlias(emoji);
this.emoji = Emoji.fromUnicode(emoji);
Checks.notNull(this.emoji, "Valid Emoji");
this.response = response;
}
@@ -59,7 +50,7 @@ public final class CommandResponse {
}
public final CommandResponse setDeletionDelay(final long delay, final TimeUnit unit) {
Checks.notNull(delay, "Delay");
Checks.notNegative(delay, "Delay");
Checks.notNull(unit, "Unit");
this.deletionDelay = delay;
@@ -68,10 +59,10 @@ public final class CommandResponse {
}
public final CommandResponse addReactionCallback(final String emoji, final ReactionCallback callback) {
Checks.notNull(emoji, "Emoji");
Checks.notEmpty(emoji, "Emoji");
Checks.notNull(callback, "Callback");
this.callbacks.put(EmojiManager.getForAlias(emoji), callback);
this.callbacks.put(Emoji.fromUnicode(emoji), callback);
return this;
}
@@ -83,7 +74,7 @@ public final class CommandResponse {
}
public final CommandResponse setReactionCallbackExpireDelay(final long delay, final TimeUnit unit) {
Checks.notNull(delay, "Delay");
Checks.notNegative(delay, "Delay");
Checks.notNull(unit, "Unit");
this.expireDelay = delay;
@@ -94,11 +85,11 @@ public final class CommandResponse {
public final void sendResponse(final TextChannel channel) {
Checks.notNull(channel, "Channel");
final MessageBuilder builder = new MessageBuilder();
builder.setContent(this.emoji.getUnicode() + " " + this.response);
final MessageCreateBuilder builder = new MessageCreateBuilder();
builder.setContent(":" + this.emoji.getFormatted() + ": " + this.response);
if (this.responseEmbed != null) {
builder.setEmbed(this.responseEmbed);
builder.addEmbeds(this.responseEmbed);
}
channel.sendMessage(builder.build()).queue(this::handleResponseCreation);
@@ -106,9 +97,9 @@ public final class CommandResponse {
private final void handleResponseCreation(final Message message) {
if ((this.deletionDelay != 0) && (this.deletionDelayUnit != null)) {
Scheduler.schedule(new MessageDeleteTask(message), this.deletionDelay, this.deletionDelayUnit);
MainThread.scheduleLater(new MessageDeleteTask(message), this.deletionDelay, this.deletionDelayUnit);
} else if ((this.expireDelay != 0) && (this.expireDelayUnit != null)) {
Scheduler.schedule(new ReactionCallbackExpireTask(message), this.expireDelay, this.expireDelayUnit);
MainThread.scheduleLater(new ReactionCallbackExpireTask(message), this.expireDelay, this.expireDelayUnit);
}
for (final Map.Entry<Emoji, ReactionCallback> callback : callbacks.entrySet()) {

View File

@@ -1,21 +1,15 @@
package dev.logal.logalbot.commands;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
public interface ReactionCallback {
void run(final Member reactor, final Message message);

View File

@@ -1,30 +1,24 @@
package dev.logal.logalbot.commands.administration;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.DataManager;
import dev.logal.logalbot.utils.StringUtil;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Settings implements Command {
@Override

View File

@@ -1,28 +1,22 @@
package dev.logal.logalbot.commands.administration;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.PermissionManager;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Whitelist implements Command {
@Override

View File

@@ -1,20 +1,12 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.audio.RequestedTrack;
import dev.logal.logalbot.commands.Command;
@@ -22,9 +14,11 @@ import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.TrackUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class ForceSkip implements Command {
@Override

View File

@@ -1,29 +1,23 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.audio.TrackScheduler;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Lock implements Command {
@Override

View File

@@ -1,26 +1,20 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.TrackUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
public final class NowPlaying implements Command {
@Override

View File

@@ -1,28 +1,22 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Pause implements Command {
@Override

View File

@@ -1,22 +1,12 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.audio.TrackScheduler;
import dev.logal.logalbot.commands.Command;
@@ -25,11 +15,15 @@ import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.DataManager;
import dev.logal.logalbot.utils.PermissionManager;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public final class Play implements Command {
@Override

View File

@@ -1,32 +1,27 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.List;
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.audio.RequestedTrack;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.tasks.CommandExecutionTask;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.CommandManager;
import dev.logal.logalbot.utils.ReactionCallbackManager;
import dev.logal.logalbot.utils.TrackUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.List;
import java.util.concurrent.TimeUnit;
public final class Queue implements Command {
@Override
@@ -56,14 +51,16 @@ public final class Queue implements Command {
if (page != 1) {
response.addReactionCallback("arrow_left", (reactor, message) -> {
ReactionCallbackManager.unregisterMessage(message, true);
CommandManager.executeCommand(("queue " + (page - 1)).split(" "), reactor, channel);
MainThread.scheduleImmediately(
new CommandExecutionTask(("queue " + (page - 1)).split(" "), reactor, channel));
});
}
if (TrackUtil.doesGreaterPageExist(queue, page)) {
response.addReactionCallback("arrow_right", (reactor, message) -> {
ReactionCallbackManager.unregisterMessage(message, true);
CommandManager.executeCommand(("queue " + (page + 1)).split(" "), reactor, channel);
MainThread.scheduleImmediately(
new CommandExecutionTask(("queue " + (page + 1)).split(" "), reactor, channel));
});
}

View File

@@ -1,35 +1,26 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.audio.RequestedTrack;
import dev.logal.logalbot.audio.TrackScheduler;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.CommandManager;
import dev.logal.logalbot.utils.ReactionCallbackManager;
import dev.logal.logalbot.utils.StringUtil;
import dev.logal.logalbot.utils.TrackUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import dev.logal.logalbot.tasks.CommandExecutionTask;
import dev.logal.logalbot.utils.*;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Remove implements Command {
@Override
@@ -69,7 +60,8 @@ public final class Remove implements Command {
response.addReactionCallback(StringUtil.intToKeycapEmoji(trackNumber).getAliases().get(0),
(reactor, message) -> {
ReactionCallbackManager.unregisterMessage(message, true);
CommandManager.executeCommand(("remove " + trackNumber).split(" "), reactor, channel);
MainThread.scheduleImmediately(
new CommandExecutionTask(("remove " + trackNumber).split(" "), reactor, channel));
});
}

View File

@@ -1,28 +1,22 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Reset implements Command {
@Override

View File

@@ -1,29 +1,23 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.audio.TrackScheduler;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Shuffle implements Command {
@Override
@@ -44,6 +38,6 @@ public final class Shuffle implements Command {
}
scheduler.shuffleQueue();
return new CommandResponse("salad", executor.getAsMention() + " shuffled the queue.");
return new CommandResponse("green_salad", executor.getAsMention() + " shuffled the queue.");
}
}

View File

@@ -1,20 +1,12 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.audio.RequestedTrack;
import dev.logal.logalbot.commands.Command;
@@ -23,9 +15,11 @@ import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.SkipTracker;
import dev.logal.logalbot.utils.TrackUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Skip implements Command {
@Override

View File

@@ -1,28 +1,22 @@
package dev.logal.logalbot.commands.audio;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.TimeUnit;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.concurrent.TimeUnit;
public final class Volume implements Command {
@Override

View File

@@ -0,0 +1,47 @@
package dev.logal.logalbot.commands.fun;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;
public final class Dice implements Command {
private final SecureRandom rng = new SecureRandom();
@Override
public CommandResponse execute(String[] arguments, Member executor, TextChannel channel) {
if (arguments.length == 0) {
return new CommandResponse("game_die",
executor.getAsMention() + ", the dice rolled **" + (rng.nextInt(6) + 1) + "**.");
} else {
final int maximumRange;
try {
maximumRange = Integer.parseInt(arguments[0]);
} catch (final NumberFormatException exception) {
return new CommandResponse("x",
"Sorry " + executor.getAsMention() + ", but the maximum range must be an integer.")
.setDeletionDelay(30, TimeUnit.SECONDS);
}
if (maximumRange < 1) {
return new CommandResponse("x",
"Sorry " + executor.getAsMention() + ", but the maximum range must be at least 1.")
.setDeletionDelay(30, TimeUnit.SECONDS);
}
return new CommandResponse("game_die",
executor.getAsMention() + ", the dice rolled **" + (rng.nextInt(maximumRange) + 1) + "**.");
}
}
}

View File

@@ -1,31 +1,24 @@
package dev.logal.logalbot.commands.fun;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import com.vdurmont.emoji.EmojiManager;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.StringUtil;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import com.vdurmont.emoji.EmojiManager;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.StringUtil;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
public final class EightBall implements Command {
private final ArrayList<String> responses = new ArrayList<>(20);
private final Random rng = new Random();

View File

@@ -1,23 +1,17 @@
package dev.logal.logalbot.commands.general;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
public final class About implements Command {
@Override

View File

@@ -1,24 +1,18 @@
package dev.logal.logalbot.commands.general;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
public final class Help implements Command {
@Override

View File

@@ -1,32 +0,0 @@
package dev.logal.logalbot.events;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import dev.logal.logalbot.utils.ReactionCallbackManager;
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.utils.Checks;
public final class GuildMessageReactionAdd extends ListenerAdapter {
@Override
public final void onGuildMessageReactionAdd(final GuildMessageReactionAddEvent event) {
Checks.notNull(event, "Event");
if (!event.getUser().equals(event.getJDA().getSelfUser())) {
ReactionCallbackManager.executeCallback(event.getMessageIdLong(), event.getChannel(), event.getMember(),
event.getReactionEmote().getName());
}
}
}

View File

@@ -1,23 +1,17 @@
package dev.logal.logalbot.events;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.core.events.guild.GuildReadyEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.events.guild.GuildReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.utils.Checks;
public final class GuildReady extends ListenerAdapter {
@Override

View File

@@ -1,65 +0,0 @@
package dev.logal.logalbot.events;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.utils.Checks;
public final class GuildVoiceLeave extends ListenerAdapter {
private static final Logger logger = LoggerFactory.getLogger(GuildVoiceLeave.class);
@Override
public final void onGuildVoiceLeave(final GuildVoiceLeaveEvent event) {
Checks.notNull(event, "Event");
final Guild guild = event.getGuild();
if (!AudioUtil.isAudioConnectionOpen(guild)) {
return;
}
if (!AudioUtil.isTrackLoaded(guild)) {
return;
}
final Member member = event.getMember();
if (member.getUser().equals(event.getJDA().getSelfUser())) {
return;
}
final VoiceChannel leftChannel = event.getChannelLeft();
if (leftChannel.equals(AudioUtil.getVoiceChannelConnectedTo(guild))) {
final List<Member> members = leftChannel.getMembers();
if (members.size() == 1 && members.get(0).getUser().equals(event.getJDA().getSelfUser())) {
logger.info("All listeners left " + leftChannel.getName() + " (" + leftChannel.getId() + ") in "
+ guild.getName() + " (" + guild.getId() + ").");
AudioUtil.getTrackScheduler(guild).clearQueue();
if (AudioUtil.isTrackLoaded(guild)) {
AudioUtil.stopTrack(guild);
}
}
}
}
}

View File

@@ -1,65 +0,0 @@
package dev.logal.logalbot.events;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.utils.Checks;
public final class GuildVoiceMove extends ListenerAdapter {
private static final Logger logger = LoggerFactory.getLogger(GuildVoiceMove.class);
@Override
public final void onGuildVoiceMove(final GuildVoiceMoveEvent event) {
Checks.notNull(event, "Event");
final Guild guild = event.getGuild();
if (!AudioUtil.isAudioConnectionOpen(guild)) {
return;
}
if (!AudioUtil.isTrackLoaded(guild)) {
return;
}
final Member member = event.getMember();
if (member.getUser().equals(event.getJDA().getSelfUser())) {
return;
}
final VoiceChannel leftChannel = event.getChannelLeft();
if (leftChannel.equals(AudioUtil.getVoiceChannelConnectedTo(guild))) {
final List<Member> members = leftChannel.getMembers();
if (members.size() == 1 && members.get(0).getUser().equals(event.getJDA().getSelfUser())) {
logger.info("All listeners left " + leftChannel.getName() + " (" + leftChannel.getId() + ") in "
+ guild.getName() + " (" + guild.getId() + ").");
AudioUtil.getTrackScheduler(guild).clearQueue();
if (AudioUtil.isTrackLoaded(guild)) {
AudioUtil.stopTrack(guild);
}
}
}
}
}

View File

@@ -0,0 +1,57 @@
package dev.logal.logalbot.events;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.tasks.ResetAudioPlayerTask;
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public final class GuildVoiceUpdate extends ListenerAdapter {
private static final Logger logger = LoggerFactory.getLogger(GuildVoiceUpdate.class);
@Override
public final void onGuildVoiceUpdate(final GuildVoiceUpdateEvent event) {
Checks.notNull(event, "Event");
final Guild guild = event.getGuild();
if (!AudioUtil.isAudioConnectionOpen(guild)) {
return;
}
if (!AudioUtil.isTrackLoaded(guild)) {
return;
}
final Member member = event.getMember();
if (member.getUser().equals(event.getJDA().getSelfUser())) {
return;
}
final VoiceChannel leftChannel = event.getChannelLeft().asVoiceChannel(); // TODO: This will break.
if (leftChannel.equals(AudioUtil.getVoiceChannelConnectedTo(guild))) {
final List<Member> members = leftChannel.getMembers();
if (members.size() == 1 && members.get(0).getUser().equals(event.getJDA().getSelfUser())) {
logger.info("All listeners left " + leftChannel.getName() + " (" + leftChannel.getId() + ") in "
+ guild.getName() + " (" + guild.getId() + ").");
MainThread.scheduleImmediately(new ResetAudioPlayerTask(guild));
}
}
}
}

View File

@@ -0,0 +1,27 @@
package dev.logal.logalbot.events;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.tasks.ReactionCallbackExecutionTask;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.utils.Checks;
public final class MessageReactionAdd extends ListenerAdapter {
@Override
public final void onMessageReactionAdd(final MessageReactionAddEvent event) {
Checks.notNull(event, "Event");
if (!event.getUser().equals(event.getJDA().getSelfUser())) {
MainThread.scheduleImmediately(new ReactionCallbackExecutionTask(event.getMessageIdLong(),
event.getChannel().asTextChannel(), event.getMember(), event.getEmoji().getName())); // TODO: This will break.
}
}
}

View File

@@ -1,51 +1,43 @@
package dev.logal.logalbot.events;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import dev.logal.logalbot.MainThread;
import dev.logal.logalbot.tasks.CommandExecutionTask;
import dev.logal.logalbot.utils.DataManager;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.internal.utils.Checks;
import java.util.Arrays;
import java.util.List;
import dev.logal.logalbot.utils.CommandManager;
import dev.logal.logalbot.utils.DataManager;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.SelfUser;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.utils.Checks;
public final class GuildMessageReceived extends ListenerAdapter {
public final class MessageReceived extends ListenerAdapter {
@Override
public final void onGuildMessageReceived(final GuildMessageReceivedEvent event) {
public final void onMessageReceived(final MessageReceivedEvent event) {
Checks.notNull(event, "Event");
final Guild guild = event.getGuild();
final Member self = guild.getSelfMember();
final TextChannel channel = event.getChannel();
final TextChannel channel = event.getChannel().asTextChannel(); // TODO: This will break.
final Message message = event.getMessage();
if (event.getAuthor().isBot() || message.isTTS() || !self.hasPermission(channel, Permission.MESSAGE_WRITE)
if (event.getAuthor().isBot() || message.isTTS() || !self.hasPermission(channel, Permission.MESSAGE_SEND)
|| !self.hasPermission(channel, Permission.MESSAGE_EMBED_LINKS)) {
return;
}
final String content = message.getContentRaw();
final SelfUser selfUser = event.getJDA().getSelfUser();
final List<Member> mentionedMembers = message.getMentionedMembers();
final List<Member> mentionedMembers = message.getMentions().getMembers();
final Member author = event.getMember();
if (mentionedMembers.size() >= 1 && mentionedMembers.get(0).getUser().getIdLong() == selfUser.getIdLong()
&& (content.startsWith(self.getAsMention()) || content.startsWith(selfUser.getAsMention()))) {
@@ -55,7 +47,7 @@ public final class GuildMessageReceived extends ListenerAdapter {
if (self.hasPermission(channel, Permission.MESSAGE_MANAGE)) {
message.delete().reason("LogalBot Command Execution").queue();
}
CommandManager.executeCommand(command, author, channel);
MainThread.scheduleImmediately(new CommandExecutionTask(command, author, channel));
}
} else {
final String commandCharacter = DataManager.getGuildValue(guild, "commandCharacter");
@@ -70,7 +62,7 @@ public final class GuildMessageReceived extends ListenerAdapter {
if (self.hasPermission(channel, Permission.MESSAGE_MANAGE)) {
message.delete().reason("LogalBot Command Execution").queue();
}
CommandManager.executeCommand(command, author, channel);
MainThread.scheduleImmediately(new CommandExecutionTask(command, author, channel));
}
}
}

View File

@@ -0,0 +1,28 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.internal.utils.Checks;
public final class CloseAudioConnectionTask implements Runnable {
private final Guild guild;
public CloseAudioConnectionTask(final Guild guild) {
Checks.notNull(guild, "Guild");
this.guild = guild;
}
@Override
public final void run() {
AudioUtil.closeAudioConnection(guild);
}
}

View File

@@ -0,0 +1,35 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.CommandManager;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.internal.utils.Checks;
public final class CommandExecutionTask implements Runnable {
private final String[] command;
private final Member executor;
private final TextChannel channel;
public CommandExecutionTask(final String[] command, final Member executor, final TextChannel channel) {
Checks.noneNull(command, "Command");
Checks.notNull(executor, "Executor");
Checks.notNull(channel, "Channel");
this.command = command;
this.executor = executor;
this.channel = channel;
}
@Override
public final void run() {
CommandManager.executeCommand(this.command, this.executor, this.channel);
}
}

View File

@@ -1,34 +0,0 @@
package dev.logal.logalbot.tasks;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.utils.Checks;
public final class IdleDisconnectTask implements Runnable {
private final Guild guild;
public IdleDisconnectTask(final Guild guild) {
Checks.notNull(guild, "Guild");
this.guild = guild;
}
@Override
public final void run() {
AudioUtil.closeAudioConnection(guild);
}
}

View File

@@ -1,22 +1,16 @@
package dev.logal.logalbot.tasks;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.ReactionCallbackManager;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.internal.utils.Checks;
public final class MessageDeleteTask implements Runnable {
private final Message messageToDelete;
@@ -30,6 +24,5 @@ public final class MessageDeleteTask implements Runnable {
@Override
public final void run() {
ReactionCallbackManager.unregisterMessage(messageToDelete, true);
messageToDelete.delete().queue();
}
}

View File

@@ -0,0 +1,28 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.internal.utils.Checks;
public final class OpenAudioConnectionTask implements Runnable {
private final VoiceChannel channel;
public OpenAudioConnectionTask(final VoiceChannel channel) {
Checks.notNull(channel, "Channel");
this.channel = channel;
}
@Override
public void run() {
AudioUtil.openAudioConnection(channel);
}
}

View File

@@ -0,0 +1,28 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.internal.utils.Checks;
public final class PlayNextTrackTask implements Runnable {
private final Guild guild;
public PlayNextTrackTask(final Guild guild) {
Checks.notNull(guild, "Guild");
this.guild = guild;
}
@Override
public void run() {
AudioUtil.playNextTrack(this.guild);
}
}

View File

@@ -0,0 +1,39 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.ReactionCallbackManager;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.internal.utils.Checks;
public final class ReactionCallbackExecutionTask implements Runnable {
private final long messageID;
private final TextChannel channel;
private final Member executor;
private final String emoji;
public ReactionCallbackExecutionTask(final long messageID, final TextChannel channel, final Member executor,
final String emoji) {
Checks.notNegative(messageID, "Message ID");
Checks.notNull(channel, "Channel");
Checks.notNull(executor, "Executor");
Checks.notEmpty(emoji, "Emoji");
this.messageID = messageID;
this.channel = channel;
this.executor = executor;
this.emoji = emoji;
}
@Override
public void run() {
ReactionCallbackManager.executeCallback(this.messageID, this.channel, this.executor, this.emoji);
}
}

View File

@@ -1,22 +1,16 @@
package dev.logal.logalbot.tasks;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.ReactionCallbackManager;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.internal.utils.Checks;
public final class ReactionCallbackExpireTask implements Runnable {
private final Message messageToExpire;

View File

@@ -0,0 +1,29 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.internal.utils.Checks;
public final class ResetAudioPlayerTask implements Runnable {
private final Guild guild;
public ResetAudioPlayerTask(final Guild guild) {
Checks.notNull(guild, "Guild");
this.guild = guild;
}
@Override
public void run() {
AudioUtil.getTrackScheduler(guild).clearQueue();
AudioUtil.stopTrack(guild);
}
}

View File

@@ -0,0 +1,48 @@
package dev.logal.logalbot.tasks;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.audio.RequestedTrack;
import dev.logal.logalbot.audio.TrackScheduler;
import dev.logal.logalbot.utils.AudioUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.internal.utils.Checks;
import java.util.LinkedList;
import java.util.List;
public final class TrackAdditionTask implements Runnable {
private final Guild guild;
private final LinkedList<RequestedTrack> tracks;
public TrackAdditionTask(final Guild guild, final RequestedTrack track) {
Checks.notNull(guild, "Guild");
Checks.notNull(track, "Track");
this.guild = guild;
tracks = new LinkedList<RequestedTrack>();
tracks.add(track);
}
public TrackAdditionTask(final Guild guild, final List<RequestedTrack> tracks) {
Checks.notNull(guild, "Guild");
Checks.noneNull(tracks, "Tracks");
this.guild = guild;
this.tracks = (LinkedList<RequestedTrack>) tracks;
}
@Override
public final void run() {
final TrackScheduler scheduler = AudioUtil.getTrackScheduler(this.guild);
for (final RequestedTrack track : this.tracks) {
scheduler.addToQueue(track);
}
}
}

View File

@@ -1,39 +1,31 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.HashMap;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dev.logal.logalbot.audio.AudioPlayerSendHandler;
import dev.logal.logalbot.audio.RequestedTrack;
import dev.logal.logalbot.audio.TrackLoadHandler;
import dev.logal.logalbot.audio.TrackScheduler;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.managers.AudioManager;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
public final class AudioUtil {
private static final Logger logger = LoggerFactory.getLogger(AudioUtil.class);
@@ -89,7 +81,7 @@ public final class AudioUtil {
public static final VoiceChannel getVoiceChannelConnectedTo(final Guild guild) {
Checks.notNull(guild, "Guild");
return guild.getAudioManager().getConnectedChannel();
return guild.getAudioManager().getConnectedChannel().asVoiceChannel(); // TODO: This will break.
}
public static final boolean isAudioConnectionOpen(final Guild guild) {
@@ -106,11 +98,20 @@ public final class AudioUtil {
loadedTracks.put(guild.getIdLong(), track);
}
public static final void playNextTrack(final Guild guild) {
Checks.notNull(guild, "Guild");
final RequestedTrack track = schedulers.get(guild.getIdLong()).popFromQueue();
if (track != null) {
playTrack(guild, track);
}
}
public static final void stopTrack(final Guild guild) {
Checks.notNull(guild, "Guild");
players.get(guild.getIdLong()).stopTrack();
loadedTracks.remove(guild.getIdLong());
players.get(guild.getIdLong()).stopTrack();
}
public static final boolean isTrackLoaded(final Guild guild) {
@@ -132,7 +133,6 @@ public final class AudioUtil {
public static final void setPausedState(final Guild guild, final boolean pausedState) {
Checks.notNull(guild, "Guild");
Checks.notNull(pausedState, "Paused state");
guild.getAudioManager().setSelfMuted(pausedState);
players.get(guild.getIdLong()).setPaused(pausedState);
@@ -166,7 +166,7 @@ public final class AudioUtil {
}
public static final void findTrack(final String query, final Member requester, final TextChannel channel) {
Checks.notNull(query, "Query");
Checks.notEmpty(query, "Query");
Checks.notNull(requester, "Requester");
Checks.notNull(channel, "Channel");

View File

@@ -1,33 +1,25 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public final class CommandManager {
private static final Logger logger = LoggerFactory.getLogger(CommandManager.class);

View File

@@ -1,26 +1,19 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.utils.Checks;
import redis.clients.jedis.Jedis;
public final class DataManager {
@@ -37,7 +30,7 @@ public final class DataManager {
public static final void verifyConnection() {
if (!jedis.isConnected()) {
jedis = new Jedis(host);
jedis = new Jedis(host, 6379);
if (password != null) {
jedis.auth(password);

View File

@@ -1,26 +1,19 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.internal.utils.Checks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.utils.Checks;
public final class PermissionManager {
private static final Logger logger = LoggerFactory.getLogger(PermissionManager.class);

View File

@@ -1,30 +1,22 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.HashMap;
import com.vdurmont.emoji.Emoji;
import com.vdurmont.emoji.EmojiManager;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import dev.logal.logalbot.commands.ReactionCallback;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.internal.utils.Checks;
import java.util.HashMap;
public final class ReactionCallbackManager {
private static final HashMap<Long, HashMap<Emoji, ReactionCallback>> callbackDictionary = new HashMap<>();
@@ -35,7 +27,7 @@ public final class ReactionCallbackManager {
}
public static final void registerCallback(final Message message, final Emoji emoji,
final ReactionCallback callback) {
final ReactionCallback callback) {
Checks.notNull(message, "Message");
Checks.notNull(emoji, "Emoji");
Checks.notNull(callback, "Callback");
@@ -45,12 +37,12 @@ public final class ReactionCallbackManager {
}
callbackDictionary.get(message.getIdLong()).put(emoji, callback);
message.addReaction(emoji.getUnicode()).queue();
message.addReaction(emoji).queue();
}
public static final void setCallbackTarget(final Message message, final User user) {
Checks.notNull(user, "User");
Checks.notNull(message, "Messsage");
Checks.notNull(user, "User");
targetDictionary.put(message.getIdLong(), user.getIdLong());
}
@@ -58,23 +50,27 @@ public final class ReactionCallbackManager {
public static final void unregisterMessage(final Message message, final boolean delete) {
Checks.notNull(message, "Message");
callbackDictionary.remove(message.getIdLong());
targetDictionary.remove(message.getIdLong());
if (delete) {
message.delete().queue();
} else {
message.addReaction(EmojiManager.getForAlias("no_entry").getUnicode()).queue();
if (callbackDictionary.containsKey(message.getIdLong())) {
message.addReaction(net.dv8tion.jda.api.entities.emoji.Emoji.fromUnicode("no_entry")).queue();
}
}
callbackDictionary.remove(message.getIdLong());
targetDictionary.remove(message.getIdLong());
}
public static final void executeCallback(final long messageID, final TextChannel channel, final Member reactor,
final String emoji) {
Checks.notNull(messageID, "Message ID");
final String emoji) {
Checks.notNegative(messageID, "Message ID");
Checks.notNull(channel, "Channel");
Checks.notNull(reactor, "Reactor");
Checks.notEmpty(emoji, "Emoji");
channel.getMessageById(messageID).queue((message) -> {
// TODO: This is broke.
/*channel.getMessageById(messageID).queue((message) -> {
if (callbackDictionary.containsKey(messageID)) {
if (targetDictionary.containsKey(messageID)
&& !targetDictionary.get(messageID).equals(reactor.getUser().getIdLong())) {
@@ -86,6 +82,6 @@ public final class ReactionCallbackManager {
callbackDictionary.get(messageID).get(parsedEmoji).run(reactor, message);
}
}
});
});*/
}
}

View File

@@ -1,48 +0,0 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.utils.Checks;
public final class Scheduler {
private static final ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
private Scheduler() {
// Static access only.
}
public static final ScheduledFuture<?> schedule(final Runnable runnable, final long delay, final TimeUnit unit) {
Checks.notNull(runnable, "Runnable");
Checks.notNull(delay, "Delay");
Checks.notNull(unit, "Unit");
return pool.schedule(runnable, delay, unit);
}
public static final ScheduledFuture<?> scheduleRepeating(final Runnable runnable, final long initialDelay,
final long period, final TimeUnit unit) {
Checks.notNull(runnable, "Runnable");
Checks.notNull(initialDelay, "Initial delay");
Checks.notNull(period, "Period");
Checks.notNull(unit, "Unit");
return pool.scheduleAtFixedRate(runnable, initialDelay, period, unit);
}
}

View File

@@ -1,26 +1,21 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.internal.utils.Checks;
import java.util.ArrayList;
import java.util.HashMap;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.utils.Checks;
public final class SkipTracker {
private static final HashMap<Long, ArrayList<Long>> skipVotesDictionary = new HashMap<>();

View File

@@ -1,23 +1,16 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.vdurmont.emoji.Emoji;
import com.vdurmont.emoji.EmojiManager;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.internal.utils.Checks;
public final class StringUtil {
private StringUtil() {
@@ -81,7 +74,7 @@ public final class StringUtil {
}
public static final String formatTime(final long milliseconds) {
Checks.notNull(milliseconds, "Milliseconds");
Checks.notNegative(milliseconds, "Milliseconds");
final long second = (milliseconds / 1000) % 60;
final long minute = (milliseconds / (1000 * 60)) % 60;

View File

@@ -1,30 +1,23 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import java.util.List;
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import dev.logal.logalbot.audio.RequestedTrack;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.internal.utils.Checks;
import java.util.List;
public final class TrackUtil {
private TrackUtil() {
@@ -65,7 +58,6 @@ public final class TrackUtil {
public static final MessageEmbed trackListInfoEmbed(final List<RequestedTrack> tracks, final boolean numbered) {
Checks.notNull(tracks, "Tracks");
Checks.notNull(numbered, "Numbered");
final EmbedBuilder builder = new EmbedBuilder();
for (int i = 0; i < tracks.size(); i++) {
@@ -94,7 +86,6 @@ public final class TrackUtil {
public static final MessageEmbed pagedTrackListInfoEmbed(final List<RequestedTrack> tracks, int page) {
Checks.notNull(tracks, "Tracks");
Checks.notNull(page, "Page");
final EmbedBuilder builder = new EmbedBuilder();
if (page < 1) {
@@ -124,7 +115,6 @@ public final class TrackUtil {
public static final boolean doesGreaterPageExist(final List<RequestedTrack> tracks, int page) {
Checks.notNull(tracks, "Tracks");
Checks.notNull(page, "Page");
final int pages = (int) Math.ceil(tracks.size() / 10d);
return (page < pages);

View File

@@ -1,22 +1,16 @@
package dev.logal.logalbot.utils;
// Copyright 2019 Logan Fick
/*
* Copyright 2022 Logan Fick
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.utils.Checks;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.internal.utils.Checks;
public final class VoiceChannelUtil {
private VoiceChannelUtil() {