Created
August 21, 2018 23:03
-
-
Save monoclex/2dba57f4c29c51042f97421b88d26df7 to your computer and use it in GitHub Desktop.
Sanitize user input in discord to prevent odd formatting issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DiscordSanitizationHelper { | |
private static char[] NeedsSanitation => new char[] { | |
'\\', '`', '-', '=', '[', ']', '\'', ',', '.', '~', '!', '@', | |
'#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', | |
':', '"', '<', '>', '?', '/', | |
}; | |
public static string DiscordSanitize(this string input) { | |
var output = input; | |
foreach (var i in NeedsSanitation) | |
output = output.Replace($"{i}", $"\\{i}"); | |
return output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment