diff --git a/DiscordBot/Extensions/StringExtensions.cs b/DiscordBot/Extensions/StringExtensions.cs
index a06ed58e..6f2153b4 100644
--- a/DiscordBot/Extensions/StringExtensions.cs
+++ b/DiscordBot/Extensions/StringExtensions.cs
@@ -122,7 +122,7 @@ public static string GetSha256(this string input)
///
/// Returns true if the string contains only upper case characters, including spaces and all punctuation ie; "I NEED HELP!?!?!?!#$?!" will return true
///
- public static bool IsAlLCaps(this string str)
+ public static bool IsAllCaps(this string str)
{
return Regex.IsMatch(str, @"^[A-Z\s\p{P}]+$");
}
@@ -133,4 +133,32 @@ public static string ToCapitalizeFirstLetter(this string str)
return string.Empty;
return char.ToUpper(str[0]) + str[1..];
}
-}
\ No newline at end of file
+
+ ///
+ /// Joins a list of strings with commas into a natural phrase:
+ /// "apples"
+ /// "apples and bananas"
+ /// "apples, bananas, and cherries"
+ ///
+ /// array or list of element phrases to be listed
+ /// final conjunction; defaults to "and" if not given
+ public static string ToCommaList(this string[] nouns, string conj=null)
+ {
+ if (conj == null)
+ conj = "and";
+ var sb = new StringBuilder();
+ for (int i = 0; i < nouns.Length; i++)
+ {
+ if (i > 0)
+ {
+ if (nouns.Length > 2)
+ sb.Append(',');
+ sb.Append(' ');
+ if (i == nouns.Length-1)
+ sb.Append(conj).Append(' ');
+ }
+ sb.Append(nouns[i]);
+ }
+ return sb.ToString();
+ }
+}
diff --git a/DiscordBot/Extensions/UserExtensions.cs b/DiscordBot/Extensions/UserExtensions.cs
index 8f341868..76ed2e0b 100644
--- a/DiscordBot/Extensions/UserExtensions.cs
+++ b/DiscordBot/Extensions/UserExtensions.cs
@@ -45,4 +45,20 @@ public static string GetUserLoggingString(this IUser user)
return $"{user.Username} `{user.Id}`";
return $"{guildUser.GetPreferredAndUsername()} `{guildUser.Id}`";
}
-}
\ No newline at end of file
+
+ public static string[] ToUserPreferredNameArray(this IUser[] users)
+ {
+ var names = new string[users.Length];
+ for (int i = 0; i < users.Length; i++)
+ names[i] = GetUserPreferredName(users[i]);
+ return names;
+ }
+
+ public static string[] ToMentionArray(this IUser[] users)
+ {
+ var mentions = new string[users.Length];
+ for (int i = 0; i < users.Length; i++)
+ mentions[i] = users[i].Mention;
+ return mentions;
+ }
+}
diff --git a/DiscordBot/Modules/UserModule.cs b/DiscordBot/Modules/UserModule.cs
index 9ad86032..9fe2994e 100644
--- a/DiscordBot/Modules/UserModule.cs
+++ b/DiscordBot/Modules/UserModule.cs
@@ -623,10 +623,36 @@ public async Task SlapUser(params IUser[] users)
var sb = new StringBuilder();
var uname = Context.User.GetUserPreferredName();
- sb.Append($"**{uname}** slaps ");
- foreach (var user in users) sb.Append(user.Mention).Append(" ");
- sb.Append("around a bit with a large ").Append(Settings.UserModuleSlapChoices[_random.Next() % Settings.UserModuleSlapChoices.Count]).Append(".");
+ if (Settings.UserModuleSlapChoices == null || Settings.UserModuleSlapChoices.Count == 0)
+ Settings.UserModuleSlapChoices = new List() { "fish", "mallet" };
+ if (Settings.UserModuleSlapFails == null || Settings.UserModuleSlapFails.Count == 0)
+ Settings.UserModuleSlapFails = new List() { "hurting themselves" };
+
+ bool fail = (_random.Next(1, 100) < 5);
+
+ if (fail)
+ sb.Append($"**{uname}** tries to slap ");
+ else
+ sb.Append($"**{uname}** slaps ");
+
+ var mentions = users.ToMentionArray();
+ sb.Append(mentions.ToCommaList());
+
+ if (fail)
+ {
+ sb.Append(" around a bit with a large ");
+ sb.Append(Settings.UserModuleSlapChoices[_random.Next() % Settings.UserModuleSlapChoices.Count]);
+ sb.Append(", but misses and ends up ");
+ sb.Append(Settings.UserModuleSlapFails[_random.Next() % Settings.UserModuleSlapFails.Count]);
+ sb.Append(".");
+ }
+ else
+ {
+ sb.Append(" around a bit with a large ");
+ sb.Append(Settings.UserModuleSlapChoices[_random.Next() % Settings.UserModuleSlapChoices.Count]);
+ sb.Append(".");
+ }
await Context.Channel.SendMessageAsync(sb.ToString());
await Context.Message.DeleteAfterSeconds(seconds: 1);
diff --git a/DiscordBot/Services/UnityHelp/UnityHelpService.cs b/DiscordBot/Services/UnityHelp/UnityHelpService.cs
index 62c77b6b..2ae6b3c4 100644
--- a/DiscordBot/Services/UnityHelp/UnityHelpService.cs
+++ b/DiscordBot/Services/UnityHelp/UnityHelpService.cs
@@ -184,7 +184,7 @@ private async Task OnThreadCreated(SocketThreadChannel thread)
}
var threadTitle = thread.Name;
- if (threadTitle.IsAlLCaps())
+ if (threadTitle.IsAllCaps())
{
threadTitle = thread.Name.ToLower();
}
@@ -750,4 +750,4 @@ public int GetTrackedQuestionCount()
#endregion // Utility Methods
-}
\ No newline at end of file
+}
diff --git a/DiscordBot/Settings/Deserialized/Settings.cs b/DiscordBot/Settings/Deserialized/Settings.cs
index 342fe0cb..e188c1c0 100644
--- a/DiscordBot/Settings/Deserialized/Settings.cs
+++ b/DiscordBot/Settings/Deserialized/Settings.cs
@@ -25,7 +25,13 @@ public class BotSettings
#region Fun Commands
- public List UserModuleSlapChoices { get; set; } = new List() { "trout", "duck", "truck", "paddle", "magikarp", "sausage", "student loan", "life choice", "bug report", "unhandled exception", "null pointer", "keyboard", "cheese wheel", "banana peel", "unresolved bug", "low poly donut" };
+ //NOTE: Deserializer will not override a List from the file if a default one is made here.
+ public List UserModuleSlapChoices { get; set; }
+ // = { "trout", "duck", "truck", "paddle", "magikarp", "sausage", "student loan",
+ // "life choice", "bug report", "unhandled exception", "null pointer", "keyboard",
+ // "cheese wheel", "banana peel", "unresolved bug", "low poly donut" };
+ public List UserModuleSlapFails { get; set; }
+ // = { "hurting themselves" };
#endregion // Fun Commands