diff --git a/Examples/function.simba b/Examples/function.simba index 68df47ac0..ab6119676 100644 --- a/Examples/function.simba +++ b/Examples/function.simba @@ -20,4 +20,4 @@ begin WriteLn(GetText()); Writeln('10x10 = ', MultiplyNumber(10, 10)); -end; \ No newline at end of file +end; diff --git a/Examples/image.simba b/Examples/image.simba index a07a04f1d..673feec76 100644 --- a/Examples/image.simba +++ b/Examples/image.simba @@ -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); diff --git a/Examples/irc.simba b/Examples/irc.simba new file mode 100644 index 000000000..539424ee5 --- /dev/null +++ b/Examples/irc.simba @@ -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. diff --git a/Examples/loop.simba b/Examples/loop.simba index 0bae6d1f5..9ec16f3e5 100644 --- a/Examples/loop.simba +++ b/Examples/loop.simba @@ -44,4 +44,4 @@ begin WriteLn('-------------------------------'); ForLoop_Continue(); WriteLn('-------------------------------'); -end. \ No newline at end of file +end. diff --git a/Source/Simba.lpi b/Source/Simba.lpi index d23df84bb..13aceb3a1 100644 --- a/Source/Simba.lpi +++ b/Source/Simba.lpi @@ -17,7 +17,7 @@ - + @@ -28,6 +28,7 @@ + diff --git a/Source/Simba.res b/Source/Simba.res index f3d99e11c..cdc30e75f 100644 Binary files a/Source/Simba.res and b/Source/Simba.res differ diff --git a/Source/forms/simba.openexampleform.pas b/Source/forms/simba.openexampleform.pas index 2da623c89..c8104a208 100644 --- a/Source/forms/simba.openexampleform.pas +++ b/Source/forms/simba.openexampleform.pas @@ -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);