mirror of
https://onedev.fprog.nl/goscreenshot
synced 2026-02-15 07:33:42 +01:00
Now using pipe instead of file.
This commit is contained in:
parent
b04d2625f8
commit
9034af447f
38
main.go
38
main.go
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -46,37 +47,18 @@ func SendScreenshots(discord *discordgo.Session, channelId string, sleepDuration
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.Create(screenshot_path)
|
imageReader, imageWriter := io.Pipe()
|
||||||
|
go func() {
|
||||||
|
err = png.Encode(imageWriter, new_image)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = png.Encode(file, new_image)
|
imageWriter.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
if err != nil {
|
_, err = discord.ChannelFileSend(channelId, screenshot_path, imageReader)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = file.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err = os.Open(screenshot_path)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = discord.ChannelFileSend(channelId, screenshot_path, file)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = file.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue