Created
November 14, 2012 16:33
-
-
Save JamesDunne/4073158 to your computer and use it in GitHub Desktop.
Big Ben C# IRC bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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