Skip to content

Commit

Permalink
Merge upstream main
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Jan 26, 2024
1 parent 539e9de commit 3a0bbb7
Show file tree
Hide file tree
Showing 19 changed files with 613 additions and 272 deletions.
68 changes: 68 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Bug Report
description: Report broken or incorrect behaviour
labels: [unconfirmed bug]
body:
- type: markdown
attributes:
value: >
Thanks for taking the time to fill out a bug.
If you want real-time support, consider reaching out to the development team on Discord.
Please note that this form is for bugs only!
- type: input
attributes:
label: Summary
description: A simple summary of your bug report
validations:
required: true
- type: textarea
attributes:
label: Reproduction Steps
description: >
What you did to make it happen.
validations:
required: true
- type: textarea
attributes:
label: Minimal Reproducible Code
description: >
A short snippet of code that showcases the bug.
render: Python
- type: textarea
attributes:
label: Expected Results
description: >
What did you expect to happen?
validations:
required: true
- type: textarea
attributes:
label: Actual Results
description: >
What actually happened?
validations:
required: true
- type: textarea
attributes:
label: System Information
description: >
Run `python -m discord -v` and paste this information below.
This command required v1.1.0 or higher of the library. If this errors out then show some basic
information involving your system such as operating system and Python version.
validations:
required: true
- type: checkboxes
attributes:
label: Checklist
description: >
Let's make sure you've properly done due diligence when reporting this issue!
options:
- label: I have searched the open issues for duplicates.
required: true
- label: I have shown the entire traceback, if possible.
required: true
- type: textarea
attributes:
label: Additional Context
description: If there is anything else to say, please do so here.
47 changes: 47 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Feature Request
description: Suggest a feature for Rodhaj
labels: [feature request]
body:
- type: input
attributes:
label: Summary
description: >
A short summary of what your feature request is.
validations:
required: true
- type: dropdown
attributes:
multiple: false
label: What is the feature request for?
options:
- Rodhaj
- The documentation
validations:
required: true
- type: textarea
attributes:
label: The Problem
description: >
What problem is your feature trying to solve?
What becomes easier or possible when this feature is implemented?
validations:
required: true
- type: textarea
attributes:
label: The Ideal Solution
description: >
What is your ideal solution to the problem?
What would you like this feature to do?
validations:
required: true
- type: textarea
attributes:
label: The Current Solution
description: >
What is the current solution to the problem, if any?
validations:
required: false
- type: textarea
attributes:
label: Additional Context
description: If there is anything else to say, please do so here.
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Summary

<!-- What is this pull request for? Does it fix any issues? -->

## Types of changes

What types of changes does your code introduce to Rodhaj
_Put an `x` in the boxes that apply_

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update (Updates to README.md, the documentation, etc)
- [ ] Other (if none of the other choices apply)


## Checklist

<!-- Put an x inside [ ] to check it, like so: [x] -->

_Put an `x` in the boxes that apply_

- [ ] If code changes were made then they have been tested.
- [ ] I have updated the documentation to reflect the changes. (if appropriate)
- [ ] All workflows (except pre-commit.ci) pass with my new changes
- [ ] This PR does **not** address a duplicate issue or PR
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
stages: [commit]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.1.14
hooks:
- id: ruff
name: Ruff
Expand Down
3 changes: 2 additions & 1 deletion bot/cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from discord.ext import commands
from discord.ext.commands import Greedy
from libs.utils import RoboContext

from rodhaj import Rodhaj

GIT_PULL_REGEX = re.compile(r"\s+(?P<filename>.*)\b\s+\|\s+[\d]")
Expand Down Expand Up @@ -104,7 +105,7 @@ def reload_lib_modules(self, module: str) -> list[tuple[str, str]]:
# To learn more about it, see the link below (and ?tag ass on the dpy server):
# https://about.abstractumbra.dev/discord.py/2023/01/29/sync-command-example.html
@commands.guild_only()
@commands.command(name="sync")
@commands.command(name="sync", hidden=True)
async def sync(
self,
ctx: RoboContext,
Expand Down
13 changes: 9 additions & 4 deletions bot/cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import msgspec
from async_lru import alru_cache
from discord.ext import commands
from libs.utils import GuildContext, is_manager
from libs.utils import GuildContext
from libs.utils.checks import bot_check_permissions, check_permissions

if TYPE_CHECKING:
from rodhaj import Rodhaj
Expand Down Expand Up @@ -119,14 +120,16 @@ async def get_guild_config(self, guild_id: int) -> Optional[GuildConfig]:
config = GuildConfig(bot=self.bot, **dict(rows))
return config

@is_manager()
@check_permissions(manage_guild=True)
@bot_check_permissions(manage_channels=True, manage_webhooks=True)
@commands.guild_only()
@commands.hybrid_group(name="config")
async def config(self, ctx: GuildContext) -> None:
"""Commands to configure, setup, or delete Rodhaj"""
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)

@commands.cooldown(1, 20, commands.BucketType.guild)
@config.command(name="setup", usage="ticket_name: <str> log_name: <str>")
async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
"""First-time setup for Rodhaj
Expand Down Expand Up @@ -252,8 +255,8 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
return

query = """
INSERT INTO guild_config (id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, ticket_broadcast_url)
VALUES ($1, $2, $3, $4, $5, $6);
INSERT INTO guild_config (id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, ticket_broadcast_url, prefix)
VALUES ($1, $2, $3, $4, $5, $6, $7);
"""
try:
await self.pool.execute(
Expand All @@ -264,6 +267,7 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
logging_channel.id,
lgc_webhook.url,
tc_webhook.url,
[],
)
except asyncpg.UniqueViolationError:
await ticket_channel.delete(reason=delete_reason)
Expand All @@ -278,6 +282,7 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
msg = f"Rodhaj channels successfully created! The ticket channel can be found under {ticket_channel.mention}"
await ctx.send(msg)

@commands.cooldown(1, 20, commands.BucketType.guild)
@config.command(name="delete")
async def delete(self, ctx: GuildContext) -> None:
"""Permanently deletes Rodhaj channels and tickets."""
Expand Down
42 changes: 20 additions & 22 deletions bot/cogs/tickets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from functools import lru_cache
from typing import TYPE_CHECKING, Annotated, NamedTuple, Optional, Union

import asyncpg
Expand All @@ -14,16 +13,17 @@
get_partial_ticket,
safe_content,
)
from libs.utils.checks import bot_check_permissions
from libs.utils.embeds import Embed, LoggingEmbed

from .config import GuildWebhookDispatcher

if TYPE_CHECKING:
from libs.utils import GuildContext, RoboContext

from rodhaj import Rodhaj


STAFF_ROLE = 1184257456419913798
TICKET_EMOJI = "\U0001f3ab" # U+1F3AB Ticket


Expand Down Expand Up @@ -101,15 +101,6 @@ def add_status_checklist(
) -> StatusChecklist:
return self.in_progress_tickets.setdefault(author_id, status)

#### Determining staff

@lru_cache(maxsize=64)
def get_staff(self, guild: discord.Guild) -> Optional[list[discord.Member]]:
mod_role = guild.get_role(STAFF_ROLE)
if mod_role is None:
return None
return [member for member in mod_role.members]

### Conditions for closing tickets

async def can_close_ticket(self, ctx: RoboContext):
Expand All @@ -128,22 +119,17 @@ async def can_close_ticket(self, ctx: RoboContext):
return False

async def can_admin_close_ticket(self, ctx: RoboContext) -> bool:
guild_id = self.bot.transprogrammer_guild_id
guild = self.bot.get_guild(guild_id) or (await self.bot.fetch_guild(guild_id))
staff_members = self.get_staff(guild)

if staff_members is None:
return False

# TODO: Add the hierarchy system here
staff_ids = [member.id for member in staff_members]
# More than likely it will be closed through the threads
# That means, it must be done in a guild. Thus, we know that
# it will always be discord.Member
perms = ctx.channel.permissions_for(ctx.author) # type: ignore
from_ticket_channel = (
isinstance(ctx.channel, discord.Thread)
and ctx.partial_config is not None
and ctx.channel.parent_id == ctx.partial_config.ticket_channel_id
)

if ctx.author.id in staff_ids and from_ticket_channel is True:
if perms.manage_threads and from_ticket_channel is True:
return True
return False

Expand Down Expand Up @@ -319,10 +305,18 @@ def get_solved_tag(

### Feature commands

# This command requires the manage_threads permissions for the bot
@is_ticket_or_dm()
@bot_check_permissions(manage_threads=True)
@commands.cooldown(1, 20, commands.BucketType.channel)
@commands.hybrid_command(name="close", aliases=["solved", "closed", "resolved"])
async def close(self, ctx: RoboContext) -> None:
"""Closes the thread"""
"""Closes a ticket
If someone requests to close the ticket
and has Manage Threads permissions, then they can
also close the ticket.
"""
query = """
DELETE FROM tickets
WHERE thread_id = $1 AND owner_id = $2;
Expand Down Expand Up @@ -356,7 +350,11 @@ async def close(self, ctx: RoboContext) -> None:
self.get_ticket_owner_id.cache_invalidate(closed_ticket.id)
await self.notify_finished_ticket(ctx, owner_id)

# 10 command invocations per 12 seconds for each member
# These values should not be tripped unless someone is spamming
# https://github.com/Rapptz/RoboDanny/blob/rewrite/cogs/mod.py#L524C9-L524C74
@is_ticket_thread()
@commands.cooldown(10, 12, commands.BucketType.member)
@commands.command(name="reply", aliases=["r"])
async def reply(
self, ctx: GuildContext, *, message: Annotated[str, commands.clean_content]
Expand Down
Loading

0 comments on commit 3a0bbb7

Please sign in to comment.