Skip to content

Commit

Permalink
Update algorithm for drunk text to be accurate to EO main
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 4, 2023
1 parent 133e2c6 commit 920dafa
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions EOLib/Domain/Chat/ChatProcessor.cs
Expand Up @@ -52,25 +52,69 @@ public string RemoveFirstCharacterIfNeeded(string chat, ChatType chatType, strin

public string MakeDrunk(string input)
{
// implementation from Phorophor::notepad (thanks Blo)
// https://discord.com/channels/723989119503696013/785190349026492437/791376941822246953

// todo: make this use the authentic algorithm here: https://discord.com/channels/723989119503696013/787685796055482368/945700924536553544
// algorithm from: https://discord.com/channels/723989119503696013/787685796055482368/945700924536553544
var ret = new StringBuilder();

//Pass 1:
//If E or A: 70 % chance to insert a j
//if U or O: 70 % chance to insert a w
//if i(lowercase only): 40 % chance to insert a u
//if not a space: 40 % chance to double the letter
foreach (var c in input)
{
var repeats = _random.Next(0, 8) < 6 ? 1 : 2;
ret.Append(c, repeats);
ret.Append(c);

if (char.ToLower(c) == 'e' || char.ToLower(c) == 'a')
{
if (_random.Next(100) < 70)
ret.Append('j');
}
else if (char.ToLower(c) == 'u' || char.ToLower(c) == 'o')
{
if (_random.Next(100) < 70)
ret.Append('w');
}
else if (c == 'i')
{
if (_random.Next(100) < 40)
ret.Append('u');
}

if ((c == 'a' || c == 'e') && _random.NextDouble() / 1.0 < 0.555)
ret.Append('j');
if (c != ' ' && _random.Next(100) < 40)
{
ret.Append(c);
}
}

if ((c == 'u' || c == 'o') && _random.NextDouble() / 1.0 < 0.444)
ret.Append('w');

if ((c == ' ') && _random.NextDouble() / 1.0 < 0.333)
ret.Append(" *hic*");
//Pass 2:
//if vowel: 1 in 12 chance to replace with *
for (int i = 0; i < ret.Length; i++)
{
var c = char.ToLower(ret[i]);

if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
if (_random.Next(12) == 6)
ret[i] = '*';
}
}

//Pass 3:
//if space, 30 % chance to insert "hic"
for (int i = 0; i < ret.Length; i++)
{
if (ret[i] == ' ' && _random.Next(100) < 30)
{
ret.Insert(i, "*hic*");
}
}

// If string length > 128: trim to 126 bytes and add ".."
if (ret.Length > 128)
{
ret = ret.Remove(126, ret.Length - 126);
ret.Append("..");
}

return ret.ToString();
Expand Down

0 comments on commit 920dafa

Please sign in to comment.