public string[] GetVoiceFileNames(VoicePhraseType voicePhraseType) { if (!voiceFileNames.ContainsKey(voicePhraseType)) { voiceFileNames[voicePhraseType] = Directory.GetFiles(Path.Combine(this.VoiceFilePath, voicePhraseType.ToString().ToLowerInvariant())); } return(voiceFileNames[voicePhraseType]); }
public async Task SendAudioAsync(IGuildUser guildUser, IVoiceChannel voiceChannel, VoicePhraseType voicePhraseType) { if (voiceChannel is IGuildChannel guildChannel) { var botGuildUser = await guildChannel.Guild.GetCurrentUserAsync(); if (voiceChannel != null && botGuildUser.VoiceChannel == voiceChannel) { if (audioInstances.TryGetValue(voiceChannel.GuildId, out AudioInstance audioInstance)) { string[] voiceFileNames = null; if (voicePhraseType == VoicePhraseType.UserJoin) { // if it's a first time rejoin, let's make it special voiceFileNames = PhrasesConfig.Instance.GetVoiceFileNames(VoicePhraseType.UserJoin); if (!audioInstance.Users.ContainsKey(guildUser.Id)) { audioInstance.Users[guildUser.Id] = AudioUserState.SeenOnce; } else if (audioInstance.Users[guildUser.Id] == AudioUserState.SeenOnce) { audioInstance.Users[guildUser.Id] = AudioUserState.SeenMultiple; voiceFileNames = PhrasesConfig.Instance.GetVoiceFileNames(VoicePhraseType.UserRejoin); } } else { voiceFileNames = PhrasesConfig.Instance.GetVoiceFileNames(VoicePhraseType.UserLeave); } await this.SendAudioAsync(audioInstance, voiceFileNames.Random()); } } } }