blob: c8bcba6cc511278cd075d6c2203d80f204f39069 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package soundchan.BotListener;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class BotListenerHelpers {
/**
* Given a MessageReceivedEvent, determines the correct reply channel for SoundChan.
* @param event a MessageReceivedEvent from the JDA ListenerAdapter
* @return Either a PrivateChannel (if SoundChan was DM'd) or a TextChannel (If SoundChan was commanded in one)
*/
public MessageChannel GetReplyChannel(MessageReceivedEvent event){
Guild guild = null;
if(event.isFromGuild()) {
guild = event.getGuild();
}
return (guild == null) ? event.getPrivateChannel() : event.getTextChannel();
}
public long urlToTimeStamp(String url){
int[] timeConversions = {1, 60, 3600};
int position = url.indexOf("?t=");
int seekTime = 0;
if(position != -1){
String linkTimestamp = url.substring(position + 3);
String[] times = linkTimestamp.split("[hms]");
for(int i = 0; i < times.length / 2; i++)
{
String temp = times[i];
times[i] = times[times.length - i - 1];
times[times.length - i - 1] = temp;
}
for (int i = 0; i < times.length; i++) {
seekTime = seekTime + timeConversions[i]*Integer.parseInt(times[i]);
}
System.out.println(seekTime);
}
return seekTime;
}
}
|