将 mIRC 颜色代码嵌入到 C# 文字中?

发布于 2024-08-04 12:58:39 字数 89 浏览 9 评论 0原文

我正在用 C# 开发一个简单的 irc 机器人,但我不知道如何将粗体/颜色等的典型 mirc 控制代码嵌入到字符串文字中。

有人能指出我该怎么做吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

偏爱你一生 2024-08-11 12:58:39

此处描述了 mIRC 颜色代码格式。我猜您是在问如何在字符串中嵌入 ^C

这称为插入符号。根据 C0 和 C1 控制代码^C 是:

'\x03'

嵌入在一个字符串:

"blabla \x035,12to be colored text and background\x03 blabla"

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"
寄居人 2024-08-11 12:58:39

我创建一个枚举并将控制代码的十六进制值分配给它们。

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 */
};

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 */
};
反目相谮 2024-08-11 12:58:39

在我的Python IRC机器人中,我可以使用\x02sometext\x02在irssi中大胆显示,它显示如下:

this is \x02some text\x02

这是一些文本

至于颜色,我相信你正在寻找\x03AA ,BB,其中 A 是前景色,B 是背景色(您在 Ctrl+K 之后输入的颜色)。但不是 100% 确定。尝试使用 telnet 连接 IRC 客户端,并检查使用 Ctrl+K 时 mIRC 的作用。

你不太可能在 IRC 客户端之间获得标准的内聚行为...ANSI 转义码由更多老式主要 Unix 客户端(如 irssi)处理,而 mIRC 有时会做自己的事情。

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.

倒带 2024-08-11 12:58:39

这可能取决于我正在使用的特定聊天库(ChatSharp),但我无法获得当前接受的答案。我最终得到的是:

channel.SendMessage((char)3 + "5,12hello");

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文