From d55d0bd73ee3e8161caaff0407cdeaf1a5e66489 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:39:47 +0100 Subject: [PATCH] remove predb --- cmd/nourybot/commands.go | 30 ------ cmd/nourybot/predb.go | 200 --------------------------------------- 2 files changed, 230 deletions(-) delete mode 100644 cmd/nourybot/predb.go diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index 353066e..4a78fc1 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -184,22 +184,6 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { case "nourybot": reply = "Lidl Twitch bot made by @nouryxd. Prefix: ()" - case "predb": - switch cmdParams[1] { - case "latest": - if userLevel >= 100 { - reply = app.PreDBLatest() - } - case "search": - if userLevel >= 100 && len(message.Message) > 16 { - reply = app.PreDBSearch(message.Message[15:len(message.Message)]) - } - case "group": - if userLevel >= 100 && len(message.Message) > 15 { - reply = app.PreDBGroup(message.Message[14:len(message.Message)]) - } - } - case "phonetic": if msgLen == 1 { reply = "Not enough arguments provided. Usage: ()phonetic " @@ -612,20 +596,6 @@ var helpText = map[string]command{ Level: "0", Usage: "()ping", }, - "predb search": { - Name: "predb search", - Alias: nil, - Description: "Returns the last 100 predb.net search results for a given query.", - Level: "100", - Usage: "()predb search ", - }, - "predb group": { - Name: "predb group", - Alias: nil, - Description: "Returns the last 100 predb.net group results for a given release group.", - Level: "100", - Usage: "()predb group ", - }, "preview": { Name: "preview", Alias: []string{"preview", "thumbnail"}, diff --git a/cmd/nourybot/predb.go b/cmd/nourybot/predb.go deleted file mode 100644 index 7b9f82f..0000000 --- a/cmd/nourybot/predb.go +++ /dev/null @@ -1,200 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "strings" -) - -type latestFullResult struct { - Status string `json:"status"` - Results int `json:"results"` - Data []latestSingleResult `json:"data"` -} - -type latestSingleResult struct { - ID string `json:"id"` - PreTime string `json:"pretime"` - Release string `json:"release"` - Section string `json:"section"` - Files string `json:"files"` - Size float64 `json:"size"` - Status string `json:"status"` - Reason string `json:"reason"` - Group string `json:"group"` - Genre string `json:"genre"` - URL string `json:"url"` - NFO string `json:"nfo"` - NFOImage string `json:"nfo_image"` -} - -func (app *application) PreDBLatest() string { - baseUrl := "https://api.predb.net/?limit=100" - - resp, err := http.Get(baseUrl) - if err != nil { - app.Log.Error(err) - return "Something went wrong FeelsBadMan" - } - - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - if err != nil { - app.Log.Error(err) - return "Something went wrong FeelsBadMan" - } - - var release latestFullResult - _ = json.Unmarshal([]byte(body), &release) - - var ts []string - for i := 0; i < release.Results; i++ { - t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n", - release.Data[i].ID, - release.Data[i].PreTime, - release.Data[i].Release, - release.Data[i].Section, - release.Data[i].Files, - release.Data[i].Size, - release.Data[i].Status, - release.Data[i].Reason, - release.Data[i].Group, - release.Data[i].Genre, - fmt.Sprint("https://predb.net"+release.Data[i].URL), - release.Data[i].NFO, - release.Data[i].NFOImage, - ) - ts = append(ts, t) - - } - - reply := app.YafUploadString(strings.Join(ts, "")) - if err != nil { - app.Log.Errorw("Error trying to retrieve all timers from database", err) - return "" - } - return reply -} - -type searchFullResult struct { - Status string `json:"status"` - Results int `json:"results"` - Data []searchSingleResult `json:"data"` -} -type searchSingleResult struct { - ID int `json:"id"` - PreTime int `json:"pretime"` - Release string `json:"release"` - Section string `json:"section"` - Files int `json:"files"` - Size float64 `json:"size"` - Status int `json:"status"` - Reason string `json:"reason"` - Group string `json:"group"` - Genre string `json:"genre"` - URL string `json:"url"` - NFO string `json:"nfo"` - NFOImage string `json:"nfo_image"` -} - -func (app *application) PreDBSearch(title string) string { - escaped := fmt.Sprintf("https://api.predb.net/?q=%s&order_by=pretime&sort=desc&limit=100", url.QueryEscape(title)) - - resp, err := http.Get(escaped) - if err != nil { - app.Log.Error(err) - return "Something went wrong FeelsBadMan" - } - - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - if err != nil { - app.Log.Error(err) - return "Something went wrong FeelsBadMan" - } - - var release searchFullResult - _ = json.Unmarshal([]byte(body), &release) - - var ts []string - for i := 0; i < release.Results; i++ { - t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n", - release.Data[i].ID, - release.Data[i].PreTime, - release.Data[i].Release, - release.Data[i].Section, - release.Data[i].Files, - release.Data[i].Size, - release.Data[i].Status, - release.Data[i].Reason, - release.Data[i].Group, - release.Data[i].Genre, - fmt.Sprint("https://predb.net"+release.Data[i].URL), - release.Data[i].NFO, - release.Data[i].NFOImage, - ) - ts = append(ts, t) - - } - - reply := app.YafUploadString(strings.Join(ts, "")) - if err != nil { - app.Log.Errorw("Error trying to retrieve all timers from database", err) - return "" - } - return reply -} - -func (app *application) PreDBGroup(group string) string { - escaped := fmt.Sprintf("https://api.predb.net/?group=%s&order_by=pretime&sort=desc&limit=100", url.QueryEscape(group)) - - resp, err := http.Get(escaped) - if err != nil { - app.Log.Error(err) - return "Something went wrong FeelsBadMan" - } - - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - if err != nil { - app.Log.Error(err) - return "Something went wrong FeelsBadMan" - } - - var release searchFullResult - _ = json.Unmarshal([]byte(body), &release) - - var ts []string - for i := 0; i < release.Results; i++ { - t := fmt.Sprintf("ID: %v\nRelease timestamp: %v\nRelease: %v\nSection: %v\nFiles: %v\nSize: %v\nStatus: %v\nReason: %v\nRelease group: %v\nRelease genre: %v\npredb.net: %v\nNFO URL: %v\nNFO Image URL: %v\n\n", - release.Data[i].ID, - release.Data[i].PreTime, - release.Data[i].Release, - release.Data[i].Section, - release.Data[i].Files, - release.Data[i].Size, - release.Data[i].Status, - release.Data[i].Reason, - release.Data[i].Group, - release.Data[i].Genre, - fmt.Sprint("https://predb.net"+release.Data[i].URL), - release.Data[i].NFO, - release.Data[i].NFOImage, - ) - ts = append(ts, t) - - } - - reply := app.YafUploadString(strings.Join(ts, "")) - if err != nil { - app.Log.Errorw("Error trying to retrieve all timers from database", err) - return "Something went wrong FeelsBadMan" - } - return reply -}