Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

New persistence system #573

Draft
wants to merge 189 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
8bfa784
Make ATC use ObjectId
freyacodes Nov 14, 2018
29a0f4c
Add saving of player state
freyacodes Nov 14, 2018
cd05493
Add half-done handling of loading players
freyacodes Nov 14, 2018
10dbc1e
Apply a mono cache pattern to player loading
freyacodes Nov 15, 2018
f805b53
Make GuildPlayers load from mongo data
freyacodes Nov 15, 2018
70741a6
Fix tests
freyacodes Nov 15, 2018
3b2ff87
Add mongo service to testing
freyacodes Nov 16, 2018
272881b
Add resuming
freyacodes Nov 23, 2018
eb19a6d
Actually set player in registry
freyacodes Nov 26, 2018
71a23da
Start player creation upon link creation
freyacodes Nov 26, 2018
6c0f7f1
Make LLC provide Sentinel-cached VSU
freyacodes Nov 27, 2018
a2c60a9
Save player state as a shutdown hook
freyacodes Nov 27, 2018
48792fc
Give registry shutdown hook a name
freyacodes Nov 29, 2018
35ad3a4
Fix mongodb not loading
freyacodes Nov 30, 2018
bd11f15
Fix recursion
freyacodes Nov 30, 2018
9573631
Add reactor-test library
freyacodes Nov 30, 2018
38b0e8c
Save player state on unsub
freyacodes Nov 30, 2018
852077d
Fix reactor-test version
freyacodes Dec 6, 2018
8212d4f
Add testLazyMono() test
freyacodes Dec 6, 2018
eabf11e
Fix Sentinel VSU not getting provided
freyacodes Dec 6, 2018
b5b8366
Fix link channel being null after cached VSU
freyacodes Dec 6, 2018
95b71da
Fix player state saving
freyacodes Dec 7, 2018
bb27786
Clean up mongo player load code
freyacodes Dec 7, 2018
c0072ec
Maybe resuming would work if we told the client to do so 🤔
freyacodes Dec 7, 2018
8579c7c
Merge branch 'dev' into player-persistence
freyacodes Dec 7, 2018
a577c8d
Fix parameter mismatch
freyacodes Dec 7, 2018
34b1355
Fix exceptions when resuming
freyacodes Dec 7, 2018
8f0bd5d
Fall back to default ;;np embed if no YT key found
freyacodes Dec 7, 2018
e16be42
Use PlayerEventListenerAdapter instead of LP listener
freyacodes Dec 7, 2018
e542681
Fix bad method signatures
freyacodes Dec 7, 2018
fd41a13
Properly populate LLC state on resume
freyacodes Dec 11, 2018
09d7753
Add mongodb to docker-compose
freyacodes Dec 12, 2018
d7e250c
Fix not setting player context on resume
freyacodes Dec 14, 2018
bf00ed1
Fix history NPE
freyacodes Dec 14, 2018
3b25f90
Stop duplication of playing track on resume
freyacodes Dec 14, 2018
4c49ed6
Merge remote-tracking branch 'origin/dev' into player-persistence
freyacodes Dec 17, 2018
aedde18
Fix resuming after Sentinel is restarted
freyacodes Dec 17, 2018
175948b
Instrument DAU, WAU, and MAU
freyacodes Dec 27, 2018
cee37b2
Add INSTRUMENT_ACTIVE_USERS feature flag
freyacodes Dec 27, 2018
655768e
Merge remote-tracking branch 'origin/activity-metrics' into player-pe…
freyacodes Dec 27, 2018
8aafd43
Fix test compile error
freyacodes Dec 27, 2018
84a2521
Merge AbstractPlayer into GuildPlayer
freyacodes Dec 27, 2018
b665566
Refactor GuildPlayer
freyacodes Dec 27, 2018
204c6c7
Extract GuildPlayer members to extensions
freyacodes Dec 27, 2018
08ecf8a
Migrate classes to kotlin for extension support
freyacodes Dec 27, 2018
4ab1da0
Add simple player info server
freyacodes Dec 28, 2018
cb80fa3
Add ConfigWebInfoCommand
freyacodes Dec 28, 2018
9aa2d1d
Fix test compile error
freyacodes Dec 28, 2018
0949d07
Fix integration test
freyacodes Dec 28, 2018
6862c57
Redo the websocket system because webflux requires reactive
freyacodes Dec 29, 2018
729b727
Attempt to fix recursion bug
freyacodes Dec 29, 2018
f401bc0
Remove Spring web starter again
freyacodes Dec 29, 2018
0491bc1
Use scheduler to get around recursion bug
freyacodes Dec 29, 2018
1af1394
Remove servlet annotation
freyacodes Dec 29, 2018
b97ebc1
Add a safeguard against recursion
freyacodes Dec 29, 2018
10e9250
Add an error check to recursion safeguard
freyacodes Dec 29, 2018
b629cdd
Fix typo
freyacodes Dec 29, 2018
5c8338e
Send thumbnail with track info
freyacodes Dec 29, 2018
6e05b81
Fix out of bounds error
freyacodes Dec 29, 2018
0c61160
Also run link post-process after GP init
freyacodes Dec 29, 2018
5ba1845
Fix track duplication bug
freyacodes Jan 8, 2019
6c94a17
Persist active text channel
freyacodes Jan 11, 2019
6307617
Update LLC
freyacodes Jan 13, 2019
9ace476
First implementation for caching mongo results (DUMP)
Nanabell Jan 24, 2019
6937a33
mongodb cache implementation dump
Feb 5, 2019
53a6f04
Implement GuildSettingsRepository
Feb 8, 2019
3648957
Implement GuildPermissionsRepository
Feb 8, 2019
82b6ade
Put common repository methods in Base-Class
Feb 8, 2019
995345e
Implement BlacklistRepository
Feb 8, 2019
3afb171
Implement PrefixRepository
Feb 8, 2019
9f40217
Combine Module, Permissions & Prefix into GuildSettings
Feb 8, 2019
aecacfd
Final Cleanup & Implement SearchResultRepository
Feb 9, 2019
d74c5e7
Merge branch 'dev' into feature/webinfo
Feb 9, 2019
0e1d50c
Remove accidental merge of the java classes
Feb 9, 2019
08de9cf
Add missing imports for PlayCommand.kt
Feb 9, 2019
f921b74
GuildPlayer context is now named internalContext
Feb 9, 2019
a40a5a6
Rename Test MockGuildPermsService.delete to .remove
Feb 9, 2019
1aba4c1
Remove QuarterdeckConfiguration.java
Feb 9, 2019
e24fa45
Nitpicks, CodeStyle
Feb 10, 2019
0e3464d
Fix GuildPlayer isTrackAnnounceEnabled always being false
Feb 10, 2019
4b84622
Fix GuildEventHandler to actually send Hello on first join
Feb 10, 2019
d3b32e5
GuildPlayer announceTrack just use 2 subscribes
Feb 10, 2019
f2684ab
GuildPlayer announceTrack to method and better name
Feb 10, 2019
23a63e8
Update blocking Blacklist Methods to return Monos instead
Feb 10, 2019
870cf40
Convert I18n.java to Kotlin
Feb 10, 2019
558bff9
Add BaseDefaultedRepository
Feb 12, 2019
27ea84e
Switch Prefix Cache to Caffeine
Feb 12, 2019
e6cbc6b
Switch Prefix Command to Caffeine cache
Feb 12, 2019
e3f54a9
Convert TrackSearcher to Kotlin and make cache calls suspend
Feb 12, 2019
d50c7aa
fred help how to?
Feb 12, 2019
cb50a8e
More suspend because its awesome
Feb 12, 2019
71a0f94
Simplify If else
Feb 12, 2019
1de6af4
Merge pull request #559 from Nanabell/feature/webinfo
freyacodes Feb 15, 2019
1736b99
Change misleading fromEnum function name
freyacodes Feb 15, 2019
244d18d
Adapt the configs for no quarterdeck
freyacodes Feb 15, 2019
ff726d3
Uh oh, @Nanabell just got BEANED https://fred.moe/HKX.png
freyacodes Feb 15, 2019
001b408
Fix 563 and add i18n for Requested by
OtterBoops Feb 15, 2019
a1aafd0
Fetch prefix async
freyacodes Feb 15, 2019
bd0934a
Remove unnecessary secondary prefix cache
freyacodes Feb 15, 2019
914e63a
Replace funky concurrency workaround
freyacodes Feb 15, 2019
877a344
Mark more i18n methods as deprecated
freyacodes Feb 15, 2019
1953a47
Update LLC
freyacodes Feb 15, 2019
32630f7
Fix WS open race condition
freyacodes Feb 16, 2019
6906e27
Update Spring-AMQP
freyacodes Feb 16, 2019
ae625e0
Fix lateinit exception
freyacodes Feb 16, 2019
cfe81fa
Fix bad import
freyacodes Feb 16, 2019
d823795
Add everyone Role to User & DJ list by default
Feb 17, 2019
5fb021a
Remove old MusicPersistenceHandler
Feb 17, 2019
68f01b2
Auto set Rand to Integer MIN when ATC is priority
Feb 17, 2019
5e2e2ad
Remove TrackProvider queueFirst, instead use atc.isPriority in add
Feb 17, 2019
7952101
Force audioLoading to use GuildPlayer to add to queue
Feb 17, 2019
cbb3854
Rename GuildPlayer addAll to queueAll
Feb 17, 2019
482a488
Fix sometimes refusing to join VC
freyacodes Feb 18, 2019
e173513
Fix rejoining channel when leaving intentionally
freyacodes Feb 18, 2019
a13aba9
Fix sending to multiple WS clients ... maybe?
freyacodes Feb 18, 2019
76c91d0
Exempt FBH mods from FBH command restriction
Nanabell Feb 22, 2019
fabc3c8
Allow I18n getLocale(Guild) to be null
Feb 23, 2019
8cb5fba
Add NullableContext as base Context
Feb 23, 2019
c0dd1e8
Make Context inherit from NullableContext
Feb 23, 2019
a839dcd
Make AudioTrackContext inherit from NullableContext
Feb 23, 2019
62d0c94
At .floo files
Feb 23, 2019
9e7ef18
#I need to commit more. Implement QueueLimiter with 4 QueueLimits for…
Feb 23, 2019
a38809c
Whitelist DJ and above for QueueLimits
Feb 23, 2019
bdd3402
Remove old databaseException Metric entry
Feb 23, 2019
236a0ac
Simplify audioLoading PlaylistLoaded QueueLimit UX handling
Feb 23, 2019
bfb51e0
Move atc priority rand set to correct place
Feb 23, 2019
9ddb76b
Update Guildplayer#loadAll (again) to take isPriority parameter
Feb 26, 2019
ce52191
Add ReplayCommand
Feb 26, 2019
d9b8056
PlayCommand only search if user is in videoSelectionCache
Feb 26, 2019
3b1346f
Limit SPLIT_SELECT_ALLOWED CharMatcher to only account for nrs 1-5
Feb 26, 2019
337337c
Merge pull request #569 from Frederikam/bugfix/number-searching
freyacodes Mar 3, 2019
07adaab
Add IQueueHandler to replace TrackProvider
Mar 3, 2019
45c54b9
Add SimpleQueueHandler to do basic logging of QueueHandler events
Mar 3, 2019
0870096
Add ShufflableQueueHandler to add shuffle capabilities to queue
Mar 3, 2019
640f3fe
Add RoundRobinQueueHandler to add roundRobin queue capabilities to queue
Mar 3, 2019
9816cd7
Add RepeatableQueueHandler to add repeat capabilities to queue
Mar 3, 2019
9ea8f43
Use new IQueueHandler in GuildPlayer and depending
Mar 3, 2019
0dae434
Fix raising onListRemove event when no tracks need to be removed
Mar 3, 2019
9fe3627
Rename guildPlayerUtils#userTackCount to getUserTrackCount
Mar 3, 2019
34eeabc
Rename ITrackProvider#size(Long) to getCountByUser(Long)
Mar 3, 2019
d07d16c
Update translations with the help of @OtterBoops
Mar 3, 2019
9aed2c5
sugar syntax
Mar 3, 2019
296c744
make config command modular and add player limit options
Mar 3, 2019
bf66a10
Add roundRobin field to GuildPlayer
Mar 3, 2019
0384c2f
Add persistence for roundRobin
Mar 3, 2019
330c7e9
add is prefix to roundRobin field
Mar 3, 2019
267b2f3
Add RoundRobinCommand
Mar 3, 2019
91614bf
Update ListCommand to show roundRobin State
Mar 3, 2019
4e948fb
Set internal default RoundRobin setting to false
Mar 3, 2019
de608b2
Simplify code a bit
freyacodes Mar 8, 2019
03ef12a
Merge pull request #564 from OtterBoops/dev
freyacodes Mar 8, 2019
a1e7195
Fredboat-566 Revert "Make AudioTrackContext inherit from NullableCont…
Mar 8, 2019
4ca3122
Only Limit non BOT_ADMINS with the new Unban & Softban
Mar 10, 2019
661b6d3
Ensure that lastTrack cannot turn null after we do null check
Mar 23, 2019
119f0f8
Add basic auth to wastebin POSTs
schnapster Mar 23, 2019
d247b05
Update translations according to fred's suggestions
Mar 31, 2019
fa79226
Unify list priority queueing across all PR's
Mar 31, 2019
2812539
Merge branch 'dev' into feature/webinfo
freyacodes Mar 31, 2019
eb91416
Make failed assertions easier to debug
freyacodes Mar 31, 2019
b42933b
Merge branch 'feature/webinfo' into feature/player-limitations
freyacodes Mar 31, 2019
d33a012
Fix assert wording
freyacodes Mar 31, 2019
1a2d83d
Rename valueFormat to validator and turn it into a typeAlias Validator
Apr 1, 2019
381610e
Move update() Subscribe to calling method
Apr 1, 2019
d89e365
Make Config Options more readable?
Apr 1, 2019
3656dd1
Merge remote-tracking branch 'origin/feature/player-limitations' into…
Apr 1, 2019
64059ed
Negate FBH Moderation Role check for blocking execution
Apr 1, 2019
d81ac12
Convert update() to expression
Apr 1, 2019
8ea1f9e
Fix if for dynamic play response always being true at this stage
Apr 2, 2019
ecc4d17
Merge pull request #566 from Frederikam/feature/player-limitations
freyacodes Apr 2, 2019
f127a96
Update translations
freyacodes Apr 2, 2019
41eed8d
Merge branch 'feature/webinfo' into feature/queue-rework
Apr 2, 2019
de09941
Merge branch 'feature/webinfo' into feature/queue-rework
Apr 2, 2019
1119779
Fix GuildPlayer#queue() starting to play track
Apr 2, 2019
9d1ded3
Add RoundRobin-On/Off translations
Nanabell Apr 7, 2019
f5d8907
Add Add help Translation String
Nanabell Apr 7, 2019
f3a4723
Merge remote-tracking branch 'origin/feature/webinfo' into feature/re…
freyacodes May 1, 2019
37b4482
Fix compile error
freyacodes May 1, 2019
afeb362
Source string tweaks
freyacodes May 1, 2019
5286354
Merge pull request #568 from Frederikam/feature/replay
freyacodes May 1, 2019
450cf6d
Rename “tbd” package to “handlers”
freyacodes May 1, 2019
95b51b9
Merge branch 'feature/webinfo' into feature/queue-rework
freyacodes May 1, 2019
941899b
RR queue source string changes
freyacodes May 1, 2019
41a7736
Merge pull request #574 from Frederikam/feature/queue-rework
freyacodes May 1, 2019
5cfe879
Update translations
freyacodes May 1, 2019
0ac8f9f
Fix connect loop regression
freyacodes Jun 22, 2019
2d50c37
Update build.gradle
freyacodes Aug 1, 2019
90639f0
Fix compile error
freyacodes Aug 4, 2019
efbb344
Revert "Fix connect loop regression"
freyacodes Aug 4, 2019
9cb7343
Revert "Revert "Fix connect loop regression""
freyacodes Aug 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .floo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"url": "https://floobits.com/Frederikam/FredBoat"
}
11 changes: 11 additions & 0 deletions .flooignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern
node_modules
tmp
vendor
.idea/workspace.xml
.idea/misc.xml
.idea

fredboat.yml
fredboat.yaml
commons.yml
freyacodes marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion FredBoat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ dependencies {
}

compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb-reactive', version: springBootVersion
compile group: 'org.springframework', name: 'spring-websocket', version: springWebSocketVersion
compile group: 'it.unimi.dsi', name: 'fastutil', version: fastUtilVersion
compile group: 'com.google.code.gson', name: 'gson', version: gsonVersion
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-reactor', version: '1.0.1'
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-reactor', version: '1.1.1'
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: '1.1.1'
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: amqpVersion
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: jacksonKotlinVersion

Expand All @@ -72,6 +75,7 @@ dependencies {
testCompile group: 'com.palantir.docker.compose', name: 'docker-compose-rule-junit4', version: dockerComposeRuleVersion
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
testCompile group: 'org.postgresql', name: 'postgresql', version: postgresJdbcVersion
testCompile 'io.projectreactor:reactor-test:3.1.6.RELEASE'
optional group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: springBootVersion

/* Explicitly set these, instead of getting outdated transitive ones */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package fredboat.agent
import com.fredboat.sentinel.entities.GuildUnsubscribeRequest
import fredboat.audio.lavalink.SentinelLavalink
import fredboat.audio.player.PlayerRegistry
import fredboat.db.mongo.PlayerRepository
import fredboat.db.mongo.convertAndSave
import fredboat.sentinel.GuildCache
import fredboat.sentinel.InternalGuild
import lavalink.client.io.Link
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Controller
import reactor.core.publisher.Mono
import java.time.Duration
import java.util.concurrent.TimeUnit

@Controller
class GuildCacheInvalidationAgent(
val guildCache: GuildCache,
private val playerRegistry: PlayerRegistry,
private val playerRepository: PlayerRepository,
private val lavalink: SentinelLavalink
) : FredBoatAgent("cache-invalidator", 5, TimeUnit.MINUTES) {

Expand Down Expand Up @@ -59,14 +64,19 @@ class GuildCacheInvalidationAgent(
}

fun invalidateGuild(guild: InternalGuild) {
try {
playerRegistry.destroyPlayer(guild)
lavalink.getExistingLink(guild)?.destroy()
} catch (e: Exception) {
log.error("Got exception when invaliding GuildPlayer and Link for {}", guild)
val mono = playerRegistry.getExisting(guild)?.let {
playerRepository.convertAndSave(it).timeout(Duration.ofSeconds(60))
} ?: Mono.empty()
mono.subscribe {
try {
playerRegistry.destroyPlayer(guild)
lavalink.getExistingLink(guild)?.destroy()
} catch (e: Exception) {
log.error("Got exception when invaliding GuildPlayer and Link for {}", guild)
}
guild.sentinel.sendAndForget(guild.routingKey, GuildUnsubscribeRequest(guild.id))
guildCache.cache.remove(guild.id)
}
guild.sentinel.sendAndForget(guild.routingKey, GuildUnsubscribeRequest(guild.id))
guildCache.cache.remove(guild.id)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class VoiceChannelCleanupAgent(
} else if (vc != null && isBeingUsed(vc)) {
vcLastUsed[vcId] = System.currentTimeMillis()
} else {
// Not being used! But there are users in te VC. Check if we've been here for a while.
// Not being used! But there are users in the VC. Check if we've been here for a while.

vcId?.let {
if (!vcLastUsed.containsKey(vcId)) {
Expand Down
4 changes: 1 addition & 3 deletions FredBoat/src/main/java/fredboat/api/MetricsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ private String buildAnswer(String[] includedParam) throws IOException {
}

Writer writer = new StringWriter();
try {
try (writer) {
TextFormat.write004(writer, registry.filteredMetricFamilySamples(params));
writer.flush();
} finally {
writer.close();
}

return writer.toString();
Expand Down
46 changes: 42 additions & 4 deletions FredBoat/src/main/java/fredboat/audio/lavalink/SentinelLavalink.kt
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
package fredboat.audio.lavalink

import com.fredboat.sentinel.entities.VoiceServerUpdate
import fredboat.audio.player.PlayerRegistry
import fredboat.config.idString
import fredboat.config.property.AppConfig
import fredboat.config.property.LavalinkConfig
import fredboat.db.mongo.ActivityMetricsController
import fredboat.sentinel.Guild
import fredboat.sentinel.GuildCache
import fredboat.sentinel.Sentinel
import fredboat.util.DiscordUtil
import fredboat.ws.UserSessionHandler
import lavalink.client.io.Lavalink
import lavalink.client.io.metrics.LavalinkCollector
import org.json.JSONObject
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import java.time.Duration
import java.util.concurrent.TimeoutException

@Suppress("ImplicitThis", "LeakingThis")
@Service
class SentinelLavalink(
val sentinel: Sentinel,
val guildCache: GuildCache,
val appConfig: AppConfig,
val activityMetrics: ActivityMetricsController,
val userSessionHandler: UserSessionHandler,
lavalinkConfig: LavalinkConfig
) : Lavalink<SentinelLink>(
sentinel.selfUser.idString,
appConfig.shardCount
) {

lateinit var playerRegistry: PlayerRegistry
private val resumeKey = "fredboat-${sentinel.selfUser.idString}"

companion object {
lateinit var INSTANCE: SentinelLavalink
private const val DEFAULT_RESUME_TIMEOUT = 300 // 5 mins
private val log: Logger = LoggerFactory.getLogger(SentinelLavalink::class.java)
}

init {
@Suppress("LeakingThis")
INSTANCE = this
lavalinkConfig.nodes.forEach { addNode(it.name, it.uri, it.password) }
@Suppress("LeakingThis")
setHoldEvents(true)
lavalinkConfig.nodes.forEach {
addNode(it.name, it.uri, it.password, resumeKey)
.setResuming(resumeKey, DEFAULT_RESUME_TIMEOUT)
}
LavalinkCollector(this).register<LavalinkCollector>()
}

override fun buildNewLink(guildId: String) = SentinelLink(this, guildId)
override fun buildNewLink(guildId: String): SentinelLink {
val shardId = DiscordUtil.getShardId(guildId.toLong(), appConfig)
val shardMono = sentinel.tracker.awaitHello(shardId)
val guildMono = guildCache.getGuildMono(guildId.toLong()).doOnSuccess { guild ->
if (guild == null) {
log.warn("Built link for non-existing guild. This should not happen.")
return@doOnSuccess
}
playerRegistry.getOrCreate(guild).subscribe()
}

shardMono.timeout(Duration.ofSeconds(120))
.onErrorMap(TimeoutException::class.java) {
RuntimeException("Attempted to resume Lavalink, but Sentinel hello timed out")
}.then(guildMono)
.subscribe()

return SentinelLink(this, guildId)
}

fun getLink(guild: Guild) = getLink(guild.id.toString())
fun getExistingLink(guild: Guild) = getExistingLink(guild.idString)
Expand Down
15 changes: 13 additions & 2 deletions FredBoat/src/main/java/fredboat/audio/lavalink/SentinelLink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fredboat.sentinel.entities.AudioQueueRequest
import com.fredboat.sentinel.entities.AudioQueueRequestEnum.*
import fredboat.perms.InsufficientPermissionException
import fredboat.perms.Permission.*
import fredboat.sentinel.Guild
import fredboat.sentinel.VoiceChannel
import lavalink.client.io.Link
import org.slf4j.Logger
Expand Down Expand Up @@ -59,6 +60,16 @@ class SentinelLink(val lavalink: SentinelLavalink, guildId: String) : Link(laval
queueAudioConnect(channel.id)
}

fun getChannel(guild: Guild): VoiceChannel? {
val id = channel ?: return null
val vc = guild.getVoiceChannel(id.toLong())

if (vc != null) return vc

log.warn("Lavalink appears to be connected to vc $id, which doesn't seem to exist in $guild")
return null
}

override fun onVoiceWebSocketClosed(code: Int, reason: String, byRemote: Boolean) {
val by = if (byRemote) "Discord" else "LLS"
log.info("{}: Lavalink voice WS closed by {}, code {}: {}", guild, by, code, reason)
Expand All @@ -75,8 +86,8 @@ class SentinelLink(val lavalink: SentinelLavalink, guildId: String) : Link(laval
queueAudioConnect(vc.toLong())
} else {
log.warn("{}: Got WS close code $code twice within $MIN_RETRY_INTERVAL ms, disconnecting " +
" to prevent bouncing and getting stuck...", guild)
queueAudioDisconnect()
"to prevent bouncing and getting stuck...", guild)
disconnect()
}
}
}
Expand Down
Loading