-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add seek command * Combine nested if statements * Put the seek command in correct place to keep alphabetical order * Add license header * Brackets on next line * Restructure if-statements * Check for permissions with DJCommand#checkDJPermission * Make regex slightly smaller * Optimize imports * Output length of current track if requested seek time is invalid * Restate seeked point when seeked successfully * Add empty newline at end of file to keep consistency * Create TimeUtil class for parsing and formatting time * Move FormatUtil#formatTime to TimeUtil, and refactor * Apply requested changes (Pass 2) * Seek based on current position in track * Apply requested changes (Pass 3) * Add javadoc param * Apply requested changes (Pass 4) * Fix merge * Avoid reassigning parameter (Codacy) * Rework timestamp parsing * Refactor timestamp parsing * Apply requested changes (Pass 5) * Add examples in help * Apply requested changes (Pass 6) * Fix missing import * Keep track of start timestamp & add "unit" times * Fix my abdominal merge with QueuedTrack * Use RequestMetadata to store start timestamp * Store request info in request metadata * Add regex to try getting a timestamp from the url * Require RequestMetadata for QueuedTracks * Add some unit tests for unit seeking * Add docs & examples --------- Co-authored-by: Whew., Inc <[email protected]>
- Loading branch information
Showing
13 changed files
with
432 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,40 +15,67 @@ | |
*/ | ||
package com.jagrosh.jmusicbot.audio; | ||
|
||
import com.jagrosh.jdautilities.command.CommandEvent; | ||
import com.jagrosh.jmusicbot.utils.TimeUtil; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; | ||
import net.dv8tion.jda.api.entities.User; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* | ||
* @author John Grosh ([email protected]) | ||
*/ | ||
public class RequestMetadata | ||
{ | ||
public static final RequestMetadata EMPTY = new RequestMetadata(null); | ||
public static final RequestMetadata EMPTY = new RequestMetadata(null, null); | ||
|
||
public final UserInfo user; | ||
public final RequestInfo requestInfo; | ||
|
||
public RequestMetadata(User user) | ||
public RequestMetadata(User user, RequestInfo requestInfo) | ||
{ | ||
this.user = user == null ? null : new UserInfo(user.getIdLong(), user.getName(), user.getDiscriminator(), user.getEffectiveAvatarUrl()); | ||
this.requestInfo = requestInfo; | ||
} | ||
|
||
public long getOwner() | ||
{ | ||
return user == null ? 0L : user.id; | ||
} | ||
|
||
public static RequestMetadata fromResultHandler(AudioTrack track, CommandEvent event) | ||
{ | ||
return new RequestMetadata(event.getAuthor(), new RequestInfo(event.getArgs(), track.getInfo().uri)); | ||
} | ||
|
||
public class RequestInfo | ||
public static class RequestInfo | ||
{ | ||
public final String query, url; | ||
|
||
private RequestInfo(String query, String url) | ||
public final long startTimestamp; | ||
|
||
public RequestInfo(String query, String url) | ||
{ | ||
this(query, url, tryGetTimestamp(query)); | ||
} | ||
|
||
private RequestInfo(String query, String url, long startTimestamp) | ||
{ | ||
this.query = query; | ||
this.url = url; | ||
this.query = query; | ||
this.startTimestamp = startTimestamp; | ||
} | ||
|
||
private static final Pattern youtubeTimestampPattern = Pattern.compile("youtu(?:\\.be|be\\..+)/.*\\?.*(?!.*list=)t=([\\dhms]+)"); | ||
private static long tryGetTimestamp(String url) | ||
{ | ||
Matcher matcher = youtubeTimestampPattern.matcher(url); | ||
return matcher.find() ? TimeUtil.parseUnitTime(matcher.group(1)) : 0; | ||
} | ||
} | ||
|
||
public class UserInfo | ||
public static class UserInfo | ||
{ | ||
public final long id; | ||
public final String username, discrim, avatar; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.