Let's commit to the go version
This commit is contained in:
parent
6c3cb6066d
commit
29fc0c67c9
17
BINARIES.md
17
BINARIES.md
@ -1,17 +0,0 @@
|
||||
# Building "binaries"
|
||||
|
||||
For perl toolchain-free distribution.
|
||||
|
||||
Install PAR::Packer first, then:
|
||||
|
||||
## Mac
|
||||
|
||||
pp -M IO::Socket::SSL -o dau-mac dau
|
||||
|
||||
## Linux
|
||||
|
||||
pp -M IO::Socket::SSL -o dau-linux dau
|
||||
|
||||
## Windows
|
||||
|
||||
pp -M IO::Socket::SSL -o dau.exe dau
|
87
README.md
87
README.md
@ -1,6 +1,6 @@
|
||||
# Automatically upload screenshots from your computer into a discord channel
|
||||
|
||||
This script automaticall uploads new screenshots that appear in a folder on your computer to Discord and posts them in a channel:
|
||||
This program automaticall uploads new screenshots that appear in a folder on your computer to Discord and posts them in a channel:
|
||||
|
||||

|
||||
|
||||
@ -10,71 +10,17 @@ Point it at your Steam screenshot folder, or similar, and shortly after you hit
|
||||
|
||||
* A folder where screenshots are stored
|
||||
* A [discord webhook](https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
|
||||
* This script and perl, or one of the provided binaries
|
||||
* This program
|
||||
|
||||
## Getting started
|
||||
|
||||
### Linux
|
||||
### Binaries
|
||||
|
||||
#### Standalone binary
|
||||
|
||||
* Grab the latest binary from `https://github.com/tardisx/discord-auto-upload/releases/latest` called 'dau-linux.gz'.
|
||||
* `gunzip dau-linux.gz`
|
||||
* `mv dau-linux dau`
|
||||
* `chmod +x dau`
|
||||
* put `dau` somewhere on your path
|
||||
|
||||
#### From Source
|
||||
|
||||
* Download the script:
|
||||
|
||||
`curl -O https://raw.githubusercontent.com/tardisx/discord-auto-upload/master/dau`
|
||||
|
||||
* Put it somewhere on your path (if you want to be able to run it from anywhere)
|
||||
* chmod +x it
|
||||
* Install the dependencies:
|
||||
|
||||
CPAN: `cpan install Mojolicious IO::Socket::SSL`
|
||||
|
||||
CPANM: `cpanm Mojolicious IO::Socket::SSL`
|
||||
|
||||
Ubuntu/Debian: `sudo apt-get install libmojolicious-perl libio-socket-ssl-perl`
|
||||
|
||||
* test it:
|
||||
|
||||
`dau --help`
|
||||
|
||||
### Mac
|
||||
|
||||
#### Standalone binary
|
||||
|
||||
* Grab the latest binary from `https://github.com/tardisx/discord-auto-upload/releases/latest` called 'dau-mac.gz'.
|
||||
* `gunzip dau-mac.gz`
|
||||
* `mv dau-mac dau`
|
||||
* `chmod +x dau`
|
||||
* put `dau` somewhere on your path
|
||||
TBD
|
||||
|
||||
#### From source
|
||||
|
||||
Basically the same as Linux above. [Perlbrew](https://perlbrew.pl) is highly recommended so as not to disturb the system perl. No need for superuser access then either.
|
||||
|
||||
### Windows
|
||||
|
||||
* Grab the latest windows exe
|
||||
|
||||
`https://github.com/tardisx/discord-auto-upload/releases/latest`
|
||||
|
||||
* Optional, put it somewhere on your path
|
||||
* Open a command prompt
|
||||
* Test it
|
||||
|
||||
`\some\path\dau --help`
|
||||
|
||||
If you want to hack it, audit it, or don't trust my exe, you can install
|
||||
[Strawberry Perl](http://strawberryperl.com) and run it using that directly.
|
||||
You'll need the same dependencies mentioned above in the Linux setup.
|
||||
|
||||
If you want to build your own .exe, see BINARIES.md
|
||||
TBD
|
||||
|
||||
## Using it
|
||||
|
||||
@ -88,32 +34,23 @@ If `dau` is on your path, you can run it from your screenshot folder and there i
|
||||
|
||||
Note that currently `dau` does not look in subdirectories. Please submit an issue if this is a use case for you.
|
||||
|
||||
The only mandatory command line parameter is the discord webhook URL:
|
||||
The only two mandatory command line parameters are the discord webhook URL:
|
||||
|
||||
`--webhook URL` - the webhook URL (see [here](https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks) for details).
|
||||
|
||||
and the directory to watch:
|
||||
|
||||
`--directory /some/path/here` - the directory that screenshots will appear in.
|
||||
|
||||
You will have to quote the path on windows, or anywhere where the directory path contains spaces.
|
||||
|
||||
Other parameters are:
|
||||
|
||||
`--watch xx` - specify how many seconds to wait between scanning the directory. The default is 10 seconds.
|
||||
|
||||
`--directory <somedir>` - the directory to watch for images to appear in. If this option is not supplied, will look in the current directory.
|
||||
|
||||
You will have to quote the path on windows, or anywhere where the directory path contains spaces.
|
||||
|
||||
`--username` - supply a 'username' with the webhook submission. Slightly misleading, it basically provides some extra text next to the "Bot" display on the upload to the channel.
|
||||
|
||||
In the example screenshot at the top of this README, this was set to "tardisx uploaded from EDD".
|
||||
|
||||
`--debug` - provide extra debugging.
|
||||
|
||||
## Example
|
||||
|
||||

|
||||
|
||||
## Limitations/bugs
|
||||
|
||||
* Only files ending jpg, gif or png are uploaded.
|
||||
* Subdirectories are not scanned.
|
||||
* If multiple screenshots occur quickly (<1 second apart) not all may be uploaded.
|
||||
|
||||
## TODO
|
||||
|
129
dau
129
dau
@ -1,129 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use feature 'say';
|
||||
|
||||
use IO::Socket::SSL;
|
||||
use Mojo::UserAgent;
|
||||
use Getopt::Long qw/GetOptions/;
|
||||
use Data::Dumper qw/Dumper/;
|
||||
|
||||
my $webhook_url;
|
||||
my $directory = "./";
|
||||
my $username;
|
||||
my $watch = 10;
|
||||
my $help;
|
||||
my $debug;
|
||||
my $now = time();
|
||||
my $error_count = 0;
|
||||
my $error_max = 10;
|
||||
my $version = '0.1';
|
||||
|
||||
GetOptions(
|
||||
"webhook=s" => \$webhook_url,
|
||||
"directory=s" => \$directory,
|
||||
"username=s" => \$username,
|
||||
"watch=i" => \$watch,
|
||||
"help" => \$help,
|
||||
"debug" => \$debug,
|
||||
) || die usage();
|
||||
|
||||
usage() if $help;
|
||||
|
||||
if (! $webhook_url) {
|
||||
usage("--webhook must be supplied");
|
||||
}
|
||||
|
||||
sub usage {
|
||||
my $error = shift || "";
|
||||
my $indent = " " x length($0);
|
||||
say "dau $version - https://github.com/tardisx/discord-auto-upload\n";
|
||||
say "$0 --webhook <url> [--directory </some/path>]";
|
||||
say "$indent [--username <\"custom username\">] [--watch <n>]\n";
|
||||
say "The current directory will be used if no directory is specified.\n";
|
||||
say "error: $error" if $error;
|
||||
exit defined $error ? 1 : 0;
|
||||
}
|
||||
|
||||
chdir $directory || die "cannot chdir to $directory: $!\n";
|
||||
|
||||
watch_dir();
|
||||
|
||||
sub watch_dir {
|
||||
while (1) {
|
||||
my @files = glob("*");
|
||||
@files = grep { qualifies($_) } @files;
|
||||
foreach my $file (sort { mtime($a) <=> mtime($b) } @files) {
|
||||
debug("examining $file");
|
||||
if (mtime($file) > $now) {
|
||||
$now = mtime($file);
|
||||
upload($file);
|
||||
}
|
||||
}
|
||||
sleep $watch;
|
||||
}
|
||||
}
|
||||
|
||||
sub mtime {
|
||||
my $f = shift;
|
||||
return (stat($f))[9];
|
||||
}
|
||||
|
||||
sub qualifies {
|
||||
my $filename = shift;
|
||||
return 1 if ($filename =~ /\.jpg$|\.gif$|\.png$/i);
|
||||
return;
|
||||
}
|
||||
|
||||
sub info {
|
||||
say "- " . shift;
|
||||
}
|
||||
|
||||
sub debug {
|
||||
return unless $debug;
|
||||
say "! " . shift;
|
||||
}
|
||||
|
||||
sub error {
|
||||
say "* " . shift;
|
||||
}
|
||||
|
||||
sub upload {
|
||||
my $file = shift;
|
||||
info("uploading $file");
|
||||
|
||||
my $ua = Mojo::UserAgent->new;
|
||||
my $data = {
|
||||
upload => { file => $file },
|
||||
$username ? ( username => $username ) : ()
|
||||
};
|
||||
|
||||
my $tx = $ua->post($webhook_url, form => $data);
|
||||
|
||||
if (my $res = $tx->success) {
|
||||
debug(Dumper($res->json));
|
||||
my $url = $res->json->{attachments}->[0]->{url};
|
||||
my $size = $res->json->{attachments}->[0]->{size};
|
||||
my $width = $res->json->{attachments}->[0]->{width};
|
||||
my $height = $res->json->{attachments}->[0]->{height};
|
||||
info("uploaded ${width}x${height} $size byte image to $url");
|
||||
}
|
||||
else {
|
||||
debug(Dumper($tx));
|
||||
|
||||
my $err = $tx->error;
|
||||
if ($err->{code}) {
|
||||
error("$err->{code} response: $err->{message}");
|
||||
}
|
||||
else {
|
||||
error("Connection error: $err->{message}");
|
||||
}
|
||||
$error_count++;
|
||||
if ($error_count >= $error_max) {
|
||||
error("Sorry - too many errors - quitting");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user