Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Contributing to discord.py
[comment]: <> (Thanks to Rapptz -maybe, this is where i took inspiration from- for making this template I've adapted for my bot)

First off, thanks for taking the time to contribute. It makes the bot substantially better. :+1:

The following is a set of guidelines for contributing to the repository. These are guidelines, not hard rules.

## This is too much to read! I want to ask a question!

Generally speaking questions are better suited in our resources below.

- The official support server: https://discord.gg/m9UsWuaYDT
- The GitHub issues page: https://github.com/SpaceBot-Development-Team/space/issues

Please try your best not to ask questions in our issue tracker. Most of them don't belong there unless they provide value to a larger audience.

## Good Bug Reports

Please be aware of the following things when filing bug reports.

1. Don't open duplicate issues. Please search your issue to see if it has been asked already. Duplicate issues will be closed.
2. When filing a bug about exceptions or tracebacks, please include the *complete* traceback. Without the complete traceback the issue might be **unsolvable** and you will be asked to provide more information.
3. Make sure to provide enough information to make the issue workable. The issue template will generally walk you through the process but they are enumerated here as well:
- A **summary** of your bug report. This is generally a quick sentence or two to describe the issue in human terms.
- Guidance on **how to reproduce the issue**. Ideally, this should have a small set of steps on how to reproduce this bug.
- Tell us **what you expected to happen**. That way we can meet that expectation.
- Tell us **what actually happens**. What ends up happening in reality? It's not helpful to say "it fails" or "it doesn't work". Say *how* it failed, does it hang? How are the expectations different from reality?

If the bug report is missing this information then it'll take us longer to fix the issue. We will probably ask for clarification, and barring that if no response was given then the issue will be closed.

## Submitting a Pull Request

Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is consistent to that found in the project. This project follows PEP-8 guidelines (mostly) with a column limit of 125.

### Git Commit Guidelines

- Use present tense (e.g. "Add feature" not "Added feature")
- Limit all lines to 72 characters or less.
- Reference issues or pull requests outside of the first line.
- Please use the shorthand `#123` and not the full URL.

If you do not meet any of these guidelines, don't fret. Chances are they will be fixed upon rebasing but please do try to meet them to remove some of the workload.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
buy_me_a_coffee: dev_anony
patreon: Developer_Anonymous
github: SpaceBot-Development-Team
50 changes: 50 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Bug Report
description: Report broken or incorrect behaviour
labels: unconfirmed bug
body:
- type: markdown
attributes:
value: >
Thanks for taking the time to fill out a bug.
If you want real-time support, consider joining our Discord at https://discord.gg/m9UsWuaYDT instead.

Please note that this form is for bugs only!
- type: input
attributes:
label: Summary
description: A simple summary of your bug report
validations:
required: true
- type: textarea
attributes:
label: Reproduction Steps
description: >
What you did to make it happen.
validations:
required: true
- type: textarea
attributes:
label: Expected Results
description: >
What did you expect to happen?
validations:
required: true
- type: textarea
attributes:
label: Actual Results
description: >
What actually happened?
validations:
required: true
- type: checkboxes
attributes:
label: Checklist
description: >
Let's make sure you've properly done due diligence when reporting this issue!
options:
- label: I have searched the open issues for duplicates.
required: true
- type: textarea
attributes:
label: Additional Context
description: If there is anything else to say, please do so here.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
about: Ask questions and discuss with other users of the library.
url: https://github.com/SpaceBot-Development-Team/space/discussions
- name: Discord Server
about: Use our official Discord server to ask for help and questions as well.
url: https://discord.gg/m9UsWuaYDT
47 changes: 47 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Feature Request
description: Suggest a feature for the bot
labels: feature request
body:
- type: input
attributes:
label: Summary
description: >
A short description of what your feature request is.
validations:
required: true
- type: dropdown
attributes:
multiple: false
label: What is this feature request for?
options:
- The bot
- The documentation
validations:
required: true
- type: textarea
attributes:
label: The Problem
description: >
What problem if your feature trying to solve?
What becomes easier or possible when this feature is implemented?
validations:
required: true
- type: textarea
attributes:
label: The Ideal Solution
description: >
What is your ideal solution to the problem?
What would you like this feature to do?
validations:
required: true
- type: textarea
attributes:
label: The Current Solution
description: >
What is the current solution to the problem, if any?
validations:
required: false
- type: textarea
attributes:
label: Additional Context
description: If there is anything else to say, please do so here.
16 changes: 16 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Summary

<!-- What is this pull request for? Does it fix any issues? -->

## Checklist

<!-- Put an x inside [ ] to check it, like so: [x] -->

- [ ] If code changes were made, then they have been tested.
- [ ] This PR fixes an issue.
- [ ] This PR adds something new (e.g. new commands or modules).
- [ ] This PR is a breaking change (e.g. commands or modules renamed or removed).
- [ ] This PR is **not** a code change (e.g. documentation, docstrings, README, changelog, ...).
- [ ] I have searched for duplicates.
- [ ] If ``type: ignore``, ``pyright: ignore``, or similar, were used, then a comment explaining why was also left.
- [ ] I have formatted the code using ``black==25.1.0``.
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint

on:
push:
pull_request:
types: [ opened, reopened, synchronize ]

jobs:
check:
runs-on: ubuntu-latest

name: check
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up CPython
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
id: install-deps
run: |
python -m pip install --upgrade pip setuptools wheel black==25.1.0 requests
pip install -U -r requirements.txt

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Run PyRight
uses: jakebailey/pyright-action@v1
with:
version: '1.1.394'
warnings: false
no-comments: true

- name: Run Black
if: ${{ always() && steps.install-deps.outcome == 'success' }}
run: |
black --check cogs store bot.py errors.py main.py paginator.py utils.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,6 @@ cython_debug/

# Configuration files
*.config

# SSH
space-bot*
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ through [this link](https://discord.com/api/oauth2/authorize?client_id=118850123

# Contributing to Development

The only requirement is to have a good understanding of Python and **know what you are writing, meaning that any attempt to create a vulnerability, joke changes, or anything that does not benefit**
**the bot will result in a contribution ban**.
For more information on how to contribute, look at [CONTRIBUTING.md](/.github/CONTRIBUTING.md)
62 changes: 38 additions & 24 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""

from __future__ import annotations

import datetime
Expand All @@ -44,14 +45,14 @@
PREMIUM_SKU_ID: Final[int] = 1256218013930094682
log = logging.getLogger(__name__)


class LegacyBotContext(commands.Context["LegacyBot"]):
__slots__ = (
'_cs_premium',
)
__slots__ = ('_cs_premium',)

guild: discord.Guild
me: discord.Member
author: discord.Member
channel: discord.TextChannel | discord.VoiceChannel | discord.StageChannel | discord.ForumChannel
channel: discord.TextChannel | discord.VoiceChannel | discord.StageChannel | discord.Thread

@property
def reference(self) -> discord.MessageReference | None:
Expand All @@ -61,7 +62,9 @@ def reference(self) -> discord.MessageReference | None:
@property
def resolved_reference(self) -> discord.Message | None:
""":class:`discord.Message`: The resolved reference message, or ``None``."""
return self.reference and (self.reference.resolved or self.reference.cached_message) # pyright: ignore[reportReturnType]
return self.reference and (
self.reference.resolved or self.reference.cached_message
) # pyright: ignore[reportReturnType]

@property
def session(self) -> aiohttp.ClientSession:
Expand Down Expand Up @@ -103,13 +106,21 @@ async def is_premium(self) -> bool:
return self._cs_premium

if self.interaction:
prem = (
(PREMIUM_SKU_ID in [e.sku_id for e in self.interaction.entitlements])
or
(PREMIUM_SKU_ID in self.interaction.entitlement_sku_ids)
prem = (PREMIUM_SKU_ID in [e.sku_id for e in self.interaction.entitlements]) or (
PREMIUM_SKU_ID in self.interaction.entitlement_sku_ids
)
else:
prem = len([_ async for _ in self.bot.entitlements(user=self.author, guild=self.guild, skus=[discord.Object(PREMIUM_SKU_ID)])]) > 0
prem = (
len(
[
_
async for _ in self.bot.entitlements(
user=self.author, guild=self.guild, skus=[discord.Object(PREMIUM_SKU_ID)]
)
]
)
> 0
)

self._cs_premium = prem
return self._cs_premium
Expand Down Expand Up @@ -267,7 +278,8 @@ async def update_disabled_modules(self, guild_id: int, disabled_modules: list[st
async with conn.transaction():
await conn.execute(
'UPDATE guilds SET disabled_modules = $1::text[] WHERE "id" = $2;',
disabled_modules, guild_id,
disabled_modules,
guild_id,
)

self._disabled_modules[guild_id] = disabled_modules
Expand All @@ -284,7 +296,8 @@ async def _create_or_cache_guild_config(self, guild_id: int) -> None:
'WITH inserted AS '
'(INSERT INTO guilds ("id", prefixes) VALUES ($1, $2::varchar[]) ON CONFLICT ("id") DO NOTHING RETURNING prefixes) '
'SELECT prefixes FROM inserted UNION ALL SELECT prefixes FROM guilds WHERE "id" = $1 LIMIT 1;',
guild_id, ['?'],
guild_id,
['?'],
)

if data is None:
Expand Down Expand Up @@ -409,8 +422,7 @@ async def on_guild_join(self, guild: discord.Guild) -> None:
guild.id,
)
await conn.execute(
'INSERT INTO claimtimes_config (guild_id) VALUES ($1) ON CONFLICT (id) DO NOTHING;',
guild.id
'INSERT INTO claimtimes_config (guild_id) VALUES ($1) ON CONFLICT (id) DO NOTHING;', guild.id
)
# ensure context manager closure
pass
Expand Down Expand Up @@ -455,17 +467,13 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
embed.description = f'You need the {r} role to execute this command!'
elif isinstance(error, commands.BotMissingPermissions):
fmt = discord.utils._human_join(
[m.replace('_', ' ').replace('guild', 'server').title()
for m in error.missing_permissions
],
[m.replace('_', ' ').replace('guild', 'server').title() for m in error.missing_permissions],
final='and',
)
embed.description = f'I need {fmt} permissions to execute this command!'
elif isinstance(error, commands.MissingPermissions):
fmt = discord.utils._human_join(
[m.replace('_', ' ').replace('guild', 'server').title()
for m in error.missing_permissions
],
[m.replace('_', ' ').replace('guild', 'server').title() for m in error.missing_permissions],
final='and',
)
embed.description = f'You need {fmt} permissions to execute this command!'
Expand Down Expand Up @@ -504,7 +512,9 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
elif isinstance(error, commands.ThreadNotFound):
embed.description = f'Thread with name or ID "{error.argument}" was not found!'
elif isinstance(error, commands.ChannelNotReadable):
embed.description = f'I do not have Read Messages permissions on {error.argument.mention}, and I need it to execute the command!'
embed.description = (
f'I do not have Read Messages permissions on {error.argument.mention}, and I need it to execute the command!'
)
elif isinstance(error, commands.ChannelNotFound):
embed.description = f'Channel with name or ID "{error.argument}" was not found!'
elif isinstance(error, commands.UserNotFound):
Expand Down Expand Up @@ -537,7 +547,9 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
elif isinstance(error, commands.PrivateMessageOnly):
embed.description = 'This command can only be used on private messages!'
elif isinstance(error, commands.BadLiteralArgument):
embed.description = f'"{error.argument}" is not a valid choice available in {discord.utils._human_join(error.literals)}'
embed.description = (
f'"{error.argument}" is not a valid choice available in {discord.utils._human_join(error.literals)}'
)
elif isinstance(error, commands.BadUnionArgument):
embed.description = f'"{error.param.name}" value was not valid!'
elif isinstance(error, commands.ExpectedClosingQuoteError):
Expand All @@ -550,7 +562,9 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
embed.description = 'You are missing one attachment to execute this command!'
elif isinstance(error, commands.MissingRequiredArgument):
assert context.command
embed.description = f'`{error.param.name}` is missing! Make sure you follow the command syntax: `{context.command.signature}`'
embed.description = (
f'`{error.param.name}` is missing! Make sure you follow the command syntax: `{context.command.signature}`'
)
elif isinstance(error, ModuleDisabled):
embed.description = str(error)
else:
Expand All @@ -563,7 +577,7 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
if send_debug_log:
await self.send_debug_message(
embed=discord.Embed(
title=f'An unknown error occurred on {context.command.name}',
title=f'An unknown error occurred on {context.command.name if context.command else "a non-command context"}',
description=f'Executed by: {context.author} ({context.author.id})\nExecution date: {discord.utils.format_dt(context.created_at)}',
colour=discord.Colour.red(),
).add_field(
Expand Down
Loading