Skip to content

Commit

Permalink
Use python 3.10 Union syntax, typing fixes and add BaseView.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenChen committed Feb 25, 2023
1 parent f803c3d commit fc624c1
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 143 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cat ./schema.sql | docker compose exec -T db psql -U kurisu -d kurisu
docker-compose down db
```

Start Kurisu with the following command. Assuming a clean setup, this will pull postgres:13 to run as the database, and python:3.9-alpine as the base image for Kurisu, then build a new Kurisu image. Then it will start up postgres first, then kurisu once the database is active.
Start Kurisu with the following command. Assuming a clean setup, this will pull postgres:13 to run as the database, and python:3.11-alpine as the base image for Kurisu, then build a new Kurisu image. Then it will start up postgres first, then kurisu once the database is active.

```
docker-compose up --build
Expand Down
8 changes: 4 additions & 4 deletions cogs/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from discord.ext import commands
from discord.utils import format_dt, snowflake_time, MISSING
from math import ceil
from typing import Union, Optional, TYPE_CHECKING
from typing import Optional, TYPE_CHECKING
from utils.checks import is_staff, check_if_user_can_sr, check_staff, is_staff_app
from utils.converters import DateOrTimeToSecondsConverter, HackMessageTransformer
from utils.utils import gen_color, send_dm_message, KurisuCooldown
Expand Down Expand Up @@ -166,7 +166,7 @@ async def uptime(self, ctx: KurisuContext):
@commands.guild_only()
@is_staff("SuperOP")
@commands.command(hidden=True, aliases=['copyrole', 'crp'])
async def copyroleperms(self, ctx: GuildContext, role: discord.Role, src_channel: Union[discord.TextChannel, discord.VoiceChannel], des_channels: commands.Greedy[Union[discord.TextChannel, discord.VoiceChannel]]):
async def copyroleperms(self, ctx: GuildContext, role: discord.Role, src_channel: discord.TextChannel | discord.VoiceChannel, des_channels: commands.Greedy[discord.TextChannel | discord.VoiceChannel]):
"""Copy role overwrites from a channel to channels"""
if any(type(c) != type(src_channel) for c in des_channels):
return await ctx.send("Voice channels and text channel permissions are incompatible!")
Expand All @@ -178,7 +178,7 @@ async def copyroleperms(self, ctx: GuildContext, role: discord.Role, src_channel
@commands.guild_only()
@is_staff("SuperOP")
@commands.command(hidden=True, aliases=['ccp'])
async def copychannelperms(self, ctx: GuildContext, src_channel: Union[discord.TextChannel, discord.VoiceChannel, discord.ForumChannel], des_channels: commands.Greedy[Union[discord.TextChannel, discord.VoiceChannel, discord.ForumChannel]]):
async def copychannelperms(self, ctx: GuildContext, src_channel: discord.TextChannel | discord.VoiceChannel | discord.ForumChannel, des_channels: commands.Greedy[discord.TextChannel | discord.VoiceChannel | discord.ForumChannel]):
"""Copy channel overwrites from a channel to channels"""
overwrites = src_channel.overwrites
for c in des_channels:
Expand Down Expand Up @@ -600,7 +600,7 @@ async def simplevote(self,
@is_staff('OP')
@commands.guild_only()
@commands.command()
async def addemoji(self, ctx: GuildContext, name: str, emoji: Union[discord.PartialEmoji, str], *roles: discord.Role):
async def addemoji(self, ctx: GuildContext, name: str, emoji: discord.PartialEmoji | str, *roles: discord.Role):
"""Add an emoji to the server. OP+ only."""
if isinstance(emoji, discord.PartialEmoji):
emoji_bytes = await emoji.read()
Expand Down
2 changes: 1 addition & 1 deletion cogs/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def wordfilter_import(self, ctx, input_file: discord.Attachment, type: Lit
@wordfilter.command(name='clear')
async def wordfilter_clear(self, ctx: KurisuContext):
"""Deletes all filtered words in the filter"""
view = ConfirmationButtons(ctx.author.id)
view = ConfirmationButtons(ctx.author)
msg = await ctx.send("WARNING: This will delete all filtered words in the wordfilter, continue?", view=view)
await view.wait()
if view.value:
Expand Down
14 changes: 7 additions & 7 deletions cogs/kickban.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from discord import app_commands
from discord.ext import commands
from discord.utils import format_dt
from typing import Union, Literal, TYPE_CHECKING, Optional
from typing import Literal, TYPE_CHECKING, Optional
from utils.converters import TimeTransformer, DateOrTimeToSecondsConverter
from utils.checks import is_staff, is_staff_app, check_bot_or_staff
from utils.utils import send_dm_message
Expand Down Expand Up @@ -69,7 +69,7 @@ async def kick_member(self, ctx: GuildContext, member: discord.Member, *, reason
@is_staff("OP")
@commands.bot_has_permissions(ban_members=True)
@commands.command(name="ban", aliases=["yeet"])
async def ban_member(self, ctx: GuildContext, member: Union[discord.Member, discord.User], days: Optional[Literal[0, 1, 2, 3, 4, 5, 6, 7]] = 0, *, reason: Optional[str] = None):
async def ban_member(self, ctx: GuildContext, member: discord.Member | discord.User, days: Optional[Literal[0, 1, 2, 3, 4, 5, 6, 7]] = 0, *, reason: Optional[str] = None):
"""Bans a user from the server. OP+ only. Optional: [days] Specify up to 7 days of messages to delete."""
if await check_bot_or_staff(ctx, member, "ban"):
return
Expand Down Expand Up @@ -155,7 +155,7 @@ async def ban_member_slash(self,
@is_staff("OP")
@commands.bot_has_permissions(ban_members=True)
@commands.command(name="superban", aliases=["superyeet"])
async def superban(self, ctx: GuildContext, member: Union[discord.Member, discord.User], days: Optional[Literal[0, 1, 2, 3, 4, 5, 6, 7]] = 0, *, reason: Optional[str] = None):
async def superban(self, ctx: GuildContext, member: discord.Member | discord.User, days: Optional[Literal[0, 1, 2, 3, 4, 5, 6, 7]] = 0, *, reason: Optional[str] = None):
"""Bans a user from the server. OP+ only. Optional: [days] Specify up to 7 days of messages to delete."""
if await check_bot_or_staff(ctx, member, "ban"):
return
Expand All @@ -178,7 +178,7 @@ async def superban(self, ctx: GuildContext, member: Union[discord.Member, discor

@commands.bot_has_permissions(ban_members=True)
@commands.command(name="unban", aliases=["unyeet"])
async def unban_member(self, ctx: GuildContext, user: Union[discord.Member, discord.User], *, reason: Optional[str] = None):
async def unban_member(self, ctx: GuildContext, user: discord.Member | discord.User, *, reason: Optional[str] = None):
"""Unbans a user from the server. OP+ only."""
try:
await ctx.guild.fetch_ban(user)
Expand Down Expand Up @@ -213,7 +213,7 @@ async def silentban_member(self, ctx: GuildContext, member: discord.Member, days
@is_staff("OP")
@commands.bot_has_permissions(ban_members=True)
@commands.command(name="timeban", aliases=["timeyeet"])
async def timeban_member(self, ctx: GuildContext, member: Union[discord.Member, discord.User], length: int = commands.parameter(converter=DateOrTimeToSecondsConverter), *, reason: Optional[str] = None):
async def timeban_member(self, ctx: GuildContext, member: discord.Member | discord.User, length: int = commands.parameter(converter=DateOrTimeToSecondsConverter), *, reason: Optional[str] = None):
"""Bans a user for a limited period of time. OP+ only.\n\nLength format: #d#h#m#s"""
if await check_bot_or_staff(ctx, member, "timeban"):
return
Expand Down Expand Up @@ -244,7 +244,7 @@ async def timeban_member(self, ctx: GuildContext, member: Union[discord.Member,
@is_staff("OP")
@commands.bot_has_permissions(kick_members=True)
@commands.command(name="softban", aliases=["gentleyeet"])
async def softban_member(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: str):
async def softban_member(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: str):
"""Soft-ban a user. OP+ only.
This "bans" the user without actually doing a ban on Discord.
Expand All @@ -263,7 +263,7 @@ async def softban_member(self, ctx: GuildContext, member: Union[discord.Member,

@is_staff("OP")
@commands.command(name="unsoftban")
async def unsoftban_member(self, ctx: GuildContext, user: Union[discord.Member, discord.User]):
async def unsoftban_member(self, ctx: GuildContext, user: discord.Member | discord.User):
"""Un-soft-ban a user based on ID. OP+ only."""
if user.id not in self.restrictions.softbans:
return await ctx.send("This user is not softbanned!")
Expand Down
12 changes: 6 additions & 6 deletions cogs/lockdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import discord

from discord.ext import commands
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Optional
from utils.checks import is_staff, check_staff

if TYPE_CHECKING:
Expand All @@ -26,7 +26,7 @@ async def cog_check(self, ctx: KurisuContext):
raise commands.NoPrivateMessage()
return True

async def lockdown_channels(self, ctx: GuildContext, *, channels: list[Union[discord.TextChannel, discord.VoiceChannel]], top_role: discord.Role,
async def lockdown_channels(self, ctx: GuildContext, *, channels: list[discord.TextChannel | discord.VoiceChannel], top_role: discord.Role,
level: int, message: Optional[str] = None) -> list[discord.TextChannel]:

locked_down = []
Expand Down Expand Up @@ -83,7 +83,7 @@ async def lockdown_channels(self, ctx: GuildContext, *, channels: list[Union[dis

@is_staff("HalfOP")
@commands.command(aliases=['lock'])
async def lockdown(self, ctx: GuildContext, channels: commands.Greedy[Union[discord.TextChannel, discord.VoiceChannel]]):
async def lockdown(self, ctx: GuildContext, channels: commands.Greedy[discord.TextChannel | discord.VoiceChannel]):
"""Lock message sending in the channel. Staff only."""

if self.locking_down:
Expand All @@ -110,7 +110,7 @@ async def lockdown(self, ctx: GuildContext, channels: commands.Greedy[Union[disc

@is_staff("Owner")
@commands.command(aliases=['slock'])
async def slockdown(self, ctx: GuildContext, channels: commands.Greedy[Union[discord.TextChannel, discord.VoiceChannel]]):
async def slockdown(self, ctx: GuildContext, channels: commands.Greedy[discord.TextChannel | discord.VoiceChannel]):
"""Lock message sending in the channel for everyone. Owners only."""

if self.locking_down:
Expand All @@ -137,7 +137,7 @@ async def slockdown(self, ctx: GuildContext, channels: commands.Greedy[Union[dis

@is_staff('Helper')
@commands.command()
async def softlock(self, ctx: GuildContext, channels: commands.Greedy[Union[discord.TextChannel, discord.VoiceChannel]]):
async def softlock(self, ctx: GuildContext, channels: commands.Greedy[discord.TextChannel | discord.VoiceChannel]):
"""Lock message sending in the channel, without the "disciplinary action" note. Staff and Helpers only."""

if self.locking_down:
Expand Down Expand Up @@ -169,7 +169,7 @@ async def softlock(self, ctx: GuildContext, channels: commands.Greedy[Union[disc

@is_staff('Helper')
@commands.command()
async def unlock(self, ctx: GuildContext, channels: commands.Greedy[Union[discord.TextChannel, discord.VoiceChannel]]):
async def unlock(self, ctx: GuildContext, channels: commands.Greedy[discord.TextChannel | discord.VoiceChannel]):
"""Unlock message sending in the channel. Staff only and Helpers only."""
author = ctx.author

Expand Down
28 changes: 14 additions & 14 deletions cogs/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from discord.ext import commands
from discord.utils import format_dt
from subprocess import call
from typing import Union, Optional, TYPE_CHECKING
from typing import Optional, TYPE_CHECKING
from utils import Restriction
from utils.converters import DateOrTimeToSecondsConverter, TimeTransformer
from utils.checks import is_staff, check_staff, check_bot_or_staff, is_staff_app
Expand Down Expand Up @@ -74,7 +74,7 @@ async def pull(self, ctx: KurisuContext):
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=['ui'])
async def userinfo(self, ctx: GuildContext, u: Union[discord.Member, discord.User]):
async def userinfo(self, ctx: GuildContext, u: discord.Member | discord.User):
"""Shows information from a user. Staff and Helpers only."""
basemsg = f"name = {u.name}\nid = {u.id}\ndiscriminator = {u.discriminator}\navatar = <{u.avatar}>\nbot = {u.bot}\ndefault_avatar= <{u.default_avatar}>\ncreated_at = {u.created_at}\n"
if isinstance(u, discord.Member):
Expand All @@ -91,7 +91,7 @@ async def userinfo(self, ctx: GuildContext, u: Union[discord.Member, discord.Use

@commands.guild_only()
@commands.command(aliases=['ui2'])
async def userinfo2(self, ctx: GuildContext, user: Union[discord.Member, discord.User] = commands.Author):
async def userinfo2(self, ctx: GuildContext, user: discord.Member | discord.User = commands.Author):
"""Shows information from a user. Staff and Helpers only."""

if not check_staff(ctx.bot, 'Helper', ctx.author.id) and (ctx.author != user or ctx.channel != self.bot.channels['bot-cmds']):
Expand Down Expand Up @@ -259,7 +259,7 @@ async def convert(self, ctx, arg: str):
@commands.bot_has_permissions(manage_channels=True)
@commands.guild_only()
@commands.command()
async def slowmode(self, ctx: GuildContext, channel: Optional[Union[discord.TextChannel, discord.VoiceChannel, discord.Thread]], *, length: int = commands.parameter(converter=DateOrTimeToSecondsConverter)):
async def slowmode(self, ctx: GuildContext, channel: Optional[discord.TextChannel | discord.VoiceChannel | discord.Thread], *, length: int = commands.parameter(converter=DateOrTimeToSecondsConverter)):
"""Apply a given slowmode time to a channel.
The time format is identical to that used for timed kicks/bans/takehelps.
Expand Down Expand Up @@ -292,7 +292,7 @@ async def slowmode(self, ctx: GuildContext, channel: Optional[Union[discord.Text
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=['clear'], extras={'examples': ['.purge #hacking-general 10 --exclude Kurisu#1234', '.purge 10', '.purge 10 --before 983086930910654594']})
async def purge(self, ctx: GuildContext, channel: Optional[Union[discord.TextChannel, discord.VoiceChannel, discord.Thread]], limit: commands.Range[int, 1], *, flags: PurgeFlags):
async def purge(self, ctx: GuildContext, channel: Optional[discord.TextChannel | discord.VoiceChannel | discord.Thread], limit: commands.Range[int, 1], *, flags: PurgeFlags):
"""Clears at most a given number of messages in current channel or a channel if given. Helpers in assistance channels and Staff only.
**Flags**
Expand Down Expand Up @@ -509,7 +509,7 @@ async def embed(self, ctx: GuildContext, member: discord.Member, *, reason: Opti
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=["nohelp", "yesnthelp"])
async def takehelp(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def takehelp(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Remove access to the assistance channels. Staff and Helpers only."""
if await check_bot_or_staff(ctx, member, "takehelp"):
return
Expand All @@ -520,7 +520,7 @@ async def takehelp(self, ctx: GuildContext, member: Union[discord.Member, discor
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=["yeshelp"])
async def givehelp(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def givehelp(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Restore access to the assistance channels. Staff and Helpers only."""
await self.restrictions.remove_restriction(member, Restriction.TakeHelp)
await ctx.send(f"{member.mention} can access the help channels again.")
Expand Down Expand Up @@ -548,7 +548,7 @@ async def timetakehelp(self, ctx: GuildContext, member: discord.Member, length:
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=["notech", "technt"])
async def taketech(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def taketech(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Remove access to the tech channel. Staff and Helpers only."""
if await check_bot_or_staff(ctx, member, "taketech"):
return
Expand All @@ -559,7 +559,7 @@ async def taketech(self, ctx: GuildContext, member: Union[discord.Member, discor
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=["yestech"])
async def givetech(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def givetech(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Restore access to the tech channel. Staff and Helpers only."""
await self.restrictions.remove_restriction(member, Restriction.NoTech)
await ctx.send(f"{member.mention} can access the tech channel again.")
Expand All @@ -585,7 +585,7 @@ async def timetaketech(self, ctx: GuildContext, member: discord.Member, length:
@is_staff("Helper")
@commands.guild_only()
@commands.command(aliases=["mutehelp"])
async def helpmute(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def helpmute(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Remove speak perms to the assistance channels. Staff and Helpers only."""
if await check_bot_or_staff(ctx, member, "helpmute"):
return
Expand Down Expand Up @@ -613,7 +613,7 @@ async def timehelpmute(self, ctx: GuildContext, member: discord.Member, length:
@is_staff("Helper")
@commands.guild_only()
@commands.command()
async def helpunmute(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def helpunmute(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Restores speak access to help channels. Helpers+ only."""
await self.restrictions.remove_restriction(member, Restriction.HelpMute)
await ctx.send(f"{member.mention} can now speak in the help channels again.")
Expand Down Expand Up @@ -650,7 +650,7 @@ async def givesmallhelp(self, ctx: GuildContext, members: commands.Greedy[discor
@is_staff("Helper")
@commands.guild_only()
@commands.command()
async def probate(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def probate(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Probate a user. Staff and Helpers only."""
if await check_bot_or_staff(ctx, member, "probate"):
return
Expand All @@ -661,7 +661,7 @@ async def probate(self, ctx: GuildContext, member: Union[discord.Member, discord
@is_staff("Helper")
@commands.guild_only()
@commands.command()
async def unprobate(self, ctx: GuildContext, member: Union[discord.Member, discord.User], *, reason: Optional[str]):
async def unprobate(self, ctx: GuildContext, member: discord.Member | discord.User, *, reason: Optional[str]):
"""Unprobate a user. Staff and Helpers only."""
await self.restrictions.remove_restriction(member, Restriction.Probation)
await ctx.send(f"{member.mention} is out of probation.")
Expand All @@ -670,7 +670,7 @@ async def unprobate(self, ctx: GuildContext, member: Union[discord.Member, disco
@is_staff("Owner")
@commands.guild_only()
@commands.command()
async def updatechannel(self, ctx: GuildContext, name: str, channel: Union[discord.TextChannel, discord.VoiceChannel, discord.Thread]):
async def updatechannel(self, ctx: GuildContext, name: str, channel: discord.TextChannel | discord.VoiceChannel | discord.Thread):
"""Changes the id of a channel"""
if name not in self.bot.channels:
await ctx.send("Invalid channel name!")
Expand Down
Loading

0 comments on commit fc624c1

Please sign in to comment.