Skip to content

Commit

Permalink
Merge pull request #126 from bayashi/chatgpt-user
Browse files Browse the repository at this point in the history
To detect ChatGPT-User
  • Loading branch information
bayashi authored Jun 23, 2024
2 parents 32b8c59 + 38bc54c commit 4729466
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Duadua.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions lib/Duadua/Parser/Bot/ChatGPTUser.pm
Original file line number Diff line number Diff line change
@@ -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 E<lt>[email protected]E<gt>
=head1 LICENSE
C<Duadua> 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
10 changes: 10 additions & 0 deletions t/testset/bot/chatgpt-user.yaml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 4729466

Please sign in to comment.