Skip to content

Instantly share code, notes, and snippets.

@oomatz
Last active October 15, 2017 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oomatz/43d673f8a8272f0fb9ff373aa317a147 to your computer and use it in GitHub Desktop.
Save oomatz/43d673f8a8272f0fb9ff373aa317a147 to your computer and use it in GitHub Desktop.
TWのチャットログを棒読みちゃんに読ませるPowerShellスクリプト
<#
.SYNOPSIS
TWのチャットログを棒読みちゃんに読ませるPowerShellスクリプト
クラブチャットとチームチャットのみ読み上げる
.DESCRIPTION
使い方
------
0. 下準備
* TWのチャットログ機能をONにする
* 棒読みちゃんをダウンロード
* 棒読みちゃんを起動させておく
* このスクリプトファイル(Bouyomi_TW_Chat.ps1)をダウンロードしておく
Rawというリンクを右クリックして、名前を付けてリンクを保存 のようなものを選択
1. 棒読みちゃんのRemoteTalkのプログラムを利用するので以下のプログラムをTWのChatLogに保存
BouyomiChan\RemoteTalk\RemoteTalk.exe
2. このスクリプトファイル(Bouyomi_TW_Chat.ps1)もChatLogフォルダに保存
3. PowerShellを実行 (Winボタンを押して、「powershell」と入力)
4. PowerShell上で以下のコマンドを入力し、TWのChatLogフォルダへ移動
cd C:\Nexon\TalesWeaver\ChatLog
5. 以下コマンドでスクリプトを実行(logファイル名は最新のものを選択)
.\Bouyomi_TW_Chat.ps1 .\TWChatLog_2017_10_14.html
注意事項
-----------
* 「デジタル署名されていません」のようなエラーが出る場合は、ExecutionPolicyを変更する必要があります。
  > Set-ExecutionPolicy Bypass -Scope CurrentUser
.EXAMPLE
./Bouyomi_TW_Chat.ps1 .\TWChatLog_2017_10_14.html
#>
function FilterString {
param
(
[Parameter(ValueFromPipeline=$True)]
$message,
$clubColor = "#94ddfa",
$teamColor = "#f7b73c"
)
process {
# $systemColor = "#ff64ff"
# $normalColor = "#c8ffc8"
$dummyString = '<message><font size="2" color="white"></font> <font size="2" color="#ff6464">dummy</font></message>'
try {
$xmlMessageAll = [xml]('<message>' + $message.Replace('</br>','').Replace('@*&#','') + '</message>')
}
catch {
Write-Error ("Invalid String Found: " + $message)
$xmlMessageAll = [xml]$dummyString
}
$xmlMessage = $xmlMessageAll.message.font[1]
switch ($xmlMessage.color) {
$clubColor {
$preMessage = ""
$display = $true
}
$teamColor {
$preMessage = ""
$display = $true
}
default {
$preMessage = ""
$display = $false
}
}
if ($display) {
#.\BouyomiChanSample.exe ($preMessage + $xmlMessage.'#text')
.\RemoteTalk.exe /Talk ($preMessage + $xmlMessage.'#text')
}
}
}
## WORKAROUND:
## ログファイルがまれに別プロセスで使用されていてエラーとなるため、リトライ処置を入れている
$complete = $false
while (-not $complete) {
try {
Get-Content -Path $Args[0] -Tail 1 -Wait -ErrorAction Stop | FilterString
$complete = $true
}
catch {
Write-Error($_.Exception)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment