Skip to content
Permalink
Browse files

Add support for specifying a particular IRC nick to show in-game as (…

…Discord) instead
  • Loading branch information...
UnknownShadow200 committed Jul 3, 2017
1 parent fb2ec86 commit 2d3fd2654eb7183abbbe55feaf09b1f21e8a5a0e
Showing with 34 additions and 28 deletions.
  1. +28 −27 fCraft/Network/IRC.cs
  2. +6 −1 fCraft/System/ConfigKey.cs
@@ -367,52 +367,53 @@ void HandleMessage([NotNull] string message)
} else {
return;
}
}

string processedMessage = ProcessMessageFromIRC(rawMessage);
if (processedMessage.Length == 0) return;
bool elapsed = DateTime.UtcNow.Subtract(IRCHandlers.lastUrlExpand).TotalSeconds > 5;
}
string text = ProcessMessageFromIRC(rawMessage);
if (text.Length == 0) return;

if (ConfigKey.IRCBotForwardFromIRC.Enabled()) {
if (msg.Type == IRCMessageType.ChannelAction) {
if (elapsed) {
Scheduler.NewTask(t => Chat.getUrls(processedMessage)).RunOnce();
IRCHandlers.lastUrlExpand = DateTime.UtcNow;
}
foreach (Player player in Server.Players) {
if (player.Info.ReadIRC) {
player.Message("&I(IRC) * {0} {1}", msg.Nick, processedMessage);
}
TryExpandUrls(text);

foreach (Player player in Server.Players.Where(pl => pl.Info.ReadIRC)) {
player.Message("&I(IRC) * {0} {1}", msg.Nick, text);
}
Logger.Log(LogType.IrcChat, "{0}: * {1} {2}", msg.Channel, msg.Nick,
IRCColorsAndNonStandardCharsExceptEmotes.Replace(rawMessage, ""));
} else if (IRCHandlers.HandleCommand(ActualBotNick, msg.Nick, rawMessage)) {
} else if (IRCHandlers.HandlePM(ActualBotNick, msg.Nick, rawMessage)) {
} else {
if (elapsed) {
Scheduler.NewTask(t => Chat.getUrls(processedMessage)).RunOnce();
IRCHandlers.lastUrlExpand = DateTime.UtcNow;
}
foreach (Player player in Server.Players.Where(player => player.Info.ReadIRC)) {
player.Message("&I(IRC) {0}{1}: {2}", msg.Nick, Color.White,
processedMessage);
TryExpandUrls(text);
string discordBotNick = ConfigKey.DiscordBotNick.GetString();
string prefix = msg.Nick == discordBotNick ? "(Discord)" : "(IRC) " + msg.Nick;

foreach (Player player in Server.Players.Where(pl => pl.Info.ReadIRC)) {
player.Message("&I{0}{1}: {2}", prefix, Color.White, text);
}
}
Logger.Log(LogType.IrcChat, "{0}: {1}: {2}", msg.Channel, msg.Nick,
IRCColorsAndNonStandardCharsExceptEmotes.Replace(rawMessage, ""));
} else if (msg.Message.StartsWith("#")) {
if (elapsed) {
Scheduler.NewTask(t => Chat.getUrls(processedMessage)).RunOnce();
IRCHandlers.lastIrcCommand = DateTime.UtcNow;
}
foreach (Player player in Server.Players.Where(player => player.Info.ReadIRC)) {
player.Message("&I(IRC) {0}{1}: {2}", msg.Nick, Color.White,
processedMessage.Substring(1));
TryExpandUrls(text);
string discordBotNick = ConfigKey.DiscordBotNick.GetString();
string prefix = msg.Nick == discordBotNick ? "(Discord)" : "(IRC) " + msg.Nick;

foreach (Player player in Server.Players.Where(pl => pl.Info.ReadIRC)) {
player.Message("&I{0}{1}: {2}", prefix, Color.White, text.Substring(1));
}
Logger.Log(LogType.IrcChat, "{0}: {1}: {2}", msg.Channel, msg.Nick,
IRCColorsAndNonStandardCharsExceptEmotes.Replace(rawMessage, ""));
}
}

void TryExpandUrls(string msg) {
bool elapsed = DateTime.UtcNow.Subtract(IRCHandlers.lastUrlExpand).TotalSeconds > 5;
if (elapsed) {
Scheduler.NewTask(t => Chat.getUrls(msg)).RunOnce();
IRCHandlers.lastUrlExpand = DateTime.UtcNow;
}
}


void HandleIrcJoin(IRCMessage msg) {
if (!ResponsibleForInputParsing) return;
@@ -446,7 +446,12 @@ public enum ConfigKey {
with IRC bots falling behind on messages.",
MinValue = 1, MaxValue=3 )]
IRCThreads,


[StringKey( ConfigSection.IRC, "",
@"Optional, nick of account that is used to relay chat to Discord.
In-game, messages sent by this account will show as (Discord) instead of (IRC).",
MinLength = 0, MaxLength = 32 )]
DiscordBotNick,
#endregion


0 comments on commit 2d3fd26

Please sign in to comment.
You can’t perform that action at this time.