Skip to content

Commit

Permalink
Add IRC example
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 4, 2023
1 parent 7646b9a commit e0b25c8
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Examples/function.simba
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ begin
WriteLn(GetText());

Writeln('10x10 = ', MultiplyNumber(10, 10));
end;
end;
2 changes: 1 addition & 1 deletion Examples/image.simba
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var
begin
Img := TImage.Create(500, 500); // Images must explictly created and freed!
Img.DrawBox([100,100,400,400], $0000FF);
Img.DrawLine([50, 50], [450, 50], 5, $00FFFF);
Img.DrawLine([50, 50], [450, 50], $00FFFF);
Img.SetPixel(250, 250, $FFFFFF);
Img.SetFontSize(25);
Img.SetFontAntialiasing(False);
Expand Down
54 changes: 54 additions & 0 deletions Examples/irc.simba
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Very simple irc "bot" to test TInternetSocket
// Joins rizon server, and replys the date and time when !date is said

const
NICK_TO_USE := 'SimbaIRCBot' + ToString(Random(999));
CHANNEL_TO_JOIN := '#SimbaIRCBot';

procedure tx(Sock: TInternetSocket; Str: String);
begin
Sock.WriteString(Str + #13#10);
end;

function rx(Sock: TInternetSocket): Boolean;
var
Line: String;
begin
for Line in Sock.ReadString().Split(#13#10) do
begin
WriteLn(Line);

if (Line.StartsWith('PING')) then
begin
tx(Sock, Line.Replace('PING', 'PONG'));

Result := True;
end;

if ('End of /MOTD command' in Line) then
tx(Sock, 'JOIN ' + CHANNEL_TO_JOIN);

if ('!date' in Line) then
tx(Sock, 'PRIVMSG ' + CHANNEL_TO_JOIN + ' :' + FormatDateTime('c', Now()));
end;
end;

var
Sock: TInternetSocket;
begin
Sock := TInternetSocket.Create('irc.rizon.net', 6667, False);
Sock.Connect();

tx(Sock, 'NICK ' + NICK_TO_USE);
tx(Sock, 'USER ' + NICK_TO_USE + ' * * *');

while True do
begin
if Sock.HasData() then
rx(Sock);

Sleep(500);
end;

Sock.Free();
end.
2 changes: 1 addition & 1 deletion Examples/loop.simba
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ begin
WriteLn('-------------------------------');
ForLoop_Continue();
WriteLn('-------------------------------');
end.
end.
3 changes: 2 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<TextDesc Value=""/>
</XPManifest>
<Icon Value="0"/>
<Resources Count="10">
<Resources Count="11">
<Resource_0 FileName="..\Examples\array.simba" Type="RCDATA" ResourceName="EXAMPLE_ARRAY"/>
<Resource_1 FileName="..\Examples\function.simba" Type="RCDATA" ResourceName="EXAMPLE_FUNCTION"/>
<Resource_2 FileName="..\Examples\loop.simba" Type="RCDATA" ResourceName="EXAMPLE_LOOP"/>
Expand All @@ -28,6 +28,7 @@
<Resource_7 FileName="..\Examples\static_method.simba" Type="RCDATA" ResourceName="EXAMPLE_STATIC_METHOD"/>
<Resource_8 FileName="..\Examples\json.simba" Type="RCDATA" ResourceName="EXAMPLE_JSON"/>
<Resource_9 FileName="..\Examples\form.simba" Type="RCDATA" ResourceName="EXAMPLE_FORM"/>
<Resource_10 FileName="..\Examples\irc.simba" Type="RCDATA" ResourceName="EXAMPLE_IRC"/>
</Resources>
</General>
<VersionInfo>
Expand Down
Binary file modified Source/Simba.res
Binary file not shown.
1 change: 1 addition & 0 deletions Source/forms/simba.openexampleform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ procedure TSimbaOpenExampleForm.FormCreate(Sender: TObject);
AddNode('Static Method', 'EXAMPLE_STATIC_METHOD' );
AddNode('JSON', 'EXAMPLE_JSON' );
AddNode('Form', 'EXAMPLE_FORM' );
AddNode('IRC', 'EXAMPLE_IRC' );
end;

procedure TSimbaOpenExampleForm.DoTreeViewSelectionChanged(Sender: TObject);
Expand Down

0 comments on commit e0b25c8

Please sign in to comment.