forked from remote/MusicBot
configurably disable fairqueue™️
This commit is contained in:
parent
4d78729f0a
commit
34f8aa382e
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="JMusicBot" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="dv8tion" />
|
||||
<option name="name" value="m2-dv8tion" />
|
||||
<option name="url" value="https://m2.dv8tion.net/releases" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jitpack.io" />
|
||||
<option name="name" value="jitpack.io" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="bintray" />
|
||||
<option name="url" value="https://jcenter.bintray.com" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -16,6 +16,7 @@
|
|||
package com.jagrosh.jmusicbot;
|
||||
|
||||
import com.jagrosh.jmusicbot.entities.Prompt;
|
||||
import com.jagrosh.jmusicbot.queue.QueueType;
|
||||
import com.jagrosh.jmusicbot.utils.FormatUtil;
|
||||
import com.jagrosh.jmusicbot.utils.OtherUtil;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
|
@ -23,6 +24,8 @@ import com.typesafe.config.*;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
|
||||
|
@ -44,6 +47,7 @@ public class BotConfig
|
|||
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
|
||||
private long owner, maxSeconds, aloneTimeUntilStop;
|
||||
private OnlineStatus status;
|
||||
private QueueType queueType;
|
||||
private Activity game;
|
||||
private Config aliases, transforms;
|
||||
|
||||
|
@ -81,6 +85,7 @@ public class BotConfig
|
|||
searchingEmoji = config.getString("searching");
|
||||
game = OtherUtil.parseGame(config.getString("game"));
|
||||
status = OtherUtil.parseStatus(config.getString("status"));
|
||||
queueType = Objects.equals(config.getString("queuetype"), "FAIR") ? QueueType.FAIR : QueueType.REGULAR;
|
||||
stayInChannel = config.getBoolean("stayinchannel");
|
||||
songInGame = config.getBoolean("songinstatus");
|
||||
npImages = config.getBoolean("npimages");
|
||||
|
@ -270,6 +275,8 @@ public class BotConfig
|
|||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public QueueType getQueueType() { return queueType; }
|
||||
|
||||
public String getHelp()
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ public class Listener extends ListenerAdapter
|
|||
{
|
||||
String defpl = bot.getSettingsManager().getSettings(guild).getDefaultPlaylist();
|
||||
VoiceChannel vc = bot.getSettingsManager().getSettings(guild).getVoiceChannel(guild);
|
||||
if(defpl!=null && vc!=null && bot.getPlayerManager().setUpHandler(guild).playFromDefault())
|
||||
if(defpl!=null && vc!=null && bot.getPlayerManager().setUpHandler(guild, bot.getConfig().getQueueType()).playFromDefault())
|
||||
{
|
||||
guild.getAudioManager().openAudioConnection(vc);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ package com.jagrosh.jmusicbot.audio;
|
|||
|
||||
import com.jagrosh.jmusicbot.JMusicBot;
|
||||
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
|
||||
import com.jagrosh.jmusicbot.queue.Queue;
|
||||
import com.jagrosh.jmusicbot.queue.QueueType;
|
||||
import com.jagrosh.jmusicbot.queue.RegularAssQueue;
|
||||
import com.jagrosh.jmusicbot.settings.RepeatMode;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
||||
|
@ -27,7 +30,6 @@ import java.util.HashSet;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import com.jagrosh.jmusicbot.queue.FairQueue;
|
||||
import com.jagrosh.jmusicbot.settings.Settings;
|
||||
import com.jagrosh.jmusicbot.utils.FormatUtil;
|
||||
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
|
||||
|
@ -50,7 +52,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
|||
public final static String PAUSE_EMOJI = "\u23F8"; // ⏸
|
||||
public final static String STOP_EMOJI = "\u23F9"; // ⏹
|
||||
|
||||
private final FairQueue<QueuedTrack> queue = new FairQueue<>();
|
||||
private final Queue<QueuedTrack> queue;
|
||||
private final List<AudioTrack> defaultQueue = new LinkedList<>();
|
||||
private final Set<String> votes = new HashSet<>();
|
||||
|
||||
|
@ -60,11 +62,12 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
|||
|
||||
private AudioFrame lastFrame;
|
||||
|
||||
protected AudioHandler(PlayerManager manager, Guild guild, AudioPlayer player)
|
||||
protected AudioHandler(PlayerManager manager, Guild guild, AudioPlayer player, QueueType queueType)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.audioPlayer = player;
|
||||
this.guildId = guild.getIdLong();
|
||||
this.queue = queueType.makeClass();
|
||||
}
|
||||
|
||||
public int addTrackToFront(QueuedTrack qtrack)
|
||||
|
@ -92,7 +95,7 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler
|
|||
return queue.add(qtrack);
|
||||
}
|
||||
|
||||
public FairQueue<QueuedTrack> getQueue()
|
||||
public Queue<QueuedTrack> getQueue()
|
||||
{
|
||||
return queue;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package com.jagrosh.jmusicbot.audio;
|
||||
|
||||
import com.jagrosh.jmusicbot.Bot;
|
||||
import com.jagrosh.jmusicbot.queue.QueueType;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
|
@ -53,14 +54,14 @@ public class PlayerManager extends DefaultAudioPlayerManager
|
|||
return guild.getAudioManager().getSendingHandler()!=null;
|
||||
}
|
||||
|
||||
public AudioHandler setUpHandler(Guild guild)
|
||||
public AudioHandler setUpHandler(Guild guild, QueueType queueType)
|
||||
{
|
||||
AudioHandler handler;
|
||||
if(guild.getAudioManager().getSendingHandler()==null)
|
||||
{
|
||||
AudioPlayer player = createPlayer();
|
||||
player.setVolume(bot.getSettingsManager().getSettings(guild).getVolume());
|
||||
handler = new AudioHandler(this, guild, player);
|
||||
handler = new AudioHandler(this, guild, player, queueType);
|
||||
player.addListener(handler);
|
||||
guild.getAudioManager().setSendingHandler(handler);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public abstract class MusicCommand extends Command
|
|||
event.replyInDm(event.getClient().getError()+" You can only use that command in "+tchannel.getAsMention()+"!");
|
||||
return;
|
||||
}
|
||||
bot.getPlayerManager().setUpHandler(event.getGuild()); // no point constantly checking for this later
|
||||
bot.getPlayerManager().setUpHandler(event.getGuild(), bot.getConfig().getQueueType()); // no point constantly checking for this later
|
||||
if(bePlaying && !((AudioHandler)event.getGuild().getAudioManager().getSendingHandler()).isMusicPlaying(event.getJDA()))
|
||||
{
|
||||
event.reply(event.getClient().getError()+" There must be music playing to use that!");
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.jagrosh.jmusicbot.Bot;
|
|||
import com.jagrosh.jmusicbot.audio.AudioHandler;
|
||||
import com.jagrosh.jmusicbot.audio.QueuedTrack;
|
||||
import com.jagrosh.jmusicbot.commands.DJCommand;
|
||||
import com.jagrosh.jmusicbot.queue.FairQueue;
|
||||
import com.jagrosh.jmusicbot.queue.Queue;
|
||||
|
||||
/**
|
||||
* Command that provides users the ability to move a track in the playlist.
|
||||
|
@ -57,7 +57,7 @@ public class MoveTrackCmd extends DJCommand
|
|||
|
||||
// Validate that from and to are available
|
||||
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
|
||||
FairQueue<QueuedTrack> queue = handler.getQueue();
|
||||
Queue<QueuedTrack> queue = handler.getQueue();
|
||||
if (isUnavailablePosition(queue, from))
|
||||
{
|
||||
String reply = String.format("`%d` is not a valid position in the queue!", from);
|
||||
|
@ -78,7 +78,7 @@ public class MoveTrackCmd extends DJCommand
|
|||
event.replySuccess(reply);
|
||||
}
|
||||
|
||||
private static boolean isUnavailablePosition(FairQueue<QueuedTrack> queue, int position)
|
||||
private static boolean isUnavailablePosition(Queue<QueuedTrack> queue, int position)
|
||||
{
|
||||
return (position < 1 || position > queue.size());
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@ import java.util.Set;
|
|||
* @author John Grosh (jagrosh)
|
||||
* @param <T>
|
||||
*/
|
||||
public class FairQueue<T extends Queueable> {
|
||||
public class FairQueue<T extends Queueable> extends Queue<T> {
|
||||
private final List<T> list = new ArrayList<>();
|
||||
private final Set<Long> set = new HashSet<>();
|
||||
|
||||
|
||||
public int add(T item)
|
||||
{
|
||||
int lastIndex;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.jagrosh.jmusicbot.queue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author John Grosh (jagrosh)
|
||||
* @author Jill "oatmealine" Monoids
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class Queue<T extends Queueable> {
|
||||
public abstract int add(T item);
|
||||
|
||||
public abstract void addAt(int index, T item);
|
||||
|
||||
public abstract int size();
|
||||
|
||||
public abstract T pull();
|
||||
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
public abstract List<T> getList();
|
||||
|
||||
public abstract T get(int index);
|
||||
|
||||
public abstract T remove(int index);
|
||||
|
||||
public abstract int removeAll(long identifier);
|
||||
|
||||
public abstract void clear();
|
||||
|
||||
public abstract int shuffle(long identifier);
|
||||
|
||||
public abstract void skip(int number);
|
||||
|
||||
/**
|
||||
* Move an item to a different position in the list
|
||||
* @param from The position of the item
|
||||
* @param to The new position of the item
|
||||
* @return the moved item
|
||||
*/
|
||||
public abstract T moveItem(int from, int to);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.jagrosh.jmusicbot.queue;
|
||||
|
||||
public enum QueueType {
|
||||
REGULAR,
|
||||
FAIR;
|
||||
|
||||
public <T extends Queueable> Queue<T> makeClass() {
|
||||
switch(this) {
|
||||
case FAIR:
|
||||
return new FairQueue<T>();
|
||||
case REGULAR:
|
||||
return new RegularAssQueue<T>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -15,10 +15,6 @@
|
|||
*/
|
||||
package com.jagrosh.jmusicbot.queue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author John Grosh <john.a.grosh@gmail.com>
|
||||
*/
|
||||
public interface Queueable {
|
||||
|
||||
public long getIdentifier();
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright 2016 John Grosh (jagrosh).
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
package com.jagrosh.jmusicbot.queue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author John Grosh (jagrosh)
|
||||
* @author Jill "oatmealine" Monoids
|
||||
* @param <T>
|
||||
*/
|
||||
public class RegularAssQueue<T extends Queueable> extends Queue<T> {
|
||||
private final List<T> list = new ArrayList<>();
|
||||
|
||||
public int add(T item)
|
||||
{
|
||||
list.add(item);
|
||||
// return the new item's index
|
||||
return list.size() - 1;
|
||||
}
|
||||
|
||||
public void addAt(int index, T item)
|
||||
{
|
||||
if(index >= list.size())
|
||||
list.add(item);
|
||||
else
|
||||
list.add(index, item);
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public T pull()
|
||||
{
|
||||
return list.remove(0);
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
public List<T> getList()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
public T get(int index)
|
||||
{
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
public T remove(int index)
|
||||
{
|
||||
return list.remove(index);
|
||||
}
|
||||
|
||||
public int removeAll(long identifier)
|
||||
{
|
||||
int count = 0;
|
||||
for(int i=list.size()-1; i>=0; i--)
|
||||
{
|
||||
if(list.get(i).getIdentifier()==identifier)
|
||||
{
|
||||
list.remove(i);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
list.clear();
|
||||
}
|
||||
|
||||
public int shuffle(long identifier)
|
||||
{
|
||||
List<Integer> iset = new ArrayList<>();
|
||||
for(int i=0; i<list.size(); i++)
|
||||
{
|
||||
if(list.get(i).getIdentifier()==identifier)
|
||||
iset.add(i);
|
||||
}
|
||||
for(int j=0; j<iset.size(); j++)
|
||||
{
|
||||
int first = iset.get(j);
|
||||
int second = iset.get((int)(Math.random()*iset.size()));
|
||||
T temp = list.get(first);
|
||||
list.set(first, list.get(second));
|
||||
list.set(second, temp);
|
||||
}
|
||||
return iset.size();
|
||||
}
|
||||
|
||||
public void skip(int number)
|
||||
{
|
||||
for(int i=0; i<number; i++)
|
||||
list.remove(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move an item to a different position in the list
|
||||
* @param from The position of the item
|
||||
* @param to The new position of the item
|
||||
* @return the moved item
|
||||
*/
|
||||
public T moveItem(int from, int to)
|
||||
{
|
||||
T item = list.remove(from);
|
||||
list.add(to, item);
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -128,6 +128,11 @@ updatealerts=true
|
|||
|
||||
lyrics.default = "A-Z Lyrics"
|
||||
|
||||
// Sets the queue type
|
||||
// FAIR: Each user gets a fair chance at the queue by rearranging it such that no user can fill it up entirely
|
||||
// REGULAR: Queue works as first-come, first-served
|
||||
|
||||
queuetype = FAIR
|
||||
|
||||
// These settings allow you to configure custom aliases for all commands.
|
||||
// Multiple aliases may be given, separated by commas.
|
||||
|
|
Loading…
Reference in New Issue