Library tutorials & articles
A Console IRC Bot
- Introduction
- Establishing the Connection
- Responding to Commands
Responding to Commands
My plan was just to display data, but let me show you how you can respond to commands. I know this could be solved cleaner, but I'm writing this as a proof of concept and to explain what would be required and how it works.
We want to welcome everyone joining a channel. But we want it by notice. When someone joins the IrcJoin method gets called:
private void IrcJoin(string[] IrcCommand) {
string IrcChannel = IrcCommand[2];
string IrcUser = IrcCommand[0].Split('!')[0];
if (eventJoin != null) { this.eventJoin(IrcChannel.Remove(0, 1), IrcUser); }
} /* IrcJoin */
Which in turns fires the join event and gets processed in our console app:
private void IrcJoin(string IrcChan, string IrcUser) {
Console.WriteLine(String.Format("{0} joins {1}", IrcUser, IrcChan));
IrcObject.IrcWriter.WriteLine(String.Format("NOTICE {0} :Hello {0}, welcome to {1}!", IrcUser, IrcChan));
IrcObject.IrcWriter.Flush ();
} /* IrcJoin */
I modified our console app a bit so it would create an object of itself in the Main with our IrcObject as a private variable. That way I can access the IrcWriter I created in there. Of course it is a bad idea to make that writer public. A better practice would be to create methods like NoticeUser , KickUser , etc... to control it's behaviour. But that exceeds the purpose of this article.
This concludes how you use C# to get on IRC.
Here are some ideas where you could extend this application:
- Listen for certain triggers in the channel, then do some action. (Example: ' !google searchterm' , have your app do a query and reply the results)
- Make this bot an opp and listen in PRIVMSG for a user to authenticate and op him. (Authenticate him against Active Directory, that way you'll learn how to work with AD as well)
- Detect kicks against trusted users and take action to prevent takeovers, or auto rejoin when the bot gets kicked.
- ...
Related articles
Related discussion
-
Help me how to dynamic create row column of TableLayoutpanel at run time ??????
by anatha1 (0 replies)
-
Very Urgent regarding deleting the images from a folder
by rameshbandi (2 replies)
-
How to Export Datagridview contents to Excel
by BarbaMariolino (8 replies)
-
Help accessing sound card
by daz4904 (0 replies)
-
How to Write a GPS Application
by stoyac (19 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
i have the same error as this guy, i know this was LONG ago but i cannot figure out how to get past this !
can someone please contact me
Email: vincecarter15x15@aol.com
AIM : skatecrashrepeat
Alternative Email: Punk123@myway.com
PLEASE I NEED THIS DESPERATELY
That is not a C# error.. It's actually an IRC error, which means you connected to the server. You need to do a few commands so that you can login/etc.
Example:
USER Veeresh Veeresh :Veeresh Veeresh\r\n
NICK Veeresh\r\n
JOIN #quakenet\r\n
PRIVMSG #quakenet :Hey, what's up\r\n
i tried to run this application, i got following error, plz help me out.
NOTICE AUTH :* Looking up your hostname NOTICE AUTH : Checking Ident NOTICE AUTH :** Couldn't look up your hostname :blueyonder2.uk.quakenet.org 451 * :Register first. :blueyonder2.uk.quakenet.org 451 * :Register first. :blueyonder2.uk.quakenet.org 451 * :Register first. :blueyonder2.uk.quakenet.org 451 * :Register first. :blueyonder2.uk.quakenet.org 451 * :Register first. :blueyonder2.uk.quakenet.org 451 * :Register first. ERROR :Closing Link: by blueyonder2.uk.quakenet.org (Registration Timeout) Cannot read from a closed TextReader.
please put it in vb.net form :]
or any vb
Welcome to Developer Fusion, David!
Feel free to ask me anything on my blog if you want more info.
This thread is for discussions of A Console IRC Bot.