Migrated from NAFF to Interactions.py
continuous-integration/drone Build is passing Details

This commit is contained in:
Vegard Berg 2023-05-31 20:07:39 +02:00
parent eb37f41b45
commit 62902206b0
13 changed files with 147 additions and 123 deletions

View File

@ -3,7 +3,7 @@ from os import getenv
from typing import Optional from typing import Optional
import sentry_sdk as sentry import sentry_sdk as sentry
from naff import ( from interactions import (
Client, Client,
Guild, Guild,
Intents, Intents,
@ -16,12 +16,12 @@ from naff import (
RoleSelectMenu, RoleSelectMenu,
is_owner, is_owner,
check, check,
OptionTypes, OptionType,
GuildChannel, GuildChannel,
DM, DM,
) )
from naff.api import events from interactions.api import events
from naff.models.discord.embed import ( from interactions.models.discord.embed import (
Embed, Embed,
EmbedAuthor, EmbedAuthor,
EmbedField, EmbedField,
@ -169,7 +169,7 @@ class HeimdallrClient(Client):
@slash_option( @slash_option(
name="module", name="module",
description="The module to reload", description="The module to reload",
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
required=True, required=True,
) )
async def owner_reload(self, ctx: InteractionContext, module: str): async def owner_reload(self, ctx: InteractionContext, module: str):
@ -188,7 +188,7 @@ class HeimdallrClient(Client):
try: try:
self.reload_extension(module) self.reload_extension(module)
except Exception as e: except Exception:
logging.warn(f"Failed to reload '{module}'.") logging.warn(f"Failed to reload '{module}'.")
await ctx.send(f"Failed to reload '{module}'.") await ctx.send(f"Failed to reload '{module}'.")
else: else:
@ -285,8 +285,6 @@ def main():
JoinLeave.create_table() JoinLeave.create_table()
# Load extensions # Load extensions
if (sentry_token := getenv("SENTRY_TOKEN")) is not None:
bot.load_extension("naff.ext.sentry", token=sentry_token)
bot.load_extension("heimdallr.commands.admin") bot.load_extension("heimdallr.commands.admin")
bot.load_extension("heimdallr.commands.gatekeep") bot.load_extension("heimdallr.commands.gatekeep")
bot.load_extension("heimdallr.commands.quote") bot.load_extension("heimdallr.commands.quote")
@ -300,5 +298,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
import naff.ext.sentry
main() main()

View File

@ -6,22 +6,21 @@ for the needs of NLL. So this is to be considered deprecated.
""" """
from naff import ( from interactions import (
slash_command, slash_command,
slash_option, slash_option,
Extension, Extension,
Client, Client,
Permissions, Permissions,
InteractionContext, InteractionContext,
OptionTypes, OptionType,
Embed, Embed,
Member, Member,
EmbedField,
EmbedAuthor, EmbedAuthor,
Modal, Modal,
InputText, InputText,
TextStyles, TextStyles,
ChannelTypes, ChannelType,
GuildText, GuildText,
) )
import logging import logging
@ -52,8 +51,8 @@ class Resources(Extension):
@slash_option( @slash_option(
name="channel", name="channel",
description="The channel in which submitted/unpublished resources should appear", description="The channel in which submitted/unpublished resources should appear",
opt_type=OptionTypes.CHANNEL, opt_type=OptionType.CHANNEL,
channel_types=[ChannelTypes.GUILD_TEXT], channel_types=[ChannelType.GUILD_TEXT],
) )
async def adm_set_submitted_resources_channel( async def adm_set_submitted_resources_channel(
self, ctx: InteractionContext, channel: GuildText | None = None self, ctx: InteractionContext, channel: GuildText | None = None
@ -72,13 +71,11 @@ class Resources(Extension):
resource_channel.channel_id = channel.id resource_channel.channel_id = channel.id
resource_channel.save() resource_channel.save()
await ctx.send(ephemeral=True, await ctx.send(
ephemeral=True,
content=f"Submitted resource channel set to {channel.mention}." content=f"Submitted resource channel set to {channel.mention}."
) )
@slash_command( @slash_command(
name="resources", name="resources",
description="Get or add resources", description="Get or add resources",
@ -95,7 +92,7 @@ class Resources(Extension):
@slash_option( @slash_option(
name="page", name="page",
description="Page of resources to show", description="Page of resources to show",
opt_type=OptionTypes.INTEGER, opt_type=OptionType.INTEGER,
required=False, required=False,
) )
async def resources_list(self, ctx: InteractionContext, page: int = 1): async def resources_list(self, ctx: InteractionContext, page: int = 1):

View File

@ -1,18 +1,18 @@
# pylint: disable=consider-using-f-string # pylint: disable=consider-using-f-string
import logging import logging
from typing import Optional from typing import Optional
from naff import ( from interactions import (
Client, Client,
Extension, Extension,
slash_command, slash_command,
slash_option, slash_option,
OptionTypes, OptionType,
Permissions, Permissions,
InteractionContext, InteractionContext,
Embed, Embed,
EmbedField, EmbedField,
GuildChannel, GuildChannel,
ChannelTypes, ChannelType,
) )
from database import GuildSettings as GuildSettingsModel, JoinLeave as JoinLeaveModel from database import GuildSettings as GuildSettingsModel, JoinLeave as JoinLeaveModel
@ -112,8 +112,8 @@ class Admin(Extension):
name="channel", name="channel",
description="Channel to set as admin channel", description="Channel to set as admin channel",
required=True, required=True,
opt_type=OptionTypes.CHANNEL, opt_type=OptionType.CHANNEL,
channel_types=[ChannelTypes.GUILD_TEXT], channel_types=[ChannelType.GUILD_TEXT],
) )
async def adm_set_admin_channel( async def adm_set_admin_channel(
self, ctx: InteractionContext, channel: GuildChannel self, ctx: InteractionContext, channel: GuildChannel
@ -126,7 +126,6 @@ class Admin(Extension):
"Admin channel set to {}".format(channel.mention), ephemeral=True "Admin channel set to {}".format(channel.mention), ephemeral=True
) )
@slash_command( @slash_command(
name="adm", name="adm",
group_name="set", group_name="set",
@ -140,7 +139,7 @@ class Admin(Extension):
name="enabled", name="enabled",
description="Whether or not to use the name filter", description="Whether or not to use the name filter",
required=True, required=True,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
async def adm_set_use_name_filter(self, ctx: InteractionContext, enabled: bool) -> None: async def adm_set_use_name_filter(self, ctx: InteractionContext, enabled: bool) -> None:
guild_settings: Optional[GuildSettingsModel] guild_settings: Optional[GuildSettingsModel]
@ -163,7 +162,7 @@ class Admin(Extension):
name="enabled", name="enabled",
description="Whether or not to use gatekeep", description="Whether or not to use gatekeep",
required=True, required=True,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
async def adm_set_use_gatekeep(self, ctx: InteractionContext, enabled: bool) -> None: async def adm_set_use_gatekeep(self, ctx: InteractionContext, enabled: bool) -> None:
guild_settings: Optional[GuildSettingsModel] guild_settings: Optional[GuildSettingsModel]
@ -186,8 +185,8 @@ class Admin(Extension):
name="channel", name="channel",
description="Channel to set as join/leave messages channel", description="Channel to set as join/leave messages channel",
required=True, required=True,
opt_type=OptionTypes.CHANNEL, opt_type=OptionType.CHANNEL,
channel_types=[ChannelTypes.GUILD_TEXT], channel_types=[ChannelType.GUILD_TEXT],
) )
async def adm_set_join_leave_channel( async def adm_set_join_leave_channel(
self, ctx: InteractionContext, channel: GuildChannel self, ctx: InteractionContext, channel: GuildChannel
@ -214,13 +213,13 @@ class Admin(Extension):
name="enabled", name="enabled",
description="Whether or not to enable the join message", description="Whether or not to enable the join message",
required=True, required=True,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
@slash_option( @slash_option(
name="message", name="message",
description="The join message", description="The join message",
required=False, required=False,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
async def adm_set_join_message( async def adm_set_join_message(
self, ctx: InteractionContext, enabled: bool, message: str = None self, ctx: InteractionContext, enabled: bool, message: str = None
@ -251,13 +250,13 @@ class Admin(Extension):
name="enabled", name="enabled",
description="Whether or not to enable the leave message", description="Whether or not to enable the leave message",
required=True, required=True,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
@slash_option( @slash_option(
name="message", name="message",
description="The leave message", description="The leave message",
required=False, required=False,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
async def adm_set_leave_message( async def adm_set_leave_message(
self, ctx: InteractionContext, enabled: bool, message: str = None self, ctx: InteractionContext, enabled: bool, message: str = None

View File

@ -2,7 +2,7 @@ from copy import deepcopy
import json import json
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
import logging import logging
from naff import ( from interactions import (
Client, Client,
Extension, Extension,
slash_command, slash_command,
@ -12,7 +12,7 @@ from naff import (
ModalContext, ModalContext,
context_menu, context_menu,
Permissions, Permissions,
CommandTypes, CommandType,
Message, Message,
) )
@ -22,7 +22,7 @@ from database import BotMessages as BotMessagesModel
message_creation_modal = Modal( message_creation_modal = Modal(
custom_id="bot-message-create", custom_id="bot-message-create",
title="Create a message as the bot", title="Create a message as the bot",
components=[ *[
ParagraphText( ParagraphText(
custom_id="embeds", custom_id="embeds",
label="Embeds", label="Embeds",
@ -120,7 +120,7 @@ class BotMessages(Extension):
# A context menu to allow moderators to edit a bot message. # A context menu to allow moderators to edit a bot message.
@context_menu( @context_menu(
name="Edit bot message", name="Edit bot message",
context_type=CommandTypes.MESSAGE, context_type=CommandType.MESSAGE,
dm_permission=False, dm_permission=False,
default_member_permissions=Permissions.MANAGE_GUILD, default_member_permissions=Permissions.MANAGE_GUILD,
) )

View File

@ -2,25 +2,25 @@ import logging
import random import random
import string import string
from io import BytesIO from io import BytesIO
from naff import ( from interactions import (
Extension, Extension,
Client, Client,
slash_command, slash_command,
slash_option, slash_option,
context_menu, context_menu,
listen, listen,
CommandTypes, CommandType,
InteractionContext, InteractionContext,
OptionTypes, OptionType,
Role, Role,
Member, Member,
File, File,
SlashCommandChoice, SlashCommandChoice,
Button, Button,
ButtonStyles, ButtonStyle,
) )
from naff.api import events from interactions.api import events
from naff.models.discord.enums import Permissions from interactions.models.discord.enums import Permissions
from captcha.image import ImageCaptcha from captcha.image import ImageCaptcha
from captcha.audio import AudioCaptcha from captcha.audio import AudioCaptcha
@ -48,7 +48,7 @@ class Gatekeep(Extension):
name="type", name="type",
description="Type of Gatekeep", description="Type of Gatekeep",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
choices=[ choices=[
SlashCommandChoice( SlashCommandChoice(
name="Manual", name="Manual",
@ -79,7 +79,7 @@ class Gatekeep(Extension):
name="role", name="role",
description="Role to grant", description="Role to grant",
required=True, required=True,
opt_type=OptionTypes.ROLE, opt_type=OptionType.ROLE,
) )
async def set_role_command(self, ctx: InteractionContext, role: Role): async def set_role_command(self, ctx: InteractionContext, role: Role):
gk: GatekeepModel gk: GatekeepModel
@ -100,7 +100,7 @@ class Gatekeep(Extension):
name="message", name="message",
description="Message to send", description="Message to send",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
async def set_message_command(self, ctx: InteractionContext, message: str): async def set_message_command(self, ctx: InteractionContext, message: str):
gk: GatekeepModel gk: GatekeepModel
@ -119,7 +119,7 @@ class Gatekeep(Extension):
name="user", name="user",
description="User to approve", description="User to approve",
required=True, required=True,
opt_type=OptionTypes.USER, opt_type=OptionType.USER,
) )
async def approve_command(self, ctx: InteractionContext, user: Member): async def approve_command(self, ctx: InteractionContext, user: Member):
gk: GatekeepModel gk: GatekeepModel
@ -172,7 +172,7 @@ class Gatekeep(Extension):
name="Approve User", name="Approve User",
dm_permission=False, dm_permission=False,
default_member_permissions=Permissions.MANAGE_ROLES, default_member_permissions=Permissions.MANAGE_ROLES,
context_type=CommandTypes.USER, context_type=CommandType.USER,
) )
async def approve_context_menu(self, ctx: InteractionContext): async def approve_context_menu(self, ctx: InteractionContext):
user: Member = ctx.target user: Member = ctx.target
@ -257,7 +257,7 @@ class Gatekeep(Extension):
name="captcha", name="captcha",
description="The captcha solution", description="The captcha solution",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
async def captcha_command(self, ctx: InteractionContext, captcha: str): async def captcha_command(self, ctx: InteractionContext, captcha: str):
@ -330,7 +330,7 @@ class Gatekeep(Extension):
components=Button( components=Button(
label="Regenerate", label="Regenerate",
emoji="🔃", emoji="🔃",
style=ButtonStyles.GRAY, style=ButtonStyle.GRAY,
custom_id=f"gatekeep-captcha-regenerate:{member.id}", custom_id=f"gatekeep-captcha-regenerate:{member.id}",
), ),
) )
@ -346,7 +346,7 @@ class Gatekeep(Extension):
components=Button( components=Button(
label="Regenerate", label="Regenerate",
emoji="🔃", emoji="🔃",
style=ButtonStyles.GRAY, style=ButtonStyle.GRAY,
custom_id=f"gatekeep-captcha-regenerate:{member.id}", custom_id=f"gatekeep-captcha-regenerate:{member.id}",
), ),
) )
@ -399,7 +399,7 @@ class Gatekeep(Extension):
components=Button( components=Button(
label="Regenerate", label="Regenerate",
emoji="🔃", emoji="🔃",
style=ButtonStyles.GRAY, style=ButtonStyle.GRAY,
custom_id=f"gatekeep-captcha-regenerate:{member.id}", custom_id=f"gatekeep-captcha-regenerate:{member.id}",
), ),
) )

View File

@ -1,11 +1,11 @@
# pylint: disable=unsubscriptable-object # pylint: disable=unsubscriptable-object
import logging import logging
from typing import List, Optional from typing import List, Optional
from naff import ( from interactions import (
Extension, Extension,
slash_command, slash_command,
slash_option, slash_option,
OptionTypes, OptionType,
InteractionContext, InteractionContext,
Embed, Embed,
EmbedField, EmbedField,
@ -14,9 +14,9 @@ from naff import (
Client, Client,
ActionRow, ActionRow,
Button, Button,
ButtonStyles, ButtonStyle,
) )
from naff.ext.paginators import Paginator from interactions.ext.paginators import Paginator
from peewee import fn from peewee import fn
from database import ( from database import (
GuildSettings, GuildSettings,
@ -76,7 +76,7 @@ class Infractions(Extension):
name="user", name="user",
description="User to view", description="User to view",
required=True, required=True,
opt_type=OptionTypes.USER, opt_type=OptionType.USER,
) )
async def user_infractions(self, ctx: InteractionContext, user: Member): async def user_infractions(self, ctx: InteractionContext, user: Member):
await ctx.defer(ephemeral=False) await ctx.defer(ephemeral=False)
@ -154,19 +154,19 @@ class Infractions(Extension):
name="user", name="user",
description="User to warn", description="User to warn",
required=True, required=True,
opt_type=OptionTypes.USER, opt_type=OptionType.USER,
) )
@slash_option( @slash_option(
name="reason", name="reason",
description="Reason for warning", description="Reason for warning",
required=False, required=False,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
@slash_option( @slash_option(
name="weight", name="weight",
description="Severity of warning", description="Severity of warning",
required=False, required=False,
opt_type=OptionTypes.NUMBER, opt_type=OptionType.NUMBER,
min_value=0.0, min_value=0.0,
max_value=10.0, max_value=10.0,
) )
@ -174,7 +174,7 @@ class Infractions(Extension):
name="silent", name="silent",
description="Silent warning (will not notify user)", description="Silent warning (will not notify user)",
required=False, required=False,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
async def warn_user( async def warn_user(
self, self,
@ -256,7 +256,7 @@ class Infractions(Extension):
name="infraction-id", name="infraction-id",
description="ID of infraction to remove", description="ID of infraction to remove",
required=True, required=True,
opt_type=OptionTypes.INTEGER, opt_type=OptionType.INTEGER,
) )
async def remove_infraction(self, ctx: InteractionContext, infraction_id: int): async def remove_infraction(self, ctx: InteractionContext, infraction_id: int):
await ctx.defer(ephemeral=True) await ctx.defer(ephemeral=True)
@ -276,12 +276,12 @@ class Infractions(Extension):
ActionRow( ActionRow(
Button( Button(
custom_id=f"remove-infraction:remove:{infraction.id}", custom_id=f"remove-infraction:remove:{infraction.id}",
style=ButtonStyles.DANGER, style=ButtonStyle.DANGER,
label="Remove infraction", label="Remove infraction",
), ),
Button( Button(
custom_id=f"remove-infraction:cancel:{infraction.id}", custom_id=f"remove-infraction:cancel:{infraction.id}",
style=ButtonStyles.SECONDARY, style=ButtonStyle.SECONDARY,
label="Cancel", label="Cancel",
), ),
) )

View File

@ -1,19 +1,19 @@
import logging import logging
from typing import List, Dict, Set from typing import List, Dict, Set
from naff import ( from interactions import (
AutocompleteContext, AutocompleteContext,
Client, Client,
Extension, Extension,
InteractionContext, InteractionContext,
OptionTypes, OptionType,
slash_command, slash_command,
slash_option, slash_option,
listen, listen,
Button, Button,
ButtonStyles, ButtonStyle,
events, events,
Message, Message,
ChannelTypes, ChannelType,
) )
from database import KeywordNotify as KeywordNotifyModel from database import KeywordNotify as KeywordNotifyModel
@ -51,7 +51,7 @@ class KeywordNotify(Extension):
@slash_option( @slash_option(
name="keyword", name="keyword",
description="The keyword", description="The keyword",
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
required=True, required=True,
max_length=16, max_length=16,
) )
@ -76,7 +76,7 @@ class KeywordNotify(Extension):
@slash_option( @slash_option(
name="keyword", name="keyword",
description="The keyword to remove", description="The keyword to remove",
opt_type=OptionTypes.INTEGER, opt_type=OptionType.INTEGER,
required=True, required=True,
autocomplete=True, autocomplete=True,
) )
@ -149,7 +149,7 @@ class KeywordNotify(Extension):
@listen(events.MessageCreate) @listen(events.MessageCreate)
async def on_message_check_keyword(self, event: events.MessageCreate): async def on_message_check_keyword(self, event: events.MessageCreate):
if event.message.channel.type in [ChannelTypes.DM, ChannelTypes.GROUP_DM]: if event.message.channel.type in [ChannelType.DM, ChannelType.GROUP_DM]:
return return
guild = event.message.channel.guild guild = event.message.channel.guild
@ -188,7 +188,7 @@ class KeywordNotify(Extension):
f"{message.author.mention}" f"{message.author.mention}"
), ),
components=Button( components=Button(
style=ButtonStyles.LINK, style=ButtonStyle.LINK,
label="Go to message", label="Go to message",
url=message.jump_url, url=message.jump_url,
), ),

View File

@ -3,7 +3,7 @@ import uuid
from database import GuildSettings from database import GuildSettings
from naff import ( from interactions import (
Extension, Extension,
Client, Client,
slash_command, slash_command,
@ -11,9 +11,9 @@ from naff import (
InteractionContext, InteractionContext,
ModalContext, ModalContext,
Permissions, Permissions,
OptionTypes, OptionType,
Button, Button,
ButtonStyles, ButtonStyle,
listen, listen,
events, events,
Modal, Modal,
@ -38,13 +38,13 @@ class ModMail(Extension):
@slash_option( @slash_option(
name="button-text", name="button-text",
description="The text that should be displayed on the button.", description="The text that should be displayed on the button.",
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
required=True required=True
) )
@slash_option( @slash_option(
name="notify-role", name="notify-role",
description="Role that should be tagged upon creation of the modmail thread.", description="Role that should be tagged upon creation of the modmail thread.",
opt_type=OptionTypes.ROLE, opt_type=OptionType.ROLE,
required=True required=True
) )
async def adm_create_modmail_button(self, ctx: InteractionContext, button_text: str, role: Role): async def adm_create_modmail_button(self, ctx: InteractionContext, button_text: str, role: Role):
@ -52,7 +52,7 @@ class ModMail(Extension):
await ctx.channel.send( await ctx.channel.send(
components=Button( components=Button(
style=ButtonStyles.GREEN, style=ButtonStyle.GREEN,
label=button_text, label=button_text,
custom_id=f"send-modmail-button:{role.id}" custom_id=f"send-modmail-button:{role.id}"
) )
@ -131,7 +131,7 @@ class ModMail(Extension):
"Message created", "Message created",
ephemeral=True, ephemeral=True,
components=Button( components=Button(
style=ButtonStyles.LINK, style=ButtonStyle.LINK,
label="Go to message", label="Go to message",
url=msg.jump_url, url=msg.jump_url,
) )

View File

@ -5,20 +5,20 @@ from datetime import datetime, timedelta
import logging import logging
import json import json
from typing import List, Tuple from typing import List, Tuple
from naff import ( from interactions import (
Client, Client,
Extension, Extension,
slash_command, slash_command,
slash_option, slash_option,
InteractionContext, InteractionContext,
OptionTypes, OptionType,
Permissions, Permissions,
Modal, Modal,
ShortText, ShortText,
ParagraphText, ParagraphText,
ModalContext, ModalContext,
Button, Button,
ButtonStyles, ButtonStyle,
Embed, Embed,
spread_to_rows, spread_to_rows,
Message, Message,
@ -28,8 +28,8 @@ from naff import (
GuildText, GuildText,
PartialEmoji, PartialEmoji,
) )
from naff.api import events from interactions.api import events
from naff.client.errors import HTTPException from interactions.client.errors import HTTPException
from peewee import fn from peewee import fn
from database import Polls as PollsModel, PollVotes as PollVotesModel from database import Polls as PollsModel, PollVotes as PollVotesModel
@ -166,19 +166,19 @@ class Polls(Extension):
name="title", name="title",
description="Title of the poll", description="Title of the poll",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
@slash_option( @slash_option(
name="duration", name="duration",
description="Duration of the poll in minutes", description="Duration of the poll in minutes",
required=False, required=False,
opt_type=OptionTypes.INTEGER, opt_type=OptionType.INTEGER,
) )
@slash_option( @slash_option(
name="multiple-choice", name="multiple-choice",
description="If users can vote for multiple options", description="If users can vote for multiple options",
required=False, required=False,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
async def create_poll( # pylint: disable=too-many-locals async def create_poll( # pylint: disable=too-many-locals
self, self,
@ -268,7 +268,7 @@ class Polls(Extension):
buttons.append( buttons.append(
Button( Button(
emoji=emoji, emoji=emoji,
style=ButtonStyles.PRIMARY, style=ButtonStyle.PRIMARY,
custom_id=f"poll-vote:{poll_entry.id}:{i}", custom_id=f"poll-vote:{poll_entry.id}:{i}",
) )
) )
@ -278,7 +278,7 @@ class Polls(Extension):
Button( Button(
emoji="🔒", emoji="🔒",
label="Lock", label="Lock",
style=ButtonStyles.DANGER, style=ButtonStyle.DANGER,
custom_id=f"poll-lock:{poll_entry.id}", custom_id=f"poll-lock:{poll_entry.id}",
) )
) )

View File

@ -1,17 +1,17 @@
import re import re
import logging import logging
from naff import ( from interactions import (
Extension, Extension,
slash_command, slash_command,
slash_option, slash_option,
InteractionContext, InteractionContext,
OptionTypes, OptionType,
Client, Client,
) )
from naff.models.discord.enums import ButtonStyles, Permissions from interactions.models.discord.enums import ButtonStyle, Permissions
from naff.models.discord.embed import Embed, EmbedAuthor, EmbedField from interactions.models.discord.embed import Embed, EmbedAuthor, EmbedField
from naff.models.discord.components import ActionRow, Button from interactions.models.discord.components import ActionRow, Button
class QuoteExtension(Extension): class QuoteExtension(Extension):
@ -23,7 +23,7 @@ class QuoteExtension(Extension):
name="url", name="url",
description="Message URL", description="Message URL",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
async def quote_command(self, ctx: InteractionContext, url: str): async def quote_command(self, ctx: InteractionContext, url: str):
@ -83,7 +83,7 @@ class QuoteExtension(Extension):
components: list[ActionRow] = [ components: list[ActionRow] = [
ActionRow( ActionRow(
Button( Button(
style=ButtonStyles.LINK, style=ButtonStyle.LINK,
emoji="🔗", emoji="🔗",
url=url, url=url,
) )

View File

@ -1,25 +1,25 @@
# pylint: disable=not-an-iterable # pylint: disable=not-an-iterable
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple
import logging import logging
from naff import ( from interactions import (
Extension, Extension,
Client, Client,
slash_command, slash_command,
slash_option, slash_option,
OptionTypes, OptionType,
Permissions, Permissions,
InteractionContext, InteractionContext,
Role, Role,
Embed, Embed,
AutocompleteContext, AutocompleteContext,
StringSelectMenu, StringSelectMenu,
SelectOption, StringSelectOption,
listen, listen,
context_menu, context_menu,
CommandTypes, CommandType,
Message, Message,
) )
from naff.api import events from interactions.api import events
from database import ( from database import (
SelfRoles as SelfRolesModel, SelfRoles as SelfRolesModel,
SelfRoleGroups as SelfRoleGroupsModel, SelfRoleGroups as SelfRoleGroupsModel,
@ -40,19 +40,19 @@ class SelfRoles(Extension):
default_member_permissions=Permissions.MANAGE_ROLES, default_member_permissions=Permissions.MANAGE_ROLES,
) )
@slash_option( @slash_option(
name="role", description="Role to add", required=True, opt_type=OptionTypes.ROLE name="role", description="Role to add", required=True, opt_type=OptionType.ROLE
) )
@slash_option( @slash_option(
name="description", name="description",
description="Description of the role", description="Description of the role",
required=False, required=False,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
@slash_option( @slash_option(
name="requires", name="requires",
description="Role required to add this role", description="Role required to add this role",
required=False, required=False,
opt_type=OptionTypes.ROLE, opt_type=OptionType.ROLE,
) )
async def role_admin_add( async def role_admin_add(
self, self,
@ -90,7 +90,7 @@ class SelfRoles(Extension):
name="role", name="role",
description="Role to remove", description="Role to remove",
required=True, required=True,
opt_type=OptionTypes.ROLE, opt_type=OptionType.ROLE,
) )
async def role_admin_remove(self, ctx: InteractionContext, role: Role): async def role_admin_remove(self, ctx: InteractionContext, role: Role):
await ctx.defer(ephemeral=True) await ctx.defer(ephemeral=True)
@ -116,19 +116,19 @@ class SelfRoles(Extension):
name="group", name="group",
description="Group to add", description="Group to add",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
@slash_option( @slash_option(
name="description", name="description",
description="Description of the group", description="Description of the group",
required=False, required=False,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
@slash_option( @slash_option(
name="exclusive", name="exclusive",
description="Whether each role in this group is exclusive", description="Whether each role in this group is exclusive",
required=False, required=False,
opt_type=OptionTypes.BOOLEAN, opt_type=OptionType.BOOLEAN,
) )
async def role_group_add_group( async def role_group_add_group(
self, self,
@ -164,7 +164,7 @@ class SelfRoles(Extension):
name="group", name="group",
description="Group to remove", description="Group to remove",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
) )
async def role_group_remove_group(self, ctx: InteractionContext, group: str): async def role_group_remove_group(self, ctx: InteractionContext, group: str):
await ctx.defer(ephemeral=True) await ctx.defer(ephemeral=True)
@ -195,14 +195,14 @@ class SelfRoles(Extension):
name="group", name="group",
description="Group to add the role to", description="Group to add the role to",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
@slash_option( @slash_option(
name="role", name="role",
description="Role to add to the group", description="Role to add to the group",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
async def role_group_add_role(self, ctx: InteractionContext, group: str, role: str): async def role_group_add_role(self, ctx: InteractionContext, group: str, role: str):
@ -265,14 +265,14 @@ class SelfRoles(Extension):
name="group", name="group",
description="Group to remove the role from", description="Group to remove the role from",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
@slash_option( @slash_option(
name="role", name="role",
description="Role to remove from the group", description="Role to remove from the group",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
async def role_group_remove_role( async def role_group_remove_role(
@ -398,7 +398,7 @@ class SelfRoles(Extension):
name="group", name="group",
description="Group to generate the message from", description="Group to generate the message from",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
async def role_group_generate(self, ctx: InteractionContext, group: str): async def role_group_generate(self, ctx: InteractionContext, group: str):
@ -427,7 +427,7 @@ class SelfRoles(Extension):
options = [] options = []
for role in roles_q: for role in roles_q:
opt = SelectOption( opt = StringSelectOption(
label=role.role_name, label=role.role_name,
value=str(role.role_id), value=str(role.role_id),
description=role.role_description, description=role.role_description,
@ -535,7 +535,7 @@ class SelfRoles(Extension):
@context_menu( @context_menu(
name="Regenerate role group message", name="Regenerate role group message",
context_type=CommandTypes.MESSAGE, context_type=CommandType.MESSAGE,
dm_permission=False, dm_permission=False,
default_member_permissions=Permissions.MANAGE_ROLES, default_member_permissions=Permissions.MANAGE_ROLES,
) )
@ -591,7 +591,7 @@ class SelfRoles(Extension):
options = [] options = []
for role in roles_q: for role in roles_q:
opt = SelectOption( opt = StringSelectOption(
label=role.role_name, label=role.role_name,
value=str(role.role_id), value=str(role.role_id),
description=role.role_description, description=role.role_description,
@ -630,7 +630,7 @@ class SelfRoles(Extension):
name="role", name="role",
description="Role to add", description="Role to add",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
async def role_add(self, ctx: InteractionContext, role: str): async def role_add(self, ctx: InteractionContext, role: str):
@ -719,7 +719,7 @@ class SelfRoles(Extension):
name="role", name="role",
description="Role to remove", description="Role to remove",
required=True, required=True,
opt_type=OptionTypes.STRING, opt_type=OptionType.STRING,
autocomplete=True, autocomplete=True,
) )
async def role_remove(self, ctx: InteractionContext, role: str): async def role_remove(self, ctx: InteractionContext, role: str):

32
poetry.lock generated
View File

@ -301,6 +301,36 @@ files = [
[package.extras] [package.extras]
graph = ["objgraph (>=1.7.2)"] graph = ["objgraph (>=1.7.2)"]
[[package]]
name = "discord-py-interactions"
version = "5.5.1"
description = "Easy, simple, scalable and modular: a Python API wrapper for interactions."
category = "main"
optional = false
python-versions = ">=3.10"
files = [
{file = "discord-py-interactions-5.5.1.tar.gz", hash = "sha256:130bdc1b22d44562d4bacf946d4d2d2b0b763ee6646b21c8f7ddf8de93ad348b"},
{file = "discord_py_interactions-5.5.1-py3-none-any.whl", hash = "sha256:b42080456432043e68f8812f0763a4acde3dc3a41654addf87717862c67bb65d"},
]
[package.dependencies]
aiohttp = "*"
attrs = ">=22.1"
discord-typings = ">=0.5.1"
emoji = "*"
tomli = "*"
[package.extras]
all = ["Brotli", "PyNaCl (>=1.5.0,<1.6)", "aioconsole (>=0.6.0)", "aiodns", "faust-cchardet", "jurigged", "orjson", "sentry-sdk", "uvloop"]
console = ["aioconsole (>=0.6.0)"]
dev = ["Brotli", "PyNaCl (>=1.5.0,<1.6)", "aioconsole (>=0.6.0)", "aiodns", "faust-cchardet", "jurigged", "mkdocs-autorefs", "mkdocs-awesome-pages-plugin", "mkdocs-git-committers-plugin-2", "mkdocs-git-revision-date-localized-plugin", "mkdocs-material", "mkdocs-minify-plugin", "mkdocstrings-python", "orjson", "pre-commit", "pytest", "pytest-asyncio", "pytest-cov", "python-dotenv", "sentry-sdk", "typeguard", "uvloop"]
docs = ["Brotli", "PyNaCl (>=1.5.0,<1.6)", "aioconsole (>=0.6.0)", "aiodns", "faust-cchardet", "jurigged", "mkdocs-autorefs", "mkdocs-awesome-pages-plugin", "mkdocs-git-committers-plugin-2", "mkdocs-git-revision-date-localized-plugin", "mkdocs-material", "mkdocs-minify-plugin", "mkdocstrings-python", "orjson", "sentry-sdk", "uvloop"]
jurigged = ["jurigged"]
sentry = ["sentry-sdk"]
speedup = ["Brotli", "aiodns", "faust-cchardet", "orjson", "uvloop"]
tests = ["pytest", "pytest-asyncio", "pytest-cov", "python-dotenv", "typeguard"]
voice = ["PyNaCl (>=1.5.0,<1.6)"]
[[package]] [[package]]
name = "discord-typings" name = "discord-typings"
version = "0.5.1" version = "0.5.1"
@ -1385,4 +1415,4 @@ multidict = ">=4.0"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "5b7f61228c5907b87063f940377c0c2f2abeb8c2454e1ab2afa7c61374f2fbc5" content-hash = "a7589e4471c957985f39101d8051738dc0102f2516d16d217ed28b0d5a1ed47b"

View File

@ -13,6 +13,7 @@ peewee = "^3.15.1"
naff = "2.1.0" naff = "2.1.0"
python-dotenv = "^0.20.0" python-dotenv = "^0.20.0"
captcha = "^0.4" captcha = "^0.4"
discord-py-interactions = "^5.5.1"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
black = "^22.6.0" black = "^22.6.0"