progress
This commit is contained in:
parent
e46f799d02
commit
cca219d20f
@ -26,7 +26,9 @@ class Game:
|
|||||||
|
|
||||||
day_vote_count = 3
|
day_vote_count = 3
|
||||||
|
|
||||||
def __init__(self, guild: discord.Guild, role: discord.Role, game_code=None):
|
def __init__(self, guild: discord.Guild, role: discord.Role=None,
|
||||||
|
category: discord.CategoryChannel=None, village: discord.TextChannel=None,
|
||||||
|
game_code=None):
|
||||||
self.guild = guild
|
self.guild = guild
|
||||||
self.game_code = game_code
|
self.game_code = game_code
|
||||||
self.game_role = role
|
self.game_role = role
|
||||||
@ -46,8 +48,8 @@ class Game:
|
|||||||
self.day_count = 0
|
self.day_count = 0
|
||||||
self.ongoing_vote = False
|
self.ongoing_vote = False
|
||||||
|
|
||||||
self.channel_category = None # discord.CategoryChannel
|
self.channel_category = category # discord.CategoryChannel
|
||||||
self.village_channel = None # discord.TextChannel
|
self.village_channel = village # discord.TextChannel
|
||||||
|
|
||||||
self.p_channels = {} # uses default_secret_channel
|
self.p_channels = {} # uses default_secret_channel
|
||||||
self.vote_groups = {} # ID : VoteGroup()
|
self.vote_groups = {} # ID : VoteGroup()
|
||||||
@ -93,11 +95,16 @@ class Game:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if self.game_role is None:
|
if self.game_role is None:
|
||||||
await ctx.send("Game role not configured, cannot start")
|
try:
|
||||||
self.roles = []
|
self.game_role = await ctx.guild.create_role(name="Players",
|
||||||
return False
|
hoist=True,
|
||||||
|
mentionable=True,
|
||||||
|
reason="(BOT) Werewolf game role")
|
||||||
|
except (discord.Forbidden, discord.HTTPException):
|
||||||
|
await ctx.send("Game role not configured and unable to generate one, cannot start")
|
||||||
|
self.roles = []
|
||||||
|
return False
|
||||||
|
|
||||||
self.started = True
|
|
||||||
await self.assign_roles()
|
await self.assign_roles()
|
||||||
|
|
||||||
# Create category and channel with individual overwrites
|
# Create category and channel with individual overwrites
|
||||||
@ -107,19 +114,29 @@ class Game:
|
|||||||
self.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True, add_reactions=True),
|
self.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True, add_reactions=True),
|
||||||
self.game_role: discord.PermissionOverwrite(read_messages=True, send_messages=True)
|
self.game_role: discord.PermissionOverwrite(read_messages=True, send_messages=True)
|
||||||
}
|
}
|
||||||
|
if self.channel_category is None:
|
||||||
self.channel_category = await self.guild.create_category("ww-game",
|
self.channel_category = await self.guild.create_category("ww-game",
|
||||||
overwrites=overwrite,
|
overwrites=overwrite,
|
||||||
reason="(BOT) New game of werewolf")
|
reason="(BOT) New game of werewolf")
|
||||||
|
else:
|
||||||
# for player in self.players:
|
for target, ow in overwrite.items():
|
||||||
# overwrite[player.member] = discord.PermissionOverwrite(read_messages=True)
|
await self.channel_category.set_permissions(target=target,
|
||||||
|
overwrite=ow,
|
||||||
self.village_channel = await self.guild.create_text_channel("Village Square",
|
reason="(BOT) New game of werewolf")
|
||||||
overwrites=overwrite,
|
if self.village_channel is None:
|
||||||
reason="(BOT) New game of werewolf",
|
self.village_channel = await self.guild.create_text_channel("Village Square",
|
||||||
category=self.channel_category)
|
overwrites=overwrite,
|
||||||
|
reason="(BOT) New game of werewolf",
|
||||||
|
category=self.channel_category)
|
||||||
|
else:
|
||||||
|
await self.village_channel.edit(name="Village Square",
|
||||||
|
category=self.channel_category,
|
||||||
|
reason="(BOT) New game of werewolf")
|
||||||
|
for target, ow in overwrite.items():
|
||||||
|
await self.village_channel.set_permissions(target=target,
|
||||||
|
overwrite=ow,
|
||||||
|
reason="(BOT) New game of werewolf")
|
||||||
|
self.started = True
|
||||||
# Assuming everything worked so far
|
# Assuming everything worked so far
|
||||||
print("Pre at_game_start")
|
print("Pre at_game_start")
|
||||||
await self._at_game_start() # This will queue channels and votegroups to be made
|
await self._at_game_start() # This will queue channels and votegroups to be made
|
||||||
|
@ -18,7 +18,10 @@ class Werewolf:
|
|||||||
self.config = Config.get_conf(self, identifier=87101114101119111108102, force_registration=True)
|
self.config = Config.get_conf(self, identifier=87101114101119111108102, force_registration=True)
|
||||||
default_global = {}
|
default_global = {}
|
||||||
default_guild = {
|
default_guild = {
|
||||||
"role_id": None
|
"role_id": None,
|
||||||
|
"category_id": None,
|
||||||
|
"channel_id": None,
|
||||||
|
"log_channel_id": None
|
||||||
}
|
}
|
||||||
|
|
||||||
self.config.register_global(**default_global)
|
self.config.register_global(**default_global)
|
||||||
@ -59,6 +62,38 @@ class Werewolf:
|
|||||||
await self.config.guild(ctx.guild).role_id.set(role.id)
|
await self.config.guild(ctx.guild).role_id.set(role.id)
|
||||||
await ctx.send("Game role has been set to **{}**".format(role.name))
|
await ctx.send("Game role has been set to **{}**".format(role.name))
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@wwset.command(name="category")
|
||||||
|
async def wwset_category(self, ctx: RedContext, category_id):
|
||||||
|
"""
|
||||||
|
Assign the channel category
|
||||||
|
"""
|
||||||
|
|
||||||
|
category = discord.utils.get(ctx.guild.categories, id=int(category_id))
|
||||||
|
if category is None:
|
||||||
|
await ctx.send("Category not found")
|
||||||
|
return
|
||||||
|
await self.config.guild(ctx.guild).category_id.set(category.id)
|
||||||
|
await ctx.send("Channel Category has been set to **{}**".format(category.name))
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@wwset.command(name="channel")
|
||||||
|
async def wwset_channel(self, ctx: RedContext, channel: discord.TextChannel):
|
||||||
|
"""
|
||||||
|
Assign the village channel
|
||||||
|
"""
|
||||||
|
await self.config.guild(ctx.guild).channel_id.set(channel.id)
|
||||||
|
await ctx.send("Game Channel has been set to **{}**".format(channel.mention))
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@wwset.command(name="logchannel")
|
||||||
|
async def wwset_channel(self, ctx: RedContext, channel: discord.TextChannel):
|
||||||
|
"""
|
||||||
|
Assign the log channel
|
||||||
|
"""
|
||||||
|
await self.config.guild(ctx.guild).log_channel_id.set(channel.id)
|
||||||
|
await ctx.send("Log Channel has been set to **{}**".format(channel.mention))
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
async def ww(self, ctx: RedContext):
|
async def ww(self, ctx: RedContext):
|
||||||
"""
|
"""
|
||||||
@ -221,11 +256,29 @@ class Werewolf:
|
|||||||
return None
|
return None
|
||||||
if ctx.guild.id not in self.games or self.games[ctx.guild.id].game_over:
|
if ctx.guild.id not in self.games or self.games[ctx.guild.id].game_over:
|
||||||
await ctx.send("Starting a new game...")
|
await ctx.send("Starting a new game...")
|
||||||
|
role = None
|
||||||
|
category = None
|
||||||
|
channel = None
|
||||||
|
log_channel = None
|
||||||
|
|
||||||
role_id = await self.config.guild(ctx.guild).role_id()
|
role_id = await self.config.guild(ctx.guild).role_id()
|
||||||
role = discord.utils.get(ctx.guild.roles, id=role_id)
|
category_id = await self.config.guild(ctx.guild).category_id()
|
||||||
if role is None:
|
channel_id = await self.config.guild(ctx.guild).channel_id()
|
||||||
await ctx.send("Game role is invalid, cannot start new game")
|
log_channel_id = await self.config.guild(ctx.guild).log_channel_id()
|
||||||
return None
|
|
||||||
|
if role_id is not None:
|
||||||
|
role = discord.utils.get(ctx.guild.roles, id=role_id)
|
||||||
|
if role is None:
|
||||||
|
await ctx.send("Game role is invalid, cannot start new game")
|
||||||
|
return None
|
||||||
|
if category_id is not None:
|
||||||
|
category = discord.utils.get(ctx.guild.categories, id=category_id)
|
||||||
|
if role is None:
|
||||||
|
await ctx.send("Game role is invalid, cannot start new game")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.games[ctx.guild.id] = Game(ctx.guild, role, game_code)
|
self.games[ctx.guild.id] = Game(ctx.guild, role, game_code)
|
||||||
|
|
||||||
return self.games[ctx.guild.id]
|
return self.games[ctx.guild.id]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user