Skip to content

Commit

Permalink
Merge pull request #2 from furtidev/main
Browse files Browse the repository at this point in the history
Migrated `Inspection` cog to Disnake & more
  • Loading branch information
hitblast authored Sep 2, 2022
2 parents 763cce2 + c6d12ad commit 3a2722b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 40 deletions.
89 changes: 51 additions & 38 deletions cogs/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
# Imports.
from datetime import datetime

import discord
from discord import app_commands
from discord.ext import commands
import disnake
from disnake import Option, OptionType
from disnake.ext import commands

import core
from core.datacls import LockRoles
Expand All @@ -43,15 +43,15 @@ def __init__(self, bot: core.IgKnite) -> None:
self.bot = bot

# guildinfo
@app_commands.command(
@commands.slash_command(
name='guildinfo',
description='Shows all important information about the server.'
description='Shows all important information about the server.',
dm_permission=False
)
@app_commands.guild_only()
@app_commands.checks.has_any_role(LockRoles.mod, LockRoles.admin)
@commands.has_any_role(LockRoles.mod, LockRoles.admin)
async def _guildinfo(
self,
inter: discord.Interaction
inter: disnake.CommandInteraction
) -> None:
embed = core.TypicalEmbed(inter).add_field(
name='Birth',
Expand All @@ -78,22 +78,26 @@ async def _guildinfo(
if inter.guild.icon:
embed.set_thumbnail(url=inter.guild.icon)

await inter.response.send_message(embed=embed)
await inter.send(embed=embed)

# userinfo
@app_commands.command(
@commands.slash_command(
name='userinfo',
description='Shows all important information on a user.'
)
@app_commands.describe(
member='Mention the server member.'
description='Shows all important information on a user.',
options=[
Option(
'member',
'Mention the server member.',
OptionType.user
)
],
dm_permission=False
)
@app_commands.guild_only()
@app_commands.checks.has_any_role(LockRoles.mod, LockRoles.admin)
@commands.has_any_role(LockRoles.mod, LockRoles.admin)
async def _userinfo(
self,
inter: discord.Interaction,
member: discord.Member = None
inter: disnake.CommandInter,
member: disnake.Member = None
) -> None:
member = inter.user if not member else member

Expand Down Expand Up @@ -126,22 +130,27 @@ async def _userinfo(
url=member.display_avatar
)

await inter.response.send_message(embed=embed)
await inter.send(embed=embed)

# roleinfo
@app_commands.command(
@commands.slash_command(
name='roleinfo',
description='Shows all important information related to a specific role.'
)
@app_commands.describe(
role='Mention the role.'
description='Shows all important information related to a specific role.',
options=[
Option(
'role',
'Mention the role.',
OptionType.role,
required=True
)
],
dm_permission=False
)
@app_commands.guild_only()
@app_commands.checks.has_any_role(LockRoles.mod, LockRoles.admin)
@commands.has_any_role(LockRoles.mod, LockRoles.admin)
async def _roleinfo(
self,
inter: discord.Interaction,
role: discord.Role
inter: disnake.CommandInteraction,
role: disnake.Role
) -> None:
embed = core.TypicalEmbed(inter).set_title(
value=f'Role information: @{role.name}'
Expand All @@ -167,21 +176,25 @@ async def _roleinfo(
value=f'`{role.id}`'
)

await inter.response.send_message(embed=embed)
await inter.send(embed=embed)

# audit
@app_commands.command(
@commands.slash_command(
name='audit',
description='Views the latest entries of the audit log in detail.'
)
@app_commands.describe(
limit='The limit for showing entries. Must be within 1 and 100.'
description='Views the latest entries of the audit log in detail.',
options=[
Option(
'limit',
'The limit for showing entries. Must be within 1 and 100.',
OptionType.integer
)
],
dm_permission=False
)
@app_commands.guild_only()
@app_commands.checks.has_any_role(LockRoles.mod, LockRoles.admin)
@commands.has_any_role(LockRoles.mod, LockRoles.admin)
async def _audit(
self,
inter: discord.Interaction,
inter: disnake.CommandInteraction,
limit: int = 5
):
if limit not in range(1, 101):
Expand All @@ -199,7 +212,7 @@ async def _audit(
inline=False
)

await inter.response.send_message(embed=embed, ephemeral=True)
await inter.send(embed=embed, ephemeral=True)


# The setup() function for the cog.
Expand Down
16 changes: 15 additions & 1 deletion guicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def build(self) -> Column:
self.owner_id = TextField(
hint_text='Enter your Discord user ID'
)
self.spotify_client_secret = TextField(
hint_text='Enter your Spotify client secret'
)
self.spotify_client_id = TextField(
hint_text='Enter your Spotify client ID'
)
self.error_viewer = Text(
value='Please fill in all the text fields!',
color='red',
Expand All @@ -61,6 +67,10 @@ def build(self) -> Column:
self.bot_token,
Text(value='Owner ID', size=20),
self.owner_id,
Text(value='Spotify Client Secet', size=20),
self.spotify_client_secret,
Text(value='Spotify Client ID', size=20),
self.spotify_client_id,
IconButton(icon='check', bgcolor='white', icon_color='black', on_click=self.generate_config),
self.error_viewer,
self.success_viewer,
Expand All @@ -71,6 +81,8 @@ def generate_config(self, _) -> None:
if (
len(self.bot_token.value) == 0
or len(self.owner_id.value) == 0
or len(self.spotify_client_id.value) == 0
or len(self.spotify_client_secret.value) == 0
):
self.error_viewer.visible = True

Expand All @@ -79,7 +91,9 @@ def generate_config(self, _) -> None:
write_mode = 'w' if os.path.exists(here) else 'x'

with open(here, write_mode) as f:
f.write(f'DISCORD_TOKEN={self.bot_token.value}\nDISCORD_OWNER_ID={self.owner_id.value}')
f.write(f'''DISCORD_TOKEN={self.bot_token.value}\nDISCORD_OWNER_ID={self.owner_id.value}
SPOTIFY_CLIENT_SECRET={self.spotify_client_secret.value}
SPOTIFY_CLIENT_ID={self.spotify_client_id.value}''')
self.success_viewer.visible = True
self.update()

Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
initial_extensions=[
'cogs.customization',
'cogs.general',
'cogs.moderation'
'cogs.moderation',
'cogs.inspection'
]
)

Expand Down

0 comments on commit 3a2722b

Please sign in to comment.