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])
|
reply, _ = commands.Currency(cmdParams[1], cmdParams[2], cmdParams[4])
|
||||||
}
|
}
|
||||||
|
|
||||||
case "cb":
|
case "catbox":
|
||||||
go commands.NewDownload("catbox", target, cmdParams[1], app.TwitchClient, app.Log)
|
go commands.NewDownload("catbox", target, cmdParams[1], app.TwitchClient, app.Log)
|
||||||
|
|
||||||
case "dl":
|
case "kappa":
|
||||||
go commands.NewDownload("custom", target, cmdParams[1], app.TwitchClient, app.Log)
|
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":
|
case "mail":
|
||||||
app.SendEmail("Test command used!", "This is an email test")
|
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 {
|
switch destination {
|
||||||
case "catbox":
|
case "catbox":
|
||||||
dl.CatboxDownload(target, link)
|
dl.CatboxDownload(target, link)
|
||||||
case "custom":
|
case "yaf":
|
||||||
dl.CustomDownload(target, link)
|
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"
|
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{})
|
result, err := goutubedl.New(context.Background(), link, goutubedl.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dl.Log.Errorln(err)
|
dl.Log.Errorln(err)
|
||||||
|
@ -67,7 +71,87 @@ func (dl *Downloader) CustomDownload(target, link string) {
|
||||||
// dl.twitchClient.Say(target, "ResidentSleeper ..")
|
// dl.twitchClient.Say(target, "ResidentSleeper ..")
|
||||||
// time.Sleep(duration)
|
// 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
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -23,8 +24,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CUSTOM_ENDPOINT = "https://i.yaf.ee/upload"
|
|
||||||
CATBOX_ENDPOINT = "https://litterbox.catbox.moe/resources/internals/api.php"
|
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 {
|
type Uploader struct {
|
||||||
|
@ -50,8 +53,12 @@ func NewUpload(destination, fileName, target string, twitchClient *twitch.Client
|
||||||
switch destination {
|
switch destination {
|
||||||
case "catbox":
|
case "catbox":
|
||||||
go ul.CatboxUpload(target, fileName)
|
go ul.CatboxUpload(target, fileName)
|
||||||
case "custom":
|
case "yaf":
|
||||||
go ul.CustomUpload(target, fileName)
|
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
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
ul.TwitchClient.Say(target, "Uploading to catbox.moe... dankCircle")
|
||||||
|
|
||||||
// if size := helper.FileSize(fileName); size > 209715200 {
|
// if size := helper.FileSize(fileName); size > 209715200 {
|
||||||
// return "", fmt.Errorf("file too large, size: %d MB", size/1024/1024)
|
// 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)
|
ul.TwitchClient.Say(target, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ul *Uploader) CustomUpload(target, path string) {
|
func (ul *Uploader) GofileUpload(target, path string) {
|
||||||
defer os.Remove(path)
|
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()
|
pr, pw := io.Pipe()
|
||||||
form := multipart.NewWriter(pw)
|
form := multipart.NewWriter(pw)
|
||||||
|
|
||||||
|
@ -150,7 +334,7 @@ func (ul *Uploader) CustomUpload(target, path string) {
|
||||||
form.Close()
|
form.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, CUSTOM_ENDPOINT, pr)
|
req, err := http.NewRequest(http.MethodPost, YAF_ENDPOINT, pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
ul.TwitchClient.Say(target, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err))
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
|
|
Loading…
Reference in a new issue