private static void Client_OnLoggedIn(DiscordSocketClient client, LoginEventArgs args) { Console.WriteLine("Logged in"); client.SetActivity(new StreamActivity() { Name = "powered by Anarchy", Url = "https://www.twitch.tv/ilinked" }); if (client.User.Type == UserType.User) { foreach (var guild in args.Guilds) { VoiceStates.Add(guild.Id, guild.ToSocketGuild().VoiceStates.ToList()); } } }
/// <summary> /// Initializes a new instance of the <see cref="VoiceService"/> class. /// </summary> /// <param name="channelsService">The app's channel service.</param> /// <param name="discordService">The app's discord service.</param> /// <param name="dispatcherHelper">The app's dispatcher helper.</param> /// <param name="gatewayService">The app's gateway service.</param> /// <param name="webrtcManager">The app's webrtc manager.</param> public VoiceService( IChannelsService channelsService, IDiscordService discordService, IDispatcherHelper dispatcherHelper, IGatewayService gatewayService, ISettingsService settingsService) { _channelsService = channelsService; _discordService = discordService; _dispatcherHelper = dispatcherHelper; _gatewayService = gatewayService; _settingsService = settingsService; _ = CreateAppService(); Messenger.Default.Register <GatewayVoiceStateUpdateMessage>(this, m => { _dispatcherHelper.CheckBeginInvokeOnUi(() => { if (VoiceStates.ContainsKey(m.VoiceState.UserId)) { var oldChannel = _channelsService.GetChannel(VoiceStates[m.VoiceState.UserId].ChannelId); oldChannel?.ConnectedUsers.Remove(m.VoiceState.UserId); if (m.VoiceState.ChannelId == null) { if (m.VoiceState.UserId == _discordService.CurrentUser.Id) { DisconnectFromVoiceChannel(); } else { VoiceStates.Remove(m.VoiceState.UserId); } } else { VoiceStates[m.VoiceState.UserId] = m.VoiceState; } } else { VoiceStates[m.VoiceState.UserId] = m.VoiceState; } }); }); Messenger.Default.Register <GatewayVoiceServerUpdateMessage>(this, m => { if (!VoiceStates.ContainsKey(_discordService.CurrentUser.Id)) { VoiceStates.Add( _discordService.CurrentUser.Id, new VoiceState() { ChannelId = m.VoiceServer.ChannelId, GuildId = m.VoiceServer.GuildId, UserId = _discordService.CurrentUser.Id, }); } ConnectToVoiceChannel(m.VoiceServer, VoiceStates[_discordService.CurrentUser.Id]); }); Messenger.Default.Register <SettingChangedMessage <string> >(this, async(m) => { // Todo: this switch (m.Key) { case SettingKeys.InputDevice: SetInputDevice(m.Value); break; case SettingKeys.OutputDevice: SetOutputDevice(m.Value); break; } }); }
private static void Client_OnJoinedGuild(DiscordSocketClient client, SocketGuildEventArgs args) { VoiceStates.Add(args.Guild.Id, args.Guild.VoiceStates.ToList()); }