You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.5 KiB
100 lines
2.5 KiB
7 years ago
|
import asyncio
|
||
|
|
||
|
import discord
|
||
|
from discord.ext import commands
|
||
|
|
||
|
from redbot.core import Config
|
||
|
|
||
7 years ago
|
from datetime import datetime, timedelta
|
||
7 years ago
|
|
||
|
from .game import Game
|
||
|
|
||
7 years ago
|
|
||
7 years ago
|
class Werewolf:
|
||
|
"""
|
||
7 years ago
|
Base to host werewolf on a guild
|
||
7 years ago
|
"""
|
||
|
|
||
|
def __init__(self, bot):
|
||
|
self.bot = bot
|
||
|
self.config = Config.get_conf(self, identifier=87101114101119111108102, force_registration=True)
|
||
|
default_global = {}
|
||
|
default_guild = {
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
self.config.register_global(**default_global)
|
||
|
self.config.register_guild(**default_guild)
|
||
|
|
||
7 years ago
|
self.games = {} # Active games stored here, id is per guild
|
||
7 years ago
|
|
||
|
@commands.group()
|
||
|
async def ww(self, ctx: commands.Context):
|
||
|
"""
|
||
|
Base command for this cog. Check help for the commands list.
|
||
|
"""
|
||
|
if ctx.invoked_subcommand is None:
|
||
|
await ctx.send_help()
|
||
7 years ago
|
|
||
7 years ago
|
@ww.command()
|
||
7 years ago
|
async def new(self, ctx, game_code):
|
||
7 years ago
|
"""
|
||
7 years ago
|
Create and join a new game of Werewolf
|
||
7 years ago
|
"""
|
||
|
|
||
7 years ago
|
game = self._get_game(ctx.guild, game_code)
|
||
7 years ago
|
|
||
7 years ago
|
if not game:
|
||
7 years ago
|
ctx.send("Failed to start a new game")
|
||
7 years ago
|
|
||
|
@ww.command()
|
||
|
async def join(self, ctx):
|
||
|
"""
|
||
|
Joins a game of Werewolf
|
||
|
"""
|
||
|
|
||
|
game = self._get_game(ctx.guild)
|
||
|
|
||
|
if not game:
|
||
|
ctx.send("No game to join!\nCreate a new one with `[p]ww new`")
|
||
7 years ago
|
return
|
||
|
|
||
7 years ago
|
await game.join(ctx.author, ctx.channel)
|
||
|
|
||
7 years ago
|
@ww.command()
|
||
|
async def quit(self, ctx):
|
||
|
"""
|
||
|
Quit a game of Werewolf
|
||
|
"""
|
||
|
|
||
7 years ago
|
game = self._get_game(ctx.guild)
|
||
7 years ago
|
|
||
7 years ago
|
await game.quit(ctx.author, ctx.channel)
|
||
|
|
||
|
@ww.command()
|
||
|
async def vote(self, ctx, id):
|
||
|
"""
|
||
|
Vote for a player by ID
|
||
|
"""
|
||
|
game = self._get_game(guild)
|
||
|
if not game:
|
||
|
ctx.send("No game running, cannot vote")
|
||
7 years ago
|
|
||
7 years ago
|
# Game handles response now
|
||
|
channel = ctx.channel
|
||
|
if channel is game.village_channel:
|
||
|
await game.vote(ctx.author, id, channel)
|
||
|
|
||
7 years ago
|
if channel in (c["channel"] for c in game.p_channels.values()):
|
||
7 years ago
|
await game.vote(ctx.author, id, channel)
|
||
7 years ago
|
|
||
7 years ago
|
def _get_game(self, guild, game_code=None):
|
||
7 years ago
|
if guild.id not in self.games:
|
||
7 years ago
|
if not game_code:
|
||
7 years ago
|
return None
|
||
7 years ago
|
self.games[guild.id] = Game(guild, game_code)
|
||
7 years ago
|
|
||
7 years ago
|
return self.games[guild.id]
|
||
7 years ago
|
|
||
|
async def _game_start(self, game):
|
||
|
await game.start()
|