public (string response, string color) OnCall(ReferenceHub sender, string[] args) { if (!sender.CheckPermission("tc.unmute")) { return(Language.CommandNotEnoughPermissionsError, "red"); } if (args.Length != 1) { return(string.Format(Language.CommandNotEnoughParametersError, 1, Usage), "red"); } Collections.Chat.Player chatPlayer = args[0].GetChatPlayer(); if (chatPlayer == null) { return(string.Format(Language.PlayerNotFoundError, args[0]), "red"); } var mute = LiteDatabase.GetCollection <Collections.Chat.Mute>().FindOne(queryMute => queryMute.Target.Id == chatPlayer.Id && queryMute.Expire > DateTime.Now); if (mute == null) { return(string.Format(Language.PlayerIsNotMutedError, chatPlayer.Name), "red"); } mute.Expire = DateTime.Now; LiteDatabase.GetCollection <Collections.Chat.Mute>().Update(mute); Player.GetPlayer(args[0])?.SendConsoleMessage(Language.UnmuteCommandSuccessPlayer, "green"); return(string.Format(Language.UnmuteCommandSuccessModerator, chatPlayer.Name), "green"); }
public (string response, string color) OnCall(ReferenceHub sender, string[] args) { if (!sender.CheckPermission("tc.showmutes")) { return(Language.CommandNotEnoughPermissionsError, "red"); } if (args.Length == 0) { return(GetPlayerMutes(LiteDatabase.GetCollection <Collections.Chat.Mute>().FindAll().ToList()).ToString(), "white"); } else if (args.Length == 1) { Collections.Chat.Player chatPlayer = args[0].GetChatPlayer(); if (chatPlayer == null) { return(string.Format(Language.PlayerNotFoundError, args[0]), "red"); } return(GetPlayerMutes(LiteDatabase.GetCollection <Collections.Chat.Mute>().Find(mute => mute.Target.Id == chatPlayer.Id).ToList()).ToString(), "white"); } return(Language.CommandTooManyArgumentsError, "red"); }
public (string response, string color) OnCall(ReferenceHub sender, string[] args) { if (!sender.CheckPermission("tc.deletemutes")) { return(Language.CommandNotEnoughPermissionsError, "red"); } if (args.Length == 0) { return(string.Format(Language.DeleteAllMutesSuccess, LiteDatabase.GetCollection <Collections.Chat.Mute>().DeleteAll()), "green"); } else if (args.Length == 1) { Collections.Chat.Player chatPlayer = args[0].GetChatPlayer(); if (chatPlayer == null) { return(string.Format(Language.PlayerNotFoundError, args[0]), "red"); } return(string.Format(Language.DeleteMutesSuccess, LiteDatabase.GetCollection <Collections.Chat.Mute>().DeleteMany(mute => mute.Target.Id == chatPlayer.Id), chatPlayer.Name), "green"); } return(Language.CommandTooManyArgumentsError, "red"); }
public (string response, string color) OnCall(ReferenceHub sender, string[] args) { if (!sender.CheckPermission("tc.mute")) { return(Language.CommandNotEnoughPermissionsError, "red"); } if (args.Length < 2) { return(string.Format(Language.CommandNotEnoughParametersError, 2, Usage), "red"); } ReferenceHub target = Player.GetPlayer(args[0]); Collections.Chat.Player chatPlayer = args[0].GetChatPlayer(); if (chatPlayer == null) { return(string.Format(Language.PlayerNotFoundError, args[0]), "red"); } if (!double.TryParse(args[1], out double duration) || duration < 1) { return(string.Format(Language.InvalidDurationError, args[1]), "red"); } string reason = string.Join(" ", args.Skip(2).Take(args.Length - 2)); if (string.IsNullOrEmpty(reason)) { return(Language.ReasonCannotBeEmptyError, "red"); } if (chatPlayer.IsChatMuted()) { return(string.Format(Language.PlayerIsAlreadyMutedError, chatPlayer.Name), "red"); } LiteDatabase.GetCollection <Collections.Chat.Mute>().Insert(new Collections.Chat.Mute() { Target = chatPlayer, Issuer = sender.GetChatPlayer(), Reason = reason, Duration = duration, Timestamp = DateTime.Now, Expire = DateTime.Now.AddMinutes(duration) }); if (Configs.showChatMutedBroadcast) { target?.ClearBroadcasts(); target?.Broadcast(Configs.chatMutedBroadcastDuration, string.Format(Configs.chatMutedBroadcast, duration, reason), false); } target?.SendConsoleMessage(string.Format(Language.MuteCommandSuccessPlayer, duration, reason), "red"); return(string.Format(Language.MuteCommandSuccessModerator, chatPlayer.Name, duration, reason), "green"); }
/// <summary> /// Gets a List of <see cref="Collections.Chat.Player"/> from a List of <see cref="ReferenceHub"/> /// </summary> /// <param name="players"></param> /// <returns></returns> public static List <Collections.Chat.Player> GetChatPlayers(this IEnumerable <ReferenceHub> players) { List <Collections.Chat.Player> chatPlayersList = new List <Collections.Chat.Player>(); foreach (ReferenceHub player in players) { Collections.Chat.Player chatPlayer = player.GetChatPlayer(); if (chatPlayer != null) { chatPlayersList.Add(chatPlayer); } } return(chatPlayersList); }
/// <summary> /// Gets the mute status from the chat of a <see cref="Collections.Chat.Player"/> /// </summary> /// <param name="player"></param> /// <returns></returns> public static bool IsChatMuted(this Collections.Chat.Player player) { return(LiteDatabase.GetCollection <Collections.Chat.Mute>().Exists(mute => mute.Target.Id == player.Id && mute.Expire > DateTime.Now)); }