-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Prepare for re-instating clip command * Restore clip command for clip length longer than current recording * Add bytes per second constant for use with clip * Disambiguate recordingSize(global) with recordingSize(local) * Delete dummy main used for experimenting clips * BYTES_PER_SECOND should be Long, and change log to debug for rec size * Implement clip by copying tape and trimming until correct length
- Loading branch information
1 parent
3bd8cea
commit b6951aa
Showing
3 changed files
with
112 additions
and
11 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
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,57 @@ | ||
package tech.gdragon.commands.audio | ||
|
||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import tech.gdragon.BotUtils | ||
import tech.gdragon.commands.Command | ||
import tech.gdragon.db.dao.Guild | ||
import tech.gdragon.listener.CombinedAudioRecorderHandler | ||
|
||
class Clip : Command { | ||
override fun action(args: Array<out String>, event: GuildMessageReceivedEvent) { | ||
val prefix = transaction { | ||
val guild = Guild.findById(event.guild.idLong) | ||
guild?.settings?.prefix ?: "!" | ||
} | ||
|
||
require(args.size in 1..2) { | ||
BotUtils.sendMessage(event.channel, usage(prefix)) | ||
} | ||
|
||
val message = | ||
if (event.guild.audioManager.connectedChannel == null) { | ||
"I wasn't recording!" | ||
} else { | ||
val voiceChannel = event.guild.audioManager.connectedChannel.name | ||
val audioReceiveHandler = event.guild.audioManager.receiveHandler as CombinedAudioRecorderHandler | ||
|
||
try { | ||
val seconds = args.first().toLong() | ||
|
||
if (args.size == 1) { | ||
audioReceiveHandler.saveClip(seconds, voiceChannel, event.channel) | ||
"" | ||
} else { | ||
val channelName = if (args[1].startsWith("#")) args[1].substring(1) else args[1] | ||
val channels = event.guild.getTextChannelsByName(channelName, true) | ||
|
||
if (channels.isEmpty()) { | ||
"Cannot find $channelName." | ||
} else { | ||
channels.forEach { audioReceiveHandler.saveClip(seconds, voiceChannel, event.channel) } | ||
"" | ||
} | ||
} | ||
} catch (e: NumberFormatException) { | ||
usage(prefix) | ||
} | ||
} | ||
|
||
if (message.isNotBlank()) | ||
BotUtils.sendMessage(event.channel, message) | ||
} | ||
|
||
override fun usage(prefix: String): String = "${prefix}clip [seconds] | ${prefix}clip [seconds] [text channel output]" | ||
|
||
override fun description(): String = "Saves a clip of the specified length (seconds) and outputs it in the current or specified text channel." | ||
} |
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