Skip to content

Commit

Permalink
Upgrade Meebey.SmartIrc4net from 0.4 to 1.1
Browse files Browse the repository at this point in the history
RCReader:
* Remove "emergency restarter" feature (for irc.wikimedia.org).
* Remove seemingly redundant code for autoreconnect.
* Remove unused 'lastError' attribute, use logger instead.
* Enable IrcClient.AutoRejoin.
* Improve code comments.

Program:
* Remove ping/pong hacks causing compile errors.
  • Loading branch information
Krinkle committed Oct 13, 2017
1 parent 6cfa1c5 commit e2d92e7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/CVNBot/CVNBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\log4net.dll</HintPath>
</Reference>
<Reference Include="Meebey.SmartIrc4net, Version=0.4.0.34161, Culture=neutral">
<Reference Include="Meebey.SmartIrc4net, Version=1.1, Culture=neutral">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Meebey.SmartIrc4net.dll</HintPath>
</Reference>
Expand Down
3 changes: 0 additions & 3 deletions src/CVNBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ static void irc_OnPong(object sender, PongEventArgs e)
sentLength = 0;
dontSendNow = false;
sendlock.Set();
//logger.Info("Got pong: " + e.Data.RawMessage);
irc.LastPongReceived = DateTime.Now; //Hacked SmartIrc4net
}

/// <summary>
Expand Down Expand Up @@ -524,7 +522,6 @@ static void msgthread()
{
// Ping the server and wait for a reply
irc.RfcPing(ircServerName); //Removed Priority.Critical
irc.LastPingSent = DateTime.Now; //Hacked SmartIrc4net
sendlock.Reset();
dontSendNow = true;
//logger.Info("Waiting for artificial PONG");
Expand Down
55 changes: 11 additions & 44 deletions src/CVNBot/RCReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class RCReader
{
public IrcClient rcirc = new IrcClient();
public DateTime lastMessage = DateTime.Now;
public string lastError = "";

// RC parsing regexen
static Regex stripColours = new Regex(@"\x04\d{0,2}\*?");
Expand All @@ -56,25 +55,24 @@ public void initiateConnection()

logger.Info("RCReader thread started");

//Set up RCReader
// Set up RCReader
rcirc.Encoding = System.Text.Encoding.UTF8;
rcirc.AutoReconnect = true;
//rcirc.AutoRejoin = true;
rcirc.AutoRejoin = true;

rcirc.OnChannelMessage += new IrcEventHandler(rcirc_OnChannelMessage);
rcirc.OnConnected += new EventHandler(rcirc_OnConnected);
rcirc.OnQueryMessage += new IrcEventHandler(rcirc_OnQueryMessage);
rcirc.OnDisconnected += new EventHandler(rcirc_OnDisconnected);
rcirc.OnConnectionError += new EventHandler(rcirc_OnConnectionError);

try
{
rcirc.Connect("irc.wikimedia.org", 6667);
}
catch (ConnectionException e)
{
lastError = "Connection error: " + e.Message;
logger.Warn( "Connection error: " + e.Message );
return;
}

try
{
rcirc.Login(Program.botNick, "CVNBot", 4, "CVNBot");
Expand All @@ -85,49 +83,18 @@ public void initiateConnection()
rcirc.RfcJoin("#" + prj);
}

//Enter loop
// Enter loop
rcirc.Listen();
// when Listen() returns the IRC session is over
rcirc.Disconnect();
}
catch (ConnectionException)
{
//Apparently this is handled, so we don't need to catch it
// Final disconnect may throw, ignore.
return;
}
}

void rcirc_OnConnectionError(object sender, EventArgs e)
{
//Let's try to catch those awkward disposal exceptions
//If it ain't a legitimate disconnection (i.e., if it wasn't ordered)
if (rcirc.AutoReconnect)
{
logger.Error("Caught connection error in RCReader class, restarting...");
Program.Restart();
}
}

void rcirc_OnDisconnected(object sender, EventArgs e)
{
if (rcirc.AutoReconnect)
{
//Was an unexpected disconnection
logger.Warn("RCReader has been disconnected, attempting reconnection");
rcirc.Reconnect();
}
}

void rcirc_OnQueryMessage(object sender, IrcEventArgs e)
{
//This is for the emergency restarter
if (e.Data.Message == Program.botNick + ":" + (string)Program.mainConfig["botpass"] + " restart")
{
logger.Warn("Emergency restart ordered by " + e.Data.Nick);
Program.PartIRC("Emergency restart ordered by " + e.Data.Nick);
Program.Restart();
}
}

void rcirc_OnConnected(object sender, EventArgs e)
{
logger.Info("Connected to RC feed");
Expand All @@ -137,7 +104,7 @@ void rcirc_OnChannelMessage(object sender, IrcEventArgs e)
{
lastMessage = DateTime.Now;

//Same as RCParser.py->parseRCmsg()
// Based on RCParser.py->parseRCmsg()
string strippedmsg = stripBold.Replace(stripColours.Replace(CVNBotUtils.replaceStrMax(e.Data.Message, '\x03', '\x04', 14), "\x03"), "");
string[] fields = strippedmsg.Split(new char[1] { '\x03' }, 15);
if (fields.Length == 15)
Expand All @@ -148,9 +115,9 @@ void rcirc_OnChannelMessage(object sender, IrcEventArgs e)
else
{
//Console.WriteLine("Ignored: " + e.Data.Message);
return; //Probably really long article title or something that got cut off; we can't handle these
//Probably really long article title or something that got cut off; we can't handle these
return;
}
//END

try
{
Expand Down
Binary file modified src/Meebey.SmartIrc4net.dll
Binary file not shown.

0 comments on commit e2d92e7

Please sign in to comment.