forked from lavalink-devs/Lavalink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adb43de
commit fcc1ffe
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ build/* | |
.project | ||
.classpath | ||
.settings | ||
/Testbot/build/ | ||
/Testbot/out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'kotlin' | ||
apply plugin: 'application' | ||
|
||
group 'lavalink' | ||
version '1.0' | ||
|
||
repositories { | ||
mavenCentral() | ||
jcenter() | ||
maven { url 'https://jitpack.io' } | ||
} | ||
|
||
dependencies { | ||
compile ('net.dv8tion:JDA:4.1.1_135') { | ||
exclude module: 'opus-java' | ||
} | ||
compile "com.github.FredBoat:Lavalink-Client:f84b333518" | ||
compile "ch.qos.logback:logback-classic:$logbackVersion" | ||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} | ||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package lavalink.testbot | ||
|
||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler | ||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager | ||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers | ||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException | ||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack | ||
import lavalink.client.io.jda.JdaLavalink | ||
import net.dv8tion.jda.api.JDA | ||
import net.dv8tion.jda.api.JDABuilder | ||
import net.dv8tion.jda.api.entities.Member | ||
import net.dv8tion.jda.api.entities.TextChannel | ||
import net.dv8tion.jda.api.events.ReadyEvent | ||
import net.dv8tion.jda.api.events.StatusChangeEvent | ||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter | ||
import net.dv8tion.jda.api.requests.GatewayIntent | ||
import net.dv8tion.jda.api.utils.cache.CacheFlag.* | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.net.URI | ||
|
||
private val log: Logger = LoggerFactory.getLogger("Testbot") | ||
private lateinit var jda: JDA | ||
private val lavalink = JdaLavalink(1) { _ -> jda } | ||
private val playerManager = DefaultAudioPlayerManager() | ||
|
||
fun main() { | ||
AudioSourceManagers.registerRemoteSources(playerManager) | ||
|
||
jda = JDABuilder.createDefault(System.getenv("TOKEN"), | ||
GatewayIntent.GUILD_MESSAGES, | ||
GatewayIntent.GUILD_VOICE_STATES) | ||
.disableCache(CLIENT_STATUS, ACTIVITY, CLIENT_STATUS, EMOTE, MEMBER_OVERRIDES) | ||
.addEventListeners(Listener, lavalink) | ||
.setVoiceDispatchInterceptor(lavalink.voiceInterceptor) | ||
.build() | ||
} | ||
|
||
object Listener : ListenerAdapter() { | ||
override fun onStatusChange(event: StatusChangeEvent) { | ||
log.info("{} -> {}", event.oldStatus, event.newStatus) | ||
} | ||
|
||
override fun onReady(event: ReadyEvent) { | ||
lavalink.setUserId(jda.selfUser.id) | ||
lavalink.addNode(URI("ws://localhost:2333"), "youshallnotpass") | ||
} | ||
|
||
override fun onGuildMessageReceived(event: GuildMessageReceivedEvent) { | ||
val member = event.member ?: return | ||
if (member.user.isBot) return | ||
|
||
try { | ||
play(event.channel, member, event.message.contentRaw) | ||
} catch (e: Exception) { | ||
event.channel.sendMessage(e.message ?: e.toString()).queue() | ||
} | ||
} | ||
} | ||
|
||
fun play(channel: TextChannel, member: Member, message: String) { | ||
if (message.startsWith(";;play ")) { | ||
val vc = member.voiceState?.channel | ||
if (vc == null) { | ||
channel.sendMessage("You must be in a voice channel").queue() | ||
return | ||
} | ||
|
||
val link = lavalink.getLink(channel.guild) | ||
link.connect(vc) | ||
|
||
val track = message.drop(";;play ".length).trim() | ||
playerManager.loadItem(track, object : AudioLoadResultHandler { | ||
override fun loadFailed(e: FriendlyException) { | ||
channel.sendMessage(e.message ?: e.toString()).queue() | ||
} | ||
|
||
override fun trackLoaded(track: AudioTrack) { | ||
channel.sendMessage("Playing " + track.info.title).queue() | ||
link.player.playTrack(track) | ||
} | ||
|
||
override fun noMatches() { | ||
channel.sendMessage("No matches").queue() | ||
} | ||
|
||
override fun playlistLoaded(playlist: AudioPlaylist) { | ||
val track = playlist.selectedTrack ?: playlist.tracks.firstOrNull() | ||
if (track == null) { | ||
channel.sendMessage("Empty playlist").queue() | ||
return | ||
} | ||
channel.sendMessage("Playing " + track.info.title).queue() | ||
link.player.playTrack(track) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
rootProject.name = 'Lavalink-Parent' | ||
include ':Lavalink-Server' | ||
include ':Testbot' | ||
|
||
project(':Lavalink-Server').projectDir = "$rootDir/LavalinkServer" as File |