From 38bc54c545efdd4787cd2b2717e9e87524fdc1ee Mon Sep 17 00:00:00 2001 From: bayashi <42190+bayashi@users.noreply.github.com> Date: Sun, 23 Jun 2024 00:51:06 +0000 Subject: [PATCH] To detect ChatGPT-User --- lib/Duadua.pm | 1 + lib/Duadua/Parser/Bot/ChatGPTUser.pm | 55 ++++++++++++++++++++++++++++ t/testset/bot/chatgpt-user.yaml | 10 +++++ 3 files changed, 66 insertions(+) create mode 100644 lib/Duadua/Parser/Bot/ChatGPTUser.pm create mode 100644 t/testset/bot/chatgpt-user.yaml diff --git a/lib/Duadua.pm b/lib/Duadua.pm index e5274e2..4426f15 100644 --- a/lib/Duadua.pm +++ b/lib/Duadua.pm @@ -34,6 +34,7 @@ my @PARSER_PROC_LIST = qw/ Duadua::Parser::Bot::FacebookCrawler Duadua::Parser::Bot::Slackbot + Duadua::Parser::Bot::ChatGPTUser Duadua::Parser::Bot::YahooSlurp Duadua::Parser::Bot::Baiduspider Duadua::Parser::Bot::Bytespider diff --git a/lib/Duadua/Parser/Bot/ChatGPTUser.pm b/lib/Duadua/Parser/Bot/ChatGPTUser.pm new file mode 100644 index 0000000..864ae3e --- /dev/null +++ b/lib/Duadua/Parser/Bot/ChatGPTUser.pm @@ -0,0 +1,55 @@ +package Duadua::Parser::Bot::ChatGPTUser; +use strict; +use warnings; + +sub try { + my ($class, $d) = @_; + + if ( index($d->ua, 'ChatGPT-User/') > -1 + && index($d->ua, '+https://openai.com/bot') > -1 + && index($d->ua, 'Mozilla/') == 0 ) { + my $h = _set_property($d, 'ChatGPT-User'); + + if ($d->opt_version) { + my ($version) = ($d->ua =~ m!ChatGPT-User/([\d.]+)!); + $h->{version} = $version if $version; + } + + return $h; + } +} + +sub _set_property { + my ($d, $name) = @_; + + my $h = { + name => $name, + is_bot => 1, + }; + + return $h; +} + +1; + +__END__ + +=encoding UTF-8 + +=head1 METHODS + +=head2 try + +Do parse + + +=head1 AUTHOR + +Dai Okabayashi Ebayashi@cpan.orgE + + +=head1 LICENSE + +C is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. (Note that, unlike the Artistic License 1.0, version 2.0 is GPL compatible by itself, hence there is no benefit to having an Artistic 2.0 / GPL disjunction.) See the file LICENSE for details. + +=cut diff --git a/t/testset/bot/chatgpt-user.yaml b/t/testset/bot/chatgpt-user.yaml new file mode 100644 index 0000000..2fd8240 --- /dev/null +++ b/t/testset/bot/chatgpt-user.yaml @@ -0,0 +1,10 @@ +# https://platform.openai.com/docs/plugins/bot +- ua: 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot' + name: ChatGPT-User + is_bot: true + is_ios: false + is_android: false + is_linux: false + is_windows: false + is_chromeos: false + version: '1.0'