|
1 | 1 | package suzuya.client; |
2 | 2 |
|
| 3 | +import com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory; |
3 | 4 | import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration; |
4 | 5 | import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; |
5 | 6 | import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; |
|
16 | 17 | import net.dv8tion.jda.api.JDABuilder; |
17 | 18 | import org.slf4j.Logger; |
18 | 19 | import org.slf4j.LoggerFactory; |
19 | | -import suzuya.util.Config; |
| 20 | +import suzuya.util.SuzuyaConfig; |
20 | 21 | import suzuya.Sortie; |
21 | 22 | import suzuya.handler.CommandHandler; |
22 | 23 | import suzuya.handler.SettingsHandler; |
23 | 24 | import suzuya.handler.TagsHandler; |
24 | 25 | import suzuya.player.SuzuyaPlayer; |
25 | 26 | import suzuya.structures.CaptchaExecutor; |
26 | | -import suzuya.structures.Page; |
| 27 | +import suzuya.util.SuzuyaUtils; |
27 | 28 |
|
28 | 29 | import javax.security.auth.login.LoginException; |
29 | 30 | import java.awt.*; |
30 | 31 | import java.lang.management.ManagementFactory; |
31 | 32 | import java.lang.management.RuntimeMXBean; |
32 | | -import java.util.Arrays; |
33 | | -import java.util.List; |
34 | 33 | import java.util.concurrent.ConcurrentHashMap; |
35 | 34 | import java.util.concurrent.ExecutorService; |
36 | 35 | import java.util.concurrent.Executors; |
37 | 36 | import java.util.concurrent.ScheduledExecutorService; |
38 | | -import java.util.stream.Collectors; |
39 | 37 |
|
40 | 38 | public class SuzuyaClient { |
41 | 39 | public final Logger SuzuyaLog = LoggerFactory.getLogger(Sortie.class); |
42 | | - public final Config config = new Config(this); |
| 40 | + |
| 41 | + public final SuzuyaConfig suzuyaConfig = new SuzuyaConfig(this); |
| 42 | + public final SuzuyaUtils util = new SuzuyaUtils(this); |
| 43 | + |
43 | 44 | public final AudioPlayerManager PlayerManager = new DefaultAudioPlayerManager(); |
44 | 45 | public final ConcurrentHashMap<String, SuzuyaPlayer> players = new ConcurrentHashMap<>(); |
45 | 46 | public final ConcurrentHashMap<String, CaptchaExecutor> captcha = new ConcurrentHashMap<>(); |
46 | | - public final CommandHandler commandHandler = new CommandHandler(this); |
47 | | - public final SettingsHandler settingsHandler = new SettingsHandler(this); |
48 | | - public final TagsHandler tagsHandler = new TagsHandler(this); |
49 | 47 |
|
50 | 48 | public final Color defaultEmbedColor = new Color(62, 180, 137); |
51 | 49 |
|
52 | 50 | public final OperatingSystemMXBean system = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); |
53 | 51 | public final RuntimeMXBean runtime_mx = ManagementFactory.getRuntimeMXBean(); |
54 | 52 | public final Runtime runtime = Runtime.getRuntime(); |
55 | 53 |
|
56 | | - public final JDA client = new JDABuilder(config.getToken()).build(); |
57 | | - |
58 | 54 | public final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); |
59 | 55 | public final ExecutorService executors = Executors.newCachedThreadPool(); |
60 | 56 |
|
| 57 | + public final JDA client; |
| 58 | + public final CommandHandler commandHandler; |
| 59 | + public final SettingsHandler settingsHandler; |
| 60 | + public final TagsHandler tagsHandler; |
| 61 | + |
61 | 62 | public Boolean isClientReady = false; |
62 | 63 |
|
63 | 64 | public SuzuyaClient() throws LoginException { |
64 | | - settingsHandler.initDb(); |
65 | | - tagsHandler.initDb(); |
66 | | - setPlayerSettings(); |
67 | | - } |
68 | | - |
69 | | - private void setPlayerSettings() { |
70 | | - AudioConfiguration audioConfig = PlayerManager.getConfiguration(); |
71 | | - audioConfig.setResamplingQuality(AudioConfiguration.ResamplingQuality.HIGH); |
72 | | - audioConfig.setOpusEncodingQuality(10); |
73 | | - SuzuyaLog.info("AudioPlayer settings are now set."); |
| 65 | + commandHandler = new CommandHandler(this) |
| 66 | + .init(); |
| 67 | + settingsHandler = new SettingsHandler(this) |
| 68 | + .init(); |
| 69 | + tagsHandler = new TagsHandler(this) |
| 70 | + .init(); |
| 71 | + client = new JDABuilder() |
| 72 | + .setToken(suzuyaConfig.getToken()) |
| 73 | + .setAudioSendFactory(new NativeAudioSendFactory()) |
| 74 | + .build(); |
| 75 | + PlayerManager |
| 76 | + .getConfiguration() |
| 77 | + .setResamplingQuality(AudioConfiguration.ResamplingQuality.HIGH); |
| 78 | + PlayerManager |
| 79 | + .getConfiguration() |
| 80 | + .setOpusEncodingQuality(10); |
74 | 81 | YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager(); |
75 | 82 | youtube.setPlaylistPageCount(1000); |
76 | 83 | PlayerManager.registerSourceManager(youtube); |
77 | | - PlayerManager.registerSourceManager(new BandcampAudioSourceManager()); |
78 | 84 | PlayerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault()); |
| 85 | + PlayerManager.registerSourceManager(new BandcampAudioSourceManager()); |
79 | 86 | PlayerManager.registerSourceManager(new TwitchStreamAudioSourceManager()); |
80 | 87 | PlayerManager.registerSourceManager(new VimeoAudioSourceManager()); |
81 | 88 | PlayerManager.registerSourceManager(new BeamAudioSourceManager()); |
82 | 89 | PlayerManager.registerSourceManager(new HttpAudioSourceManager()); |
83 | 90 | PlayerManager.registerSourceManager(new LocalAudioSourceManager()); |
84 | | - SuzuyaLog.info("Registered the AudioPlayer sources managers"); |
85 | | - } |
86 | | - |
87 | | - public Page paginate(Integer length, Integer page, Integer max) { |
88 | | - if (page == null) page = 1; |
89 | | - int limit = length / max + ((length % max == 0) ? 0 : 1); |
90 | | - int selected = page < 1 ? 1 : page > limit ? limit : page; |
91 | | - int start = (selected - 1) * max; |
92 | | - return new Page(selected, limit, start, length > max ? start + max : length); |
93 | | - } |
94 | | - |
95 | | - public void errorTrace(String title, StackTraceElement[] traces) { |
96 | | - List<String> trace = Arrays.stream(traces) |
97 | | - .map(val -> val.toString() + "\n") |
98 | | - .collect(Collectors.toList()); |
99 | | - trace.add(0, title + "\n"); |
100 | | - SuzuyaLog.error(trace.toString()); |
101 | | - } |
102 | | - |
103 | | - public void errorTrace(String message) { |
104 | | - if (message == null) return; |
105 | | - SuzuyaLog.error(message); |
106 | 91 | } |
107 | 92 | } |
0 commit comments