/// <summary> /// Handles a ban command from Discord. /// </summary> /// <param name="channelID">ChannelID of the channel the command was used in.</param> /// <param name="steamID">SteamID of player to be banned.</param> /// <param name="duration">Duration of ban expressed as xu where x is a number and u is a character representing a unit of time.</param> /// <param name="reason">Optional reason for the ban.</param> private void BanCommand(string channelID, string steamID, string duration, string reason, string adminTag) { // Perform very basic SteamID validation. if (!IsPossibleSteamID(steamID)) { Dictionary <string, string> variables = new Dictionary <string, string> { { "steamid", steamID } }; plugin.SendMessageByID(channelID, "botresponses.invalidsteamid", variables); return; } // Create duration timestamp. string humanReadableDuration = ""; DateTime endTime; try { endTime = ParseBanDuration(duration, ref humanReadableDuration); } catch (IndexOutOfRangeException) { endTime = DateTime.MinValue; } if (endTime == DateTime.MinValue) { Dictionary <string, string> variables = new Dictionary <string, string> { { "duration", duration } }; plugin.SendMessageByID(channelID, "botresponses.invalidduration", variables); return; } string name = ""; if (!plugin.GetPlayerName(steamID, ref name)) { name = "Offline player"; } //Semicolons are separators in the ban file so cannot be part of strings name = name.Replace(";", ""); reason = reason.Replace(";", ""); if (reason == "") { reason = "No reason provided."; } // Add the player to the SteamIDBans file. StreamWriter streamWriter = new StreamWriter(FileManager.GetAppFolder(true, true) + "UserIdBans.txt", true); streamWriter.WriteLine(name + ';' + steamID + ';' + endTime.Ticks + ';' + reason + ";" + adminTag + ";" + DateTime.UtcNow.Ticks); streamWriter.Dispose(); // Kicks the player if they are online. plugin.KickPlayer(steamID, "Banned for the following reason: '" + reason + "'"); Dictionary <string, string> banVars = new Dictionary <string, string> { { "name", name }, { "steamid", steamID }, { "reason", reason }, { "duration", humanReadableDuration }, { "admintag", adminTag } }; plugin.SendMessage(Config.GetArray("channels.statusmessages"), "botresponses.playerbanned", banVars); }