90 changed files with 1484 additions and 1334 deletions
@ -1,69 +0,0 @@ |
|||
import discord |
|||
from discord import app_commands |
|||
|
|||
import traceback |
|||
|
|||
# Just default intents and a `discord.Client` instance |
|||
# We don't need a `commands.Bot` instance because we are not |
|||
# creating text-based commands. |
|||
intents = discord.Intents.default() |
|||
client = discord.Client(intents=intents) |
|||
|
|||
# We need an `discord.app_commands.CommandTree` instance |
|||
# to register application commands (slash commands in this case) |
|||
tree = app_commands.CommandTree(client) |
|||
|
|||
# The guild in which this slash command will be registered. |
|||
# As global commands can take up to an hour to propagate, it is ideal |
|||
# to test it in a guild. |
|||
TEST_GUILD = discord.Object(ID) |
|||
|
|||
@client.event |
|||
async def on_ready(): |
|||
print(f'Logged in as {client.user} (ID: {client.user.id})') |
|||
print('------') |
|||
|
|||
# Sync the application command with Discord. |
|||
await tree.sync(guild=TEST_GUILD) |
|||
|
|||
class Feedback(discord.ui.Modal, title='Feedback'): |
|||
# Our modal classes MUST subclass `discord.ui.Modal`, |
|||
# but the title can be whatever you want. |
|||
|
|||
# This will be a short input, where the user can enter their name |
|||
# It will also have a placeholder, as denoted by the `placeholder` kwarg. |
|||
# By default, it is required and is a short-style input which is exactly |
|||
# what we want. |
|||
name = discord.ui.TextInput( |
|||
label='Name', |
|||
placeholder='Your name here...', |
|||
) |
|||
|
|||
# This is a longer, paragraph style input, where user can submit feedback |
|||
# Unlike the name, it is not required. If filled out, however, it will |
|||
# only accept a maximum of 300 characters, as denoted by the |
|||
# `max_length=300` kwarg. |
|||
feedback = discord.ui.TextInput( |
|||
label='What do you think of this new feature?', |
|||
style=discord.TextStyle.long, |
|||
placeholder='Type your feedback here...', |
|||
required=False, |
|||
max_length=300, |
|||
) |
|||
|
|||
async def on_submit(self, interaction: discord.Interaction): |
|||
await interaction.response.send_message(f'Thanks for your feedback, {self.name.value}!', ephemeral=True) |
|||
|
|||
async def on_error(self, error: Exception, interaction: discord.Interaction) -> None: |
|||
await interaction.response.send_message('Oops! Something went wrong.', ephemeral=True) |
|||
|
|||
# Make sure we know what the error actually is |
|||
traceback.print_tb(error.__traceback__) |
|||
|
|||
|
|||
@tree.command(guild=TEST_GUILD, description="Submit feedback") |
|||
async def feedback(interaction: discord.Interaction): |
|||
# Send the modal with an instance of our `Feedback` class |
|||
await interaction.response.send_modal(Feedback()) |
|||
|
|||
client.run('token') |
@ -0,0 +1,129 @@ |
|||
""" |
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) 2015-present Rapptz |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a |
|||
copy of this software and associated documentation files (the "Software"), |
|||
to deal in the Software without restriction, including without limitation |
|||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|||
and/or sell copies of the Software, and to permit persons to whom the |
|||
Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in |
|||
all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|||
DEALINGS IN THE SOFTWARE. |
|||
""" |
|||
|
|||
from __future__ import annotations |
|||
|
|||
from io import BytesIO |
|||
|
|||
import discord |
|||
|
|||
|
|||
FILE = BytesIO() |
|||
|
|||
|
|||
def test_file_with_no_name(): |
|||
f = discord.File('.gitignore') |
|||
assert f.filename == '.gitignore' |
|||
|
|||
|
|||
def test_io_with_no_name(): |
|||
f = discord.File(FILE) |
|||
assert f.filename == 'untitled' |
|||
|
|||
|
|||
def test_file_with_name(): |
|||
f = discord.File('.gitignore', 'test') |
|||
assert f.filename == 'test' |
|||
|
|||
|
|||
def test_io_with_name(): |
|||
f = discord.File(FILE, 'test') |
|||
assert f.filename == 'test' |
|||
|
|||
|
|||
def test_file_with_no_name_and_spoiler(): |
|||
f = discord.File('.gitignore', spoiler=True) |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_with_spoiler_name_and_implicit_spoiler(): |
|||
f = discord.File('.gitignore', 'SPOILER_.gitignore') |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_with_spoiler_name_and_spoiler(): |
|||
f = discord.File('.gitignore', 'SPOILER_.gitignore', spoiler=True) |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_with_spoiler_name_and_not_spoiler(): |
|||
f = discord.File('.gitignore', 'SPOILER_.gitignore', spoiler=False) |
|||
assert f.filename == '.gitignore' |
|||
assert f.spoiler == False |
|||
|
|||
|
|||
def test_file_with_name_and_double_spoiler_and_implicit_spoiler(): |
|||
f = discord.File('.gitignore', 'SPOILER_SPOILER_.gitignore') |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_with_name_and_double_spoiler_and_spoiler(): |
|||
f = discord.File('.gitignore', 'SPOILER_SPOILER_.gitignore', spoiler=True) |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_with_name_and_double_spoiler_and_not_spoiler(): |
|||
f = discord.File('.gitignore', 'SPOILER_SPOILER_.gitignore', spoiler=False) |
|||
assert f.filename == '.gitignore' |
|||
assert f.spoiler == False |
|||
|
|||
|
|||
def test_file_with_spoiler_with_overriding_name_not_spoiler(): |
|||
f = discord.File('.gitignore', spoiler=True) |
|||
f.filename = '.gitignore' |
|||
assert f.filename == '.gitignore' |
|||
assert f.spoiler == False |
|||
|
|||
|
|||
def test_file_with_spoiler_with_overriding_name_spoiler(): |
|||
f = discord.File('.gitignore', spoiler=True) |
|||
f.filename = 'SPOILER_.gitignore' |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_not_spoiler_with_overriding_name_not_spoiler(): |
|||
f = discord.File('.gitignore') |
|||
f.filename = '.gitignore' |
|||
assert f.filename == '.gitignore' |
|||
assert f.spoiler == False |
|||
|
|||
|
|||
def test_file_not_spoiler_with_overriding_name_spoiler(): |
|||
f = discord.File('.gitignore') |
|||
f.filename = 'SPOILER_.gitignore' |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
|||
|
|||
|
|||
def test_file_not_spoiler_with_overriding_name_double_spoiler(): |
|||
f = discord.File('.gitignore') |
|||
f.filename = 'SPOILER_SPOILER_.gitignore' |
|||
assert f.filename == 'SPOILER_.gitignore' |
|||
assert f.spoiler == True |
Loading…
Reference in new issue