www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - kameloso IRC bot

reply Anonymouse <asdf asdf.net> writes:
Announcing kameloso IRC bot, 1.0.0.

It's a bot, not a parser library, though the parsing can 
technically be lifted out and reused.

On GitHub: https://github.com/zorael/kameloso, also 
https://kameloso.dub.pm.

There's notes to offline users, pasted URL title lookup, logs, 
automatic mode sets (e.g. +o on join), s/this/that/ substitution, 
user quotes, !seen, a basic Twitch streamer plugin. Some other 
legacy features and trivialities like the original venerable echo 
command. Ideas needed.

Absolute bare minimum required to try it:

git clone https://github.com/zorael/kameloso.git
cd kameloso
dub build
./kameloso --channels "#d,#freenode

With no other settings this will just be in client mode as a 
guest user and won't pollute the channels. (#d alone is too quiet 
to make a good example.) ./kameloso --writeconfig to set up 
further, see --help and the readme. Windows Powershell/cmd users 
may need an extra step to get terminal colours instead of \033[0m 
everywhere, see the readme.

The MVPs here are definitely UDAs, slices and mixin templates. 
There are some clever things in there that I'm really proud of, 
and some blemishes that I've learned to live with.

dscanner --sloc weighs it in at ~11k lines, excluding most tests. 
Much of it is  safe but it's not  nogc, nor -betterC. Naturally 
it tries to avoid allocating low-hanging fruit but there's 
Exceptions, associative and dynamic arrays, string 
concatenations, closures, and all kinds of convenient D things.

Parsing looks like this (automatically generated unit test): 
https://github.com/zorael/kameloso/commit/dde05a06

Plugins like this (automatically called module-level function):

 (IRCEvent.Type.CHAN)
 (PrivilegeLevel.anyone)
 (ChannelPolicy.home)
 BotCommand(PrefixPolicy.prefixed, "hello")
 BotCommand(PrefixPolicy.nickname, "poke")
 Description("Sends a hello world to the current channel.")
void onCommandHello(MyPlugin plugin, const IRCEvent event)
{
     plugin.chan(event.channel, "Hello world!");
}

Because of how code.dlang.org and dub deals with versions 
(announces pre-releases but serves releases), having previously 
pulled this from there at any point up until now will have landed 
you with an ancient version. So please don't judge this by any 
previous builds.

A normal dub build takes 9 seconds with dmd on this laptop 
(Linux) and eats 4036 Mb of RAM, down from 7800+ Mb. Profiling 
does not seem to show any particular surprising hotspots anymore. 
All compilers segfault in various situations[1][2][3].

Feedback appreciated.


[1]: https://issues.dlang.org/show_bug.cgi?id=18026
[2]: https://issues.dlang.org/show_bug.cgi?id=19123
[3]: https://bugzilla.gdcproject.org/show_bug.cgi?id=307
Feb 02 2019
parent Anonymouse <zorael gmail.com> writes:
On Saturday, 2 February 2019 at 15:45:11 UTC, Anonymouse wrote:
 Announcing kameloso IRC bot, 1.0.0.
[...] Tagging v1.2.0. https://github.com/zorael/kameloso It's been a while so diffs everywhere. One plugin was merged into another, a third was broken out of a fourth. Small tweaks, more clever things. Queued sends should not block the client by sleeping anymore. A few crashes fixed. Compilation memory use grew some. Binary size did too. There's more Twitch stuff, but it remains optional at compilation since it's nothing you're going to use. As before, all plugins can be opted out from being compiled at all, by choice of dub build configuration or by manually tailoring dub.json[1]. So it's as lean as you want it to be. (Still pretty big.) Plugins not crucial for the bot to properly operate can also be disabled at runtime, even if built, in the configuration file. https://github.com/zorael/kameloso/blob/master/source/kameloso/plugins/hello.d [1]: https://github.com/zorael/kameloso/blob/c00af3b9/dub.json#L22-L38 A week in 25 channels: [...] ^C...caught signal 2! [12:35:23] Aborting... Number of collections: 8 Total GC prep time: 0 milliseconds Total mark time: 42 milliseconds Total sweep time: 2 milliseconds Max Pause Time: 10 milliseconds Grand total GC time: 46 milliseconds GC summary: 176 MB, 8 GC 46 ms, Pauses 43 ms < 10 ms ./kameloso --DRT-gcopt=profile:1 419.10s user 1243.21s system 0% cpu 180:06:10.53 total avg shared (code): 0 KB avg unshared (data/stack): 0 KB total (sum): 0 KB max memory: 204 MB page faults from disk: 0 other page faults: 6156
Aug 16 2019