Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72588642b6 | ||
|
|
7ff4685a70 | ||
|
|
f6b92ee8bd | ||
|
|
68d9ab7859 | ||
|
|
d2d7843b6f |
24
.gitignore
vendored
24
.gitignore
vendored
@@ -1,20 +1,4 @@
|
|||||||
/blib/
|
dist
|
||||||
/.build/
|
release
|
||||||
_build/
|
discord-auto-upload
|
||||||
cover_db/
|
discord-auto-upload.exe
|
||||||
inc/
|
|
||||||
Build
|
|
||||||
!Build/
|
|
||||||
Build.bat
|
|
||||||
.last_cover_stats
|
|
||||||
/Makefile
|
|
||||||
/Makefile.old
|
|
||||||
/MANIFEST.bak
|
|
||||||
/META.yml
|
|
||||||
/META.json
|
|
||||||
/MYMETA.*
|
|
||||||
nytprof.out
|
|
||||||
/pm_to_blib
|
|
||||||
*.o
|
|
||||||
*.bs
|
|
||||||
/_eumm/
|
|
||||||
|
|||||||
52
build-release.pl
Executable file
52
build-release.pl
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
open my $fh, "<", "dau.go" || die $!;
|
||||||
|
|
||||||
|
my $version;
|
||||||
|
while (<$fh>) {
|
||||||
|
$version = $1 if /^const\s+current_version.*?"([\d\.]+)"/;
|
||||||
|
}
|
||||||
|
close $fh;
|
||||||
|
|
||||||
|
die "no version?" unless defined $version;
|
||||||
|
|
||||||
|
# so lazy
|
||||||
|
system "rm", "-rf", "release", "dist";
|
||||||
|
system "mkdir", "release";
|
||||||
|
system "mkdir", "dist";
|
||||||
|
|
||||||
|
my %build = (
|
||||||
|
win => { env => { GOOS => 'windows', GOARCH => '386' }, filename => 'dau.exe' },
|
||||||
|
linux => { env => { GOOS => 'linux', GOARCH => '386' }, filename => 'dau' },
|
||||||
|
mac => { env => { GOOS => 'darwin', GOARCH => '386' }, filename => 'dau' },
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach my $type (keys %build) {
|
||||||
|
mkdir "release/$type";
|
||||||
|
}
|
||||||
|
|
||||||
|
add_extras();
|
||||||
|
|
||||||
|
foreach my $type (keys %build) {
|
||||||
|
local $ENV{GOOS} = $build{$type}->{env}->{GOOS};
|
||||||
|
local $ENV{GOARCH} = $build{$type}->{env}->{GOARCH};
|
||||||
|
system "go", "build", "-o", "release/$type/" . $build{$type}->{filename};
|
||||||
|
system "zip", "-j", "dist/dau-$type-$version.zip", ( glob "release/$type/*" );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub add_extras {
|
||||||
|
# bat file for windows
|
||||||
|
|
||||||
|
open (my $fh, ">", "release/win/dau.bat") || die $!;
|
||||||
|
print $fh 'set WEBHOOK_URL=https://yourdiscordwebhookURLhere' . "\r\n";
|
||||||
|
print $fh 'set SCREENSHOTS="C:\your\screenshot\directory\here"' ."\r\n";
|
||||||
|
print $fh 'set USERNAME="Posted by Joe Bloggs"' . "\r\n";
|
||||||
|
print $fh 'set WATCH=10' . "\r\n";
|
||||||
|
|
||||||
|
print $fh 'dau.exe --webhook %WEBHOOK_URL% --directory %SCREENSHOTS% --username %USERNAME% --watch %WATCH%' . "\r\n";
|
||||||
|
print $fh 'pause' . "\r\n";
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
47
dau.go
47
dau.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var current_version = "0.3"
|
const current_version = "0.4"
|
||||||
|
|
||||||
var last_check = time.Now()
|
var last_check = time.Now()
|
||||||
var new_last_check = time.Now()
|
var new_last_check = time.Now()
|
||||||
@@ -24,20 +24,12 @@ var new_last_check = time.Now()
|
|||||||
var webhook_url string
|
var webhook_url string
|
||||||
var username string
|
var username string
|
||||||
|
|
||||||
type webhook_response struct {
|
|
||||||
Test string
|
|
||||||
}
|
|
||||||
|
|
||||||
func keepLines(s string, n int) string {
|
|
||||||
result := strings.Join(strings.Split(s, "\n")[:n], "\n")
|
|
||||||
return strings.Replace(result, "\r", "", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
webhook_opt, path, watch, username_opt := parse_options()
|
webhook_opt, path, watch, username_opt := parse_options()
|
||||||
webhook_url = webhook_opt
|
webhook_url = webhook_opt
|
||||||
username = username_opt
|
username = username_opt
|
||||||
|
|
||||||
|
check_path(path)
|
||||||
check_updates()
|
check_updates()
|
||||||
|
|
||||||
log.Print("Waiting for images to appear in ", path)
|
log.Print("Waiting for images to appear in ", path)
|
||||||
@@ -45,13 +37,23 @@ func main() {
|
|||||||
// wander the path, forever
|
// wander the path, forever
|
||||||
for {
|
for {
|
||||||
err := filepath.Walk(path, check_file)
|
err := filepath.Walk(path, check_file)
|
||||||
if err != nil { log.Fatal("oh dear") }
|
if err != nil { log.Fatal("could not watch path", err) }
|
||||||
//fmt.Printf("filepath.Walk() returned %v\n", err)
|
|
||||||
last_check = new_last_check
|
last_check = new_last_check
|
||||||
time.Sleep(time.Duration(watch)*time.Second)
|
time.Sleep(time.Duration(watch)*time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func check_path(path string) {
|
||||||
|
src, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if !src.IsDir() {
|
||||||
|
log.Fatal(path, " is not a directory")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func check_updates() {
|
func check_updates() {
|
||||||
|
|
||||||
type GithubRelease struct {
|
type GithubRelease struct {
|
||||||
@@ -80,20 +82,17 @@ func check_updates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (current_version < latest.Tag_name) {
|
if (current_version < latest.Tag_name) {
|
||||||
fmt.Println("A new version is available:", latest.Tag_name)
|
fmt.Printf("You are currently on version %s, but version %s is available\n", current_version, latest.Tag_name)
|
||||||
fmt.Println("----------- Release Info -----------")
|
fmt.Println("----------- Release Info -----------")
|
||||||
fmt.Println(latest.Body)
|
fmt.Println(latest.Body)
|
||||||
fmt.Println("------------------------------------")
|
fmt.Println("------------------------------------")
|
||||||
fmt.Println("( You are currently on version:", current_version, ")")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func parse_options() (webhook_url string, path string, watch int, username string) {
|
func parse_options() (webhook_url string, path string, watch int, username string) {
|
||||||
|
|
||||||
// Declare the flags to be used
|
// Declare the flags to be used
|
||||||
// helpFlag := getopt.Bool('h', "display help")
|
|
||||||
webhookFlag := getopt.StringLong("webhook", 'w', "", "discord webhook URL")
|
webhookFlag := getopt.StringLong("webhook", 'w', "", "discord webhook URL")
|
||||||
pathFlag := getopt.StringLong("directory", 'd', "", "directory to scan, optional, defaults to current directory")
|
pathFlag := getopt.StringLong("directory", 'd', "", "directory to scan, optional, defaults to current directory")
|
||||||
watchFlag := getopt.Int16Long ("watch", 's', 10, "time between scans")
|
watchFlag := getopt.Int16Long ("watch", 's', 10, "time between scans")
|
||||||
@@ -110,6 +109,7 @@ func parse_options() (webhook_url string, path string, watch int, username strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*versionFlag) {
|
if (*versionFlag) {
|
||||||
|
fmt.Println("dau - https://github.com/tardisx/discord-auto-upload")
|
||||||
fmt.Printf("Version: %s\n", current_version)
|
fmt.Printf("Version: %s\n", current_version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
@@ -154,9 +154,7 @@ func file_eligible(file string) (bool) {
|
|||||||
func process_file(file string) {
|
func process_file(file string) {
|
||||||
log.Print("Uploading ", file)
|
log.Print("Uploading ", file)
|
||||||
|
|
||||||
extraParams := map[string]string{
|
extraParams := map[string]string{ }
|
||||||
// "username": "Some username",
|
|
||||||
}
|
|
||||||
|
|
||||||
if (username != "") {
|
if (username != "") {
|
||||||
extraParams["username"] = username
|
extraParams["username"] = username
|
||||||
@@ -173,13 +171,14 @@ func process_file(file string) {
|
|||||||
|
|
||||||
type DiscordAPIResponse struct {
|
type DiscordAPIResponse struct {
|
||||||
Attachments []DiscordAPIResponseAttachment
|
Attachments []DiscordAPIResponseAttachment
|
||||||
id int64
|
Id int64 `json:",string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
request, err := newfileUploadRequest(webhook_url, extraParams, "file", file)
|
request, err := newfileUploadRequest(webhook_url, extraParams, "file", file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
start := time.Now()
|
||||||
client := &http.Client{ Timeout: time.Second * 30 }
|
client := &http.Client{ Timeout: time.Second * 30 }
|
||||||
resp, err := client.Do(request)
|
resp, err := client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -204,7 +203,7 @@ func process_file(file string) {
|
|||||||
|
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Print("could not parse JSON: ", err)
|
log.Print("could not parse JSON: ", err)
|
||||||
fmt.Println("Response was:", res_body)
|
fmt.Println("Response was:", string(res_body[:]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (len(res.Attachments) < 1) {
|
if (len(res.Attachments) < 1) {
|
||||||
@@ -212,7 +211,11 @@ func process_file(file string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var a = res.Attachments[0]
|
var a = res.Attachments[0]
|
||||||
log.Printf("Uploaded to %s %dx%d, %d bytes\n", a.Url, a.Width, a.Height, a.Size)
|
elapsed := time.Since(start)
|
||||||
|
rate := float64(a.Size) / elapsed.Seconds() / 1024.0
|
||||||
|
|
||||||
|
log.Printf("Uploaded to %s %dx%d", a.Url, a.Width, a.Height)
|
||||||
|
log.Printf("id: %d, %d bytes transferred in %.2f seconds (%.2f KiB/s)", res.Id, a.Size, elapsed.Seconds(), rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user