|
|
@ -1,17 +1,31 @@
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from typing import List, Union
|
|
|
|
|
|
|
|
|
|
|
|
import discord
|
|
|
|
import discord
|
|
|
|
from redbot.core import Config, checks, commands
|
|
|
|
from redbot.core import Config, checks, commands
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
from redbot.core.commands import Cog
|
|
|
|
from redbot.core.commands import Cog
|
|
|
|
|
|
|
|
from redbot.core.utils import AsyncIter
|
|
|
|
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
|
|
|
|
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
|
|
|
|
|
|
|
|
|
|
|
|
from .builder import (
|
|
|
|
from werewolf.builder import (
|
|
|
|
GameBuilder,
|
|
|
|
GameBuilder,
|
|
|
|
role_from_alignment,
|
|
|
|
role_from_alignment,
|
|
|
|
role_from_category,
|
|
|
|
role_from_category,
|
|
|
|
role_from_id,
|
|
|
|
role_from_id,
|
|
|
|
role_from_name,
|
|
|
|
role_from_name,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from .game import Game
|
|
|
|
from werewolf.game import Game
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger("red.fox_v3.werewolf")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def anyone_has_role(
|
|
|
|
|
|
|
|
member_list: List[discord.Member], role: discord.Role
|
|
|
|
|
|
|
|
) -> Union[None, discord.Member]:
|
|
|
|
|
|
|
|
return await AsyncIter(member_list).find(
|
|
|
|
|
|
|
|
lambda m: AsyncIter(m.roles).find(lambda r: r.id == role.id)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Werewolf(Cog):
|
|
|
|
class Werewolf(Cog):
|
|
|
@ -43,7 +57,7 @@ class Werewolf(Cog):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def __unload(self):
|
|
|
|
def __unload(self):
|
|
|
|
print("Unload called")
|
|
|
|
log.debug("Unload called")
|
|
|
|
for game in self.games.values():
|
|
|
|
for game in self.games.values():
|
|
|
|
del game
|
|
|
|
del game
|
|
|
|
|
|
|
|
|
|
|
@ -58,9 +72,9 @@ class Werewolf(Cog):
|
|
|
|
code = await gb.build_game(ctx)
|
|
|
|
code = await gb.build_game(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
if code != "":
|
|
|
|
if code != "":
|
|
|
|
await ctx.send("Your game code is **{}**".format(code))
|
|
|
|
await ctx.maybe_send_embed(f"Your game code is **{code}**")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("No code generated")
|
|
|
|
await ctx.maybe_send_embed("No code generated")
|
|
|
|
|
|
|
|
|
|
|
|
@checks.guildowner()
|
|
|
|
@checks.guildowner()
|
|
|
|
@commands.group()
|
|
|
|
@commands.group()
|
|
|
@ -77,31 +91,36 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Lists current guild settings
|
|
|
|
Lists current guild settings
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
success, role, category, channel, log_channel = await self._get_settings(ctx)
|
|
|
|
valid, role, category, channel, log_channel = await self._get_settings(ctx)
|
|
|
|
if not success:
|
|
|
|
# if not valid:
|
|
|
|
await ctx.send("Failed to get settings")
|
|
|
|
# await ctx.send("Failed to get settings")
|
|
|
|
return None
|
|
|
|
# return None
|
|
|
|
|
|
|
|
|
|
|
|
embed = discord.Embed(title="Current Guild Settings")
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
|
|
|
title="Current Guild Settings",
|
|
|
|
|
|
|
|
description=f"Valid: {valid}",
|
|
|
|
|
|
|
|
color=0x008000 if valid else 0xFF0000,
|
|
|
|
|
|
|
|
)
|
|
|
|
embed.add_field(name="Role", value=str(role))
|
|
|
|
embed.add_field(name="Role", value=str(role))
|
|
|
|
embed.add_field(name="Category", value=str(category))
|
|
|
|
embed.add_field(name="Category", value=str(category))
|
|
|
|
embed.add_field(name="Channel", value=str(channel))
|
|
|
|
embed.add_field(name="Channel", value=str(channel))
|
|
|
|
embed.add_field(name="Log Channel", value=str(log_channel))
|
|
|
|
embed.add_field(name="Log Channel", value=str(log_channel))
|
|
|
|
|
|
|
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@wwset.command(name="role")
|
|
|
|
@wwset.command(name="role")
|
|
|
|
async def wwset_role(self, ctx: commands.Context, role: discord.Role = None):
|
|
|
|
async def wwset_role(self, ctx: commands.Context, role: discord.Role = None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Assign the game role
|
|
|
|
Set the game role
|
|
|
|
This role should not be manually assigned
|
|
|
|
This role should not be manually assigned
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if role is None:
|
|
|
|
if role is None:
|
|
|
|
await self.config.guild(ctx.guild).role_id.set(None)
|
|
|
|
await self.config.guild(ctx.guild).role_id.set(None)
|
|
|
|
await ctx.send("Cleared Game Role")
|
|
|
|
await ctx.maybe_send_embed("Cleared Game Role")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
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.maybe_send_embed("Game Role has been set to **{}**".format(role.name))
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@wwset.command(name="category")
|
|
|
|
@wwset.command(name="category")
|
|
|
@ -111,14 +130,16 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if category_id is None:
|
|
|
|
if category_id is None:
|
|
|
|
await self.config.guild(ctx.guild).category_id.set(None)
|
|
|
|
await self.config.guild(ctx.guild).category_id.set(None)
|
|
|
|
await ctx.send("Cleared Game Channel Category")
|
|
|
|
await ctx.maybe_send_embed("Cleared Game Channel Category")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
category = discord.utils.get(ctx.guild.categories, id=int(category_id))
|
|
|
|
category = discord.utils.get(ctx.guild.categories, id=int(category_id))
|
|
|
|
if category is None:
|
|
|
|
if category is None:
|
|
|
|
await ctx.send("Category not found")
|
|
|
|
await ctx.maybe_send_embed("Category not found")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
await self.config.guild(ctx.guild).category_id.set(category.id)
|
|
|
|
await self.config.guild(ctx.guild).category_id.set(category.id)
|
|
|
|
await ctx.send("Game Channel Category has been set to **{}**".format(category.name))
|
|
|
|
await ctx.maybe_send_embed(
|
|
|
|
|
|
|
|
"Game Channel Category has been set to **{}**".format(category.name)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@wwset.command(name="channel")
|
|
|
|
@wwset.command(name="channel")
|
|
|
@ -128,10 +149,12 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if channel is None:
|
|
|
|
if channel is None:
|
|
|
|
await self.config.guild(ctx.guild).channel_id.set(None)
|
|
|
|
await self.config.guild(ctx.guild).channel_id.set(None)
|
|
|
|
await ctx.send("Cleared Game Channel")
|
|
|
|
await ctx.maybe_send_embed("Cleared Game Channel")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await self.config.guild(ctx.guild).channel_id.set(channel.id)
|
|
|
|
await self.config.guild(ctx.guild).channel_id.set(channel.id)
|
|
|
|
await ctx.send("Game Channel has been set to **{}**".format(channel.mention))
|
|
|
|
await ctx.maybe_send_embed(
|
|
|
|
|
|
|
|
"Game Channel has been set to **{}**".format(channel.mention)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@wwset.command(name="logchannel")
|
|
|
|
@wwset.command(name="logchannel")
|
|
|
@ -141,10 +164,12 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if channel is None:
|
|
|
|
if channel is None:
|
|
|
|
await self.config.guild(ctx.guild).log_channel_id.set(None)
|
|
|
|
await self.config.guild(ctx.guild).log_channel_id.set(None)
|
|
|
|
await ctx.send("Cleared Game Log Channel")
|
|
|
|
await ctx.maybe_send_embed("Cleared Game Log Channel")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await self.config.guild(ctx.guild).log_channel_id.set(channel.id)
|
|
|
|
await self.config.guild(ctx.guild).log_channel_id.set(channel.id)
|
|
|
|
await ctx.send("Game Log Channel has been set to **{}**".format(channel.mention))
|
|
|
|
await ctx.maybe_send_embed(
|
|
|
|
|
|
|
|
"Game Log Channel has been set to **{}**".format(channel.mention)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@commands.group()
|
|
|
|
@commands.group()
|
|
|
|
async def ww(self, ctx: commands.Context):
|
|
|
|
async def ww(self, ctx: commands.Context):
|
|
|
@ -162,9 +187,9 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
game = await self._get_game(ctx, game_code)
|
|
|
|
game = await self._get_game(ctx, game_code)
|
|
|
|
if not game:
|
|
|
|
if not game:
|
|
|
|
await ctx.send("Failed to start a new game")
|
|
|
|
await ctx.maybe_send_embed("Failed to start a new game")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("Game is ready to join! Use `[p]ww join`")
|
|
|
|
await ctx.maybe_send_embed("Game is ready to join! Use `[p]ww join`")
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@ww.command(name="join")
|
|
|
|
@ww.command(name="join")
|
|
|
@ -173,28 +198,49 @@ class Werewolf(Cog):
|
|
|
|
Joins a game of Werewolf
|
|
|
|
Joins a game of Werewolf
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game: Game = await self._get_game(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
if not game:
|
|
|
|
if not game:
|
|
|
|
await ctx.send("No game to join!\nCreate a new one with `[p]ww new`")
|
|
|
|
await ctx.maybe_send_embed("Failed to join a game!")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
await game.join(ctx.author, ctx.channel)
|
|
|
|
await game.join(ctx, ctx.author)
|
|
|
|
|
|
|
|
await ctx.tick()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
|
|
|
|
@commands.admin()
|
|
|
|
|
|
|
|
@ww.command(name="forcejoin")
|
|
|
|
|
|
|
|
async def ww_forcejoin(self, ctx: commands.Context, target: discord.Member):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Force someone to join a game of Werewolf
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
game: Game = await self._get_game(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not game:
|
|
|
|
|
|
|
|
await ctx.maybe_send_embed("Failed to join a game!")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await game.join(ctx, target)
|
|
|
|
|
|
|
|
await ctx.tick()
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@ww.command(name="code")
|
|
|
|
@ww.command(name="code")
|
|
|
|
async def ww_code(self, ctx: commands.Context, code):
|
|
|
|
async def ww_code(self, ctx: commands.Context, code):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Adjust game code
|
|
|
|
Adjusts the game code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See `[p]buildgame` to generate a new code
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
if not game:
|
|
|
|
if not game:
|
|
|
|
await ctx.send("No game to join!\nCreate a new one with `[p]ww new`")
|
|
|
|
await ctx.maybe_send_embed("No game to join!\nCreate a new one with `[p]ww new`")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
await game.set_code(ctx, code)
|
|
|
|
await game.set_code(ctx, code)
|
|
|
|
|
|
|
|
await ctx.tick()
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@ww.command(name="quit")
|
|
|
|
@ww.command(name="quit")
|
|
|
@ -206,6 +252,7 @@ class Werewolf(Cog):
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
await game.quit(ctx.author, ctx.channel)
|
|
|
|
await game.quit(ctx.author, ctx.channel)
|
|
|
|
|
|
|
|
await ctx.tick()
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@ww.command(name="start")
|
|
|
|
@ww.command(name="start")
|
|
|
@ -215,10 +262,12 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
if not game:
|
|
|
|
if not game:
|
|
|
|
await ctx.send("No game running, cannot start")
|
|
|
|
await ctx.maybe_send_embed("No game running, cannot start")
|
|
|
|
|
|
|
|
|
|
|
|
if not await game.setup(ctx):
|
|
|
|
if not await game.setup(ctx):
|
|
|
|
pass # Do something?
|
|
|
|
pass # ToDo something?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await ctx.tick()
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@ww.command(name="stop")
|
|
|
|
@ww.command(name="stop")
|
|
|
@ -226,17 +275,18 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Stops the current game
|
|
|
|
Stops the current game
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if ctx.guild is None:
|
|
|
|
# if ctx.guild is None:
|
|
|
|
# Private message, can't get guild
|
|
|
|
# # Private message, can't get guild
|
|
|
|
await ctx.send("Cannot start game from PM!")
|
|
|
|
# await ctx.send("Cannot stop game from PM!")
|
|
|
|
return
|
|
|
|
# return
|
|
|
|
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("No game to stop")
|
|
|
|
await ctx.maybe_send_embed("No game to stop")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game.game_over = True
|
|
|
|
game.game_over = True
|
|
|
|
await ctx.send("Game has been stopped")
|
|
|
|
game.current_action.cancel()
|
|
|
|
|
|
|
|
await ctx.maybe_send_embed("Game has been stopped")
|
|
|
|
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.guild_only()
|
|
|
|
@ww.command(name="vote")
|
|
|
|
@ww.command(name="vote")
|
|
|
@ -250,7 +300,7 @@ class Werewolf(Cog):
|
|
|
|
target_id = None
|
|
|
|
target_id = None
|
|
|
|
|
|
|
|
|
|
|
|
if target_id is None:
|
|
|
|
if target_id is None:
|
|
|
|
await ctx.send("`id` must be an integer")
|
|
|
|
await ctx.maybe_send_embed("`id` must be an integer")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# if ctx.guild is None:
|
|
|
|
# if ctx.guild is None:
|
|
|
@ -267,7 +317,7 @@ class Werewolf(Cog):
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
game = await self._get_game(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
if game is None:
|
|
|
|
if game is None:
|
|
|
|
await ctx.send("No game running, cannot vote")
|
|
|
|
await ctx.maybe_send_embed("No game running, cannot vote")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Game handles response now
|
|
|
|
# Game handles response now
|
|
|
@ -277,7 +327,7 @@ class Werewolf(Cog):
|
|
|
|
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, target_id, channel)
|
|
|
|
await game.vote(ctx.author, target_id, channel)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("Nothing to vote for in this channel")
|
|
|
|
await ctx.maybe_send_embed("Nothing to vote for in this channel")
|
|
|
|
|
|
|
|
|
|
|
|
@ww.command(name="choose")
|
|
|
|
@ww.command(name="choose")
|
|
|
|
async def ww_choose(self, ctx: commands.Context, data):
|
|
|
|
async def ww_choose(self, ctx: commands.Context, data):
|
|
|
@ -288,7 +338,7 @@ class Werewolf(Cog):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.guild is not None:
|
|
|
|
if ctx.guild is not None:
|
|
|
|
await ctx.send("This action is only available in DM's")
|
|
|
|
await ctx.maybe_send_embed("This action is only available in DM's")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
# DM nonsense, find their game
|
|
|
|
# DM nonsense, find their game
|
|
|
|
# If multiple games, panic
|
|
|
|
# If multiple games, panic
|
|
|
@ -296,7 +346,7 @@ class Werewolf(Cog):
|
|
|
|
if await game.get_player_by_member(ctx.author):
|
|
|
|
if await game.get_player_by_member(ctx.author):
|
|
|
|
break # game = game
|
|
|
|
break # game = game
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("You're not part of any werewolf game")
|
|
|
|
await ctx.maybe_send_embed("You're not part of any werewolf game")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
await game.choose(ctx, data)
|
|
|
|
await game.choose(ctx, data)
|
|
|
@ -317,7 +367,7 @@ class Werewolf(Cog):
|
|
|
|
if from_name:
|
|
|
|
if from_name:
|
|
|
|
await menu(ctx, from_name, DEFAULT_CONTROLS)
|
|
|
|
await menu(ctx, from_name, DEFAULT_CONTROLS)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("No roles containing that name were found")
|
|
|
|
await ctx.maybe_send_embed("No roles containing that name were found")
|
|
|
|
|
|
|
|
|
|
|
|
@ww_search.command(name="alignment")
|
|
|
|
@ww_search.command(name="alignment")
|
|
|
|
async def ww_search_alignment(self, ctx: commands.Context, alignment: int):
|
|
|
|
async def ww_search_alignment(self, ctx: commands.Context, alignment: int):
|
|
|
@ -327,7 +377,7 @@ class Werewolf(Cog):
|
|
|
|
if from_alignment:
|
|
|
|
if from_alignment:
|
|
|
|
await menu(ctx, from_alignment, DEFAULT_CONTROLS)
|
|
|
|
await menu(ctx, from_alignment, DEFAULT_CONTROLS)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("No roles with that alignment were found")
|
|
|
|
await ctx.maybe_send_embed("No roles with that alignment were found")
|
|
|
|
|
|
|
|
|
|
|
|
@ww_search.command(name="category")
|
|
|
|
@ww_search.command(name="category")
|
|
|
|
async def ww_search_category(self, ctx: commands.Context, category: int):
|
|
|
|
async def ww_search_category(self, ctx: commands.Context, category: int):
|
|
|
@ -337,7 +387,7 @@ class Werewolf(Cog):
|
|
|
|
if pages:
|
|
|
|
if pages:
|
|
|
|
await menu(ctx, pages, DEFAULT_CONTROLS)
|
|
|
|
await menu(ctx, pages, DEFAULT_CONTROLS)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("No roles in that category were found")
|
|
|
|
await ctx.maybe_send_embed("No roles in that category were found")
|
|
|
|
|
|
|
|
|
|
|
|
@ww_search.command(name="index")
|
|
|
|
@ww_search.command(name="index")
|
|
|
|
async def ww_search_index(self, ctx: commands.Context, idx: int):
|
|
|
|
async def ww_search_index(self, ctx: commands.Context, idx: int):
|
|
|
@ -347,24 +397,32 @@ class Werewolf(Cog):
|
|
|
|
if idx_embed is not None:
|
|
|
|
if idx_embed is not None:
|
|
|
|
await ctx.send(embed=idx_embed)
|
|
|
|
await ctx.send(embed=idx_embed)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.send("Role ID not found")
|
|
|
|
await ctx.maybe_send_embed("Role ID not found")
|
|
|
|
|
|
|
|
|
|
|
|
async def _get_game(self, ctx: commands.Context, game_code=None):
|
|
|
|
async def _get_game(self, ctx: commands.Context, game_code=None) -> Union[Game, None]:
|
|
|
|
guild: discord.Guild = ctx.guild
|
|
|
|
guild: discord.Guild = getattr(ctx, "guild", None)
|
|
|
|
|
|
|
|
|
|
|
|
if guild is None:
|
|
|
|
if guild is None:
|
|
|
|
# Private message, can't get guild
|
|
|
|
# Private message, can't get guild
|
|
|
|
await ctx.send("Cannot start game from PM!")
|
|
|
|
await ctx.maybe_send_embed("Cannot start game from DM!")
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
if guild.id not in self.games or self.games[guild.id].game_over:
|
|
|
|
if guild.id not in self.games or self.games[guild.id].game_over:
|
|
|
|
await ctx.send("Starting a new game...")
|
|
|
|
await ctx.maybe_send_embed("Starting a new game...")
|
|
|
|
success, role, category, channel, log_channel = await self._get_settings(ctx)
|
|
|
|
valid, role, category, channel, log_channel = await self._get_settings(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
if not success:
|
|
|
|
if not valid:
|
|
|
|
await ctx.send("Cannot start a new game")
|
|
|
|
await ctx.maybe_send_embed("Cannot start a new game")
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
self.games[guild.id] = Game(guild, role, category, channel, log_channel, game_code)
|
|
|
|
who_has_the_role = await anyone_has_role(guild.members, role)
|
|
|
|
|
|
|
|
if who_has_the_role:
|
|
|
|
|
|
|
|
await ctx.maybe_send_embed(
|
|
|
|
|
|
|
|
f"Cannot continue, {who_has_the_role.display_name} already has the game role."
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
self.games[guild.id] = Game(
|
|
|
|
|
|
|
|
self.bot, guild, role, category, channel, log_channel, game_code
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return self.games[guild.id]
|
|
|
|
return self.games[guild.id]
|
|
|
|
|
|
|
|
|
|
|
@ -385,23 +443,30 @@ class Werewolf(Cog):
|
|
|
|
|
|
|
|
|
|
|
|
if role_id is not None:
|
|
|
|
if role_id is not None:
|
|
|
|
role = discord.utils.get(guild.roles, id=role_id)
|
|
|
|
role = discord.utils.get(guild.roles, id=role_id)
|
|
|
|
if role is None:
|
|
|
|
# if role is None:
|
|
|
|
await ctx.send("Game Role is invalid")
|
|
|
|
# # await ctx.send("Game Role is invalid")
|
|
|
|
return False, None, None, None, None
|
|
|
|
# return False, None, None, None, None
|
|
|
|
if category_id is not None:
|
|
|
|
if category_id is not None:
|
|
|
|
category = discord.utils.get(guild.categories, id=category_id)
|
|
|
|
category = discord.utils.get(guild.categories, id=category_id)
|
|
|
|
if category is None:
|
|
|
|
# if category is None:
|
|
|
|
await ctx.send("Game Category is invalid")
|
|
|
|
# # await ctx.send("Game Category is invalid")
|
|
|
|
return False, None, None, None, None
|
|
|
|
# return False, role, None, None, None
|
|
|
|
if channel_id is not None:
|
|
|
|
if channel_id is not None:
|
|
|
|
channel = discord.utils.get(guild.text_channels, id=channel_id)
|
|
|
|
channel = discord.utils.get(guild.text_channels, id=channel_id)
|
|
|
|
if channel is None:
|
|
|
|
# if channel is None:
|
|
|
|
await ctx.send("Village Channel is invalid")
|
|
|
|
# # await ctx.send("Village Channel is invalid")
|
|
|
|
return False, None, None, None, None
|
|
|
|
# return False, role, category, None, None
|
|
|
|
|
|
|
|
|
|
|
|
if log_channel_id is not None:
|
|
|
|
if log_channel_id is not None:
|
|
|
|
log_channel = discord.utils.get(guild.text_channels, id=log_channel_id)
|
|
|
|
log_channel = discord.utils.get(guild.text_channels, id=log_channel_id)
|
|
|
|
if log_channel is None:
|
|
|
|
# if log_channel is None:
|
|
|
|
await ctx.send("Log Channel is invalid")
|
|
|
|
# # await ctx.send("Log Channel is invalid")
|
|
|
|
return False, None, None, None, None
|
|
|
|
# return False, None, None, None, None
|
|
|
|
|
|
|
|
|
|
|
|
return True, role, category, channel, log_channel
|
|
|
|
return (
|
|
|
|
|
|
|
|
role is not None and category is not None and channel is not None,
|
|
|
|
|
|
|
|
role,
|
|
|
|
|
|
|
|
category,
|
|
|
|
|
|
|
|
channel,
|
|
|
|
|
|
|
|
log_channel,
|
|
|
|
|
|
|
|
)
|
|
|
|