Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ConfigCommand(name: String, vararg aliases: String) : Command(name, *alias
.append(context.i18nFormat("configNoArgs", context.guild.name)).append("\n")
.append("track_announce = ${gc.isTrackAnnounce}\n")
.append("auto_resume = ${gc.isAutoResume}\n")
.append("clear_on_empty = ${gc.isClearOnEmpty}")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a \n for good measure

.append("```") //opening ``` is part of the configNoArgs language string

context.reply(mb.build())
Expand Down Expand Up @@ -94,6 +95,13 @@ class ConfigCommand(name: String, vararg aliases: String) : Command(name, *alias
} else {
context.reply(context.i18nFormat("configMustBeBoolean", invoker.effectiveName.escapeAndDefuse()))
}
} else if (key == "clear_on_empty") {
if (`val`.equals("true", ignoreCase = true) or `val`.equals("false", ignoreCase = true)) {
Launcher.botController.guildConfigService.transformGuildConfig(context.guild.id) {
gc -> gc.setClearOnEmpty(java.lang.Boolean.parseBoolean(`val`))
}
context.replyWithName("`clear_on_empty`" + context.i18nFormat("configSetTo", `val`))
}
} else context.reply(context.i18nFormat("configUnknownKey", invoker.effectiveName.escapeAndDefuse()))
}

Expand Down
10 changes: 10 additions & 0 deletions FredBoat/src/main/java/fredboat/db/transfer/GuildConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class GuildConfig implements TransferObject<String> {
private String guildId = "";
private boolean trackAnnounce = false;
private boolean autoResume = false;
private boolean clearOnEmpty = true;
private String lang = "en_US";

@Override
Expand Down Expand Up @@ -65,6 +66,15 @@ public GuildConfig setAutoResume(boolean autoplay) {
return this;
}

public boolean isClearOnEmpty() {
return clearOnEmpty;
}

public GuildConfig setClearOnEmpty(boolean clearOnEmpty) {
this.clearOnEmpty = clearOnEmpty;
return this;
}

public String getLang() {
return lang;
}
Expand Down
29 changes: 27 additions & 2 deletions FredBoat/src/main/java/fredboat/event/AudioEventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ class AudioEventHandler(
}

override fun onVoiceLeave(channel: VoiceChannel, member: Member) {
checkForAutoPause(channel)
if (!checkForAutoStop(channel))
checkForAutoPause(channel)

if (!member.isUs) return
getLink(channel).onDisconnected()
}

override fun onVoiceMove(oldChannel: VoiceChannel, newChannel: VoiceChannel, member: Member) {
checkForAutoResume(newChannel, member)
checkForAutoPause(oldChannel)
if (!checkForAutoStop(newChannel))
checkForAutoPause(oldChannel)

if (!member.isUs) return
getLink(newChannel).setChannel(newChannel.id.toString())
}
Expand Down Expand Up @@ -77,4 +81,25 @@ class AudioEventHandler(
}
}

/**
* Check if the player should be stopped, if yes it will stop the player and return true
* else returns false
*
* @return Boolean if player has been stopped
**/
private fun checkForAutoStop(channel: VoiceChannel): Boolean {
Comment thread
freyacodes marked this conversation as resolved.
Outdated
val player = playerRegistry.getExisting(channel.guild) ?: return false

if (!player.isQueueEmpty
&& player.humanUsersInCurrentVC.isEmpty()
&& guildConfigService.fetchGuildConfig(channel.guild.id).isClearOnEmpty) {
player.stop()
player.activeTextChannel?.send(I18n.get(channel.guild).getString("eventAutoStop"))?.subscribe()

return true
}

return false
}

}
1 change: 1 addition & 0 deletions FredBoat/src/main/resources/lang/en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ userinfoBlacklisted=Blacklisted\:
skipDeniedTooManyTracks=You can't skip someone else's tracks if you are not a DJ.\nConsider using the Voteskip command.
eventUsersLeftVC=All users have left the voice channel. The player has been paused.
eventAutoResumed=User presence detected, automatically resuming the player.
eventAutoStop=All user have left the voice channel. The player has been cleared.
Comment thread
Nanabell marked this conversation as resolved.
Outdated
commandsFun=Fun
commandsMemes=Memes
commandsUtility=Utility
Expand Down