dnh-bot / dnh-werewolf-bot

DNH Werewolf Discord bot
The Unlicense
10 stars 7 forks source link
discord-bot werewolf-game

DNH Werewolf bot (Bot Ma Sói, Thỏ và Sói).

This is a Discord bot for hosting Werewolf game (Ma Sói, Thỏ và Sói). This bot is created and contributed by DNH members

The game will automatically run without a human hoster. More fun!

Original making for Vietnamese player but able to port to any language.

Setup running environment

Require python >= 3.9 Please note that this repo use Python 3.9 features, so it cannot run on python3.7

Install dependency packages:

python3.9 -m pip install -r requirements.txt

It's also possible to use pyenv if you want to install this independently.

Setup .env file

cp .env.example .env

Change the fill in the Mandatory fields:

# Mandatory fields
BOT_PREFIX=!         =====> For use command in game like `!join` `!vote`
BOT_NAME=EXAMPLE_BOT   =====> Your bot name, not important
GAME_CATEGORY=GAME     =====> The bot will create a new Category channel in your discord server

DISCORD_TOKEN=ODgx**********************.YSsNGw.ya5O**********************.   ===> Replace this by your own Bot token, generated in https://discord.com/developers/applications/<your_bot_id>/oauth2/general 
DISCORD_DEPLOY_SERVER_ID=881**************     ====> right click on your Discord server and copy the server id.

Right Click to copy ServerID:

Alt text

Deployment

Create and add Bot to Discord server

Follow guide to create a new Discord bot and how to add it into your Discord server: https://discordpy.readthedocs.io/en/stable/discord.html

Note: You may need Priviledged Gateway Intents permissions to get the bot work properly due to Discord bug Alt text

You need to set bot's permission to allow it to create channel and run game.

In OAuth2 tab, choose bot in Scopes, then choose Adminstrator permission.

Alt text

Run bot

Simply run:

python3.9 bot.py

The bot should connect to your Discord server and online:

Alt text

Create Admin and Members roles

You MUST create these Admin role and Members role to play the game.

Note that you do not need to provide Admin and Members any permission. The bot will provide proper permission for them under GAME_CATEGORY.

Follow this guide to create and assign roles: https://www.howtogeek.com/809671/how-to-add-assign-roles-discord/

Create GAME_CATEGORY

Assign you as Admin role. Then run this command: !fcreate @bot_name where @bot_name tag your bot display name in your server

Alt text

if your bot can read the message, then it will automatically create a new category channel like:

Alt text

If you want to be a normal player, you can safely remove your Admin role now and enjoy the game.

Useful commands:

!version  
!help
!help cmd vote
!help role cupid

Alt text

Game story

Vietnamese version

English version: TODO

You can custom langauge under ./json directory.

Gameplay

User can join game via !join command or !f_join by Admin:

Alt text

Then players vote to start game via !start command. After if the votes are greater than half of players, the game will be started:

Alt text

Each player will have a personal channel, where they can cast spell or sleep :D

Alt text

Players can discuss, !vote for werewolf.

Alt text

Player who is killed by werewolf/witch or is voted to die will be sent to cemetery channel:

Alt text

But don't worry, you have chance to reborn :D (witch,zombie roles)

The game includes 2 phases every game day time:

The game will be ended if all werewolves are eliminated (villager win) or number of werewolves greater or equal number of villagers (werewolves win).

Alt text

Leaderboard saves endgame result every game.

Enjoy!

Test

python3 test.py

Sample successful output:

successfully loaded json/command_info.json
successfully loaded json/text_template.json
successfully loaded json/role_info.json
reset_game_state

# Code standard
We apply Autopep8 for this project.
Please run `./format.sh` before creating new PR.

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
====== Begin test case at testcases/case-witch-reborn-wolf.json =====
...
<Many lines hidden here>
...
reset_game_state
#lobby: Trò chơi đã kết thúc.
gameplay created!
====== End test case =====

FINISH ALL TEST CASES SUCCESSFULLY

Tips: you can reduce the TEST_THREAD_DELAY_TIME for faster run

How to run bot on free deployment service

As usual, free deployment services have certain limitations, typically after a period of inactivity, your bot may go to sleep and all data will be lost.

To address this issue, please follow these steps:

  1. Install necessary packages in web/requirements.txt
  2. Use the keep_alive() function in bot.py. Now we have our website running together.
  3. Link your web URL to UptimeRobot (or anything related), please see below references. https://uptimerobot.com/ https://dev.to/12944qwerty/hosting-a-discord-py-bot-with-repl-it-3l5a

Explanation: Your bot will be alive because the monitoring services request(ping) every 5-10 minutes and keeps our website running up.

Alternatives: Some deployment services may block request from UptimeRobot, please consider others website: https://www.fastcron.com/ https://cron-job.org/en/ https://uptime.com/ https://uptime-monitor.io/

How to use Gist Github as a database

Currently, data can be stored in local json files or in Github Gist files To use the Gist, please follow these steps:

  1. Create a personal access token Recommended: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access- token Or: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic

  2. Create a personal Gist (private or public) with the same filename as the local json, please be aware that a gist can include multiple files

Important note: Gist file and local json file must have the same name to ensure synchronization

  1. Add GITHUB_GIST_TOKEN and GITHUB_GIST_ID_URL to the .env file. Please see .env.example for more details. If Gist is not used, you MUST NOT include those variables

Known issue

Library bug

A library bug while adding member to gameplay channel if using discord.py==2.2.2

Prefer to use discord.py==1.7.3

Game Rules

Vietnamese

STORY_VN.md

Contact

It's open source and free to use Discord bot.

Don't hesitate to contact us for guiding setup. Discord chat group: https://discord.gg/ceJAgPEMCw

Contributors