Implemented the Webhook request; all my URL gone
This commit is contained in:
parent
629b3406ac
commit
fd6616ef8b
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -35,5 +35,6 @@ inc/
|
|||
/pm_to_blib
|
||||
/*.zip
|
||||
|
||||
# Conf file
|
||||
# Conf files
|
||||
/guestbook-ng.conf
|
||||
/.tom.url
|
||||
|
|
1
.tom.url
1
.tom.url
|
@ -1 +0,0 @@
|
|||
https://discord.com/api/webhooks/713532266986602617/JE-RZGCxIM-iVTxujoV-9lmlPlHGA5F_Rf8FcK6Hf6gF_PSDkDlqFQUT8rniNQQ6nfxz
|
1
cpanfile
1
cpanfile
|
@ -9,3 +9,4 @@ requires 'Regexp::Common::URI';
|
|||
requires 'CSS::Minifier::XS';
|
||||
requires 'Number::Format';
|
||||
requires WebService::Discord::Webhook;
|
||||
requires 'IO::Socket::SSL';
|
||||
|
|
|
@ -85,15 +85,28 @@ any [qw{GET POST}], '/sign' => sub ($c) {
|
|||
$c->stash(status => 400)
|
||||
}
|
||||
else {
|
||||
my $blah =
|
||||
my $new_message_id =
|
||||
$c->message->create_post($name, $message, $url, $spam);
|
||||
say Dumper $blah;
|
||||
|
||||
if ($spam) {
|
||||
$c->flash(error => 'This message was flagged as spam')
|
||||
}
|
||||
# Send this notification if there's a Webhook 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'});
|
||||
|
|
|
@ -18,8 +18,7 @@ sub get_posts($self, $this_page = undef) {
|
|||
my $row_count = $self->{'max_posts'};
|
||||
my $offset = ($this_page - 1) * $row_count;
|
||||
|
||||
return $self->pg->db
|
||||
->query(<<~'END_SQL', $row_count, $offset)->arrays();
|
||||
$self->pg->db->query(<<~'END_SQL', $row_count, $offset)->arrays();
|
||||
SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
|
||||
visitor_name,
|
||||
message,
|
||||
|
@ -32,7 +31,7 @@ sub get_posts($self, $this_page = undef) {
|
|||
END_SQL
|
||||
}
|
||||
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'),
|
||||
visitor_name,
|
||||
message,
|
||||
|
@ -50,8 +49,7 @@ sub get_spam($self, $this_page = undef) {
|
|||
my $row_count = $self->{'max_posts'};
|
||||
my $offset = ($this_page - 1) * $row_count;
|
||||
|
||||
return $self->pg->db
|
||||
->query(<<~'END_SQL', $row_count, $offset)->arrays();
|
||||
$self->pg->db->query(<<~'END_SQL', $row_count, $offset)->arrays();
|
||||
SELECT TO_CHAR(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
|
||||
visitor_name,
|
||||
message,
|
||||
|
@ -64,7 +62,7 @@ sub get_spam($self, $this_page = undef) {
|
|||
END_SQL
|
||||
}
|
||||
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'),
|
||||
visitor_name,
|
||||
message,
|
||||
|
@ -78,6 +76,8 @@ sub get_spam($self, $this_page = undef) {
|
|||
}
|
||||
|
||||
sub create_post($self, $name, $message, $url = undef, $spam = 1) {
|
||||
my $message_id = $self->get_last_message_id();
|
||||
|
||||
if ($url) {
|
||||
$self->pg->db->query(<<~'END_SQL', $name, $message, $url, $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
|
||||
}
|
||||
|
||||
return;
|
||||
++$message_id;
|
||||
}
|
||||
|
||||
sub max_posts($self, $value = undef) {
|
||||
|
@ -134,4 +134,11 @@ sub get_post_by_id($self, $message_id) {
|
|||
END_SQL
|
||||
}
|
||||
|
||||
sub get_last_message_id($self) {
|
||||
$self->pg->db->query(<<~'END_SQL')->text()
|
||||
SELECT MAX(message_id)
|
||||
FROM messages;
|
||||
END_SQL
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in a new issue