Permalink
Browse files

Added event handler on quitting.

  • Loading branch information...
1 parent 9c28d7c commit 326f192b852c72cd4b3ab80c2e646723c03872d5 polyethene committed Nov 30, 2011
Showing with 34 additions and 23 deletions.
  1. +12 −12 Bot.cs
  2. +11 −6 FunBots.cs
  3. +11 −5 Paste.cs
View
24 Bot.cs
@@ -1,12 +1,13 @@
using System;
-using System.Collections.Generic;
using System.Diagnostics;
using robokins.IRC;
namespace robokins
{
partial class Bot
{
+ public event EventHandler Quitting;
+
public Bot()
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(delegate(object sender, EventArgs e) { quit = true; });
@@ -26,6 +27,15 @@ public void Start()
MessageEvent += new EventHandler<MessageEventArgs>(Trigger);
+ Quitting += new EventHandler(delegate(object sender, EventArgs e)
+ {
+ if (irc.Connected)
+ {
+ client.Quit("Got to go, bye!");
+ irc.Client.Close(SendDelay);
+ }
+ });
+
while ((line = client.Receive.ReadLine()) != null)
{
Echo(line);
@@ -43,17 +53,7 @@ public void Start()
if (quit)
{
- if (paste != null && paste.Enabled)
- paste.Stop();
-
- if (bots != null && bots.Enabled)
- bots.Stop();
-
- if (irc.Connected)
- {
- client.Quit("Got to go, bye!");
- irc.Client.Close(SendDelay);
- }
+ Quitting(this, new EventArgs());
break;
}
}
View
@@ -6,18 +6,23 @@ namespace robokins
{
partial class Bot
{
- Timer bots = null;
-
[Conditional("FUNBOTS")]
void FunBotsSetup()
{
- var random = new Random();
- bots = new Timer(60 * 60 * 1000 / 2);
- bots.Elapsed += new ElapsedEventHandler(delegate(object sender, ElapsedEventArgs e)
+ var timer = new Timer(60 * 60 * 1000 / 2);
+
+ timer.Elapsed += new ElapsedEventHandler(delegate(object sender, ElapsedEventArgs e)
{
Message(client, "lolikins", "!stuff");
});
- bots.Start();
+
+ Quitting += new EventHandler(delegate(object sender, EventArgs e)
+ {
+ if (timer.Enabled)
+ timer.Stop();
+ });
+
+ timer.Start();
}
}
}
View
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Timers;
@@ -8,24 +9,29 @@ namespace robokins
{
partial class Bot
{
- Timer paste = null;
List<string> pasteIds;
[Conditional("PASTE")]
void PasteSetup()
{
pasteIds = new List<string>();
- paste = new Timer(PasteFreq);
+ var timer = new Timer(PasteFreq);
var local = Directory.Exists(PasteSync);
- paste.Elapsed += local ? new ElapsedEventHandler(pasteDirectoryCheck) : new ElapsedEventHandler(pasteFeedCheck);
+ timer.Elapsed += local ? new ElapsedEventHandler(pasteDirectoryCheck) : new ElapsedEventHandler(pasteFeedCheck);
if (!local)
{
foreach (var item in pasteFetch().Keys)
pasteIds.Add(item);
}
- paste.Start();
+ Quitting += new System.EventHandler(delegate(object sender, EventArgs e)
+ {
+ if (timer.Enabled)
+ timer.Stop();
+ });
+
+ timer.Start();
}
void pasteDirectoryCheck(object sender, ElapsedEventArgs e)

0 comments on commit 326f192

Please sign in to comment.