internal string GetVCLinkedGameCode(IVoiceChannel vc) { if (vc is null) { return(null); } if (VCLinkedGames.TryGetValue(vc.Id, out var code)) { _logger.LogDebug($"Game found. vc({vc.Name}) => game[{code}]"); return(code); } return(null); }
internal bool DestroyMuteController(string code, SocketGuildUser user = null) { if (_controllers.TryGetValue(code, out var controller)) { controller.RestoreMuteControl(0); var ch = controller.Channel; var destroyer = (user == null) ? "Server" : user.Mention; var content = $"The link to game `{code}` was destroyed by {destroyer}."; Task.WaitAll(ch.SendMessageAsync(content), controller.DeleteEmbedAsync()); // Delete mute-controller object VCLinkedGames.Remove(controller.VoiceChannel.Id); _controllers.Remove(code); return(true); } return(false); }
internal void RemoveGuildUser(IGuildUser user, SocketVoiceChannel vc) { if (null == vc) { return; } if (VCLinkedGames.TryGetValue(vc.Id, out var code)) { if (_controllers.TryGetValue(code, out var muteController)) { muteController.LeaveFromVC(user); return; } _logger.LogError($"There is no mute controller to pair with game `{code}`."); return; } _logger.LogDebug($"It isn't connected to any game. : VC \"{vc.Name}\""); return; }
internal async Task CreateMuteController(SocketMessage from, string code) { // Find the game var upperCode = code.ToUpper(); IGame game; if (!Games.TryGetValue(upperCode, out game)) { await from.Channel.SendMessageAsync($"There is no game with the game code `{upperCode}`."); return; } // Find a mute controller to pair with the game. MuteController existsController; if (!_controllers.TryGetValue(game.Code.Code, out existsController)) { // not found, create the controller. var user = from.Author as SocketGuildUser; if (VCLinkedGames.TryGetValue(user.VoiceChannel.Id, out var LinkRemainedMC)) { // If the program is not correct, it will arrive here. _logger.LogWarning($"Discard the remaining links in game `{game.Code.Code}` and create a new mute controller."); _logger.LogWarning($"A memory leak may have occurred."); } try{ var controller = new MuteController(_logger, game, user, _config, _emoteManager); _controllers[game.Code.Code] = controller; VCLinkedGames[user.VoiceChannel.Id] = game.Code.Code; await controller.GenerateEmbedMsg(from.Channel); } catch (Exception e) { _logger.LogError($"{e.GetType()} -- {e.Message}"); _logger.LogError($"{e.StackTrace}"); } return; } await from.Channel.SendMessageAsync($"Game `{upperCode}` is already linked to :speaker: \"{existsController.VoiceChannel}\"."); return; }