Esempio n. 1
0
        /// <summary>
        /// Handles a ban command from Discord.
        /// </summary>
        /// <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 steamID, string duration, string reason = "")
        {
            // Perform very basic SteamID validation.
            if (!IsPossibleSteamID(steamID))
            {
                Dictionary <string, string> variables = new Dictionary <string, string>
                {
                    { "steamid", steamID }
                };
                plugin.SendMessageToBot("default", "botresponses.invalidsteamid", variables);
                return;
            }

            // Create duration timestamp.
            string   humanReadableDuration = "";
            DateTime endTime = ParseBanDuration(duration, ref humanReadableDuration);

            if (endTime == DateTime.MinValue)
            {
                Dictionary <string, string> variables = new Dictionary <string, string>
                {
                    { "duration", duration }
                };
                plugin.SendMessageToBot("default", "botresponses.invalidduration", variables);
                return;
            }

            string name = "";

            if (!plugin.GetPlayerName(steamID, ref name))
            {
                name = "Offline player";
            }

            //Semicolons are seperators 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() + "/SteamIdBans.txt", true);

            streamWriter.WriteLine(name + ';' + steamID + ';' + endTime.Ticks + ';' + reason + ";DISCORD;" + 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 }
            };

            plugin.SendMessageToBot("default", "botresponses.playerbanned", banVars);
        }