Skip to content

Commit

Permalink
Merge pull request #241 from hitblast/disnake-sync
Browse files Browse the repository at this point in the history
✨ [feat] Added `/makestage`; modified Customization cog commands and more
  • Loading branch information
hitblast authored Jun 23, 2023
2 parents 2b9da77 + 74613ce commit ea69f94
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
"postCreateCommand": "sudo apt update && sudo apt install -y --no-install-recommends ffmpeg && pip install -U pip && pip install -r requirements.txt && pip install ruff",
"postCreateCommand": "sudo apt update && sudo apt install -y --no-install-recommends ffmpeg && pip install -U pip && pip install -r requirements.txt && pip install black ruff",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff"
]
}
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/linting.yml

This file was deleted.

65 changes: 65 additions & 0 deletions .github/workflows/stylecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SPDX-License-Identifier: MIT

name: Style Check

on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
linting:
name: Ruff
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Run Ruff
uses: chartboost/ruff-action@v1

formatting:
name: Black

runs-on: ubuntu-latest
needs: [linting]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check
id: checkifneeded
uses: psf/black@stable
with:
options: "--check --verbose"
version: "~= 23.0"
continue-on-error: true

- name: Format
uses: psf/black@stable
with:
options: "--verbose"
version: "~= 23.0"

- name: Create pull request
if: steps.checkifneeded.outcome != 'success'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "🎨 [tuning] Resolved formatting errors"
commit-message: "format code using psf/black"
body: |
Formatter errors found in: ${{ github.sha }}.
base: ${{ github.head_ref }}
branch: actions/black
reviewers: hitblast
delete-branch: true
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
],
"unwantedRecommendations": [
"ms-python.vscode-pylance",
"ms-python.isort"
]
}
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: MIT
{
"[python]": {
"editor.defaultFormatter": null,
"editor.codeActionsOnSave": {
"source.fixAll.ruff": true,
"source.organizeImports.ruff": true
}
}
},
"editor.formatOnSave": true
},
"python.formatting.provider": "black"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<br> <img src="static/banner.png">

[![CodeSee](https://github.com/IgKniteDev/IgKnite/actions/workflows/codesee-arch-diagram.yml/badge.svg)](https://github.com/IgKniteDev/IgKnite/actions/workflows/codesee-arch-diagram.yml)
[![Linting](https://github.com/IgKniteDev/IgKnite/actions/workflows/linting.yml/badge.svg)](https://github.com/IgKniteDev/IgKnite/actions/workflows/linting.yml)
[![Style Check](https://github.com/IgKniteDev/IgKnite/actions/workflows/stylecheck.yml/badge.svg)](https://github.com/IgKniteDev/IgKnite/actions/workflows/stylecheck.yml)

</div>

Expand Down
109 changes: 104 additions & 5 deletions cogs/customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


# Imports.
from typing import List

import disnake
from disnake import ChannelType, OptionChoice
from disnake.ext import commands
Expand All @@ -23,6 +25,23 @@ def get_color(hex: str) -> disnake.Colour:

# The actual cog.
class Customization(commands.Cog):
__slowmode_choices__: List[OptionChoice] = [
OptionChoice('Remove Slowmode', 0),
OptionChoice('5s', 5),
OptionChoice('10s', 10),
OptionChoice('15s', 15),
OptionChoice('30s', 30),
OptionChoice('1m', 60),
OptionChoice('2m', 120),
OptionChoice('5m', 300),
OptionChoice('10m', 600),
OptionChoice('15m', 900),
OptionChoice('30m', 1800),
OptionChoice('1h', 3600),
OptionChoice('2h', 7200),
OptionChoice('6h', 21600),
]

def __init__(self, bot: core.IgKnite) -> None:
self.bot = bot

Expand Down Expand Up @@ -138,6 +157,30 @@ async def _nick(
await member.edit(nick=nickname)
await inter.send(f'Member {member.mention} has been nicked to **{nickname}**!')

# slowmode
@commands.slash_command(
name='slowmode',
description='Sets slowmode for the current channel.',
dm_permission=False,
)
@commands.has_any_role(LockRoles.mod, LockRoles.admin)
async def _slowmode(
self,
inter: disnake.CommandInteraction,
duration: int = Param(
description='The amount of seconds to set the slowmode to. Set 0 to disable.',
min_value=0,
max_value=21600,
choices=__slowmode_choices__,
),
) -> None:
await inter.channel.edit(slowmode_delay=duration)

if duration == 0:
await inter.send('Slowmode has been disabled!')
else:
await inter.send(f'Slowmode has been set to **{duration}** seconds.')

# makechannel
@commands.slash_command(
name='makechannel',
Expand All @@ -155,13 +198,22 @@ async def _makechannel(
channel_types=[ChannelType.category],
),
topic: str = Param(description='Give a topic for the new channel.', default=None),
slowmode: int = Param(
description='The amount of seconds to set the slowmode to. Default is 0.',
default=0,
min_value=0,
max_value=21600,
choices=__slowmode_choices__,
),
) -> None:
channel = await inter.guild.create_text_channel(name=name, topic=topic, category=category)
channel = await inter.guild.create_text_channel(
name=name, topic=topic, category=category, slowmode_delay=slowmode
)
await inter.send(f'Channel {channel.mention} has been created!')

# makevc
@commands.slash_command(
name='makevc',
name='makevoice',
description='Create a new voice channel.',
dm_permission=False,
)
Expand All @@ -175,9 +227,47 @@ async def _makevc(
default=None,
channel_types=[ChannelType.category],
),
slowmode: int = Param(
description='The amount of seconds to set the slowmode to. Default is 0.',
default=0,
min_value=0,
max_value=21600,
choices=__slowmode_choices__,
),
) -> None:
vc = await inter.guild.create_voice_channel(name=name, category=category)
await inter.send(f'VC {vc.mention} has been created!')
vc = await inter.guild.create_voice_channel(
name=name, category=category, slowmode_delay=slowmode
)
await inter.send(f'{vc.mention} has been created!')

# makestage
@commands.slash_command(
name='makestage',
description='Creates a new stage channel.',
dm_permission=False,
)
@commands.has_role(LockRoles.admin)
async def _makestage(
self,
inter: disnake.CommandInteraction,
name: str = Param(description='Give a name for the new voice channel.'),
category: disnake.CategoryChannel = Param(
description='Specify the category to put the channel into. Defaults to none.',
default=None,
channel_types=[ChannelType.category],
),
slowmode: int = Param(
description='The amount of seconds to set the slowmode to. Default is 0.',
default=0,
min_value=0,
max_value=21600,
choices=__slowmode_choices__,
),
):
stage = await inter.guild.create_stage_channel(
name=name, category=category, slowmode_delay=slowmode
)
await inter.send(f'{stage.mention} has been created!')

# makecategory
@commands.slash_command(
Expand Down Expand Up @@ -206,7 +296,16 @@ async def _removechannel(
inter: disnake.CommandInteraction,
channel: disnake.TextChannel
| disnake.VoiceChannel
| disnake.StageChannel = Param(description='Specify the channel that you want to delete.'),
| disnake.StageChannel
| disnake.CategoryChannel = Param(
description='Specify the channel that you want to delete.',
channel_types=[
ChannelType.text,
ChannelType.voice,
ChannelType.category,
ChannelType.stage_voice,
],
),
) -> None:
await channel.delete()
await inter.send('Channel has been deleted!')
Expand Down
39 changes: 0 additions & 39 deletions cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,45 +370,6 @@ async def _clearpins(self, inter: disnake.CommandInteraction) -> None:

await inter.send('There are no pins to clear!')

# slowmode
@commands.slash_command(
name='slowmode',
description='Sets slowmode for the current channel.',
dm_permission=False,
)
@commands.has_any_role(LockRoles.mod, LockRoles.admin)
async def _slowmode(
self,
inter: disnake.CommandInteraction,
duration: int = Param(
description='The amount of seconds to set the slowmode to. Set 0 to disable.',
min_value=0,
max_value=21600,
choices=[
OptionChoice('Remove Slowmode', 0),
OptionChoice('5s', 5),
OptionChoice('10s', 10),
OptionChoice('15s', 15),
OptionChoice('30s', 30),
OptionChoice('1m', 60),
OptionChoice('2m', 120),
OptionChoice('5m', 300),
OptionChoice('10m', 600),
OptionChoice('15m', 900),
OptionChoice('30m', 1800),
OptionChoice('1h', 3600),
OptionChoice('2h', 7200),
OptionChoice('6h', 21600),
],
),
) -> None:
await inter.channel.edit(slowmode_delay=duration)

if duration == 0:
await inter.send('Slowmode has been disabled!')
else:
await inter.send(f'Slowmode has been set to **{duration}** seconds.')

# banword
@commands.slash_command(
name='banword',
Expand Down
2 changes: 1 addition & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .ui import *

# Set version number.
__version_info__ = ('2023', '6', '21') # Year.Month.Day
__version_info__ = ('2023', '6', '23') # Year.Month.Day
__version__ = '.'.join(__version_info__)


Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# SPDX-License-Identifier: MIT

[tool.black]
line-length = 100
skip-string-normalization = true

[tool.ruff]
target-version = "py311"
line-length = 100
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT

disnake[voice]==2.8.1
disnake[voice]==2.9.0
python-decouple==3.8
spotipy==2.23.0
yt-dlp==2023.6.21
yt-dlp==2023.6.22

0 comments on commit ea69f94

Please sign in to comment.