+Started music integration

Voice channel join/disconnect
This commit is contained in:
Alex Stewart
2019-07-30 01:19:34 -07:00
parent 9cc703ab63
commit a62c10d06e
11 changed files with 124 additions and 5 deletions
+6 -1
View File
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/commons-codec-1.11.jar"/> <classpathentry kind="lib" path="lib/commons-codec-1.11.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/> <classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/>
<classpathentry kind="lib" path="lib/gson-2.6.2.jar"/> <classpathentry kind="lib" path="lib/gson-2.6.2.jar"/>
@@ -20,5 +24,6 @@
<classpathentry kind="lib" path="lib/commons-collections4-4.3.jar"/> <classpathentry kind="lib" path="lib/commons-collections4-4.3.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.9.jar"/> <classpathentry kind="lib" path="lib/commons-lang3-3.9.jar"/>
<classpathentry kind="lib" path="lib/commons-text-1.6.jar"/> <classpathentry kind="lib" path="lib/commons-text-1.6.jar"/>
<classpathentry kind="lib" path="C:/Users/Rin/Documents/Java/KittyBot/lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
+3
View File
@@ -38,6 +38,7 @@
"Localized Commands","leaderboard","" "Localized Commands","leaderboard",""
"Localized Commands","map","" "Localized Commands","map",""
"Localized Commands","mod","" "Localized Commands","mod",""
"Localized Commands","music",""
"Localized Commands","perish, thenperish","" "Localized Commands","perish, thenperish",""
"Localized Commands","ping","" "Localized Commands","ping",""
"Localized Commands","poll","" "Localized Commands","poll",""
@@ -191,6 +192,7 @@
"Localized Strings","MapSeed","Seed" "Localized Strings","MapSeed","Seed"
"Localized Strings","MapVersion","Using mapgen v0.1" "Localized Strings","MapVersion","Using mapgen v0.1"
"Localized Strings","MapWidth","" "Localized Strings","MapWidth",""
"Localized Strings","MusicInfo",""
"Localized Strings","PerishInfo","Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned" "Localized Strings","PerishInfo","Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned"
"Localized Strings","PingInfo","Will respond with Pong!" "Localized Strings","PingInfo","Will respond with Pong!"
"Localized Strings","PingResponse","Pong!" "Localized Strings","PingResponse","Pong!"
@@ -296,6 +298,7 @@
"Command Enabler","leaderboard","1" "Command Enabler","leaderboard","1"
"Command Enabler","map","1" "Command Enabler","map","1"
"Command Enabler","mod","1" "Command Enabler","mod","1"
"Command Enabler","music","1"
"Command Enabler","perish, thenperish","1" "Command Enabler","perish, thenperish","1"
"Command Enabler","ping","1" "Command Enabler","ping","1"
"Command Enabler","poll","1" "Command Enabler","poll","1"
1 Type Key Value
38 Localized Commands leaderboard
39 Localized Commands map
40 Localized Commands mod
41 Localized Commands music
42 Localized Commands perish, thenperish
43 Localized Commands ping
44 Localized Commands poll
192 Localized Strings MapSeed Seed
193 Localized Strings MapVersion Using mapgen v0.1
194 Localized Strings MapWidth
195 Localized Strings MusicInfo
196 Localized Strings PerishInfo Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned
197 Localized Strings PingInfo Will respond with Pong!
198 Localized Strings PingResponse Pong!
298 Command Enabler leaderboard 1
299 Command Enabler map 1
300 Command Enabler mod 1
301 Command Enabler music 1
302 Command Enabler perish, thenperish 1
303 Command Enabler ping 1
304 Command Enabler poll 1
Binary file not shown.
+26
View File
@@ -0,0 +1,26 @@
package commands.music;
import core.Command;
import core.LocStrings;
import core.SubCommandFramework;
import dataStructures.*;
public class CommandMusicMain extends Command
{
SubCommandFramework framework = new SubCommandFramework();
public CommandMusicMain(KittyRole level, KittyRating rating)
{
super(level, rating);
framework.addCommand("join", new SubCommandJoin(KittyRole.General, KittyRating.Safe));
framework.addCommand("leave", new SubCommandLeave(KittyRole.General, KittyRating.Safe));
}
@Override
public String getHelpText() { return LocStrings.stub("MusicInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
framework.run(guild, channel, user, input).Call(res);
}
}
+21
View File
@@ -0,0 +1,21 @@
package commands.music;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class SubCommandJoin extends SubCommand
{
public SubCommandJoin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
return new SubCommandFormattable("" + guild.audio.joinChannel(input.args));
}
}
+21
View File
@@ -0,0 +1,21 @@
package commands.music;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class SubCommandLeave extends SubCommand
{
public SubCommandLeave(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
return new SubCommandFormattable("" + guild.audio.leaveChannel());
}
}
+2 -1
View File
@@ -48,6 +48,7 @@ import commands.general.CommandWolfram;
import commands.general.CommandYeet; import commands.general.CommandYeet;
import commands.guildrole.CommandGuildRoleMain; import commands.guildrole.CommandGuildRoleMain;
import commands.mod.CommandModMain; import commands.mod.CommandModMain;
import commands.music.CommandMusicMain;
import commands.poll.CommandPollMain; import commands.poll.CommandPollMain;
import commands.raffle.CommandRaffleMain; import commands.raffle.CommandRaffleMain;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
@@ -152,7 +153,7 @@ public class CommandManager
this.register(LocCommands.stub("character"), new CommandCharacterMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("character"), new CommandCharacterMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
} }
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands) // Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
+2 -1
View File
@@ -17,6 +17,7 @@ import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import offline.Ref; import offline.Ref;
import utils.AdminControl; import utils.AdminControl;
import utils.AudioUtils;
import utils.GlobalLog; import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
@@ -140,7 +141,7 @@ public class ObjectBuilderFactory
else else
{ {
// Construct a new guild with defaults // Construct a new guild with defaults
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString); guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, new AudioUtils(event.getGuild()));
DatabaseManager.instance.globalRegister(guild); DatabaseManager.instance.globalRegister(guild);
guildCache.put(uid, guild); guildCache.put(uid, guild);
} }
+4 -1
View File
@@ -5,6 +5,7 @@ import java.util.ArrayList;
import core.DatabaseManager; import core.DatabaseManager;
import core.DatabaseTrackedObject; import core.DatabaseTrackedObject;
import utils.AdminControl; import utils.AdminControl;
import utils.AudioUtils;
// Context for a given guild for kittybot. Primarily designed to hold guild-specific settings. // Context for a given guild for kittybot. Primarily designed to hold guild-specific settings.
public class KittyGuild extends DatabaseTrackedObject public class KittyGuild extends DatabaseTrackedObject
@@ -21,6 +22,7 @@ public class KittyGuild extends DatabaseTrackedObject
public ArrayList<String> emoji = new ArrayList<String>(); public ArrayList<String> emoji = new ArrayList<String>();
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>(); public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
public AdminControl control; public AdminControl control;
public AudioUtils audio;
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>(); public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
public ArrayList <KittyUser> raffleUsersChosen = new ArrayList<KittyUser>(); public ArrayList <KittyUser> raffleUsersChosen = new ArrayList<KittyUser>();
@@ -40,7 +42,7 @@ public class KittyGuild extends DatabaseTrackedObject
} }
// Default content for a guild // Default content for a guild
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji) public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji, AudioUtils audio)
{ {
super(uniqueID); super(uniqueID);
this.uniqueID = uniqueID; this.uniqueID = uniqueID;
@@ -52,6 +54,7 @@ public class KittyGuild extends DatabaseTrackedObject
this.contentRating = KittyRating.Safe; this.contentRating = KittyRating.Safe;
this.polling = false; this.polling = false;
this.emoji = emoji; this.emoji = emoji;
this.audio = audio;
setCommandIndicator("!"); setCommandIndicator("!");
} }
+38
View File
@@ -0,0 +1,38 @@
package utils;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.managers.AudioManager;
public class AudioUtils
{
private Guild guild;
AudioManager audio;
public AudioUtils(Guild guild)
{
this.guild = guild;
audio = guild.getAudioManager();
}
public boolean joinChannel(String channelName)
{
VoiceChannel channel = null;
channel = guild.getVoiceChannelsByName(channelName, true).get(0);
if(channel != null)
{
audio.openAudioConnection(channel);
return true;
}
return false;
}
public boolean leaveChannel()
{
if(audio.isConnected())
{
audio.closeAudioConnection();
return true;
}
return false;
}
}