Skip to content

Add: Huggable bot#404

Merged
lizmat merged 4 commits intoRaku:mainfrom
4zv4l:main
Apr 5, 2026
Merged

Add: Huggable bot#404
lizmat merged 4 commits intoRaku:mainfrom
4zv4l:main

Conversation

@4zv4l
Copy link
Copy Markdown
Collaborator

@4zv4l 4zv4l commented Apr 3, 2026

A bot that simply gives hug when sending '.hug'

It's pretty simple, I tried to follow what I have seen from other bot source file.
Not totally sure if I understand the selfrun and the fuzzy-nick.

Made it after reading this: https://raku.github.io/CCR/Remaster/Zoffix%20Znet/On-Troll-Hugging-Hole-Digging-and-Improving-Open-Source-Communities.html
And realizing that the bot isn't active anymore.

If it is ok to be added, I can also edit the Wiki to add the Huggable entry 🙏

A bot that simply gives hug when sending '.hug'
@AlexDaniel
Copy link
Copy Markdown
Member

AlexDaniel commented Apr 3, 2026

Not totally sure if I understand the selfrun and the fuzzy-nick.

fuzzy-nick('huggable6', 2)]

This just means that it'll respond to other messages with an approximate distance of 2. So “hugable6:”, “hugable:”, etc. will all trigger the bot, you can test that. One thing to keep in mind is that this distance shouldn't be too big, otherwise one command might trigger more than one bot if the nicknames are similar (“gugpable6” – is that greppable or huggable?).

To make it deploy automatically on merge you'll need to tweak https://github.com/Raku/whateverable/blob/main/compose.yaml

@lizmat
Copy link
Copy Markdown
Contributor

lizmat commented Apr 3, 2026

Cool!

Two comments: Raku scripts, if given an extension, are sorta expected to have the .raku extension nowadays. Also, Raku test files nowadays have the .rakutest extension.

@AlexDaniel
Copy link
Copy Markdown
Member

AlexDaniel commented Apr 3, 2026

Two comments: Raku scripts, if given an extension, are sorta expected to have the .raku extension nowadays. Also, Raku test files nowadays have the .rakutest extension.

Either all bots need to change the extension or none should use the new extension. There's some logic in Akefile that requires the extension to be .p6 at this point. Feel free to change that, of course, but this PR (in its current scope) is correct.

@lizmat
Copy link
Copy Markdown
Contributor

lizmat commented Apr 3, 2026

@4zv4l ok, then either leave the .p6 extension. Or if you feel brave, modernize all of the .p6 extensions (possibly in a separate PR?)

@AlexDaniel
Copy link
Copy Markdown
Member

AlexDaniel commented Apr 3, 2026

Also, the closest bot in terms of functionality is tellable. Here's how it implements .seen:

#| seen
multi method irc-to-me($msg where { .Str ~~ m:r/^ \s* [seen \s+]?
$<who>=<.&irc-nick> <[:,]>* \s* $/ }) {
my $who = ~$<who>;
my %seen := $db-seen.read;
my $entry = %seen{normalize-weirdly $who};
without $entry {
return I haven't seen any guests around if guest-like $who;
return I haven't seen $who around
~ maybe , did you mean %s?, did-you-mean-seen $who, %seen
}
# Format CTCP ACTION aka /me
my $said = $entry<text> ~~ /^ \x[01] ‘ACTION ’ <( .* )> \x[01] $/ ??
* $entry<nick> $/ !!
<$entry<nick>> $entry<text>;
I saw $who $entry<timestamp> in $entry<channel>: $said
}

(and see some other code around it, too)

There's a reason for some of this. For example, in this PR, you only seem to support messages like:
<lizmat> .hug AlexDaniel

But whateverable consistently supports messages like this too:
<lizmat> huggable6: hug AlexDaniel

And the new bot could easily also support this:
<lizmat> huggable6: AlexDaniel

People rarely remember the correct command, so all whateverable bots consistently DWIM.

Note that tellable also implements some of the nickname normalization (e.g. .hug alexdaniel_ would actually deliver the hug to AlexDaniel) – you should maybe rely on it too, so that names get normalized the same way and unknown names result in “did you mean …” messages (or, if you intend “everyone” to work, then feel free not to).

@4zv4l
Copy link
Copy Markdown
Collaborator Author

4zv4l commented Apr 3, 2026

Thanks for all your nice reply !

I'll check to add the support to use the bot name.
Is that ok to set the fuzzy to 0 ? It makes more sense to me to use the right name to call the bot, because what if someone is named huggable67 (vs huggable6) would the bot pick it up as well ? But of course whatever value that you think is appropriate I can set.

Not sure about the nickname vs supporting arbitrary string after "hugs", imo the arbitrary string also allows to handle the discord bridge users, so maybe preferred ?

Once I've done that, I'll check if I can make another pr to update the extension of the Raku module and test files without breaking everything, happy to contribute with anything my brain is able to produce/handle !

4zv4l added 2 commits April 4, 2026 09:56
allow to send message to bot directly to hug (and the tests for it)

Add:

compose file to start huggable6
Allow to simply priv msg the bot nicknames to hug (or everyone)
@AlexDaniel
Copy link
Copy Markdown
Member

Is that ok to set the fuzzy to 0 ?

Not recommended, as people will be misspelling it as “huggable”, “hugable6”, etc. – the fuzzy name logic was added based on actual usage. A distance of 1 or 2 is fine.

because what if someone is named huggable67

I always thought that it wouldn't reply if it's a direct match of another user, but I couldn't find the code for that, so maybe it wasn't implemented. Still, though, I don't remember of any cases where the user's name was too similar (and there are a lot of bots with different names!).

Not sure about the nickname vs supporting arbitrary string after "hugs", imo the arbitrary string also allows to handle the discord bridge users, so maybe preferred ?

Discord bridge users are supported anyway. All bots work across the bridge, in fact discord users will be able to use .hug to hug other users. When you run tests, they actually run twice (once normally and once for discord bridge).

xbin/Huggable.p6 Outdated
#| .hug <nick>...
method irc-privmsg-channel ($msg where / [\s|^] '.hug' [\s|$] /) {
my $idx = $msg.text.index('.hug') + 4;
$.irc.send: :where($msg.channel) :text("hugs" ~ ($msg.text.substr($idx) // ""));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes that a /me action?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see what you mean, the bot should reply with a * hugs <nick> ?
But I am not sure how to trigger this instead of a normal message with IRC::Client.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do :text(“\x01ACTION hugs ” ~ $nick ~ “\x01”);, does it work?

xt/Huggable.t Outdated

my $t = Huggable.new: bot => ‘Huggable’;

$t.common-tests: help => ‘Like this: .hug’;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs to show an example of hugging someone

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better now ? I basically took the same as Tellable bot.

xt/Huggable.t Outdated
#| .hug <nick>
$t.test('.hug',
'hug',
'hugs');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the nickname was not provided, then I clearly expect a hug for myself. IMO it should hug the sender.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to default hug the sender if no nick is provider 🙏

Help shows how to hug someone with .hug <nick>

Rename Huggable.t to match other test files
#| .hug
#| .hug <nick>...
#| hugs the sender if no nick is provided
method irc-privmsg-channel ($msg where / [\s|^] '.hug' [\s|$] /) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd prefer to see it in the regex itself rather than doing the cutting of the string with an index:

Something like:

multi method irc-to-me($msg where { .Str ~~ m:r/^ \s* [.hug \s+]? $<who>=<.&irc-nick> <[:,]>* \s* $/ }) {
  hugs  ~ $<who>
}

Copy link
Copy Markdown
Member

@AlexDaniel AlexDaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the /me action to be figured out, and the regex to use irc-nick and all that, but other than that it's good enough.

@lizmat lizmat merged commit a53a4f8 into Raku:main Apr 5, 2026
@AlexDaniel
Copy link
Copy Markdown
Member

@4zv4l we're merging this now but feel free to submit more improvements. Thank you! 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants