mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-02 16:43:12 +00:00
added ruff
This commit is contained in:
parent
38d6908c39
commit
3dced41570
17 changed files with 94 additions and 47 deletions
17
.github/workflows/linting.yml
vendored
17
.github/workflows/linting.yml
vendored
|
@ -1,5 +1,5 @@
|
|||
name: 'Linting'
|
||||
on: [push, pull_request]
|
||||
on: [ push, pull_request ]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
@ -32,13 +32,14 @@ jobs:
|
|||
restore-keys: |
|
||||
${{ runner.os }}-poetry-
|
||||
|
||||
# Use Lint Action for linting and formatting
|
||||
- name: Run linters
|
||||
uses: wearerequired/lint-action@v2.3.0
|
||||
# Use Ruff Action for linting
|
||||
- name: Run Ruff
|
||||
uses: chartboost/ruff-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.github_token }}
|
||||
auto_fix: true
|
||||
version: 'latest' # Use the latest version of Ruff
|
||||
args: '--check .' # Replace with any arguments you want to pass to Ruff
|
||||
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
- name: Commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: 'style fixes by linter'
|
||||
commit_message: 'style fixes by ruff'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_bulk_message_delete.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_guild_channel_create.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_guild_channel_delete.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
# on_guild_channel_pins_update.py
|
||||
from datetime import datetime
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_guild_channel_update.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_guild_role_create.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_guild_role_delete.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_guild_role_update.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_member_ban.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_member_join.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_member_remove.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_member_unban.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,43 +1,74 @@
|
|||
# Import the necessary modules
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
# Initialize the logger
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
||||
# Define the OnMemberUpdate class, which is a subclass of commands.Cog
|
||||
class OnMemberUpdate(commands.Cog):
|
||||
# Initialize the class with the bot as an argument
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
# Define a listener for the 'on_member_update' event
|
||||
@commands.Cog.listener("on_member_update")
|
||||
async def on_member_update(self, before: discord.Member, after: discord.Member):
|
||||
"""
|
||||
Handles the event when a Discord member updates their profile.
|
||||
This function is triggered when a member's profile is updated.
|
||||
It compares the before and after states of the member, logs any changes,
|
||||
creates an embed for the changes, and sends the embed to a specified channel.
|
||||
"""
|
||||
try:
|
||||
# Compare the before and after states of the member
|
||||
changes = self.compare_member_changes(before, after)
|
||||
if changes:
|
||||
# Log the changes
|
||||
self.log_member_changes(changes)
|
||||
# Create an embed for the changes
|
||||
embed = self.create_embed_for_changes(changes)
|
||||
# Send the embed to a specified channel
|
||||
await self.send_embed(embed)
|
||||
except Exception as e:
|
||||
# Log any errors that occur
|
||||
logger.error(f"Error handling member update: {e}")
|
||||
|
||||
This function is triggered when a member's nickname, roles, pending status, timeout status, guild avatar, or flags are modified. It does not react when a member's timeout expires due to a restriction in Discord.
|
||||
def compare_member_changes(self, before, after):
|
||||
"""
|
||||
This function compares the before and after states of a member.
|
||||
It currently only checks for changes in nickname, but more comparisons can be added as needed.
|
||||
"""
|
||||
changes = {}
|
||||
if before.nick != after.nick:
|
||||
changes['nickname'] = {'before': before.nick, 'after': after.nick}
|
||||
return changes
|
||||
|
||||
Args:
|
||||
before (discord.Member): The previous state of the member before the update.
|
||||
after (discord.Member): The updated state of the member after the update.
|
||||
def log_member_changes(self, changes):
|
||||
"""
|
||||
This function logs any changes that have occurred.
|
||||
"""
|
||||
for change, values in changes.items():
|
||||
logger.info(f"{change} changed from {values['before']} to {values['after']}")
|
||||
|
||||
Note:
|
||||
This function requires the `Intents.members` to be enabled.
|
||||
|
||||
https://discordpy.readthedocs.io/en/stable/api.html#discord.on_member_update
|
||||
""" # noqa E501
|
||||
|
||||
# TODO: On member update logic goes here.
|
||||
|
||||
# You can use the before and after objects to compare the changes.
|
||||
# We should probably abstract this into multiple functions:
|
||||
|
||||
# 1. Comparing changes
|
||||
# 2. Logging changes
|
||||
# 3. Creating the embed
|
||||
# 4. Sending the embed
|
||||
|
||||
logger.debug(f"Member {before} updated to {after}.")
|
||||
def create_embed_for_changes(self, changes):
|
||||
"""
|
||||
This function creates an embed for the changes that have occurred.
|
||||
"""
|
||||
embed = discord.Embed(title="Member Update", description="A member has updated their profile.")
|
||||
for change, values in changes.items():
|
||||
embed.add_field(name=f"Old {change}", value=values['before'], inline=False)
|
||||
embed.add_field(name=f"New {change}", value=values['after'], inline=False)
|
||||
return embed
|
||||
|
||||
async def send_embed(self, embed):
|
||||
"""
|
||||
This function sends the embed to a specified channel.
|
||||
The channel ID needs to be replaced with the actual ID of the channel you want to send the embed to.
|
||||
"""
|
||||
some_channel = self.bot.get_channel(channel_id) # Replace 'channel_id' with the actual ID
|
||||
await some_channel.send(embed=embed)
|
||||
|
||||
# Define an asynchronous setup function that adds the OnMemberUpdate cog to the bot
|
||||
async def setup(bot):
|
||||
await bot.add_cog(OnMemberUpdate(bot))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_message.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_message_delete.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# on_message_edit.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from utils._tux_logger import TuxLogger
|
||||
from tux.utils.tux_logger import TuxLogger
|
||||
|
||||
logger = TuxLogger(__name__)
|
||||
|
||||
|
|
Loading…
Reference in a new issue