mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add kappa and gofile uploaders
This commit is contained in:
parent
8532494aab
commit
9030a3efc3
|
@ -83,11 +83,17 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
reply, _ = commands.Currency(cmdParams[1], cmdParams[2], cmdParams[4])
|
||||
}
|
||||
|
||||
case "cb":
|
||||
case "catbox":
|
||||
go commands.NewDownload("catbox", target, cmdParams[1], app.TwitchClient, app.Log)
|
||||
|
||||
case "dl":
|
||||
go commands.NewDownload("custom", target, cmdParams[1], app.TwitchClient, app.Log)
|
||||
case "kappa":
|
||||
go commands.NewDownload("kappa", target, cmdParams[1], app.TwitchClient, app.Log)
|
||||
|
||||
case "yaf":
|
||||
go commands.NewDownload("yaf", target, cmdParams[1], app.TwitchClient, app.Log)
|
||||
|
||||
case "gofile":
|
||||
go commands.NewDownload("gofile", target, cmdParams[1], app.TwitchClient, app.Log)
|
||||
|
||||
case "mail":
|
||||
app.SendEmail("Test command used!", "This is an email test")
|
||||
|
|
|
@ -26,15 +26,19 @@ func NewDownload(destination, target, link string, tc *twitch.Client, log *zap.S
|
|||
switch destination {
|
||||
case "catbox":
|
||||
dl.CatboxDownload(target, link)
|
||||
case "custom":
|
||||
dl.CustomDownload(target, link)
|
||||
case "yaf":
|
||||
dl.YafDownload(target, link)
|
||||
case "kappa":
|
||||
dl.KappaDownload(target, link)
|
||||
case "gofile":
|
||||
dl.GofileDownload(target, link)
|
||||
}
|
||||
}
|
||||
|
||||
func (dl *Downloader) CustomDownload(target, link string) {
|
||||
func (dl *Downloader) YafDownload(target, link string) {
|
||||
goutubedl.Path = "yt-dlp"
|
||||
|
||||
dl.TwitchClient.Say(target, "[custom] Downloading... dankCircle")
|
||||
dl.TwitchClient.Say(target, "Downloading... dankCircle")
|
||||
result, err := goutubedl.New(context.Background(), link, goutubedl.Options{})
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
|
@ -67,7 +71,87 @@ func (dl *Downloader) CustomDownload(target, link string) {
|
|||
// dl.twitchClient.Say(target, "ResidentSleeper ..")
|
||||
// time.Sleep(duration)
|
||||
|
||||
go NewUpload("custom", fileName, target, dl.TwitchClient, dl.Log)
|
||||
go NewUpload("yaf", fileName, target, dl.TwitchClient, dl.Log)
|
||||
|
||||
}
|
||||
|
||||
func (dl *Downloader) KappaDownload(target, link string) {
|
||||
goutubedl.Path = "yt-dlp"
|
||||
|
||||
dl.TwitchClient.Say(target, "Downloading... dankCircle")
|
||||
result, err := goutubedl.New(context.Background(), link, goutubedl.Options{})
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
rExt := result.Info.Ext
|
||||
downloadResult, err := result.Download(context.Background(), "best")
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
dl.TwitchClient.Say(target, "Downloaded.")
|
||||
uuidFilename, err := uuid.NewUUID()
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
fileName := fmt.Sprintf("%s.%s", uuidFilename, rExt)
|
||||
f, err := os.Create(fileName)
|
||||
dl.TwitchClient.Say(target, fmt.Sprintf("Filename: %s", fileName))
|
||||
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err = io.Copy(f, downloadResult); err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
|
||||
downloadResult.Close()
|
||||
f.Close()
|
||||
// duration := 5 * time.Second
|
||||
// dl.twitchClient.Say(target, "ResidentSleeper ..")
|
||||
// time.Sleep(duration)
|
||||
|
||||
go NewUpload("kappa", fileName, target, dl.TwitchClient, dl.Log)
|
||||
|
||||
}
|
||||
|
||||
func (dl *Downloader) GofileDownload(target, link string) {
|
||||
goutubedl.Path = "yt-dlp"
|
||||
|
||||
dl.TwitchClient.Say(target, "Downloading... dankCircle")
|
||||
result, err := goutubedl.New(context.Background(), link, goutubedl.Options{})
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
rExt := result.Info.Ext
|
||||
downloadResult, err := result.Download(context.Background(), "best")
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
dl.TwitchClient.Say(target, "Downloaded.")
|
||||
uuidFilename, err := uuid.NewUUID()
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
fileName := fmt.Sprintf("%s.%s", uuidFilename, rExt)
|
||||
f, err := os.Create(fileName)
|
||||
dl.TwitchClient.Say(target, fmt.Sprintf("Filename: %s", fileName))
|
||||
|
||||
if err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err = io.Copy(f, downloadResult); err != nil {
|
||||
dl.Log.Errorln(err)
|
||||
}
|
||||
|
||||
downloadResult.Close()
|
||||
f.Close()
|
||||
// duration := 5 * time.Second
|
||||
// dl.twitchClient.Say(target, "ResidentSleeper ..")
|
||||
// time.Sleep(duration)
|
||||
|
||||
go NewUpload("gofile", fileName, target, dl.TwitchClient, dl.Log)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -23,8 +24,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
CUSTOM_ENDPOINT = "https://i.yaf.ee/upload"
|
||||
CATBOX_ENDPOINT = "https://litterbox.catbox.moe/resources/internals/api.php"
|
||||
GOFILE_ENDPOINT = "https://store1.gofile.io/uploadFile"
|
||||
KAPPA_ENDPOINT = "https://kappa.lol/api/upload"
|
||||
YAF_ENDPOINT = "https://i.yaf.ee/upload"
|
||||
)
|
||||
|
||||
type Uploader struct {
|
||||
|
@ -50,8 +53,12 @@ func NewUpload(destination, fileName, target string, twitchClient *twitch.Client
|
|||
switch destination {
|
||||
case "catbox":
|
||||
go ul.CatboxUpload(target, fileName)
|
||||
case "custom":
|
||||
go ul.CustomUpload(target, fileName)
|
||||
case "yaf":
|
||||
go ul.YafUpload(target, fileName)
|
||||
case "kappa":
|
||||
go ul.KappaUpload(target, fileName)
|
||||
case "gofile":
|
||||
go ul.GofileUpload(target, fileName)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +71,7 @@ func (ul *Uploader) CatboxUpload(target, fileName string) {
|
|||
return
|
||||
}
|
||||
defer file.Close()
|
||||
ul.TwitchClient.Say(target, "Uploading to catbox.moe... dankCircle")
|
||||
|
||||
// if size := helper.FileSize(fileName); size > 209715200 {
|
||||
// return "", fmt.Errorf("file too large, size: %d MB", size/1024/1024)
|
||||
|
@ -110,9 +118,185 @@ func (ul *Uploader) CatboxUpload(target, fileName string) {
|
|||
ul.TwitchClient.Say(target, reply)
|
||||
}
|
||||
|
||||
func (ul *Uploader) CustomUpload(target, path string) {
|
||||
func (ul *Uploader) GofileUpload(target, path string) {
|
||||
defer os.Remove(path)
|
||||
ul.TwitchClient.Say(target, "Uploading... dankCircle")
|
||||
ul.TwitchClient.Say(target, "Uploading to gofile.io... dankCircle")
|
||||
pr, pw := io.Pipe()
|
||||
form := multipart.NewWriter(pw)
|
||||
|
||||
type gofileData struct {
|
||||
DownloadPage string `json:"downloadPage"`
|
||||
Code string `json:"code"`
|
||||
ParentFolder string `json:"parentFolder"`
|
||||
FileId string `json:"fileId"`
|
||||
FileName string `json:"fileName"`
|
||||
Md5 string `json:"md5"`
|
||||
}
|
||||
|
||||
type gofileResponse struct {
|
||||
Status string `json:"status"`
|
||||
Data gofileData
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer pw.Close()
|
||||
|
||||
file, err := os.Open(path) // path to image file
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
w, err := form.CreateFormFile("file", path)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(w, file)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
form.Close()
|
||||
}()
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, GOFILE_ENDPOINT, pr)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
req.Header.Set("Content-Type", form.FormDataContentType())
|
||||
|
||||
httpClient := http.Client{
|
||||
Timeout: 300 * time.Second,
|
||||
}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
ul.Log.Errorln("Error while sending HTTP request:", err)
|
||||
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
ul.TwitchClient.Say(target, "Uploaded PogChamp")
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
ul.Log.Errorln("Error while reading response:", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse := new(gofileResponse)
|
||||
if err := json.Unmarshal(body, jsonResponse); err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
ul.Log.Errorln("Error while unmarshalling JSON response:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var reply = jsonResponse.Data.DownloadPage
|
||||
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Removing file: %s", path))
|
||||
ul.TwitchClient.Say(target, reply)
|
||||
}
|
||||
|
||||
func (ul *Uploader) KappaUpload(target, path string) {
|
||||
defer os.Remove(path)
|
||||
ul.TwitchClient.Say(target, "Uploading to kappa.lol... dankCircle")
|
||||
pr, pw := io.Pipe()
|
||||
form := multipart.NewWriter(pw)
|
||||
|
||||
type kappaResponse struct {
|
||||
Link string `json:"link"`
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer pw.Close()
|
||||
|
||||
err := form.WriteField("name", "xd")
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Open(path) // path to image file
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
w, err := form.CreateFormFile("file", path)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(w, file)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
form.Close()
|
||||
}()
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, KAPPA_ENDPOINT, pr)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
req.Header.Set("Content-Type", form.FormDataContentType())
|
||||
|
||||
httpClient := http.Client{
|
||||
Timeout: 300 * time.Second,
|
||||
}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
ul.Log.Errorln("Error while sending HTTP request:", err)
|
||||
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
ul.TwitchClient.Say(target, "Uploaded PogChamp")
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
ul.Log.Errorln("Error while reading response:", err)
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse := new(kappaResponse)
|
||||
if err := json.Unmarshal(body, jsonResponse); err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
ul.Log.Errorln("Error while unmarshalling JSON response:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var reply = jsonResponse.Link
|
||||
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Removing file: %s", path))
|
||||
ul.TwitchClient.Say(target, reply)
|
||||
}
|
||||
func (ul *Uploader) YafUpload(target, path string) {
|
||||
defer os.Remove(path)
|
||||
ul.TwitchClient.Say(target, "Uploading to yaf.ee... dankCircle")
|
||||
pr, pw := io.Pipe()
|
||||
form := multipart.NewWriter(pw)
|
||||
|
||||
|
@ -150,7 +334,7 @@ func (ul *Uploader) CustomUpload(target, path string) {
|
|||
form.Close()
|
||||
}()
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, CUSTOM_ENDPOINT, pr)
|
||||
req, err := http.NewRequest(http.MethodPost, YAF_ENDPOINT, pr)
|
||||
if err != nil {
|
||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||
os.Remove(path)
|
||||
|
|
Loading…
Reference in a new issue