Skip to content
Open
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
44 changes: 23 additions & 21 deletions BetterChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class BetterChat : CovalencePlugin
};
#endif

#endregion
#endregion

#region Classes

Expand Down Expand Up @@ -69,6 +69,23 @@ public ChatGroup.FormatSettings GetOutput()
["Date"] = DateTime.Now.ToString()
};

foreach (var thirdPartyTitle in ThirdPartyTitles)
{
try
{
string title = thirdPartyTitle.Value(Player);

if (!string.IsNullOrEmpty(title))
replacements.Add(thirdPartyTitle.Key.Name, title);
else
replacements.Add(thirdPartyTitle.Key.Name, "");
}
catch (Exception ex)
{
Instance.PrintError($"Error when trying to get third-party title from plugin '{thirdPartyTitle.Key}'{Environment.NewLine}{ex}");
}
}

output.Chat = Format.Chat;
output.Console = Format.Console;

Expand All @@ -78,11 +95,11 @@ public ChatGroup.FormatSettings GetOutput()
output.Chat = Instance.covalence.FormatText(output.Chat.Replace($"{{{replacement.Key}}}", replacement.Value));
}

if (output.Chat.StartsWith(" "))
output.Chat = output.Chat.Remove(0, 1);
output.Chat = Regex.Replace(output.Chat, "[ ]{2,}"," ");
output.Chat = output.Chat.Trim();

if (output.Console.StartsWith(" "))
output.Console = output.Console.Remove(0, 1);
output.Console = Regex.Replace(output.Console, "[ ]{2,}"," ");
output.Console = output.Console.Trim();

return output;
}
Expand Down Expand Up @@ -222,21 +239,6 @@ public static BetterChatMessage FormatMessage(IPlayer player, string message)

titles = titles.GetRange(0, Math.Min(Configuration.MaxTitles, titles.Count));

foreach (var thirdPartyTitle in ThirdPartyTitles)
{
try
{
string title = thirdPartyTitle.Value(player);

if (!string.IsNullOrEmpty(title))
titles.Add(title);
}
catch (Exception ex)
{
Instance.PrintError($"Error when trying to get third-party title from plugin '{thirdPartyTitle.Key}'{Environment.NewLine}{ex}");
}
}

return new BetterChatMessage
{
Player = player,
Expand Down Expand Up @@ -316,7 +318,7 @@ public class FormatSettings
public string Chat = "{Title} {Username}: {Message}";
public string Console = "{Title} {Username}: {Message}";
}

public class Field
{
public Func<ChatGroup, object> Getter { get; }
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ You can do a lot with the formatting of a group. You can customize it with:
- **{Date}** = Date Stamp
- **{Time}** = Time Stamp
- **{Group}** = Primary Group
- **{PluginName}** = Titles added by third party plugins*

... but also just add words, letters, numbers, and symbols to it. You could just put the Title behind the name for example.

\* Third party titles are registered using the build in BetterChat API. An example for one of those titles is `{Clans}` when the [Clans](https://umod.org/plugins/clans) plugin is installed.

## Chat Group Setup

For setting groups up, use the command 'chat'. If you want to set it up in the chat, you need to grant yourself the permission `betterchat.admin` and prefix the command with a forward slash (/). You can grant yourself the permission by typing the following command into the server console where you replace `<name or ID>` with your username or ID *(Steam ID for most games)*: `oxide.grant user <name or ID> betterchat.admin` Now you can use the command '/chat' in the chat.
Expand Down Expand Up @@ -192,7 +195,7 @@ To get chat groups a player is in:
private List<JObject> API_GetUserGroups(IPlayer player)
```

To register a title for players:
To register a title for players: (One per plugin, the plugin name is used as replacement tag in the config)
```csharp
private void API_RegisterThirdPartyTitle(Plugin plugin, Func<IPlayer, string> titleGetter)
```
Expand Down