You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
217 lines
4.6 KiB
217 lines
4.6 KiB
/*
|
|
* Copyright (C) 2022 jimj316
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package moe.nekojimi.chords;
|
|
|
|
import com.amihaiemil.eoyaml.YamlMapping;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import moe.nekojimi.chords.commands.Invocation;
|
|
import moe.nekojimi.musicsearcher.Result;
|
|
|
|
/**
|
|
*
|
|
* @author jimj316
|
|
*/
|
|
public class TrackRequest implements Comparable<TrackRequest>
|
|
{
|
|
private Invocation invocation;
|
|
|
|
private String query;
|
|
private URL url;
|
|
|
|
private List<Result> searchResults;
|
|
|
|
private Result result;
|
|
|
|
private final List<Track> tracks = new ArrayList<>();
|
|
|
|
private String requestedBy;
|
|
private String requestedIn;
|
|
|
|
private double priority = 1.0;
|
|
|
|
public YamlMapping toYAML()
|
|
{
|
|
throw new UnsupportedOperationException("Not supported yet.");
|
|
}
|
|
|
|
public static TrackRequest fromYAML(YamlMapping yaml)
|
|
{
|
|
TrackRequest ret = new TrackRequest();
|
|
|
|
return ret;
|
|
}
|
|
|
|
public List<Result> getSearchResults()
|
|
{
|
|
return searchResults;
|
|
}
|
|
|
|
public void setSearchResults(List<Result> searchResults)
|
|
{
|
|
this.searchResults = searchResults;
|
|
}
|
|
|
|
public Result getResult()
|
|
{
|
|
return result;
|
|
}
|
|
|
|
public void setResult(Result result)
|
|
{
|
|
this.result = result;
|
|
}
|
|
|
|
public Invocation getInvocation()
|
|
{
|
|
return invocation;
|
|
}
|
|
|
|
public void setInvocation(Invocation invocation)
|
|
{
|
|
this.invocation = invocation;
|
|
requestedBy = invocation.getRequestMessage().getAuthor().getName();
|
|
requestedIn = invocation.getRequestMessage().getChannel().getId();
|
|
}
|
|
|
|
// public Message getRequestMessage()
|
|
// {
|
|
// return requestMessage;
|
|
// }
|
|
//
|
|
// public void setRequestMessage(Message requestMessage)
|
|
// {
|
|
// this.requestMessage = requestMessage;
|
|
// }
|
|
//
|
|
// public Message getResponseMessage()
|
|
// {
|
|
// return responseMessage;
|
|
// }
|
|
//
|
|
// public void setResponseMessage(Message responseMessage)
|
|
// {
|
|
// this.responseMessage = responseMessage;
|
|
// }
|
|
|
|
public String getQuery()
|
|
{
|
|
return query;
|
|
}
|
|
|
|
public void setQuery(String query)
|
|
{
|
|
this.query = query;
|
|
}
|
|
|
|
public URL getUrl()
|
|
{
|
|
return url;
|
|
}
|
|
|
|
public void setUrl(URL url)
|
|
{
|
|
this.url = url;
|
|
}
|
|
|
|
public List<Track> getTracks()
|
|
{
|
|
return tracks;
|
|
}
|
|
|
|
public void addTrack(Track track)
|
|
{
|
|
tracks.add(track);
|
|
}
|
|
|
|
public void clearTracks()
|
|
{
|
|
tracks.clear();
|
|
}
|
|
|
|
public String getRequestedBy()
|
|
{
|
|
return requestedBy;
|
|
}
|
|
|
|
public String getRequestedIn()
|
|
{
|
|
return requestedIn;
|
|
}
|
|
|
|
public String toString()
|
|
{
|
|
String trackName;
|
|
if (tracks.isEmpty())
|
|
trackName = "Request";
|
|
else
|
|
{
|
|
trackName = tracks.get(1).toString();
|
|
if (tracks.size() > 1)
|
|
trackName += " & " + (tracks.size() - 1) + " more tracks";
|
|
}
|
|
|
|
String requestName = "";
|
|
if (!requestedBy.isEmpty())
|
|
requestName = "for " + requestedBy;
|
|
|
|
return (trackName + " " + requestName).trim();
|
|
}
|
|
|
|
@Override
|
|
public int hashCode()
|
|
{
|
|
int hash = 7;
|
|
hash = 83 * hash + Objects.hashCode(this.url);
|
|
return hash;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj)
|
|
{
|
|
if (this == obj)
|
|
return true;
|
|
if (obj == null)
|
|
return false;
|
|
if (getClass() != obj.getClass())
|
|
return false;
|
|
final TrackRequest other = (TrackRequest) obj;
|
|
if (!Objects.equals(this.url, other.url))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
@Override
|
|
public int compareTo(TrackRequest o)
|
|
{
|
|
return -Double.compare(priority, o.priority); // backwards so higher priority comes first
|
|
}
|
|
|
|
public double getPriority()
|
|
{
|
|
return priority;
|
|
}
|
|
|
|
public void setPriority(double priority)
|
|
{
|
|
this.priority = priority;
|
|
}
|
|
|
|
}
|
|
|