Skip to content

Commit

Permalink
Merge pull request #6 from ryuuta0217/master
Browse files Browse the repository at this point in the history
ニコニコ動画対応と和訳修正
  • Loading branch information
kosugikun authored Sep 9, 2019
2 parents 7506ca5 + a039a82 commit e26d515
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 270 deletions.
140 changes: 0 additions & 140 deletions .idea/workspace.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/jmusicbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void closeAudioConnection(long guildId)

public void resetGame()
{
Game game = config.getGame()==null || config.getGame().getName().equalsIgnoreCase("none") ? null : config.getGame();
Game game = config.getGame()==null || config.getGame().getName().toLowerCase().matches("(none|なし)") ? null : config.getGame();
if(!Objects.equals(jda.getPresence().getGame(), game))
jda.getPresence().setGame(game);
}
Expand Down
55 changes: 38 additions & 17 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public class BotConfig
{
private final Prompt prompt;
private final static String CONTEXT = "Config";
private final static String START_TOKEN = "/// START OF JMUSICBOT CONFIG ///";
private final static String END_TOKEN = "/// END OF JMUSICBOT CONFIG ///";
private final static String START_TOKEN = "/// START OF JMUSICBOT-JP CONFIG ///";
private final static String END_TOKEN = "/// END OF JMUSICBOT-JP CONFIG ///";

private Path path = null;
// [JMusicBot-JP] added nicoEmail, nicoPass
private String token, prefix, altprefix, helpWord, playlistsFolder,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji, nicoEmail, nicoPass;
// [JMusicBot-JP] added useNicoNico
private boolean useNicoNico, stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds;
private OnlineStatus status;
private Game game;
Expand Down Expand Up @@ -74,7 +76,7 @@ public void load()
prefix = config.getString("prefix");
altprefix = config.getString("altprefix");
helpWord = config.getString("help");
owner = config.getLong("owner");
owner = (config.getAnyRef("owner") instanceof String ? 0L : config.getLong("owner"));
successEmoji = config.getString("success");
warningEmoji = config.getString("warning");
errorEmoji = config.getString("error");
Expand All @@ -90,20 +92,25 @@ public void load()
maxSeconds = config.getLong("maxtime");
playlistsFolder = config.getString("playlistsfolder");
dbots = owner == 113156185389092864L;

// [JMusicBot-JP] new function: support niconico play
useNicoNico = config.getBoolean("useniconico");
nicoEmail = config.getString("nicomail");
nicoPass = config.getString("nicopass");
// [JMusicBot-JP] End

// we may need to write a new config file
boolean write = false;

// validate bot token
if(token==null || token.isEmpty() || token.equalsIgnoreCase("BOT_TOKEN_HERE"))
{
if(token==null || token.isEmpty() || token.matches("(BOT_TOKEN_HERE|Botトークンをここに貼り付け)")) {
token = prompt.prompt("BOTトークンを入力してください。"
+ "\nトークンを取得する方法はこちらから:"
+ "\nhttps://github.com/jagrosh/MusicBot/wiki/Getting-a-Bot-Token."
+ "\nBOTトークン: ");
if(token==null)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "No token provided! Exiting.\n\nConfig Location: " + path.toAbsolutePath().toString());
prompt.alert(Prompt.Level.WARNING, CONTEXT, "トークンが入力されていません!終了します。\n\n設定ファイルの場所: " + path.toAbsolutePath().toString());
return;
}
else
Expand All @@ -117,19 +124,19 @@ public void load()
{
try
{
owner = Long.parseLong(prompt.prompt("オーナーIDがみつからない、または有効ではありません。"
+ "\nBOTのオーナーのオーナーIDを入力してください。"
owner = Long.parseLong(prompt.prompt("所有者のユーザーIDが設定されていない、または有効なIDではありません。"
+ "\nBOTの所有者のユーザーIDを入力してください。"
+ "\nユーザーIDの入手方法はこちらから:"
+ "\nhttps://github.com/jagrosh/MusicBot/wiki/Finding-Your-User-ID"
+ "\nオーナーユーザーID: "));
+ "\n所有者のユーザーID: "));
}
catch(NumberFormatException | NullPointerException ex)
{
owner = 0;
}
if(owner<=0)
{
prompt.alert(Prompt.Level.ERROR, CONTEXT, "Invalid User ID! Exiting.\n\nConfig Location: " + path.toAbsolutePath().toString());
prompt.alert(Prompt.Level.ERROR, CONTEXT, "無効なユーザーIDです!終了します。\n\n設定ファイルの場所: " + path.toAbsolutePath().toString());
System.exit(0);
}
else
Expand All @@ -149,8 +156,8 @@ public void load()
else
{
bytes = original.substring(original.indexOf(START_TOKEN)+START_TOKEN.length(), original.indexOf(END_TOKEN))
.replace("BOT_TOKEN_HERE", token)
.replace("0 // OWNER ID", Long.toString(owner))
.replace("BOT_TOKEN_HERE", token).replace("Botトークンをここに貼り付け", token)
.replace("0 // OWNER ID", Long.toString(owner)).replace("所有者IDをここに貼り付け", Long.toString(owner))
.trim().getBytes();
}
try
Expand All @@ -159,8 +166,8 @@ public void load()
}
catch(IOException ex)
{
prompt.alert(Prompt.Level.WARNING, CONTEXT, "Failed to write new config options to config.txt: "+ex
+ "\nPlease make sure that the files are not on your desktop or some other restricted area.\n\nConfig Location: "
prompt.alert(Prompt.Level.WARNING, CONTEXT, "新しい設定を書き込めませんでした: "+ex
+ "\nファイルがデスクトップまたはその他の制限された領域にないことを確認してください。\n\n設定ファイルの場所: "
+ path.toAbsolutePath().toString());
}
}
Expand All @@ -170,7 +177,7 @@ public void load()
}
catch (ConfigException ex)
{
prompt.alert(Prompt.Level.ERROR, CONTEXT, ex + ": " + ex.getMessage() + "\n\nConfig Location: " + path.toAbsolutePath().toString());
prompt.alert(Prompt.Level.ERROR, CONTEXT, ex + ": " + ex.getMessage() + "\n\n設定ファイルの場所: " + path.toAbsolutePath().toString());
}
}

Expand Down Expand Up @@ -295,4 +302,18 @@ public boolean isTooLong(AudioTrack track)
return false;
return Math.round(track.getDuration()/1000.0) > maxSeconds;
}

// [JMusicBot-JP] new function: support niconico play
public boolean isNicoNicoEnabled() {
return useNicoNico;
}

public String getNicoNicoEmailAddress() {
return nicoEmail;
}

public String getNicoNicoPassword() {
return nicoPass;
}
// [JMusicBot-JP] End
}
18 changes: 8 additions & 10 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static void main(String[] args)
cb.setStatus(config.getStatus());
if(config.getGame()==null)
cb.useDefaultGame();
else if(config.getGame().getName().equalsIgnoreCase("none"))
else if(config.getGame().getName().toLowerCase().matches("(none|なし)"))
{
cb.setGame(null);
nogame = true;
Expand All @@ -169,7 +169,7 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
}
}

log.info(config.getConfigLocation()+"からロードされた設定");
log.info(config.getConfigLocation() + " から設定を読み込みました");

// attempt to log in and start
try
Expand All @@ -186,18 +186,16 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
}
catch (LoginException ex)
{
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\nあなたがいることを確認してください"

+ "正しいconfig.txtファイルを編集し、あなたが使ったことがある"

+ "正しいトークン('secret'ではありません!)\n設定場所:"+config.getConfigLocation());
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\n" +
"正しい設定ファイルを編集していることを確認してください。Botトークンでのログインに失敗しました。" +
"正しいBotトークンを入力してください。(CLIENT SECRET ではありません!)\n" +
"設定ファイルの場所: "+config.getConfigLocation());
System.exit(1);
}
catch(IllegalArgumentException ex)
{
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "設定のいくつかの側面は "

+ "無効: " + ex + "\n設定場所:"+config.getConfigLocation());
prompt.alert(Prompt.Level.ERROR, "JMusicBot", "設定の一部が無効です:" + ex + "\n" +
"設定ファイルの場所: "+config.getConfigLocation());
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public String getTopicFormat(JDA jda)
String title = track.getInfo().title;
if(title==null || title.equals("不明なタイトル"))
title = track.getInfo().uri;
return "**"+title+"** ["+(userid==0 ? "オートプレイ" : "<@"+userid+">")+"]"
return "**"+title+"** ["+(userid==0 ? "自動再生" : "<@"+userid+">")+"]"
+ "\n" + (audioPlayer.isPaused() ? JMusicBot.PAUSE_EMOJI : JMusicBot.PLAY_EMOJI) + " "
+ "[" + FormatUtil.formatTime(track.getDuration()) + "] "
+ FormatUtil.volumeIcon(audioPlayer.getVolume());
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/audio/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.source.nico.NicoAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import net.dv8tion.jda.core.entities.Guild;

Expand All @@ -40,6 +41,13 @@ public void init()
AudioSourceManagers.registerRemoteSources(this);
AudioSourceManagers.registerLocalSource(this);
source(YoutubeAudioSourceManager.class).setPlaylistPageCount(10);
if(bot.getConfig().isNicoNicoEnabled()) {
registerSourceManager(
new NicoAudioSourceManager(
bot.getConfig().getNicoNicoEmailAddress(),
bot.getConfig().getNicoNicoPassword())
);
}
}

public Bot getBot()
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/utils/FormatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.jagrosh.jmusicbot.utils;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
Expand All @@ -25,7 +28,14 @@
* @author John Grosh <[email protected]>
*/
public class FormatUtil {

public static String getStacktraceByString(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.flush();
return sw.toString();
}

public static String formatTime(long duration)
{
if(duration == Long.MAX_VALUE)
Expand Down
Loading

0 comments on commit e26d515

Please sign in to comment.