Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement guild configuration #146

Merged
merged 58 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4de84d2
the start of some very sus code
No767 May 21, 2024
f01bea8
Intergrate base guild settings
No767 May 22, 2024
786d6b0
Fmt files + bump default python version to 312
No767 May 22, 2024
2534e15
check to ensure that base prefixes are not deleted
No767 May 22, 2024
12e000e
Fix config options not showing
No767 May 25, 2024
17562e2
Merge branch 'main' into noelle/guild-configs
No767 May 30, 2024
f66395a
set the base of the config commands
No767 May 31, 2024
ce102b1
finish toggle command
No767 Jun 2, 2024
3c58507
merge from main
No767 Jun 2, 2024
cf9ebb4
merge changes
No767 Jun 2, 2024
dec1bb7
Merge branch 'main' into noelle/guild-configs
No767 Jun 21, 2024
e7c5941
Merge branch 'main' into noelle/guild-configs
No767 Jul 2, 2024
b20725c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 2, 2024
0f21263
finish config setting for now....
No767 Jul 3, 2024
f90b354
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 3, 2024
5b60e66
sonarcloud suggest
No767 Jul 3, 2024
36eee22
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 3, 2024
261f637
ensure mentions are caputured
No767 Jul 3, 2024
7b1c8da
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 3, 2024
c96f6db
Merge branch 'main' into noelle/guild-configs
No767 Jul 13, 2024
905a33b
add new deps
No767 Jul 16, 2024
a1beb85
merge changes
No767 Jul 16, 2024
66669a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
9a16965
merge
No767 Jul 16, 2024
19015a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
fac8028
add pdt
No767 Jul 16, 2024
66904b2
changeS
No767 Jul 16, 2024
c0d6bee
merge changes
No767 Jul 16, 2024
ab0ad18
finish up code for guild configs
No767 Jul 17, 2024
13134f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
e1b7590
intergrate guild mention into creation of tickets
No767 Jul 17, 2024
ec5e656
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
16c9c1c
Apply guild and account age into ticket checks
No767 Jul 17, 2024
1e14d67
remove todos
No767 Jul 17, 2024
5bbf379
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
cdc77cc
remove arrow
No767 Jul 17, 2024
eb68803
remvoe test command
No767 Jul 17, 2024
c9b3434
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 17, 2024
9e60f82
merge and relock poetry.lock
No767 Jul 17, 2024
8a213ba
Update documentation to reflect new configuration changes
No767 Jul 17, 2024
45abb04
merge from main
No767 Jul 18, 2024
ba277eb
merge from main
No767 Jul 19, 2024
2215496
relock lockfile
No767 Jul 22, 2024
6e28a89
Merge branch 'main' into noelle/guild-configs
No767 Jul 22, 2024
2f4e2e3
finally finish this PR
No767 Jul 23, 2024
33b1b3e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
29f2754
compress errors
No767 Jul 23, 2024
600bb7d
Merge branch 'noelle/guild-configs' of https://github.com/transprogra…
No767 Jul 23, 2024
d360d20
replace checks with better ones
No767 Jul 23, 2024
9474950
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
81051da
Add options help
No767 Jul 23, 2024
cc2aa89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 23, 2024
37baf08
finish the help commands
No767 Jul 24, 2024
b99b49c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
39fbbb2
fixes
No767 Jul 24, 2024
9be96ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
8821c0f
add slash command documentation
No767 Jul 24, 2024
04fbb71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
522 changes: 492 additions & 30 deletions bot/cogs/config.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bot/cogs/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ async def create_ticket(self, ticket: TicketThread) -> Optional[TicketOutput]:
]
processed_tags = [tag for tag in applied_tags if tag is not None]

content = f"({ticket.user.display_name}, {discord.utils.format_dt(ticket.created_at)})\n\n{ticket.content}"
content = f"({ticket.mention} - {ticket.user.display_name}, {discord.utils.format_dt(ticket.created_at)})\n\n{ticket.content}"
created_ticket = await tc.create_thread(
applied_tags=processed_tags,
name=ticket.title,
Expand Down
4 changes: 2 additions & 2 deletions bot/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aiohttp import ClientSession
from libs.utils import KeyboardInterruptHandler, RodhajLogger
from libs.utils.config import RodhajConfig
from rodhaj import Rodhaj
from rodhaj import Rodhaj, init

if os.name == "nt":
from winloop import run
Expand All @@ -27,7 +27,7 @@

async def main() -> None:
async with ClientSession() as session, asyncpg.create_pool(
dsn=POSTGRES_URI, min_size=25, max_size=25, command_timeout=30
dsn=POSTGRES_URI, min_size=25, max_size=25, init=init, command_timeout=30
) as pool:
async with Rodhaj(
config=config, intents=intents, session=session, pool=pool
Expand Down
1 change: 1 addition & 0 deletions bot/libs/tickets/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TicketThread(msgspec.Struct):
title: str
user: Union[discord.User, discord.Member]
location_id: int
mention: str
content: str
tags: list[str]
files: list[discord.File]
Expand Down
41 changes: 41 additions & 0 deletions bot/libs/tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
if TYPE_CHECKING:
from libs.utils.context import RoboContext

from bot.cogs.config import Config
from bot.cogs.tickets import Tickets
from bot.rodhaj import Rodhaj

Expand Down Expand Up @@ -133,6 +134,7 @@ def __init__(
bot: Rodhaj,
ctx: RoboContext,
cog: Tickets,
config_cog: Config,
content: str,
guild: discord.Guild,
delete_after: bool = True,
Expand All @@ -142,6 +144,7 @@ def __init__(
self.bot = bot
self.ctx = ctx
self.cog = cog
self.config_cog = config_cog
self.content = content
self.guild = guild
self.delete_after = delete_after
Expand All @@ -162,6 +165,18 @@ async def delete_response(self, interaction: discord.Interaction):

self.stop()

async def get_or_fetch_member(self, member_id: int) -> Optional[discord.Member]:
member = self.guild.get_member(member_id)
if member is not None:
return member

members = await self.guild.query_members(
limit=1, user_ids=[member_id], cache=True
)
if not members:
return None
return members[0]

@discord.ui.button(
label="Checklist",
style=discord.ButtonStyle.primary,
Expand Down Expand Up @@ -228,6 +243,31 @@ async def confirm(

applied_tags = [k for k, v in tags.items() if v is True]

guild_settings = await self.config_cog.get_guild_settings(self.guild.id)
potential_member = await self.get_or_fetch_member(author.id)

if not guild_settings:
await interaction.response.send_message(
"Unable to find guild settings", ephemeral=True
)
return

if (self.guild.created_at - interaction.created_at) < guild_settings.guild_age:
await interaction.response.send_message(
"The guild is too young in order to utilize Rodhaj.", ephemeral=True
)
return
elif (
potential_member
): # Since we are checking join times, if we don't have the proper member, we can only skip it.
joined_at = potential_member.joined_at or discord.utils.utcnow()
if (joined_at - interaction.created_at) < guild_settings.account_age:
await interaction.response.send_message(
"This account joined the server too soon in order to utilize Rodhaj.",
ephemeral=True,
)
return

if not status.title.is_set() or not status.tags.is_set():
dict_status = {"title": status.title, "tags": status.tags}
formatted_status = "\n".join(
Expand Down Expand Up @@ -255,6 +295,7 @@ async def confirm(
title=title,
user=author,
location_id=self.guild.id,
mention=guild_settings.mention,
content=self.content,
tags=applied_tags,
files=files,
Expand Down
37 changes: 37 additions & 0 deletions bot/libs/utils/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from typing import Any, Generic, Optional, TypeVar, Union, overload

import orjson
import yaml

_T = TypeVar("_T")
Expand Down Expand Up @@ -44,3 +45,39 @@ def __len__(self) -> int:

def all(self) -> dict[str, Union[_T, Any]]:
return self._config


class OptionsHelp(Generic[_T]):
def __init__(self, path: Path):
self.path = path
self._config: dict[str, Union[_T, Any]] = {}
self.load_from_file()

def load_from_file(self) -> None:
try:
with open(self.path, "r") as f:
self._config: dict[str, Union[_T, Any]] = orjson.loads(f.read())
except FileNotFoundError:
self._config = {}

@overload
def get(self, key: Any) -> Optional[Union[_T, Any]]: ...

@overload
def get(self, key: Any, default: Any) -> Union[_T, Any]: ...

def get(self, key: Any, default: Any = None) -> Optional[Union[_T, Any]]:
"""Retrieves a config entry."""
return self._config.get(str(key), default)

def __contains__(self, item: Any) -> bool:
return str(item) in self._config

def __getitem__(self, item: Any) -> Union[_T, Any]:
return self._config[str(item)]

def __len__(self) -> int:
return len(self._config)

def all(self) -> dict[str, Union[_T, Any]]:
return self._config
Loading
Loading