roles and updates

fight-fixes
bobloy 7 years ago
parent 5a79919c4d
commit cd6ea57af7

@ -1,10 +1,8 @@
import asyncio
import discord
# Import all roles here
from werewolf.roles.seer import Seer
from werewolf.roles.vanillawerewolf import VanillaWerewolf
from werewolf.roles.villager import Villager
from werewolf.roles.seer import Seer
# All roles in this list for iterating
role_list = [Villager, VanillaWerewolf]

@ -30,9 +30,10 @@ class Game:
#
# return super().__new__(cls, guild, game_code)
def __init__(self, guild, game_code):
def __init__(self, guild, role, game_code):
self.guild = guild
self.game_code = ["VanillaWerewolf"]
self.game_role = role
self.roles = []
@ -92,19 +93,26 @@ class Game:
self.roles = []
return False
if self.game_role is None:
await ctx.send("Game role not configured, cannot start")
self.roles = []
return False
await self.assign_roles()
# Create category and channel with individual overwrites
overwrite = {
self.guild.default_role: discord.PermissionOverwrite(read_messages=False, send_messages=True),
self.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True)
self.guild.default_role: discord.PermissionOverwrite(read_messages=True, send_messages=False,
add_reactions=False),
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.channel_category = await self.guild.create_category("ww-game", overwrites=overwrite, reason="New game of "
"werewolf")
for player in self.players:
overwrite[player.member] = discord.PermissionOverwrite(read_messages=True)
# for player in self.players:
# overwrite[player.member] = discord.PermissionOverwrite(read_messages=True)
self.village_channel = await self.guild.create_text_channel("Village Square",
overwrites=overwrite,
@ -582,10 +590,10 @@ class Game:
await self.dead_perms(self.village_channel, target.member)
async def get_night_target(self, target_id, source=None):
return self.players[target_id] # ToDo
return self.players[target_id] # ToDo check source
async def get_day_target(self, target_id, source=None):
return self.players[target_id] # ToDo
return self.players[target_id] # ToDo check source
async def get_roles(self, game_code=None):
if game_code is not None:
@ -621,25 +629,26 @@ class Game:
return None
async def dead_perms(self, channel, member):
await channel.set_permissions(member, read_messages=True, send_messages=False, add_reactions=False)
await channel.set_permissions(member, overwrite=None)
await member.remove_roles(*[self.game_role])
async def night_perms(self, channel):
await channel.set_permissions(self.guild.default_role, read_messages=False, send_messages=False)
await channel.set_permissions(self.game_role, read_messages=True, send_messages=False)
async def day_perms(self, channel):
await channel.set_permissions(self.guild.default_role, read_messages=False)
await channel.set_permissions(self.game_role, read_messages=True, send_messages=True)
async def speech_perms(self, channel, member, undo=False):
if undo:
await channel.set_permissions(member, read_messages=True)
await channel.set_permissions(member, overwrite=None)
else:
await channel.set_permissions(self.guild.default_role, read_messages=False, send_messages=False)
await channel.set_permissions(member, read_messages=True, send_messages=True)
await channel.set_permissions(self.game_role, read_messages=True, send_messages=False)
await channel.set_permissions(member, send_messages=True)
async def normal_perms(self, channel, member_list):
await channel.set_permissions(self.guild.default_role, read_messages=False)
for member in member_list:
await channel.set_permissions(member, read_messages=True)
await channel.set_permissions(self.game_role, read_messages=True, send_messages=True)
# for member in member_list:
# await channel.set_permissions(member, read_messages=True)
async def _check_game_over(self):
# ToDo

@ -15,7 +15,7 @@ class Seer(Role):
)
def __init__(self, game):
super().__init__()
super().__init__(game)
# self.game = game
# self.player = None
# self.blocked = False
@ -63,14 +63,14 @@ class Seer(Role):
"""
return "Village"
async def _get_role(self, source=None):
async def get_role(self, source=None):
"""
Interaction for powerful access of role
Unlikely to be able to deceive this
"""
return "Villager"
async def _see_role(self, source=None):
async def see_role(self, source=None):
"""
Interaction for investigative roles.
More common to be able to deceive these roles
@ -133,9 +133,9 @@ class Seer(Role):
async def choose(self, ctx, data):
"""Handle night actions"""
id = int(data)
target_id = int(data)
try:
target = self.game.players[id]
target = self.game.players[target_id]
except IndexError:
target = None
@ -143,5 +143,5 @@ class Seer(Role):
await ctx.send("Not a valid ID")
return
self.see_target = id
self.see_target = target_id
await ctx.send("**You will attempt to see the role of {} tonight...**".format(target.member.display_name))

@ -61,14 +61,14 @@ class VanillaWerewolf(Role):
"""
return "Werewolf"
async def _get_role(self, source=None):
async def get_role(self, source=None):
"""
Interaction for powerful access of role
Unlikely to be able to deceive this
"""
return "Werewolf"
async def _see_role(self, source=None):
async def see_role(self, source=None):
"""
Interaction for investigative roles.
More common to be able to deceive these roles

@ -14,7 +14,7 @@ class Villager(Role):
)
def __init__(self, game):
super().__init__()
super().__init__(game)
# self.game = game
# self.player = None
# self.blocked = False
@ -63,14 +63,14 @@ class Villager(Role):
"""
return "Village"
async def _get_role(self, source=None):
async def get_role(self, source=None):
"""
Interaction for powerful access of role
Unlikely to be able to deceive this
"""
return "Villager"
async def _see_role(self, source=None):
async def see_role(self, source=None):
"""
Interaction for investigative roles.
More common to be able to deceive these roles

@ -93,9 +93,9 @@ class VoteGroup:
# ToDo: Trigger deletion of votegroup
pass
async def vote(self, target, author, id):
async def vote(self, target, author, target_id):
"""
Receive vote from game
"""
self.vote_results[author.id] = id
self.vote_results[author.id] = target_id

@ -1,6 +1,7 @@
import discord
from discord.ext import commands
from redbot.core import Config
from redbot.core import RedContext
from werewolf.game import Game
@ -29,7 +30,7 @@ class Werewolf:
del game
@commands.group()
async def wwset(self, ctx: commands.Context):
async def wwset(self, ctx: RedContext):
"""
Base command to adjust settings. Check help for command list.
"""
@ -43,11 +44,11 @@ class Werewolf:
Assign the game role
This role should not be manually assigned
"""
await self.config.guild(ctx.guild).role.set(role)
await self.config.guild(ctx.guild).role.set(role.id)
await ctx.send("Game role has been set to **{}**".format(role.name))
@commands.group()
async def ww(self, ctx: commands.Context):
async def ww(self, ctx: RedContext):
"""
Base command for this cog. Check help for the commands list.
"""
@ -61,7 +62,7 @@ class Werewolf:
Create and join a new game of Werewolf
"""
game = self._get_game(ctx.guild, game_code)
game = await self._get_game(ctx.guild, game_code)
if not game:
await ctx.send("Failed to start a new game")
@ -75,7 +76,7 @@ class Werewolf:
Joins a game of Werewolf
"""
game = self._get_game(ctx.guild)
game = await self._get_game(ctx.guild)
if not game:
await ctx.send("No game to join!\nCreate a new one with `[p]ww new`")
@ -90,7 +91,7 @@ class Werewolf:
Quit a game of Werewolf
"""
game = self._get_game(ctx.guild)
game = await self._get_game(ctx.guild)
await game.quit(ctx.author, ctx.channel)
@ -100,7 +101,7 @@ class Werewolf:
"""
Checks number of players and attempts to start the game
"""
game = self._get_game(ctx.guild)
game = await self._get_game(ctx.guild)
if not game:
await ctx.send("No game running, cannot start")
@ -112,7 +113,7 @@ class Werewolf:
"""
Stops the current game
"""
game = self._get_game(ctx.guild)
game = await self._get_game(ctx.guild)
if not game:
await ctx.send("No game running, cannot stop")
@ -120,16 +121,16 @@ class Werewolf:
@commands.guild_only()
@ww.command()
async def vote(self, ctx, id: int):
async def vote(self, ctx, target_id: int):
"""
Vote for a player by ID
"""
try:
id = int(id)
target_id = int(target_id)
except:
id = None
target_id = None
if id is None:
if target_id is None:
await ctx.send("`id` must be an integer")
return
@ -144,7 +145,7 @@ class Werewolf:
# return
# else:
game = self._get_game(ctx.guild)
game = await self._get_game(ctx.guild)
if game is None:
await ctx.send("No game running, cannot vote")
@ -153,9 +154,9 @@ class Werewolf:
# Game handles response now
channel = ctx.channel
if channel == game.village_channel:
await game.vote(ctx.author, id, channel)
await game.vote(ctx.author, target_id, channel)
elif channel in (c["channel"] for c in game.p_channels.values()):
await game.vote(ctx.author, id, channel)
await game.vote(ctx.author, target_id, channel)
else:
await ctx.send("Nothing to vote for in this channel")
@ -182,14 +183,18 @@ class Werewolf:
await game.choose(ctx, data)
def _get_game(self, guild, game_code=None):
async def _get_game(self, guild, game_code=None):
if guild is None:
# Private message, can't get guild
return None
if guild.id not in self.games:
if not game_code:
return None
self.games[guild.id] = Game(guild, game_code)
role = await self.config.guild(guild).role()
role = discord.utils.get(guild.roles, id=role)
if role is None:
return None
self.games[guild.id] = Game(guild, role, game_code)
return self.games[guild.id]

Loading…
Cancel
Save