mirror of
https://onedev.fprog.nl/goscreenshot
synced 2026-02-14 19:03:43 +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 (
|
||||
"encoding/json"
|
||||
"image/png"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
|
@ -46,37 +47,18 @@ func SendScreenshots(discord *discordgo.Session, channelId string, sleepDuration
|
|||
panic(err)
|
||||
}
|
||||
|
||||
file, err := os.Create(screenshot_path)
|
||||
imageReader, imageWriter := io.Pipe()
|
||||
go func() {
|
||||
err = png.Encode(imageWriter, new_image)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = png.Encode(file, new_image)
|
||||
imageWriter.Close()
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
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()
|
||||
_, err = discord.ChannelFileSend(channelId, screenshot_path, imageReader)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue