Search in sources :

Example 1 with Prompt

use of com.jagrosh.jmusicbot.entities.Prompt in project MusicBot by jagrosh.

the class BotConfig method writeDefaultConfig.

public static void writeDefaultConfig() {
    Prompt prompt = new Prompt(null, null, true, true);
    prompt.alert(Prompt.Level.INFO, "JMusicBot Config", "Generating default config file");
    Path path = BotConfig.getConfigPath();
    byte[] bytes = BotConfig.loadDefaultConfig().getBytes();
    try {
        prompt.alert(Prompt.Level.INFO, "JMusicBot Config", "Writing default config file to " + path.toAbsolutePath().toString());
        Files.write(path, bytes);
    } catch (Exception ex) {
        prompt.alert(Prompt.Level.ERROR, "JMusicBot Config", "An error occurred writing the default config file: " + ex.getMessage());
    }
}
Also used : Path(java.nio.file.Path) Prompt(com.jagrosh.jmusicbot.entities.Prompt) IOException(java.io.IOException)

Example 2 with Prompt

use of com.jagrosh.jmusicbot.entities.Prompt in project MusicBot by jagrosh.

the class JMusicBot method startBot.

private static void startBot() {
    // create prompt to handle startup
    Prompt prompt = new Prompt("JMusicBot");
    // startup checks
    OtherUtil.checkVersion(prompt);
    OtherUtil.checkJavaVersion(prompt);
    // load config
    BotConfig config = new BotConfig(prompt);
    config.load();
    if (!config.isValid())
        return;
    LOG.info("Loaded config from " + config.getConfigLocation());
    // set up the listener
    EventWaiter waiter = new EventWaiter();
    SettingsManager settings = new SettingsManager();
    Bot bot = new Bot(waiter, config, settings);
    AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(), "a music bot that is [easy to host yourself!](https://github.com/jagrosh/MusicBot) (v" + OtherUtil.getCurrentVersion() + ")", new String[] { "High-quality music playback", "FairQueue™ Technology", "Easy to host yourself" }, RECOMMENDED_PERMS);
    aboutCommand.setIsAuthor(false);
    // 🎶
    aboutCommand.setReplacementCharacter("\uD83C\uDFB6");
    // set up the command client
    CommandClientBuilder cb = new CommandClientBuilder().setPrefix(config.getPrefix()).setAlternativePrefix(config.getAltPrefix()).setOwnerId(Long.toString(config.getOwnerId())).setEmojis(config.getSuccess(), config.getWarning(), config.getError()).setHelpWord(config.getHelp()).setLinkedCacheSize(200).setGuildSettingsManager(settings).addCommands(aboutCommand, new PingCommand(), new SettingsCmd(bot), new LyricsCmd(bot), new NowplayingCmd(bot), new PlayCmd(bot), new PlaylistsCmd(bot), new QueueCmd(bot), new RemoveCmd(bot), new SearchCmd(bot), new SCSearchCmd(bot), new ShuffleCmd(bot), new SkipCmd(bot), new ForceRemoveCmd(bot), new ForceskipCmd(bot), new MoveTrackCmd(bot), new PauseCmd(bot), new PlaynextCmd(bot), new RepeatCmd(bot), new SkiptoCmd(bot), new StopCmd(bot), new VolumeCmd(bot), new PrefixCmd(bot), new SetdjCmd(bot), new SkipratioCmd(bot), new SettcCmd(bot), new SetvcCmd(bot), new AutoplaylistCmd(bot), new DebugCmd(bot), new PlaylistCmd(bot), new SetavatarCmd(bot), new SetgameCmd(bot), new SetnameCmd(bot), new SetstatusCmd(bot), new ShutdownCmd(bot));
    if (config.useEval())
        cb.addCommand(new EvalCmd(bot));
    boolean nogame = false;
    if (config.getStatus() != OnlineStatus.UNKNOWN)
        cb.setStatus(config.getStatus());
    if (config.getGame() == null)
        cb.useDefaultGame();
    else if (config.getGame().getName().equalsIgnoreCase("none")) {
        cb.setActivity(null);
        nogame = true;
    } else
        cb.setActivity(config.getGame());
    if (!prompt.isNoGUI()) {
        try {
            GUI gui = new GUI(bot);
            bot.setGUI(gui);
            gui.init();
        } catch (Exception e) {
            LOG.error("Could not start GUI. If you are " + "running on a server or in a location where you cannot display a " + "window, please run in nogui mode using the -Dnogui=true flag.");
        }
    }
    // attempt to log in and start
    try {
        JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS)).enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE).disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS).setActivity(nogame ? null : Activity.playing("loading...")).setStatus(config.getStatus() == OnlineStatus.INVISIBLE || config.getStatus() == OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB).addEventListeners(cb.build(), waiter, new Listener(bot)).setBulkDeleteSplittingEnabled(true).build();
        bot.setJDA(jda);
    } catch (LoginException ex) {
        prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nPlease make sure you are " + "editing the correct config.txt file, and that you have used the " + "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation());
        System.exit(1);
    } catch (IllegalArgumentException ex) {
        prompt.alert(Prompt.Level.ERROR, "JMusicBot", "Some aspect of the configuration is " + "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation());
        System.exit(1);
    }
}
Also used : GUI(com.jagrosh.jmusicbot.gui.GUI) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) LoginException(javax.security.auth.login.LoginException) SettingsManager(com.jagrosh.jmusicbot.settings.SettingsManager) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) LoginException(javax.security.auth.login.LoginException) Prompt(com.jagrosh.jmusicbot.entities.Prompt)

Example 3 with Prompt

use of com.jagrosh.jmusicbot.entities.Prompt in project flowermoon by wolf-yuan-6115.

the class JMusicBot method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // startup log
    Logger log = LoggerFactory.getLogger("啟動");
    // create prompt to handle startup
    Prompt prompt = new Prompt("機器人", "正在切換到無視窗模式,您可以使用 -Dnogui=false 來關閉這個功能");
    // get and check latest version
    String version = OtherUtil.checkVersion(prompt);
    // check for valid java version
    if (!System.getProperty("java.vm.name").contains("64"))
        prompt.alert(Prompt.Level.WARNING, "Java版本", "您的Java可能無法跟此程式相容,請使用64位元的Java");
    // load config
    BotConfig config = new BotConfig(prompt);
    config.load();
    if (!config.isValid())
        return;
    // set up the listener
    EventWaiter waiter = new EventWaiter();
    SettingsManager settings = new SettingsManager();
    Bot bot = new Bot(waiter, config, settings);
    AboutCommand aboutCommand = new AboutCommand(Color.BLUE.brighter(), "一個 [可以自己運行的音樂機器人](https://github.com/wolf-yuan-6115/flowermoon) (" + version + ")", new String[] { "高品質的音樂", "FairQueue™ 技術" }, RECOMMENDED_PERMS);
    aboutCommand.setIsAuthor(false);
    // 🎶
    aboutCommand.setReplacementCharacter("\uD83C\uDFB6");
    // set up the command client
    CommandClientBuilder cb = new CommandClientBuilder().setPrefix(config.getPrefix()).setAlternativePrefix(config.getAltPrefix()).setOwnerId(Long.toString(config.getOwnerId())).setEmojis(config.getSuccess(), config.getWarning(), config.getError()).setHelpWord(config.getHelp()).setLinkedCacheSize(200).setGuildSettingsManager(settings).addCommands(aboutCommand, new PingCommand(), new SettingsCmd(bot), new LyricsCmd(bot), new NowplayingCmd(bot), new PlayCmd(bot), new PlaylistsCmd(bot), new QueueCmd(bot), new RemoveCmd(bot), new SearchCmd(bot), new SCSearchCmd(bot), new ShuffleCmd(bot), new SkipCmd(bot), new ForceRemoveCmd(bot), new ForceskipCmd(bot), new MoveTrackCmd(bot), new PauseCmd(bot), new PlaynextCmd(bot), new RepeatCmd(bot), new SkiptoCmd(bot), new StopCmd(bot), new VolumeCmd(bot), new PrefixCmd(bot), new SetdjCmd(bot), new SettcCmd(bot), new SetvcCmd(bot), new AutoplaylistCmd(bot), new DebugCmd(bot), new PlaylistCmd(bot), new SetavatarCmd(bot), new SetgameCmd(bot), new SetnameCmd(bot), new SetstatusCmd(bot), new ShutdownCmd(bot));
    if (config.useEval())
        cb.addCommand(new EvalCmd(bot));
    boolean nogame = false;
    if (config.getStatus() != OnlineStatus.UNKNOWN)
        cb.setStatus(config.getStatus());
    if (config.getGame() == null)
        cb.useDefaultGame();
    else if (config.getGame().getName().equalsIgnoreCase("none")) {
        cb.setActivity(null);
        nogame = true;
    } else
        cb.setActivity(config.getGame());
    if (!prompt.isNoGUI()) {
        try {
            GUI gui = new GUI(bot);
            bot.setGUI(gui);
            gui.init();
        } catch (Exception e) {
            log.error("無法開啟視窗,如果您的伺服器或電腦沒有螢幕,請使用 -Dnogui=true 來啟動機器人");
        }
    }
    log.info("成功從 " + config.getConfigLocation() + " 讀取配置");
    // attempt to log in and start
    try {
        JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS)).enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE).disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS).setActivity(nogame ? null : Activity.playing("載入中...")).setStatus(config.getStatus() == OnlineStatus.INVISIBLE || config.getStatus() == OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB).addEventListeners(cb.build(), waiter, new Listener(bot)).setBulkDeleteSplittingEnabled(true).build();
        bot.setJDA(jda);
    } catch (LoginException ex) {
        prompt.alert(Prompt.Level.ERROR, "機器人", ex + "\n請確定您更改了正確的配置文件,並且放置了正確的機器人Token (不是secret)" + "\n配置文件路徑: " + config.getConfigLocation());
        System.exit(1);
    } catch (IllegalArgumentException ex) {
        prompt.alert(Prompt.Level.ERROR, "機器人", "部分配置文件語法錯誤: " + ex + "\n配置文件路徑: " + config.getConfigLocation());
        System.exit(1);
    }
}
Also used : GUI(com.jagrosh.jmusicbot.gui.GUI) CommandClientBuilder(com.jagrosh.jdautilities.command.CommandClientBuilder) LoginException(javax.security.auth.login.LoginException) Logger(org.slf4j.Logger) SettingsManager(com.jagrosh.jmusicbot.settings.SettingsManager) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) LoginException(javax.security.auth.login.LoginException) Prompt(com.jagrosh.jmusicbot.entities.Prompt)

Aggregations

Prompt (com.jagrosh.jmusicbot.entities.Prompt)3 CommandClientBuilder (com.jagrosh.jdautilities.command.CommandClientBuilder)2 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)2 GUI (com.jagrosh.jmusicbot.gui.GUI)2 SettingsManager (com.jagrosh.jmusicbot.settings.SettingsManager)2 LoginException (javax.security.auth.login.LoginException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Logger (org.slf4j.Logger)1