diff --git a/general/__init__.py b/general/__init__.py index c012cf439..b7f21876d 100644 --- a/general/__init__.py +++ b/general/__init__.py @@ -1,7 +1,6 @@ from .betheprofessional import BeTheProfessionalCog from .custom_commands import CustomCommandsCog from .discord_bot_token_deleter import DiscordBotTokenDeleterCog -from .news import NewsCog from .polls import PollsCog from .reactionpin import ReactionPinCog from .reactionrole import ReactionRoleCog @@ -14,7 +13,6 @@ "BeTheProfessionalCog", "CustomCommandsCog", "DiscordBotTokenDeleterCog", - "NewsCog", "PollsCog", "ReactionPinCog", "ReactionRoleCog", diff --git a/general/news/__init__.py b/general/news/__init__.py deleted file mode 100644 index e2bedcc88..000000000 --- a/general/news/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .cog import NewsCog - - -__all__ = ["NewsCog"] diff --git a/general/news/cog.py b/general/news/cog.py deleted file mode 100644 index 52d384245..000000000 --- a/general/news/cog.py +++ /dev/null @@ -1,161 +0,0 @@ -from typing import Optional - -from discord import Embed, Forbidden, Guild, HTTPException, Member, Role, TextChannel -from discord.ext import commands -from discord.ext.commands import CommandError, Context, UserInputError, guild_only - -from PyDrocsid.cog import Cog -from PyDrocsid.command import reply -from PyDrocsid.converter import Color -from PyDrocsid.database import db, select -from PyDrocsid.embeds import send_long_embed -from PyDrocsid.translations import t -from PyDrocsid.util import attachment_to_file, read_normal_message - -from .colors import Colors -from .models import NewsAuthorization -from .permissions import NewsPermission -from ...contributor import Contributor -from ...pubsub import send_to_changelog - - -tg = t.g -t = t.news - - -class NewsCog(Cog, name="News"): - CONTRIBUTORS = [Contributor.Defelo, Contributor.wolflu] - - @commands.group() - @guild_only() - async def news(self, ctx: Context): - """ - manage news channels - """ - - if ctx.invoked_subcommand is None: - raise UserInputError - - @news.group(name="auth", aliases=["a"]) - @NewsPermission.read.check - async def news_auth(self, ctx: Context): - """ - manage authorized users and channels - """ - - if ctx.invoked_subcommand is None: - raise UserInputError - - @news_auth.command(name="list", aliases=["l", "?"]) - async def news_auth_list(self, ctx: Context): - """ - list authorized users and channels - """ - - out = [] - guild: Guild = ctx.guild - async for authorization in await db.stream(select(NewsAuthorization)): - text_channel: Optional[TextChannel] = guild.get_channel(authorization.channel_id) - member: Optional[Member] = guild.get_member(authorization.user_id) - if text_channel is None or member is None: - await db.delete(authorization) - continue - line = f":small_orange_diamond: {member.mention} -> {text_channel.mention}" - if authorization.notification_role_id is not None: - role: Optional[Role] = guild.get_role(authorization.notification_role_id) - if role is None: - await db.delete(authorization) - continue - line += f" ({role.mention})" - out.append(line) - embed = Embed(title=t.news, colour=Colors.News) - if out: - embed.description = "\n".join(out) - else: - embed.colour = Colors.error - embed.description = t.no_news_authorizations - await send_long_embed(ctx, embed) - - @news_auth.command(name="add", aliases=["a", "+"]) - @NewsPermission.write.check - async def news_auth_add(self, ctx: Context, user: Member, channel: TextChannel, notification_role: Optional[Role]): - """ - authorize a new user to send news to a specific channel - """ - - if await db.exists(select(NewsAuthorization).filter_by(user_id=user.id, channel_id=channel.id)): - raise CommandError(t.news_already_authorized) - if not channel.permissions_for(channel.guild.me).send_messages: - raise CommandError(t.news_not_added_no_permissions) - - role_id = notification_role.id if notification_role is not None else None - - await NewsAuthorization.create(user.id, channel.id, role_id) - embed = Embed(title=t.news, colour=Colors.News, description=t.news_authorized) - await reply(ctx, embed=embed) - await send_to_changelog(ctx.guild, t.log_news_authorized(user.mention, channel.mention)) - - @news_auth.command(name="remove", aliases=["del", "r", "d", "-"]) - @NewsPermission.write.check - async def news_auth_remove(self, ctx: Context, user: Member, channel: TextChannel): - """ - remove user authorization - """ - - authorization: Optional[NewsAuthorization] = await db.first( - select(NewsAuthorization).filter_by(user_id=user.id, channel_id=channel.id) - ) - if authorization is None: - raise CommandError(t.news_not_authorized) - - await db.delete(authorization) - embed = Embed(title=t.news, colour=Colors.News, description=t.news_unauthorized) - await reply(ctx, embed=embed) - await send_to_changelog(ctx.guild, t.log_news_unauthorized(user.mention, channel.mention)) - - @news.command(name="send", aliases=["s"]) - async def news_send( - self, ctx: Context, channel: TextChannel, color: Optional[Color] = None, *, message: Optional[str] - ): - """ - send a news message - """ - - authorization: Optional[NewsAuthorization] = await db.first( - select(NewsAuthorization).filter_by(user_id=ctx.author.id, channel_id=channel.id) - ) - if authorization is None: - raise CommandError(t.news_you_are_not_authorized) - - if message is None: - message = "" - - embed = Embed(title=t.news, colour=Colors.News, description="") - if not message and not ctx.message.attachments: - embed.description = t.send_message - await reply(ctx, embed=embed) - message, files = await read_normal_message(self.bot, ctx.channel, ctx.author) - else: - files = [await attachment_to_file(attachment) for attachment in ctx.message.attachments] - - content = "" - send_embed = Embed(title=t.news, description=message, colour=Colors.News) - send_embed.set_footer(text=t.sent_by(ctx.author, ctx.author.id), icon_url=ctx.author.display_avatar.url) - - if authorization.notification_role_id is not None: - role: Optional[Role] = ctx.guild.get_role(authorization.notification_role_id) - if role is not None: - content = role.mention - - send_embed.colour = color if color is not None else Colors.News - - if files and any(files[0].filename.lower().endswith(ext) for ext in ["jpg", "jpeg", "png", "gif"]): - send_embed.set_image(url="attachment://" + files[0].filename) - - try: - await channel.send(content=content, embed=send_embed, files=files) - except (HTTPException, Forbidden): - raise CommandError(t.msg_could_not_be_sent) - else: - embed.description = t.msg_sent - await reply(ctx, embed=embed) diff --git a/general/news/colors.py b/general/news/colors.py deleted file mode 100644 index b4555e3c1..000000000 --- a/general/news/colors.py +++ /dev/null @@ -1,5 +0,0 @@ -from PyDrocsid.material_colors import MaterialColors - - -class Colors(MaterialColors): - News = MaterialColors.orange diff --git a/general/news/documentation.md b/general/news/documentation.md deleted file mode 100644 index 9f28701fc..000000000 --- a/general/news/documentation.md +++ /dev/null @@ -1,4 +0,0 @@ -# News - - -*Work in Progress* diff --git a/general/news/models.py b/general/news/models.py deleted file mode 100644 index d97a40cd2..000000000 --- a/general/news/models.py +++ /dev/null @@ -1,19 +0,0 @@ -from typing import Optional, Union - -from sqlalchemy import BigInteger, Column - -from PyDrocsid.database import Base, db - - -class NewsAuthorization(Base): - __tablename__ = "news_authorization" - - user_id: Union[Column, int] = Column(BigInteger, primary_key=True) - channel_id: Union[Column, int] = Column(BigInteger, primary_key=True) - notification_role_id: Union[Column, int] = Column(BigInteger) - - @staticmethod - async def create(user_id: int, channel_id: int, notification_role_id: Optional[int]) -> "NewsAuthorization": - row = NewsAuthorization(user_id=user_id, channel_id=channel_id, notification_role_id=notification_role_id) - await db.add(row) - return row diff --git a/general/news/permissions.py b/general/news/permissions.py deleted file mode 100644 index ed5c5d6f7..000000000 --- a/general/news/permissions.py +++ /dev/null @@ -1,13 +0,0 @@ -from enum import auto - -from PyDrocsid.permission import BasePermission -from PyDrocsid.translations import t - - -class NewsPermission(BasePermission): - @property - def description(self) -> str: - return t.news.permissions[self.name] - - read = auto() - write = auto() diff --git a/general/news/translations/en.yml b/general/news/translations/en.yml deleted file mode 100644 index 019f390d3..000000000 --- a/general/news/translations/en.yml +++ /dev/null @@ -1,19 +0,0 @@ -permissions: - read: read news authorizations - write: write news authorizations - -news: News -news_already_authorized: User is already authorized to send news in this channel. -news_authorized: "User has been authorized to send news in this channel. :white_check_mark:" -log_news_authorized: "User {} has been **authorized** to **send news** in {}." -news_not_authorized: User is not authorized to send news in this channel. -news_unauthorized: "User has been unauthorized to send news in this channel. :white_check_mark:" -log_news_unauthorized: "User {} has been **unauthorized** to **send news** in {}." -no_news_authorizations: No user has been authorized to send news yet. -news_not_added_no_permissions: > - User could not be authorized because I don't have `send_messages` permission in this channel. -news_you_are_not_authorized: You are not authorized to send news in this channel. -sent_by: Sent by @{} ({}) -send_message: Now send me the message! -msg_could_not_be_sent: Message could not be sent. -msg_sent: "Message has been sent successfully. :white_check_mark:"