Skip to content

Instantly share code, notes, and snippets.

@JamesDunne
Created November 14, 2012 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesDunne/4073158 to your computer and use it in GitHub Desktop.
Save JamesDunne/4073158 to your computer and use it in GitHub Desktop.
Big Ben C# IRC bot
using System;
using System.Linq;
using System.Threading.Tasks;
namespace IrcBots {
public class BigBenIrcBot : PircBot {
const string IRC_CHANNEL = "#bitswebteam";
public BigBenIrcBot() { setName("isu_big_ben"); }
static void Main() {
var bot = new BigBenIrcBot();
bot.connect("irc.freenode.net");
bot.joinChannel(IRC_CHANNEL);
Task.Run(async () => {
while (true) {
const long secN = TimeSpan.TicksPerSecond * (60 * 60);
var now = DateTime.UtcNow;
var nextN = new DateTime(((now.Ticks + secN) / secN) * secN, DateTimeKind.Utc);
await Task.Delay(nextN.Subtract(now));
int n = DateTime.Now.Hour % 12;
bot.sendMessage(IRC_CHANNEL, String.Join(" ", Enumerable.Repeat("*BONG*", n == 0 ? 12 : n)));
// Prevent from retriggering:
await Task.Delay(TimeSpan.FromSeconds(1.0d));
}
}).Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment