Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DiscordBot/Data/FuzzTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public void Add(IEnumerable<string> stream)
// Lines starting with a '#' character are ignored, as are blank lines.
// Each remaining line of the file is trimmed of leading and trailing whitespace.
// Each line is added as a new choice, and duplicates are allowed for weighting.
// If the file is missing, nothing is done, but any other exception is thrown.
//
public void Load(string filename)
{
if (!File.Exists(filename))
return;
foreach (string line in File.ReadLines(filename))
{
string choice = line.Trim();
Expand Down
36 changes: 16 additions & 20 deletions DiscordBot/Modules/UserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,16 @@ public async Task DisableCodeTips()
[Summary("Slap the specified user(s). Syntax : !slap @user1 [@user2 @user3...]")]
public async Task SlapUser(params IUser[] users)
{
var sb = new StringBuilder();

var uname = Context.User.GetUserPreferredName();

try
{
if (_slapObjects.Count == 0)
_slapObjects.Load(Settings.UserModuleSlapObjectsTable);
}
catch (Exception e)
{
await LoggingService.LogChannelAndFile($"Error while loading '{Settings.UserModuleSlapObjectsTable}'.\nEx:{e}",
ExtendedLogSeverity.LowWarning);
}
if (_slapObjects.Count == 0)
_slapObjects.Add(Settings.UserModuleSlapChoices);
if (_slapObjects.Count == 0)
Expand All @@ -637,35 +643,25 @@ public async Task SlapUser(params IUser[] users)
if (_slapFails.Count == 0)
_slapFails.Add("hurting themselves");

// if (Settings.UserModuleSlapChoices == null || Settings.UserModuleSlapChoices.Count == 0)
// Settings.UserModuleSlapChoices = new List<string>() { "fish", "mallet" };
// if (Settings.UserModuleSlapFails == null || Settings.UserModuleSlapFails.Count == 0)
// Settings.UserModuleSlapFails = new List<string>() { "hurting themselves" };
var sb = new StringBuilder();
var uname = Context.User.GetUserPreferredName();
var mentions = users.ToMentionArray().ToCommaList();

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($"**{uname}** tries to slap {mentions} ");
sb.Append(" around a bit with a large ");
sb.Append(_slapObjects.Pick(true));
//sb.Append(Settings.UserModuleSlapChoices[_random.Next() % Settings.UserModuleSlapChoices.Count]);
sb.Append(", but misses and ends up ");
sb.Append(_slapFails.Pick(true));
//sb.Append(Settings.UserModuleSlapFails[_random.Next() % Settings.UserModuleSlapFails.Count]);
sb.Append(".");
}
else
{
sb.Append($"**{uname}** slaps {mentions} ");
sb.Append(" around a bit with a large ");
sb.Append(Settings.UserModuleSlapChoices[_random.Next() % Settings.UserModuleSlapChoices.Count]);
sb.Append(_slapObjects.Pick(true));
sb.Append(".");
}

Expand Down
4 changes: 3 additions & 1 deletion DiscordBot/Settings/Deserialized/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class BotSettings

#region Fun Commands

//NOTE: Deserializer will not override a List<string> from the file if a default one is made here.
public string UserModuleSlapObjectsTable { get; set; } = null;
// = "udc-slap.txt"
//NOTE: Deserializer will not override a List<string> from the json if a default one is made here.
public List<string> UserModuleSlapChoices { get; set; }
// = { "trout", "duck", "truck", "paddle", "magikarp", "sausage", "student loan",
// "life choice", "bug report", "unhandled exception", "null pointer", "keyboard",
Expand Down
Loading