Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/docker/setup-build…
Browse files Browse the repository at this point in the history
…x-action-3
  • Loading branch information
natelandau authored Oct 2, 2023
2 parents d539505 + a571190 commit ae62b8c
Show file tree
Hide file tree
Showing 38 changed files with 1,319 additions and 621 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repos:
rev: "v0.0.291"
hooks:
- id: ruff
args: ["--extend-ignore", "I001,D301,D401"]
args: ["--extend-ignore", "I001,D301,D401", "--preview"]
exclude: tests/

- repo: "https://github.com/jendrikseipp/vulture"
Expand Down
231 changes: 131 additions & 100 deletions poetry.lock

Large diffs are not rendered by default.

81 changes: 50 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

[tool.poetry.dependencies]
aiofiles = "^23.2.1"
arrow = "^1.2.3"
arrow = "^1.3.0"
boto3 = "^1.28.49"
inflect = "^7.0.0"
loguru = "^0.7.2"
Expand All @@ -29,6 +29,7 @@
python-dotenv = "^1.0.0"
semver = "^3.0.1"
typer = { extras = ["all"], version = "^0.9.0" }
rich = "^13.6.0"

[tool.poetry.group.test.dependencies]
dirty-equals = "^0.6.0"
Expand Down Expand Up @@ -151,7 +152,7 @@
"build",
"dist",
"node_modules",
"src/valentina/cogs/test_cog.py",
# "src/valentina/cogs/test_cog.py",
"venv",
]
# Avoiding flagging (and removing) `V101` from any `# noqa`
Expand All @@ -172,6 +173,7 @@
"D408",
"D409",
"D413",
"E266",
"E501",
"N805",
"PGH001",
Expand All @@ -195,37 +197,54 @@
"PLR0913",
"PLR2004",
"S101",
], "src/valentina/cogs/*.py" = [
"PLR0904",
"PLR6301",
], "src/valentina/utils/converters.py" = [
"PLR6301",
] }
select = [
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"BLE", # flake8-blind-exception
"C40", # flake8-comprehensions
"C90", # McCabe
"D", # pydocstyle
"E", # pycodestyle Errors
"ERA", # flake8-eradicate
"EXE", # flake8-executable
"F", # pyflakes
"I", # iSort
"N", # Pep8-naming
"PGH", # pygrep-hooks
"PLC", # pylint Convention
"PLE", # pylint Error
"PLR", # pylint Refactor
"PLW", # pylint Warning
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"Q", # flake8-quotes
"RET", # flake8-return
"RUF", # Ruff-specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle Warnings
"YTT", # flake8-2020
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
"B", # flake8-bugbear
"BLE", # flake8-blind-exception
"C4", # flake8-comprehensions
"C90", # McCabe
"D", # pydocstyle
"E", # pycodestyle Errors
"EM", # flake8-errmsg
"ERA", # flake8-eradicate
"EXE", # flake8-executable
"F", # pyflakes
"FA", # flake8-future
"FLY", # flynt
"FURB", # refurb
"I", # iSort
"ISC", # flake8-implicit-str-concat
"N", # Pep8-naming
"NPY", # flake8-numpy
"PERF", # Perflint
"PGH", # pygrep-hooks
"PL", # pylint
"PLC", # pylint Convention
"PLE", # pylint Error
"PLR", # pylint Refactor
"PLW", # pylint Warning
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"Q", # flake8-quotes
"RET", # flake8-return
"RUF", # Ruff-specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"T20", # flake8-print
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle Warnings
"YTT", # flake8-2020
# "DTZ", # flake8-datetimez
]
src = ["src", "tests"]
target-version = "py310"
Expand Down
27 changes: 18 additions & 9 deletions src/valentina/cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ async def kick(
) -> None:
"""Kick a target member, by ID or mention."""
if member.id == ctx.author.id:
raise errors.ValidationError("You cannot kick yourself.")
msg = "You cannot kick yourself."
raise errors.ValidationError(msg)

if member.top_role >= ctx.author.top_role:
raise errors.ValidationError("You cannot kick this member.")
msg = "You cannot kick this member."
raise errors.ValidationError(msg)

# Confirm the action
title = f"Kick {member.display_name} from this guild"
Expand Down Expand Up @@ -134,10 +136,12 @@ async def ban(
await assert_permissions(ctx, ban_members=True)
if user := discord.utils.get(ctx.guild.members, id=user.id):
if user.id == ctx.author.id:
raise errors.ValidationError("You cannot ban yourself.")
msg = "You cannot ban yourself."
raise errors.ValidationError(msg)

if user.top_role >= ctx.author.top_role:
raise errors.ValidationError("You cannot ban this member.")
msg = "You cannot ban this member."
raise errors.ValidationError(msg)

# Confirm the action
title = f"Ban {user.display_name} from this guild"
Expand Down Expand Up @@ -234,10 +238,12 @@ async def massban(
for user in converted_members:
if user := discord.utils.get(ctx.guild.members, id=user.id):
if user.id == ctx.author.id:
raise errors.ValidationError("You cannot ban yourself.")
msg = "You cannot ban yourself."
raise errors.ValidationError(msg)

if user.top_role >= ctx.author.top_role:
raise errors.ValidationError("You cannot ban this member.")
msg = "You cannot ban this member."
raise errors.ValidationError(msg)

await ctx.guild.ban(user, reason=f"{ctx.author} ({ctx.author.id}): {reason}")

Expand Down Expand Up @@ -384,7 +390,8 @@ async def slowmode(
) -> None:
"""Set slowmode for the current channel."""
if not isinstance(ctx.channel, discord.TextChannel):
raise commands.BadArgument("Slowmode can only be set in text channels.")
msg = "Slowmode can only be set in text channels."
raise commands.BadArgument(msg)

await assert_permissions(ctx, manage_channels=True)

Expand Down Expand Up @@ -430,7 +437,8 @@ async def lock(
await assert_permissions(ctx, manage_roles=True)

if not isinstance(ctx.channel, discord.TextChannel):
raise commands.BadArgument("Only text channels can be locked")
msg = "Only text channels can be locked"
raise commands.BadArgument(msg)

if ctx.channel.overwrites_for(ctx.guild.default_role).send_messages is False:
await ctx.respond("This channel is already locked.", ephemeral=True)
Expand Down Expand Up @@ -472,7 +480,8 @@ async def unlock(
"""Set the `Send Message` permission to the default state for the default role."""
await assert_permissions(ctx, manage_roles=True)
if not isinstance(ctx.channel, discord.TextChannel):
raise commands.BadArgument("Only text channels can be locked or unlocked")
msg = "Only text channels can be locked or unlocked"
raise commands.BadArgument(msg)

if ctx.channel.overwrites_for(ctx.guild.default_role).send_messages is not False:
await ctx.respond("This channel isn't locked.", ephemeral=True)
Expand Down
32 changes: 21 additions & 11 deletions src/valentina/cogs/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,12 @@ async def campaign_list(
return

fields = []
for c in sorted(campaigns, key=lambda x: x.name):
fields.append((f"**{c.name}** (Active)" if c.is_active else f"**{c.name}**", ""))
fields.extend(
[
(f"**{c.name}** (Active)" if c.is_active else f"**{c.name}**", "")
for c in sorted(campaigns, key=lambda x: x.name)
]
)

await present_embed(ctx, title="Campaigns", fields=fields, level="info")
logger.debug("CAMPAIGN: List all campaigns")
Expand Down Expand Up @@ -365,13 +369,15 @@ async def list_npcs(
return

fields = []
for npc in sorted(npcs, key=lambda x: x.name):
fields.append(
fields.extend(
[
(
f"**__{npc.name}__**",
f"**Class:** {npc.npc_class}\n**Description:** {npc.description}",
)
)
for npc in sorted(npcs, key=lambda x: x.name)
]
)

await present_embed(ctx, title="NPCs", fields=fields, level="info", ephemeral=hidden)

Expand Down Expand Up @@ -521,13 +527,15 @@ async def list_chapters(
return

fields = []
for chapter in sorted(chapters, key=lambda x: x.chapter_number):
fields.append(
fields.extend(
[
(
f"**{chapter.chapter_number}.** **__{chapter.name}__**",
f"{chapter.short_description}",
)
)
for chapter in sorted(chapters, key=lambda x: x.chapter_number)
]
)

await present_embed(ctx, title="Chapters", fields=fields, level="info")

Expand Down Expand Up @@ -700,15 +708,17 @@ async def list_notes(
return

fields = []
for note in sorted(notes, key=lambda x: x.name):
fields.append(
fields.extend(
[
(
f"**__{note.name}__**",
f"**Chapter:** {note.chapter.chapter_number}\n{note.description}"
if note.chapter
else f"{note.description}",
)
)
for note in sorted(notes, key=lambda x: x.name)
]
)

await present_embed(
ctx, title=f"Notes for **{campaign.name}**", fields=fields, level="info"
Expand Down
61 changes: 53 additions & 8 deletions src/valentina/cogs/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
select_vampire_clan,
)
from valentina.views import (
AddFromSheetWizard,
BioModal,
CharGenWizard,
ConfirmCancelButtons,
CustomSectionModal,
ProfileModal,
S3ImageReview,
Expand All @@ -65,8 +67,8 @@ def __init__(self, bot: Valentina) -> None:
section = chars.create_subgroup("section", "Work with character custom sections")
trait = chars.create_subgroup("trait", "Work with character traits")

@chars.command(name="create", description="Create a new character")
async def create_character(
@chars.command(name="add", description="Add a character to Valentina from a sheet")
async def add_character(
self,
ctx: discord.ApplicationContext,
char_class: Option(
Expand Down Expand Up @@ -114,7 +116,7 @@ async def create_character(
# Fetch all traits and set them
fetched_traits = self.bot.trait_svc.fetch_all_class_traits(char_class.name)

wizard = CharGenWizard(
wizard = AddFromSheetWizard(
ctx,
fetched_traits,
first_name=first_name,
Expand Down Expand Up @@ -150,6 +152,51 @@ async def create_character(
)
logger.info(f"CHARACTER: Create character {character}")

@chars.command(name="create", description="Create a new character from scratch")
async def create_character(
self,
ctx: discord.ApplicationContext,
hidden: Option(
bool,
description="Make the interaction only visible to you (default true).",
default=True,
),
) -> None:
"""Create a new character from scratch."""
campaign = self.bot.campaign_svc.fetch_active(ctx)
user = await self.bot.user_svc.fetch_user(ctx)
(
campaign_xp,
_,
_,
_,
_,
) = user.fetch_experience(campaign.id)

view = ConfirmCancelButtons(ctx.author)
msg = await present_embed(
ctx,
title="Create a new character",
description=f"This will walk you through the character creation process.\n\nThis will cost `10` xp and you have `{campaign_xp}` xp available.",
view=view,
ephemeral=hidden,
)
await view.wait()
if not view.confirmed:
embed = discord.Embed(
title=f"{Emoji.CANCEL.value} Cancelled",
description="Create a new character",
color=EmbedColor.WARNING.value,
)
await msg.edit_original_response(embed=embed, view=None)
return

# Spend 10 xp
user.spend_experience(campaign.id, 10)

wizard = CharGenWizard(ctx, campaign=campaign, user=user, msg=msg, hidden=hidden)
await wizard.begin()

@chars.command(name="set_active", description="Select a character as your active character")
async def set_active_character(
self,
Expand Down Expand Up @@ -579,7 +626,8 @@ async def add_custom_section(
if section_title.replace("-", "_").replace(" ", "_").lower() in [
x.title.replace("-", "_").replace(" ", "_").lower() for x in existing_sections
]:
raise errors.ValidationError("Custom section already exists")
msg = "Custom section already exists"
raise errors.ValidationError(msg)

self.bot.char_svc.custom_section_update_or_add(
ctx, character, section_title, section_description
Expand Down Expand Up @@ -756,10 +804,7 @@ async def update_profile(
await ctx.send_modal(modal)
await modal.wait()
if modal.confirmed:
update_data: dict = {}
for k, v in modal.results.items():
if v:
update_data[k] = v
update_data: dict = {k: v for k, v in modal.results.items() if v}

await self.bot.char_svc.update_or_add(ctx, character=character, data=update_data)

Expand Down
3 changes: 2 additions & 1 deletion src/valentina/cogs/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ async def repost_changelog(
) -> None:
"""Post the changelog."""
if semver.compare(oldest_version, newest_version) > 0:
raise commands.BadArgument(
msg = (
f"Oldest version `{oldest_version}` is newer than newest version `{newest_version}`"
)
raise commands.BadArgument(msg)

changelog_channel = self.bot.guild_svc.fetch_changelog_channel(ctx.guild)
if not changelog_channel:
Expand Down
Loading

0 comments on commit ae62b8c

Please sign in to comment.