parent
38f5246679
commit
0ed0891f60
@ -0,0 +1,60 @@
|
||||
import asyncio
|
||||
|
||||
import discord
|
||||
|
||||
from datetime import datetime,timedelta
|
||||
|
||||
from .builder import parse_code
|
||||
|
||||
class Game:
|
||||
"""
|
||||
Base to host a game of werewolf
|
||||
"""
|
||||
|
||||
def __init__(self, role_code=None):
|
||||
self.roles = []
|
||||
self.role_code = role_code
|
||||
|
||||
if self.role_code:
|
||||
self.get_roles()
|
||||
|
||||
self.players = []
|
||||
self.start_vote = 0
|
||||
|
||||
self.started = False
|
||||
|
||||
async def setup(self, ctx):
|
||||
"""
|
||||
Runs the initial setup
|
||||
"""
|
||||
if self.role_code:
|
||||
if not await self.get_roles():
|
||||
|
||||
if not self.roles:
|
||||
ctx.send("No game code set, cannot start until this is set")
|
||||
|
||||
async def join(self, member: discord.Member):
|
||||
"""
|
||||
Joins a game
|
||||
"""
|
||||
if self.started:
|
||||
return "**Game has already started!**"
|
||||
|
||||
if member in self.players:
|
||||
return "{} is already in the game!".format(member.mention)
|
||||
|
||||
self.started.append(member)
|
||||
|
||||
return "{} has been added to the game, total players is **{}**".format(member.mention, len(self.players))
|
||||
|
||||
async def get_roles(self, role_code=None):
|
||||
if role_code:
|
||||
self.role_code=role_code
|
||||
|
||||
if not self.role_code:
|
||||
return False
|
||||
|
||||
self.roles = await parse_code(self.role_code)
|
||||
|
||||
if not self.roles:
|
||||
return False
|
@ -0,0 +1,32 @@
|
||||
import asyncio
|
||||
|
||||
import discord
|
||||
|
||||
from datetime import datetime,timedelta
|
||||
|
||||
class Player:
|
||||
"""
|
||||
Base to host a game of werewolf
|
||||
"""
|
||||
|
||||
def __init__(self, member: discord.Member):
|
||||
self.user = member
|
||||
self.role = None
|
||||
self.alive = True
|
||||
self.muted = False
|
||||
|
||||
|
||||
async def assign_role(self, role):
|
||||
"""
|
||||
Base command for this cog. Check help for the commands list.
|
||||
"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
|
||||
async def join(self, ctx: commands.Context):
|
||||
"""
|
||||
Joins a game
|
||||
"""
|
||||
|
||||
await self.config.guild(ctx.guild).days.set(days)
|
||||
await ctx.send("Success")
|
@ -0,0 +1,82 @@
|
||||
import asyncio
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
from redbot.core import Config
|
||||
|
||||
from datetime import datetime,timedelta
|
||||
|
||||
from .game import Game
|
||||
|
||||
class Werewolf:
|
||||
"""
|
||||
Base to host a game of werewolf
|
||||
"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.config = Config.get_conf(self, identifier=87101114101119111108102, force_registration=True)
|
||||
default_global = {}
|
||||
default_guild = {
|
||||
}
|
||||
|
||||
|
||||
self.config.register_global(**default_global)
|
||||
self.config.register_guild(**default_guild)
|
||||
|
||||
self.games = {} # Active games stored here, id is per server
|
||||
|
||||
@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()
|
||||
|
||||
@ww.command()
|
||||
async def join(self, ctx, setup_id=None):
|
||||
"""
|
||||
Joins a game of Werewolf or start a new one
|
||||
"""
|
||||
|
||||
game = self._get_game(ctx, setup_id)
|
||||
out = await game.join(ctx.author)
|
||||
|
||||
ctx.send(out)
|
||||
|
||||
@ww.command()
|
||||
async def quit(self, ctx):
|
||||
"""
|
||||
Quit a game of Werewolf
|
||||
"""
|
||||
|
||||
game = self._get_game(ctx)
|
||||
|
||||
out = await game.quit(ctx.author)
|
||||
|
||||
ctx.send(out)
|
||||
|
||||
@ww.command()
|
||||
async def start(self, ctx):
|
||||
"""
|
||||
Vote to start a game of Werewolf
|
||||
"""
|
||||
|
||||
game = self._get_game(ctx)
|
||||
|
||||
out = await game.start_vote(ctx.author)
|
||||
|
||||
ctx.send(out)
|
||||
|
||||
def _get_game(self, ctx, setup):
|
||||
if ctx.guild.id not in self.games:
|
||||
self.games[ctx.guild.id] = Game()
|
||||
|
||||
return self.games[ctx.guild.id]
|
||||
|
||||
|
||||
async def _game_start(self, game):
|
||||
await game.start()
|
||||
|
@ -0,0 +1,5 @@
|
||||
from .werewolf import Werewolf
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Werewolf(bot))
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"author" : ["Bobloy"],
|
||||
"bot_version" : [3,0,0],
|
||||
"description" : "Customizable Werewolf Game",
|
||||
"hidden" : false,
|
||||
"install_msg" : "Thank you for installing Werewolf! Use [p]wwset to run inital setup",
|
||||
"requirements" : [],
|
||||
"short" : "Werewolf Game",
|
||||
"tags" : ["fun", "game", "bobloy"]
|
||||
}
|
Loading…
Reference in new issue