Implemented the Webhook request; all my URL gone

This commit is contained in:
swagg boi 2022-07-22 00:49:33 -04:00
parent 629b3406ac
commit fd6616ef8b
5 changed files with 33 additions and 12 deletions

3
.gitignore vendored
View file

@ -35,5 +35,6 @@ inc/
/pm_to_blib /pm_to_blib
/*.zip /*.zip
# Conf file # Conf files
/guestbook-ng.conf /guestbook-ng.conf
/.tom.url

View file

@ -1 +0,0 @@
https://discord.com/api/webhooks/713532266986602617/JE-RZGCxIM-iVTxujoV-9lmlPlHGA5F_Rf8FcK6Hf6gF_PSDkDlqFQUT8rniNQQ6nfxz

View file

@ -9,3 +9,4 @@ requires 'Regexp::Common::URI';
requires 'CSS::Minifier::XS'; requires 'CSS::Minifier::XS';
requires 'Number::Format'; requires 'Number::Format';
requires WebService::Discord::Webhook; requires WebService::Discord::Webhook;
requires 'IO::Socket::SSL';

View file

@ -85,15 +85,28 @@ any [qw{GET POST}], '/sign' => sub ($c) {
$c->stash(status => 400) $c->stash(status => 400)
} }
else { else {
my $blah = my $new_message_id =
$c->message->create_post($name, $message, $url, $spam); $c->message->create_post($name, $message, $url, $spam);
say Dumper $blah;
if ($spam) { if ($spam) {
$c->flash(error => 'This message was flagged as spam') $c->flash(error => 'This message was flagged as spam')
} }
# Send this notification if there's a Webhook URL
elsif (-s '.tom.url') { elsif (-s '.tom.url') {
say 'do stuff here...' my ($url_file, $url, $webhook);
open($url_file, '.tom.url') || die "$@";
chomp($url = <$url_file>);
$webhook = WebService::Discord::Webhook->new(
url => $url,
verify_SSL => 1
);
$webhook->execute(
'content',
"https://guestbook.swagg.net/message/$new_message_id"
);
} }
return $c->redirect_to(page => {page => 'view'}); return $c->redirect_to(page => {page => 'view'});

View file

@ -18,8 +18,7 @@ sub get_posts($self, $this_page = undef) {
my $row_count = $self->{'max_posts'}; my $row_count = $self->{'max_posts'};
my $offset = ($this_page - 1) * $row_count; my $offset = ($this_page - 1) * $row_count;
return $self->pg->db $self->pg->db->query(<<~'END_SQL', $row_count, $offset)->arrays();
->query(<<~'END_SQL', $row_count, $offset)->arrays();
SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
visitor_name, visitor_name,
message, message,
@ -32,7 +31,7 @@ sub get_posts($self, $this_page = undef) {
END_SQL END_SQL
} }
else { else {
return $self->pg->db->query(<<~'END_SQL')->arrays() $self->pg->db->query(<<~'END_SQL')->arrays()
SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
visitor_name, visitor_name,
message, message,
@ -50,8 +49,7 @@ sub get_spam($self, $this_page = undef) {
my $row_count = $self->{'max_posts'}; my $row_count = $self->{'max_posts'};
my $offset = ($this_page - 1) * $row_count; my $offset = ($this_page - 1) * $row_count;
return $self->pg->db $self->pg->db->query(<<~'END_SQL', $row_count, $offset)->arrays();
->query(<<~'END_SQL', $row_count, $offset)->arrays();
SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
visitor_name, visitor_name,
message, message,
@ -64,7 +62,7 @@ sub get_spam($self, $this_page = undef) {
END_SQL END_SQL
} }
else { else {
return $self->pg->db->query(<<~'END_SQL')->arrays() $self->pg->db->query(<<~'END_SQL')->arrays()
SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
visitor_name, visitor_name,
message, message,
@ -78,6 +76,8 @@ sub get_spam($self, $this_page = undef) {
} }
sub create_post($self, $name, $message, $url = undef, $spam = 1) { sub create_post($self, $name, $message, $url = undef, $spam = 1) {
my $message_id = $self->get_last_message_id();
if ($url) { if ($url) {
$self->pg->db->query(<<~'END_SQL', $name, $message, $url, $spam) $self->pg->db->query(<<~'END_SQL', $name, $message, $url, $spam)
INSERT INTO messages (visitor_name, message, homepage_url, is_spam) INSERT INTO messages (visitor_name, message, homepage_url, is_spam)
@ -91,7 +91,7 @@ sub create_post($self, $name, $message, $url = undef, $spam = 1) {
END_SQL END_SQL
} }
return; ++$message_id;
} }
sub max_posts($self, $value = undef) { sub max_posts($self, $value = undef) {
@ -134,4 +134,11 @@ sub get_post_by_id($self, $message_id) {
END_SQL END_SQL
} }
sub get_last_message_id($self) {
$self->pg->db->query(<<~'END_SQL')->text()
SELECT MAX(message_id)
FROM messages;
END_SQL
}
1; 1;