11

I'm working on a simple irc bot in C#, and I can't figure out how to embed the typical mirc control codes for bold/color etc into string literals.

Can someone point me towards how to do this?

FlySwat
  • 172,459
  • 74
  • 246
  • 311
  • 1
    Do what? What's a mIRC colour code? What are you trying to do? – Noon Silk Sep 08 '09 at 02:06
  • 2
    A mirc color code is simply a special character inserting into a string that most irc clients parse and then colorcode appropriately. – FlySwat Sep 08 '09 at 02:08

4 Answers4

19

The mIRC color code format is described here. I guess you're asking how to embed a ^C in a string.

This is known as Caret notation. According to C0 and C1 control codes, ^C is:

'\x03'

Embedded in a string:

"blabla \x035,12to be colored text and background\x03 blabla"
dtb
  • 213,145
  • 36
  • 401
  • 431
11

I create an enum and assign the hex values for the control codes to them.

enum ColorCode {
    White           =   0,   /**< White */
    Black           =   1,   /**< Black */
    DarkBlue        =   2,   /**< Dark blue */
    DarkGreen       =   3,   /**< Dark green */
    Red         =   4,   /**< Red */
    DarkRed         =   5,   /**< Dark red */
    DarkViolet      =   6,   /**< Dark violet */
    Orange          =   7,   /**< Orange */
    Yellow          =   8,   /**< Yellow */
    LightGreen      =   9,   /**< Light green */
    Cyan            =  10,   /**< Cornflower blue */
    LightCyan       =  11,   /**< Light blue */
    Blue            =  12,   /**< Blue */
    Violet          =  13,   /**< Violet */
    DarkGray            =  14,   /**< Dark gray */
    LightGray       =  15   /**< Light gray */
};

enum ControlCode {
    Bold            = 0x02,     /**< Bold */
    Color           = 0x03,     /**< Color */
    Italic          = 0x09,     /**< Italic */
    StrikeThrough           = 0x13,     /**< Strike-Through */
    Reset           = 0x0f,     /**< Reset */
    Underline       = 0x15,     /**< Underline */
    Underline2      = 0x1f,     /**< Underline */
    Reverse         = 0x16      /**< Reverse */
};
Joseph Crowell
  • 111
  • 1
  • 2
8

In my Python IRC bot, I can get bold to show up in irssi using \x02sometext\x02, which shows up like:

this is \x02some text\x02

this is some text

As for colors, I believe you're looking for \x03AA,BB where A is the foreground color and B the background color (what you'd type in after Ctrl+K). Not 100% for sure, though. Try connecting an IRC client using telnet, and check what mIRC does when you use Ctrl+K.

You're not likely to get a standard cohesive behavior across IRC clients...ANSI escape codes are processed by more of the old-fare staple Unix clients like irssi, and mIRC sometimes does its own thing.

Jed Smith
  • 15,584
  • 8
  • 52
  • 59
  • 2
    mIRC has it's own colour codes (denoted by \x03), and I believe this is well supported across atleast GUI clients these days. I'd probably take this route for an IRC client. Also, I doubt irssi and similar commandline clients parse the ANSI codes, they just parse them through to the console and let it worry about them. – Matthew Scharley Sep 08 '09 at 02:22
  • 1
    mIRC colors are pretty standard, and while some clients might have their own palettes, most clients should use the same palette, even if not exactly the same. ANSI escape codes are not supported by all clients, the only ones I know of are Irssi and (surprisingly) HexChat. – alexia Feb 16 '14 at 12:30
0

This might be down to the specific chat library I was using (ChatSharp), but I couldn't get the current accepted answer to work. What I ended up with was:

channel.SendMessage((char)3 + "5,12hello");
Chris Rae
  • 5,627
  • 2
  • 36
  • 51