You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何直接捕获解析IRC中Whateverable bots的Perl 6输出?

Great question! Manually copying and trimming Perl 6 eval bot output from IRC is such a tedious task—let’s break down some practical solutions for both client-side (WeeChat/Irssi) and server-side (Gist integration) workflows to make this easier.

Client-Side Solutions (WeeChat/Irssi Scripts)

The most straightforward way to automate this is with a client-side script that listens for messages from evalable6, extracts the output, and saves it directly to a file (or even copies it to your clipboard).

WeeChat Script Example

WeeChat has a robust API for scripting, and a simple Perl script can handle this job:

use strict;
use warnings;
use WeeChat;

WeeChat::register(
    'p6-output-saver',
    'Your Name',
    '1.0',
    'MIT',
    'Automatically save Perl 6 eval bot output',
    '',
    ''
);

WeeChat::hook_signal('weechat_print', 'handle_print', '');

sub handle_print {
    my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message) = @_;
    # Target only messages from evalable6 containing OUTPUT
    if ($prefix eq 'evalable6' && $message =~ /OUTPUT: «(.*?)»/s) {
        my $output = $1;
        # Replace IRC newline symbols with actual newlines for readability
        $output =~ s/␤/\n/g;
        # Append to a dedicated output file
        open my $fh, '>>', "$ENV{HOME}/p6-eval-outputs.txt" or die $!;
        print $fh "--- " . localtime() . " ---\n";
        print $fh $output . "\n\n";
        close $fh;
        # Optional: Send a confirmation in your WeeChat buffer
        WeeChat::print($buffer, "[p6-saver] Saved output to ~/p6-eval-outputs.txt");
    }
    return WeeChat::WEECHAT_RC_OK;
}

Setup steps:

  1. Save this script as p6-output-saver.pl in your WeeChat scripts directory (usually ~/.weechat/scripts/).
  2. Load it in WeeChat with /script load p6-output-saver.pl.
  3. For auto-loading on startup, move the script to ~/.weechat/scripts/autorun/.

Irssi Script Example

If you use Irssi instead, a similar Perl script will work:

use strict;
use Irssi;

our $VERSION = '1.0';
our %IRSSI = (
    name        => 'p6-output-saver',
    description => 'Automatically save Perl 6 eval bot output',
    authors     => 'Your Name',
    license     => 'MIT',
);

sub sig_message_public {
    my ($server, $msg, $nick, $addr, $target) = @_;
    # Skip unless the message comes from evalable6
    return unless $nick eq 'evalable6';
    if ($msg =~ /OUTPUT: «(.*?)»/s) {
        my $output = $1;
        $output =~ s/␤/\n/g;
        # Append to a file
        open my $fh, '>>', "$ENV{HOME}/p6-eval-outputs.txt" or die $!;
        print $fh "--- " . localtime() . " ---\n";
        print $fh $output . "\n\n";
        close $fh;
        # Print confirmation in Irssi
        Irssi::print("[p6-saver] Saved output to ~/p6-eval-outputs.txt");
    }
}

Irssi::signal_add('message public', 'sig_message_public');

Setup steps:

  1. Save as p6-output-saver.pl in ~/.irssi/scripts/.
  2. Load it with /script load p6-output-saver.pl.
  3. For auto-loading, create a symlink in ~/.irssi/scripts/autorun/ pointing to the script.

Server-Side Solution: Auto-Save to Gist

If you want to share or archive your Perl 6 evals more permanently, you can set up a helper bot that listens for evalable6 output and automatically creates a GitHub Gist with both your original code and the output.

Helper Bot Example (Python)

This bot uses the IRC library and GitHub API to handle the workflow:

import irc.bot
import requests
import json

class P6GistBot(irc.bot.SingleServerIRCBot):
    def __init__(self, channel, nickname, server, port=6667, github_token=None):
        super().__init__([(server, port)], nickname, nickname)
        self.channel = channel
        self.github_token = github_token
        self.last_user_command = {}  # Track each user's last Perl 6 command

    def on_welcome(self, c, e):
        c.join(self.channel)

    def on_pubmsg(self, c, e):
        message = e.arguments[0]
        sender_nick = e.source.nick

        # Capture user's Perl 6 command
        if message.startswith('p6: '):
            self.last_user_command[sender_nick] = message[4:].strip()
        
        # Capture evalable6's output and create a Gist
        elif sender_nick == 'evalable6':
            if ', OUTPUT: «' in message:
                # Extract the original user from the bot's response
                target_user = message.split(',')[0].strip()
                # Extract and format the output
                raw_output = message.split('OUTPUT: «')[1].split('»')[0]
                formatted_output = raw_output.replace('␤', '\n')

                if target_user in self.last_user_command:
                    # Prepare Gist data
                    gist_payload = {
                        "description": f"Perl 6 eval from {target_user} on #{self.channel}",
                        "public": False,  # Set to True for public Gists
                        "files": {
                            "code.p6": {"content": self.last_user_command[target_user]},
                            "output.txt": {"content": formatted_output}
                        }
                    }

                    # Send request to GitHub API
                    headers = {'Authorization': f'token {self.github_token}'}
                    response = requests.post(
                        'https://api.github.com/gists',
                        json=gist_payload,
                        headers=headers
                    )

                    if response.status_code == 201:
                        gist_url = response.json()['html_url']
                        c.privmsg(self.channel, f"{target_user}: Your Perl 6 eval is saved to Gist: {gist_url}")
                    else:
                        c.privmsg(self.channel, f"{target_user}: Oops, failed to create Gist.")
                    
                    # Clear the stored command after processing
                    del self.last_user_command[target_user]

if __name__ == "__main__":
    # Replace these values with your own
    bot = P6GistBot(
        channel='#perl6',
        nickname='p6-gist-bot',
        server='irc.libera.chat',
        github_token='YOUR_GITHUB_PERSONAL_ACCESS_TOKEN'
    )
    bot.start()

Setup steps:

  1. Install required packages: pip install irc requests.
  2. Generate a GitHub personal access token with gist permissions (in GitHub Settings > Developer settings > Personal access tokens).
  3. Replace the placeholder values in the script (channel, server, token).
  4. Run the bot—it will join the channel, track p6: commands, and create Gists when evalable6 returns output.

Bonus: Quick Client-Side Filter

If you don’t want to use a script right away, you can use WeeChat’s built-in filter to isolate evalable6 messages:

/filter add p6-eval * evalable6 *

This will send all messages from evalable6 to a separate buffer, making it easier to copy output without extra noise.

内容的提问来源于stack exchange,提问作者jjmerelo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:03:49