Replace custom chat tokens on IRC. (Thanks Joseph)

This commit is contained in:
UnknownShadow200 2016-09-01 22:48:12 +10:00
parent 80c99fa2e9
commit 979b9b4763
2 changed files with 14 additions and 10 deletions

View File

@ -45,6 +45,15 @@ namespace MCGalaxy {
sb.Replace(token.Key, token.Value);
}
public static string ApplyCustom(string text) {
if (CustomTokens.Count == 0) return text;
StringBuilder sb = new StringBuilder(text);
foreach (var token in CustomTokens)
sb.Replace(token.Key, token.Value);
return sb.ToString();
}
internal static Dictionary<string, TokenParser> standardTokens = new Dictionary<string, TokenParser> {
{ "$name", p => p.DisplayName == null ? null :
(Server.dollarNames ? "$" : "") + Colors.StripColors(p.DisplayName) },

View File

@ -108,6 +108,7 @@ namespace MCGalaxy {
message = ".";
message = EmotesHandler.Replace(message);
message = FullCP437Handler.Replace(message);
message = ChatTokens.ApplyCustom(message);
message = CP437Writer.ConvertToUnicode(message);
if (color)
@ -174,21 +175,15 @@ namespace MCGalaxy {
}
void Player_PlayerDisconnect(Player p, string reason) {
if (!Server.irc ||!IsConnected()) return;
if (!Server.irc ||!IsConnected() || p.hidden) return;
if (!Server.guestLeaveNotify && p.Rank <= LevelPermission.Guest) return;
string msg = p.DisplayName + " %Sleft the game (" + reason + ")";
msg = ConvertMessage(msg, true);
if (!p.hidden) connection.Sender.PublicMessage(channel, msg);
Say(p.DisplayName + " %Sjoined the game (" + reason + "%S)", false);
}
void Player_PlayerConnect(Player p) {
if (!Server.irc ||!IsConnected()) return;
if (!Server.irc ||!IsConnected() || p.hidden) return;
if (!Server.guestJoinNotify && p.Rank <= LevelPermission.Guest) return;
string msg = p.DisplayName + " %Sjoined the game";
msg = ConvertMessage(msg, true);
if (!p.hidden) connection.Sender.PublicMessage(channel, msg);
Say(p.DisplayName + " %Sjoined the game", false);
}
void Player_PlayerChat(Player p, string message) {