<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Minecraft | hgrs&#039;s Blog</title>
	<atom:link href="/archives/tag/minecraft/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>文字好きエンジニアの技術メモ</description>
	<lastBuildDate>Fri, 07 Aug 2020 05:57:12 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.1</generator>

<image>
	<url>/wp-content/uploads/2019/05/cropped-port_512-32x32.png</url>
	<title>Minecraft | hgrs&#039;s Blog</title>
	<link>/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Minecraft のマルチサーバでログイン通知を Slack / Discord / LINE に送る</title>
		<link>/archives/401.html</link>
					<comments>/archives/401.html#comments</comments>
		
		<dc:creator><![CDATA[hgrs]]></dc:creator>
		<pubDate>Sun, 23 Feb 2020 14:30:18 +0000</pubDate>
				<category><![CDATA[技術メモ]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[shell]]></category>
		<guid isPermaLink="false">/?p=401</guid>

					<description><![CDATA[はじめに 研究室の人たちとマイクラのマルチで遊んでるんですが、誰がインしているかを知りたいため、ログ...]]></description>
										<content:encoded><![CDATA[<h2>はじめに</h2>
<p>研究室の人たちとマイクラのマルチで遊んでるんですが、誰がインしているかを知りたいため、ログイン通知をつけています。せっかくなのでその方法を公開します。</p>
<h2>前提条件</h2>
<p>通知を送信する際に Python 製のライブラリを使用するので Python が使用できることが前提です。</p>
<p>僕の環境の場合は <code>3.8.0</code> で動作しています。</p>
<p>必要ライブラリのインストールは以下のコマンドでできます。</p>
<pre><code class="language-bash">pip install pynotificator</code></pre>
<p>インストールした PyNotificator は Slack、Discord、LINE にメッセージを送信することができるので、受け取り先を決めて必要なURL、トークンを以下から取得します。</p>
<p>-Slack: <a href="https://api.slack.com/apps">Slack API</a><br />
-Discord: サーバー設定 &gt; ウェブフック より、Webhook 用の URL を取得<br />
-LINE: <a href="https://notify-bot.line.me/">LINE Notify</a></p>
<h2>通知用のスクリプト</h2>
<p>マイクラのサーバ実行スクリプトからパイプで通知用コマンドにログを流します。</p>
<p>実行コマンドの大枠は以下のとおりです。</p>
<pre><code class="language-bash">&lt;マイクラのサーバ実行コマンド&gt; | while read -r line
do
  if [[ $line == *joined\ the\ game* ]]; then echo &quot;${line:33}&quot; | &lt;slack|discord|line&gt;-notify -m &quot;$(cut -d &#039; &#039; -f 1) がログインしました。&quot; &lt;URL|token&gt; ; fi
  if [[ $line == *left\ the\ game* ]]; then echo &quot;${line:33}&quot; | &lt;slack|discord|line&gt;-notify -m &quot;$(cut -d &#039; &#039; -f 1) がログアウトしました。&quot; &lt;URL|token&gt; ; fi
done;</code></pre>
<p>これをもとに Slack か Discord か LINE を選択して、上記の <code>&lt;&gt;</code> で囲まれた部分を書き換えてください。<br />
例えば以下のようなコマンドになります。</p>
<pre><code class="language-bash">java -jar server.jar nogui | while read -r line
do
  if [[ $line == *joined\ the\ game* ]]; then echo &quot;${line:33}&quot; | slack-notify -m &quot;$(cut -d &#039; &#039; -f 1) がログインしました。&quot; https://hooks.slack.com/services/xxx ; fi
  if [[ $line == *left\ the\ game* ]]; then echo &quot;${line:33}&quot; | slack-notify -m &quot;$(cut -d &#039; &#039; -f 1) がログアウトしました。&quot; https://hooks.slack.com/services/yyy ; fi
done;</code></pre>
<h2>動作例</h2>
<p>僕の環境では Discordに送っているので、このようになります。</p>
<p><img decoding="async" src="/wp-content/uploads/2020/02/89910b38358d76a8d22755b7f8edc910.png" alt="" /></p>
<p>ちなみに、このスクリプトを少し応用すると、死亡通知などもつけることができるようになります。</p>
<p><img decoding="async" src="/wp-content/uploads/2020/02/d14862fc9f102ea9a3c63a3ee3156edf.png" alt="" /></p>
<h2>おわりに</h2>
<p>情報系の研究室っぽく、マイクラをやる環境もどんどん便利にしていきたいですね。</p>
]]></content:encoded>
					
					<wfw:commentRss>/archives/401.html/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
