Skip to content

Commit

Permalink
fix: missing GoLive end notification (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuahp authored Nov 8, 2023
1 parent 92f84b0 commit 8eefad1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/kotlin/com/jaoafa/vcspeaker/events/GoLiveEndEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,32 @@ class GoLiveEndEvent : Extension() {
// 読み上げチャンネルが設定されていること
val settings = GuildStore.getOrDefault(event.state.guildId)
failIf(settings.channelId == null)
// VCに参加したときではないこと
failIf(event.old?.isSelfStreaming == null)
// GoLiveのステータスが変わったときのみ
failIf(event.old?.isSelfStreaming == event.state.isSelfStreaming)
// GoLiveを終了したときのみ
failIf(event.state.isSelfStreaming)

val oldStreaming = event.old?.isSelfStreaming ?: false
val newStreaming = event.state.isSelfStreaming
val userLeft = event.old?.getChannelOrNull() != null && event.state.getChannelOrNull() == null

// GoLive を終了 or GoLive をしたまま VC から退出
if ((oldStreaming && !newStreaming) || (oldStreaming && userLeft)) {
pass()
} else fail()
}

action {
val guild = event.state.getGuildOrNull() ?: return@action // checked
val member = event.state.getMember()
val channelGoLiveStarted = event.state.getChannelOrNull() ?: return@action // checked
val channelGoLiveEnded = event.old?.getChannelOrNull() ?: return@action // checked

val selfChannel = guild.selfVoiceChannel()

val voice = if (channelGoLiveStarted == selfChannel) {
val voice = if (channelGoLiveEnded == selfChannel) {
NarrationScripts.userEndGoLive(member)
} else {
NarrationScripts.userEndGoLiveOtherChannel(member, channelGoLiveStarted)
NarrationScripts.userEndGoLiveOtherChannel(member, channelGoLiveEnded)
}
guild.announce(
voice = voice,
text = ":satellite: `@${member.username}` が ${channelGoLiveStarted.mention} で GoLive を終了しました。"
text = ":satellite: `@${member.username}` が ${channelGoLiveEnded.mention} で GoLive を終了しました。"
)
}
}
Expand Down

0 comments on commit 8eefad1

Please sign in to comment.