roles and updates

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

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

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

@ -15,7 +15,7 @@ class Seer(Role):
) )
def __init__(self, game): def __init__(self, game):
super().__init__() super().__init__(game)
# self.game = game # self.game = game
# self.player = None # self.player = None
# self.blocked = False # self.blocked = False
@ -63,14 +63,14 @@ class Seer(Role):
""" """
return "Village" return "Village"
async def _get_role(self, source=None): async def get_role(self, source=None):
""" """
Interaction for powerful access of role Interaction for powerful access of role
Unlikely to be able to deceive this Unlikely to be able to deceive this
""" """
return "Villager" return "Villager"
async def _see_role(self, source=None): async def see_role(self, source=None):
""" """
Interaction for investigative roles. Interaction for investigative roles.
More common to be able to deceive these roles More common to be able to deceive these roles
@ -133,9 +133,9 @@ class Seer(Role):
async def choose(self, ctx, data): async def choose(self, ctx, data):
"""Handle night actions""" """Handle night actions"""
id = int(data) target_id = int(data)
try: try:
target = self.game.players[id] target = self.game.players[target_id]
except IndexError: except IndexError:
target = None target = None
@ -143,5 +143,5 @@ class Seer(Role):
await ctx.send("Not a valid ID") await ctx.send("Not a valid ID")
return 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)) 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" return "Werewolf"
async def _get_role(self, source=None): async def get_role(self, source=None):
""" """
Interaction for powerful access of role Interaction for powerful access of role
Unlikely to be able to deceive this Unlikely to be able to deceive this
""" """
return "Werewolf" return "Werewolf"
async def _see_role(self, source=None): async def see_role(self, source=None):
""" """
Interaction for investigative roles. Interaction for investigative roles.
More common to be able to deceive these roles More common to be able to deceive these roles

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

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

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

Loading…
Cancel
Save