Skip to content

Commit

Permalink
Merge pull request #255 from hitblast/main
Browse files Browse the repository at this point in the history
🔨 [tuning] Updated configurations and fixed broken `/help` command
  • Loading branch information
furtidev authored Jan 27, 2024
2 parents c8e155e + b7f0205 commit a043f0a
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"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 black ruff",
"postCreateCommand": "sudo apt update && sudo apt install -y --no-install-recommends ffmpeg && pip install -U pip && pip install -r requirements.txt && pip install ruff",
"customizations": {
"vscode": {
"extensions": [
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-License-Identifier: MIT

name: Format

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

permissions:
contents: write
pull-requests: write

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

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

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

- name: Check
id: formatcheck
uses: chartboost/ruff-action@v1
continue-on-error: true
with:
args: format --check .

- name: Format
uses: chartboost/ruff-action@v1
with:
args: format .

- name: Create pull request
if: steps.formatcheck.outcome != 'success'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "🎨 Automated formatting errors fix"
commit-message: "fixed formatting errors (ruff)"
body: |
Formatter errors found in: ${{ github.sha }}.
base: ${{ github.head_ref }}
branch: actions/ruff
delete-branch: true
reviewers: hitblast
54 changes: 54 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-License-Identifier: MIT

name: Lint

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

permissions:
contents: write
pull-requests: write

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

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

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

- name: Check
id: lintcheck
uses: chartboost/ruff-action@v1
continue-on-error: true
with:
args: check .

- name: Lint
uses: chartboost/ruff-action@v1
with:
args: check . --fix

- name: Create pull request
if: steps.lintcheck.outcome != 'success'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "🎨 Automated linting errors fix"
commit-message: "fixed linting errors (ruff)"
body: |
Linter errors found in: ${{ github.sha }}.
base: ${{ github.head_ref }}
branch: actions/ruff
reviewers: hitblast
delete-branch: true
65 changes: 0 additions & 65 deletions .github/workflows/stylecheck.yml

This file was deleted.

18 changes: 10 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: MIT

{
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll.ruff": true,
"source.organizeImports.ruff": true
},
"editor.formatOnSave": true
},
"python.formatting.provider": "black"
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
},
"ruff.importStrategy": "fromEnvironment"
}
2 changes: 1 addition & 1 deletion cogs/customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def _unassignrole(
role: disnake.Role = Param(description='Mention the role to remove from the user.'),
) -> None:
if role not in member.roles:
return await inter.send('The member doesn\'t has this role.', ephemeral=True)
return await inter.send("The member doesn't has this role.", ephemeral=True)

await member.remove_roles(role)
await inter.send(f'Role {role.mention} has been removed from **{member.display_name}**!')
Expand Down
10 changes: 5 additions & 5 deletions cogs/exceptionhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ def __init__(self, bot: core.IgKnite) -> None:

def get_view(self, inter: disnake.CommandInter) -> core.SmallView:
view = core.SmallView(inter).add_button(
label='Think it\'s a bug?',
label="Think it's a bug?",
url=core.BotData.repo + '/issues/new?template=bug.yml',
style=disnake.ButtonStyle.red,
)
return view

async def process_error(self, inter: disnake.CommandInter, error: Any) -> None:
'''
"""
A method for processing the exceptions caused in interaction commands and responding
accordingly.
'''
"""

error = getattr(error, 'original', error)
embed = core.TypicalEmbed(inter=inter, is_error=True)
Expand All @@ -37,13 +37,13 @@ async def process_error(self, inter: disnake.CommandInter, error: Any) -> None:
if isinstance(error, commands.errors.MissingPermissions) or isinstance(
error, errors.Forbidden
):
embed.title = 'Nice try! I don\'t have permission to do that.'
embed.title = "Nice try! I don't have permission to do that."

# MissingRole
elif isinstance(error, commands.errors.MissingRole) or isinstance(
error, commands.errors.MissingAnyRole
):
embed.title = 'Oops! You\'re missing a role.'
embed.title = "Oops! You're missing a role."

# Anything else...
else:
Expand Down
12 changes: 6 additions & 6 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def on_raw_reaction_add(self, payload: disnake.RawReactionActionEvent) ->
chnl = self.bot.get_channel(payload.channel_id)
msg = disnake.utils.get(await chnl.history(limit=5).flatten(), id=payload.message_id)
embed = core.TypicalEmbed(
title='You\'ve bookmarked a message.',
title="You've bookmarked a message.",
description=msg.content
+ f'\n\nSent by {msg.author.name} '
+ f'on {payload.member.guild.name}',
Expand All @@ -84,7 +84,7 @@ async def on_raw_reaction_add(self, payload: disnake.RawReactionActionEvent) ->
async def _avatar_backend(
self, inter: disnake.CommandInter, member: disnake.Member = None
) -> None:
embed = core.TypicalEmbed(inter=inter, title='Here\'s what I found!').set_image(
embed = core.TypicalEmbed(inter=inter, title="Here's what I found!").set_image(
url=member.avatar
)

Expand Down Expand Up @@ -121,10 +121,10 @@ async def _ping(self, inter: disnake.CommandInter) -> None:
@commands.slash_command(name='help', description='Get to know IgKnite!')
async def help(self, inter: disnake.CommandInter):
embed = core.TypicalEmbed(
inter,
title='Hey there! I\'m IgKnite.',
description='I\'m a bot with no text commands (you heard that right) '
+ 'and I\'m here to help you manage and moderate your Discord server alongside '
inter=inter,
title="Hey there! I'm IgKnite.",
description="I'm a bot with no text commands (you heard that right) "
+ "and I'm here to help you manage and moderate your Discord server alongside "
+ 'having a midnight music party with your friends in a random voice channel. '
+ 'Looking forward to being friends with you!',
disabled_footer=True,
Expand Down
2 changes: 1 addition & 1 deletion cogs/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def _userinfo_backend(self, inter: disnake.CommandInter, member: disnake.M
),
)
.add_field(name='On Mobile', value=member.is_on_mobile())
.add_field(name='Race', value="Bot" if member.bot else "Human")
.add_field(name='Race', value='Bot' if member.bot else 'Human')
.add_field(name='Roles', value=len(member.roles))
.add_field(name='Position', value=member.top_role.mention)
.add_field(name='Identifier', value=member.id)
Expand Down
2 changes: 1 addition & 1 deletion cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ async def _showbannedwords(self, inter: disnake.CommandInter) -> None:
if rule.name == 'IgKnite Banwords':
words += (f'{item} \n' for item in rule.trigger_metadata.keyword_filter)
embed = core.TypicalEmbed(
inter, title='Here\'s the list of banned words:', description=words
inter, title="Here's the list of banned words:", description=words
)
await inter.send(embed=embed)

Expand Down
Loading

0 comments on commit a043f0a

Please sign in to comment.