diff --git a/src/main/java/com/github/ucchyocean/lc/Channel.java b/src/main/java/com/github/ucchyocean/lc/Channel.java index 9ec0649..b8b7f2c 100644 --- a/src/main/java/com/github/ucchyocean/lc/Channel.java +++ b/src/main/java/com/github/ucchyocean/lc/Channel.java @@ -32,6 +32,13 @@ public class Channel { private static final String MSG_JOIN = Resources.get("joinMessage"); private static final String MSG_QUIT = Resources.get("quitMessage"); + private static final String PREINFO = Resources.get("infoPrefix"); + private static final String NGWORD_PREFIX = Resources.get("ngwordPrefix"); + private static final String MSG_KICKED = Resources.get("cmdmsgKicked"); + private static final String MSG_BANNED = Resources.get("cmdmsgBanned"); + + // ngwordPrefix + /** 参加者 */ protected List members; @@ -96,6 +103,16 @@ public class Channel { */ protected void chat(Player player, String message) { + // NGワード発言をしたかどうかのチェック + boolean isNG = false; + for ( String word : LunaChat.config.ngword ) { + if ( message.contains(word) ) { + message = message.replace( + word, getAstariskString(word.length())); + isNG = true; + } + } + // Japanize変換 if ( LunaChat.config.displayJapanize ) { // 2byteコードを含まない場合にのみ、処理を行う @@ -125,6 +142,30 @@ public class Channel { if ( LunaChat.config.loggingChat ) { LunaChat.log(msg); } + + // NGワード発言者に、NGワードアクションを実行する + // ただしグローバルチャンネルの場合は、アクションは実行されない + if ( isNG && !LunaChat.config.globalChannel.equals(name) ) { + if ( LunaChat.config.ngwordAction == NGWordAction.BAN ) { + // BANする + + banned.add(player.getName()); + removeMember(player.getName()); + String temp = PREINFO + NGWORD_PREFIX + MSG_BANNED; + String m = String.format( + Utility.replaceColorCode(temp), name); + player.sendMessage(m); + + } else if ( LunaChat.config.ngwordAction == NGWordAction.KICK ) { + // キックする + + removeMember(player.getName()); + String temp = PREINFO + NGWORD_PREFIX + MSG_KICKED; + String m = String.format( + Utility.replaceColorCode(temp), name); + player.sendMessage(m); + } + } } /** @@ -342,4 +383,17 @@ public class Channel { return members.size(); } + + /** + * 指定された文字数のアスタリスクの文字列を返す + * @param length アスタリスクの個数 + * @return 指定された文字数のアスタリスク + */ + private String getAstariskString(int length) { + StringBuilder buf = new StringBuilder(); + for ( int i=0; i ngword; + + /** NGワードを発言した人に対して実行するアクション
+ * mask = マスクするのみ
+ * kick = マスクしてチャンネルからキックする
+ * ban = マスクしてチャンネルからBANする */ + protected NGWordAction ngwordAction; + /** * コンストラクタ */ @@ -69,6 +79,8 @@ public class LunaChatConfig { createChannelOnJoinCommand = config.getBoolean("createChannelOnJoinCommand", true); globalChannel = config.getString("globalChannel", ""); + ngword = config.getStringList("ngword"); + ngwordAction = NGWordAction.fromID(config.getString("ngwordAction", "mask")); } /** diff --git a/src/main/java/com/github/ucchyocean/lc/NGWordAction.java b/src/main/java/com/github/ucchyocean/lc/NGWordAction.java new file mode 100644 index 0000000..f616380 --- /dev/null +++ b/src/main/java/com/github/ucchyocean/lc/NGWordAction.java @@ -0,0 +1,60 @@ +/* + * @author ucchy + * @license GPLv3 + * @copyright Copyright ucchy 2013 + */ +package com.github.ucchyocean.lc; + + +/** + * @author ucchy + * NGワードを発言した人に与えるアクションの設定の種類 + */ +public enum NGWordAction { + + /** マスクするのみ */ + MASK("mask"), + + /** マスクしつつ、チャンネルからキックする */ + KICK("kick"), + + /** マスクしつつ、チャンネルからBANする */ + BAN("ban"); + + private String id; + + /** + * コンストラクタ + * @param id ID + */ + NGWordAction(String id) { + this.id = id; + } + + /** + * 識別文字列を返す + * @see java.lang.Enum#toString() + */ + @Override + public String toString() { + return id; + } + + /** + * 識別文字列から、NGWordActionを作成して返す。 + * 無効な文字列が指定された場合は、nullが返される。 + * @param id 識別文字列 + * @return 対応したNGWordAction + */ + public static NGWordAction fromID(String id) { + if ( id == null ) { + return null; + } + for (NGWordAction value : values()) { + if (id.equalsIgnoreCase(value.id)) { + return value; + } + } + return null; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 64e709f..9d4786d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -11,3 +11,5 @@ zeroMemberRemove: false showListOnJoin: false createChannelOnJoinCommand: true globalChannel: '' +ngword: [] +ngwordAction: mask diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 54dee35..ef905dd 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -3,7 +3,6 @@ defaultFormat: '&a[%ch]%prefix%username%suffix&a: %msg' joinMessage: '&a[%ch]&7%username さんがチャンネルチャットに参加しました。' quitMessage: '&a[%ch]&7%username さんがチャンネルチャットから退出しました。' breakupMessage: '&a[%s]&7チャンネルチャットが削除されました。' -moderatorChangedMessage: '&a[%s]&7モデレータ %s さんが退出するので、%s さんが次のモデレータになりました。' listFirstLine: '&8---------- &bチャンネルリスト &8----------' listEndLine: '&8----------------------------------' @@ -68,6 +67,8 @@ errmsgCannotBANGlobal: 'チャンネル %s はグローバルチャンネルな errmsgCannotRemoveGlobal: 'チャンネル %s はグローバルチャンネルなので、削除できません。' errmsgCannotModeratorGlobal: 'チャンネル %s はグローバルチャンネルなので、モデレーターを設定できません。' +ngwordPrefix: 'NGワード発言により、' + usageJoin: '&7/%s join (channel) - チャンネルに参加します。' usageLeave: '&7/%s leave - 参加しているチャンネルから退出します。' usageList: '&7/%s list - チャンネルのリストを表示します。' diff --git a/target/LunaChat.jar b/target/LunaChat.jar index 6536b61..f5b1175 100644 Binary files a/target/LunaChat.jar and b/target/LunaChat.jar differ