Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
merge: Dev -> master
Browse files Browse the repository at this point in the history
Dis-Snek finale - the final release of dis-snek. Now rebranding to naff
  • Loading branch information
LordOfPolls authored May 16, 2022
2 parents c2651cd + f10c859 commit 92a8a37
Show file tree
Hide file tree
Showing 156 changed files with 3,668 additions and 866 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ jobs:
pytest:
name: runner / pytest tests
runs-on: ubuntu-latest
strategy:
matrix:
extras:
- .
- .[speedup]
- .[voice]
- .[all]
- .[docs]

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
Expand All @@ -12,7 +21,7 @@ jobs:
python-version: '3.10'
- name: Install pytest
run: |
pip install -e .[all]
pip install -e ${{ matrix.extras }}
pip install pytest pytest-recording pytest-asyncio pytest-cov
- name: Run Tests
run: |
Expand Down
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -12,7 +12,11 @@ repos:
language_version: python3.10
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/PyCQA/autoflake
rev: v1.4
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --in-place, --ignore-init-module-imports]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ While this library shares features and some stylistic choices with `discord.py`,
## How do I use this?
Here is a basic example:
```python
from dis_snek import Snake, Button, ButtonStyles, CommandTypes, context_menu, message_command, listen
from dis_snek import Snake, Button, ButtonStyles, CommandTypes, context_menu, prefixed_command, listen

bot = Snake(sync_interactions=True)

Expand All @@ -32,7 +32,7 @@ async def on_startup():
print("Ready")
print(f"This bot is owned by {bot.owner}")

@message_command()
@prefixed_command()
async def test_button(ctx):
await ctx.send("Blurple button example!", components=Button(ButtonStyles.BLURPLE, "Click me"))

Expand Down
4 changes: 2 additions & 2 deletions dis_snek/api/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .discord import *
from .internal import *

__all__ = [
__all__ = (
"RawGatewayEvent",
"ChannelCreate",
"ChannelUpdate",
Expand Down Expand Up @@ -61,4 +61,4 @@
"Component",
"Button",
"Select",
]
)
6 changes: 2 additions & 4 deletions dis_snek/api/events/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def on_guild_join(event):
from dis_snek.client.utils.attr_utils import define, field, docs
from .internal import BaseEvent, GuildEvent

__all__ = [
__all__ = (
"BanCreate",
"BanRemove",
"ChannelCreate",
Expand Down Expand Up @@ -76,7 +76,7 @@ def on_guild_join(event):
"TypingStart",
"VoiceStateUpdate",
"WebhooksUpdate",
]
)


if TYPE_CHECKING:
Expand Down Expand Up @@ -321,7 +321,6 @@ class RoleDelete(BaseEvent, GuildEvent):
"""The deleted role"""


# todo implementation missing
@define(kw_only=False)
class GuildMembersChunk(BaseEvent, GuildEvent):
"""
Expand Down Expand Up @@ -490,7 +489,6 @@ class WebhooksUpdate(BaseEvent, GuildEvent):
"""The ID of the webhook was updated"""


# todo implementation missing
@define(kw_only=False)
class InteractionCreate(BaseEvent):
"""Dispatched when a user uses an Application Command."""
Expand Down
4 changes: 2 additions & 2 deletions dis_snek/api/events/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def on_guild_join(event):
from dis_snek.models.discord.snowflake import to_snowflake
from dis_snek.client.utils.attr_utils import define, field, docs

__all__ = [
__all__ = (
"BaseEvent",
"Button",
"Component",
Expand All @@ -40,7 +40,7 @@ def on_guild_join(event):
"Select",
"Startup",
"WebsocketReady",
]
)


if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dis_snek.client.smart_cache import GlobalCache
from dis_snek.api.events.internal import BaseEvent

__all__ = ["Processor", "EventMixinTemplate"]
__all__ = ("Processor", "EventMixinTemplate")

log = logging.getLogger(logger_name)

Expand Down
3 changes: 1 addition & 2 deletions dis_snek/api/events/processors/channel_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from typing import TYPE_CHECKING

import dis_snek.api.events as events
from dis_snek.models.discord.channel import BaseChannel
from dis_snek.models.discord.invite import Invite
from dis_snek.client.const import MISSING, logger_name
from ._template import EventMixinTemplate, Processor

if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["ChannelEvents"]
__all__ = ("ChannelEvents",)

log = logging.getLogger(logger_name)

Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/guild_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["GuildEvents"]
__all__ = ("GuildEvents",)

log = logging.getLogger(logger_name)

Expand Down
6 changes: 5 additions & 1 deletion dis_snek/api/events/processors/member_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["MemberEvents"]
__all__ = ("MemberEvents",)

log = logging.getLogger(logger_name)

Expand All @@ -20,12 +20,16 @@ class MemberEvents(EventMixinTemplate):
async def _on_raw_guild_member_add(self, event: "RawGatewayEvent") -> None:
g_id = event.data.pop("guild_id")
member = self.cache.place_member_data(g_id, event.data)
guild = self.cache.get_guild(g_id)
guild.member_count += 1
self.dispatch(events.MemberAdd(g_id, member))

@Processor.define()
async def _on_raw_guild_member_remove(self, event: "RawGatewayEvent") -> None:
g_id = event.data.pop("guild_id")
user = self.cache.place_user_data(event.data["user"])
guild = self.cache.get_guild(g_id)
guild.member_count -= 1
self.dispatch(events.MemberRemove(g_id, self.cache.get_member(g_id, user.id) or user))

@Processor.define()
Expand Down
3 changes: 1 addition & 2 deletions dis_snek/api/events/processors/message_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["MessageEvents"]
__all__ = ("MessageEvents",)

log = logging.getLogger(logger_name)

Expand All @@ -29,7 +29,6 @@ async def _on_raw_message_create(self, event: "RawGatewayEvent") -> None:
msg = self.cache.place_message_data(event.data)
if not msg._guild_id and event.data.get("guild_id"):
msg._guild_id = event.data["guild_id"]
# todo: Determine why this isn't set *always*

if not msg.author:
# sometimes discord will only send an author ID, not the author. this catches that
Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/reaction_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["ReactionEvents"]
__all__ = ("ReactionEvents",)

log = logging.getLogger(logger_name)

Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/role_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["RoleEvents"]
__all__ = ("RoleEvents",)

log = logging.getLogger(logger_name)

Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/stage_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["StageEvents"]
__all__ = ("StageEvents",)

log = logging.getLogger(logger_name)

Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/thread_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["ThreadEvents"]
__all__ = ("ThreadEvents",)

log = logging.getLogger(logger_name)

Expand Down
10 changes: 6 additions & 4 deletions dis_snek/api/events/processors/user_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["UserEvents"]
__all__ = ("UserEvents",)

log = logging.getLogger(logger_name)

Expand Down Expand Up @@ -57,7 +57,9 @@ async def _on_raw_presence_update(self, event: "RawGatewayEvent") -> None:
"""
g_id = to_snowflake(event.data["guild_id"])
if user := self.cache.get_user(event.data["user"]["id"]):
status = Status[event.data["status"].upper()]
activities = Activity.from_list(event.data.get("activities"))
user.status = Status[event.data["status"].upper()]
user.activities = Activity.from_list(event.data.get("activities"))

self.dispatch(events.PresenceUpdate(user, status, activities, event.data.get("client_status", None), g_id))
self.dispatch(
events.PresenceUpdate(user, user.status, user.activities, event.data.get("client_status", None), g_id)
)
2 changes: 1 addition & 1 deletion dis_snek/api/events/processors/voice_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dis_snek.api.events import RawGatewayEvent

__all__ = ["VoiceEvents"]
__all__ = ("VoiceEvents",)

log = logging.getLogger(logger_name)

Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .state import ConnectionState
from dis_snek.models.discord.snowflake import Snowflake_Type

__all__ = ["GatewayClient"]
__all__ = ("GatewayClient",)

log = logging.getLogger(logger_name)

Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/gateway/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if TYPE_CHECKING:
from dis_snek import Snake, Snowflake_Type

__all__ = ["ConnectionState"]
__all__ = ("ConnectionState",)

log = logging.getLogger(logger_name)

Expand Down
3 changes: 1 addition & 2 deletions dis_snek/api/gateway/websocket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import collections
import logging
import random
import time
import zlib
from abc import abstractmethod
Expand All @@ -18,7 +17,7 @@
if TYPE_CHECKING:
from dis_snek.api.gateway.state import ConnectionState

__all__ = ["WebsocketClient", "WebsocketRateLimit"]
__all__ = ("WebsocketClient", "WebsocketRateLimit")

log = logging.getLogger(logger_name)

Expand Down
14 changes: 11 additions & 3 deletions dis_snek/api/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@
WebhookRequests,
ScheduledEventsRequests,
)
from dis_snek.client.const import __py_version__, __repo_url__, __version__, logger_name, MISSING, Absent
from dis_snek.client.const import (
__py_version__,
__repo_url__,
__version__,
logger_name,
MISSING,
Absent,
__api_version__,
)
from dis_snek.client.errors import DiscordError, Forbidden, GatewayNotFound, HTTPException, NotFound, LoginError
from dis_snek.client.utils.input_utils import response_decode
from dis_snek.client.utils.serializer import dict_filter_missing
from dis_snek.models import CooldownSystem
from .route import Route

__all__ = ["HTTPClient"]
__all__ = ("HTTPClient",)

log = logging.getLogger(logger_name)

Expand Down Expand Up @@ -346,7 +354,7 @@ async def get_gateway(self) -> str:
data: dict = await self.request(Route("GET", "/gateway"))
except HTTPException as exc:
raise GatewayNotFound from exc
return "{0}?encoding={1}&v=9&compress=zlib-stream".format(data["url"], "json")
return "{0}?encoding={1}&v={2}&compress=zlib-stream".format(data["url"], "json", __api_version__)

async def websocket_connect(self, url: str) -> ClientWebSocketResponse:
"""
Expand Down
4 changes: 2 additions & 2 deletions dis_snek/api/http/http_requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .users import UserRequests
from .webhooks import WebhookRequests

__all__ = [
__all__ = (
"BotRequests",
"ChannelRequests",
"EmojiRequests",
Expand All @@ -26,4 +26,4 @@
"ThreadRequests",
"UserRequests",
"WebhookRequests",
]
)
2 changes: 1 addition & 1 deletion dis_snek/api/http/http_requests/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ..route import Route

__all__ = ["BotRequests"]
__all__ = ("BotRequests",)


class BotRequests:
Expand Down
4 changes: 2 additions & 2 deletions dis_snek/api/http/http_requests/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from dis_snek.client.const import MISSING, Absent
from dis_snek.models.discord.enums import ChannelTypes, StagePrivacyLevel, Permissions, OverwriteTypes
from ..route import Route
from dis_snek.client.utils.serializer import dict_filter_none, dict_filter_missing
from dis_snek.client.utils.serializer import dict_filter_none

__all__ = ["ChannelRequests"]
__all__ = ("ChannelRequests",)


if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion dis_snek/api/http/http_requests/emojis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dis_snek.client.const import MISSING, Absent
from ..route import Route

__all__ = ["EmojiRequests"]
__all__ = ("EmojiRequests",)


if TYPE_CHECKING:
Expand Down
Loading

0 comments on commit 92a8a37

Please sign in to comment.