Skip to content

Commit b64bdfd

Browse files
committed
chore: Storing state for debug with Remy
1 parent df1966d commit b64bdfd

File tree

4 files changed

+154
-3
lines changed

4 files changed

+154
-3
lines changed

pasirclogbot.example.config

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[IRC]
2-
Host="localhost"
2+
#Host="localhost"
3+
Host="irc.libera.chat"
34
Port=6667
4-
NickName="[PasLogBot]"
5-
UserName="paslogbot"
5+
#NickName="[PasLogBot]"
6+
NickName="[PasLogBotDev]"
7+
UserName="paslogbotdev"
68
RealName="IRC channel #pascal log bot"
79
Channel="#pascal"
10+
UseUTF8=1
811
[DB]
912
File="paslogbot.db"

research/ChatGPT-Colours.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Prompt
2+
3+
Can you please teach me how to include colour in IRC messages?
4+
5+
# Answer
6+
7+
8+
9+
Including color in IRC messages involves using special control codes that are recognized by most IRC clients. These control codes allow you to format your messages with different colors or styles like bold or underline. Here's how you can do it:
10+
11+
### 1. **Color Control Code**
12+
- The control code for color is **`Ctrl + K`**, which appears as `\x03` in raw text.
13+
- After the color code, you specify the foreground color number, optionally followed by a comma and the background color number.
14+
15+
### 2. **Color Codes**
16+
Here are the standard IRC color codes:
17+
18+
| Code | Color | Code | Color |
19+
|------|----------------|------|----------------|
20+
| 00 | White | 08 | Yellow |
21+
| 01 | Black | 09 | Light Green |
22+
| 02 | Blue (Navy) | 10 | Cyan |
23+
| 03 | Green | 11 | Light Cyan |
24+
| 04 | Red | 12 | Light Blue |
25+
| 05 | Brown (Maroon) | 13 | Pink |
26+
| 06 | Purple | 14 | Grey |
27+
| 07 | Orange | 15 | Light Grey |
28+
29+
### 3. **Example Usage**
30+
To include color in your messages, use the format:
31+
32+
```
33+
\x03<foreground>,<background>Text
34+
```
35+
36+
#### Examples:
37+
1. **Simple colored text** (e.g., Red text):
38+
```
39+
\x034This text is red.
40+
```
41+
Output: *This text is red.*
42+
43+
2. **Text with a background color** (e.g., Green text on a Yellow background):
44+
```
45+
\x033,08This text is green with a yellow background.
46+
```
47+
Output: *This text is green with a yellow background.*
48+
49+
3. **Resetting the color**:
50+
To stop the color effect, you can use the reset code: **`Ctrl + O`** (`\x0F` in raw text).
51+
52+
Example:
53+
```
54+
\x034Red text\x0F Normal text
55+
```
56+
Output: *Red text Normal text.*
57+
58+
### 4. **Styling Codes**
59+
You can combine colors with other styles:
60+
61+
| Style | Code | Description |
62+
|---------------|--------|---------------------------------|
63+
| Bold | \x02 | Makes the text bold. |
64+
| Underline | \x1F | Underlines the text. |
65+
| Italic | \x1D | Italicizes the text. |
66+
| Reverse Color | \x16 | Swaps foreground and background. |
67+
68+
#### Example with Bold and Color:
69+
```
70+
\x02\x034Bold and Red\x0F Normal text
71+
```
72+
Output: **Bold and Red** *Normal text.*
73+
74+
### 5. **Send Messages**
75+
When typing in an IRC client:
76+
- Use `Ctrl + K` to insert the color code.
77+
- Follow with the numeric codes for foreground and background colors as needed.
78+
79+
If you're scripting for an IRC bot or using raw IRC commands, include the control characters as their ASCII values (`\x03`, `\x02`, etc.) directly in your message string.
80+
81+
Let me know if you’d like examples in a specific programming language, like Go or PHP, for sending these formatted IRC messages!

src/bot/irclogbot.bot.pas

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ interface
77
uses
88
Classes
99
, SysUtils
10+
, IdGlobal
1011
, IdContext
12+
, IdComponent
13+
, IdCmdTCPClient
1114
, IdIRC
1215
, IRCLogBot.Config
1316
, IRCLogBot.Database
@@ -37,6 +40,14 @@ TIRCLogBot = class(TObject)
3740
AChannel: String);
3841
procedure OnPrivateMessage(ASender: TIdContext; const ANickname, AHost,
3942
ATarget, AMessage: String);
43+
procedure OnISupport(ASender: TIdContext; AParameters: TStrings);
44+
procedure OnStatus(ASender: TObject; const AStatus: TIdStatus;
45+
const AStatusText: string);
46+
procedure OnRaw(ASender: TIdContext; AIn: Boolean; const AMessage: String);
47+
procedure OnBeforeCommandHandler(ASender: TIdCmdTCPClient;
48+
var AData: string; AContext: TIdContext);
49+
procedure OnAfterCommandHandler(ASender: TIdCmdTCPClient;
50+
AContext: TIdContext);
4051

4152
procedure Help(const ATarget: String);
4253
procedure Version(const ATarget: String);
@@ -103,6 +114,12 @@ procedure TIRCLogBot.OnJoin(ASender: TIdContext; const ANickname, AHost,
103114
]);
104115
if (ANickname = FConfig.NickName) and (AChannel = FConfig.Channel) then
105116
begin
117+
if FConfig.UseUTF8 then
118+
begin
119+
debug('Using UTF8');
120+
FIRC.IOHandler.DefStringEncoding:= IndyTextEncoding_UTF8;
121+
end;
122+
106123
debug('Successfully joined my channel.');
107124
FJoinedChannel:= True;
108125
FIRC.Say(AChannel, 'I have arrived!!! TADAAAAA!!! Send me a private message with ".help" to see what I can do for you.');
@@ -194,6 +211,38 @@ procedure TIRCLogBot.OnPrivateMessage(ASender: TIdContext; const ANickname,
194211
end;
195212
end;
196213

214+
procedure TIRCLogBot.OnISupport(ASender: TIdContext; AParameters: TStrings);
215+
begin
216+
debug('I Support: %s', [AParameters]);
217+
end;
218+
219+
procedure TIRCLogBot.OnStatus(ASender: TObject; const AStatus: TIdStatus;
220+
const AStatusText: string);
221+
begin
222+
debug('Status: (%d) %s', [Ord(AStatus), AStatusText]);
223+
end;
224+
225+
procedure TIRCLogBot.OnRaw(ASender: TIdContext; AIn: Boolean;
226+
const AMessage: String);
227+
begin
228+
if AIn then
229+
debug('RAW(In ): "%s"', [AMessage])
230+
else
231+
debug('RAW(Out): "%s"', [AMessage]);
232+
end;
233+
234+
procedure TIRCLogBot.OnBeforeCommandHandler(ASender: TIdCmdTCPClient;
235+
var AData: string; AContext: TIdContext);
236+
begin
237+
debug('Before Command: %s', [AData]);
238+
end;
239+
240+
procedure TIRCLogBot.OnAfterCommandHandler(ASender: TIdCmdTCPClient;
241+
AContext: TIdContext);
242+
begin
243+
debug('After Command');
244+
end;
245+
197246
procedure TIRCLogBot.Help(const ATarget: String);
198247
begin
199248
debug('Help command.');
@@ -304,12 +353,24 @@ constructor TIRCLogBot.Create(const AConfig: TBotConfig);
304353
FIRC.RealName:= FConfig.RealName;
305354
FIRC.Host:= FConfig.Host;
306355
FIRC.Port:= FConfig.Port;
356+
{ #todo 100 -ogcarreno : Need to revisit these }
357+
//FIRC.Replies.ClientInfo:= 'PasLogBot';
358+
//FIRC.Replies.Finger:= 'paslogbot';
359+
//FIRC.Replies.UserInfo:= 'paslogbot';
360+
//FIRC.Replies.Version:= cVersion;
361+
362+
// Events
307363
FIRC.OnConnected:= @OnConnected;
308364
FIRC.OnDisconnected:= @OnDisconnected;
309365
FIRC.OnServerQuit:= @OnServerQuit;
310366
FIRC.OnJoin:= @OnJoin;
311367
FIRC.OnNotice:= @OnNotice;
312368
FIRC.OnPrivateMessage:= @OnPrivateMessage;
369+
//FIRC.OnISupport:= @OnISupport;
370+
//FIRC.OnStatus:= @OnStatus;
371+
//FIRC.OnRaw:= @OnRaw;
372+
//FIRC.OnBeforeCommandHandler:= @OnBeforeCommandHandler;
373+
//FIRC.OnAfterCommandHandler:= @OnAfterCommandHandler;
313374

314375
// Setup Database
315376
FDB:= TDatabase.Create(FConfig.Database);

src/config/irclogbot.config.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ TBotConfig = class(TObject)
2323
FIRCUserName: String;
2424
FIRCRealName: String;
2525
FIRCChannel: String;
26+
FIRCUseUTF8: Boolean;
2627

2728
FDBFile: String;
2829
protected
@@ -50,6 +51,9 @@ TBotConfig = class(TObject)
5051
property Channel: String
5152
read FIRCChannel
5253
write FIRCChannel;
54+
property UseUTF8: Boolean
55+
read FIRCUseUTF8
56+
write FIRCUseUTF8;
5357

5458
property Database: String
5559
read FDBFile
@@ -70,6 +74,7 @@ constructor TBotConfig.Create(AConfigFile: String);
7074
FIRCUserName:= '';
7175
FIRCRealName:= '';
7276
FIRCChannel:= '';
77+
FIRCUseUTF8:= False;
7378
end;
7479

7580
destructor TBotConfig.Destroy;
@@ -89,6 +94,7 @@ procedure TBotConfig.LoadValues;
8994
FIRCUserName:= FINI.ReadString('IRC', 'UserName', '');
9095
FIRCRealName:= FINI.ReadString('IRC', 'RealName', '');
9196
FIRCChannel:= FINI.ReadString('IRC', 'Channel', '');
97+
FIRCUseUTF8:= FINI.ReadBool('IRC', 'UseUTF8', False);
9298

9399
FDBFile:= FINI.ReadString('DB', 'File', 'paslogbot.db');
94100

0 commit comments

Comments
 (0)