Skip to content

ゲームサーバーをdiscord slash commandから起動するためのBOT

Notifications You must be signed in to change notification settings

ilovejikkenjisshu/ILJJ-Mk-XVII

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game Server Slash Command BOT

ゲームサーバーの「起動/終了/再起動/状態確認」を実行できるdiscordbot

Slash Command

/gssc [command] [game]

commandには実行されるコマンドを記述します。

command 実行される内容
start サーバーを起動 /gssc start valheim
stop サーバーを終了 /gssc stop valheim
restart サーバーを再起動 /gssc restart valheim
status サーバーの状態 /gssc status valheim
list サーバーの一覧表示 /gssc list

gameには起動するゲームサーバーのaliasを記述します。

Game Server Settings

以下のようなjson形式で記述し、game_servers.jsonとしてGCP上のBUCKEt_NAMEバケットに配置します。

{
  "valheim": {
    "name": "Valheim",
    "instance_name": "gcp insrance name",
    "zone": "asia-northeast1-b"
  },
  "minecraft-vanila": {
    "name": "Minecraft Vanila",
    "instance_name": "gcp insrance name",
    "zone": "asia-northeast1-b"
  }
}

Setup Guide

1. Create Discord Application

Using discord developers.

2. GCP Settings

REGION=asia-northeast1
BUCKET_NAME=your-bucket-name
POOL_ID=your-pool-id
PROVIDER_ID=your-provider-id
gcloud init
gsutil mb -b on -c standard -l ${REGION} gs://${BUCKET_NAME}
gcloud services enable iamcredentials.googleapis.com
gcloud iam service-accounts create terraform --display-name="terraform"
# Service Accountに必要な権限を付与: Storage Object Admin, Cloud Functions Admin
SERVICE_ACCOUNT_EMAIL=your-service-account-email
GITHUB_REPOSITORY="github-user-name/github-repository-name"
PROJECT_NUMBER=$(gcloud projects list --format="table(projectNumber,projectId)" | grep $(gcloud config get-value project) | cut -d ' ' -f1)
gcloud iam workload-identity-pools create ${POOL_ID} --loation="global" --description="gssc-pool"
gcloud iam workload-identity-pools providers create-oidc ${PROVIDER_ID} \
  --location="global" \
  --workload-identity-pool=${POOL_ID} \
  --attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository,attribute.actor=assertion.actor" \
  --issuer-uri="https://token.actions.githubusercontent.com"
gcloud iam service-accounts add-iam-policy-binding \
  "${SERVICE_ACCOUNT_EMAIL}" \
  --role="roles/iam.workloadIdentityUser" \
  --member="principalSet://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/${POOL_ID}/subject/attribute.repository/${GITHUB_REPOSITORY}"

コマンドでうまく行かない場合、 GitHub Actions で OIDC を使用して GCP 認証を行う を見て、ポチポチしてください。

3. Github Actinos Settings

Variables

Name Value
PROJECT_ID GCP Project Number
POOL_ID GCP Pool ID
PROVIDER_ID GCP Provider ID
SERVICE_ACCOUNT_EMAIL GCP Service Account Email
REGION GCP Region
BUCKET_NAME GCP Bucket Name
DISCORD_BOT_ID Discord Bot ID
CLIENT_PUBLIC_KEY Discord Bot Public Key

Secrets

Name Value
DISCORD_TOKEN Discord Bot Token
DISCORD_GUILD Discord Guild ID

参考情報

About

ゲームサーバーをdiscord slash commandから起動するためのBOT

Resources

Stars

Watchers

Forks