Skip to content

Commit

Permalink
Society and Society
Browse files Browse the repository at this point in the history
  • Loading branch information
Shell1010 committed Feb 4, 2024
1 parent f9186c6 commit 2d0aa90
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 25 deletions.
49 changes: 48 additions & 1 deletion selfcord/api/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,51 @@ def Playing(
"afk": self.afk
}
}
return payload
return payload

def Spotify(self,
end: int,
large_image: str,
large_text: str,
details: str,
state: str,
party_id: str,
):


activity = {
"type": 2,
"name": "Spotify",
"assets": {
"large_image": large_image,
"large_text": large_text
},
"details": details,
"state": state,
"timestamps": {
"start": int(time.time()),
"end": end
},
"party": {
"id": party_id,
},
"sync_id": "spotify",
"flags": 48,
"metadata": {
"context_uri": "spotify:playlist:37i9dQZF1DX0XUsuxWHRQd",
"album_id": "382659064",
"artist_ids": ["06HL4z0CvFAxyc27GXpf02"],
},

}
payload = {
"op": 3,
"d": {
"since": time.time(),
"activities": [activity],
"status": self.status,
"afk": self.afk
}
}
return payload

32 changes: 18 additions & 14 deletions selfcord/api/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,7 @@ async def identify(self):
}
await self.send_json(payload)

async def gather_members(self, guild_id: str, channel_id: str):
payload = {
"op": 14,
"d": {
"guild_id": guild_id,
"channels": {
channel_id: [[0, 99]]
}
},
}
await self.send_json(payload)


async def heartbeat(self, interval: int):
heartbeat_json = {"op": 1, "d": time.time()}
Expand Down Expand Up @@ -329,6 +319,18 @@ def correct_channels(self, guild: Guild):
break

return list(set(channels))

async def subscriptions(self, guild: Guild):
# In Progres...
# Basically discord no longer uses op 14, uses this now
payload = {
"op": 37,
"d": {
"subscriptions": {
"guild_id":{"channels": {"channel_id": []}}
}
}
}

async def chunk_members(self, guild: Guild):
channels = self.correct_channels(guild)
Expand All @@ -340,16 +342,18 @@ async def chunk_members(self, guild: Guild):
ranges.append(
[i, self.roundup(i + (guild.member_count - i)) - 1]
) if i + 99 > guild.member_count else ranges.append([i, i + 99])
print(ranges)

for item in self.chunks(ranges, 3):

queries = {}
payload = {
payload = payload = {
"op": 14,
"d": {
"guild_id": guild.id,
"typing": True,
"threads": True
"threads": False,
"activities": True,
}
}
data = payload['d']
Expand All @@ -361,7 +365,7 @@ async def chunk_members(self, guild: Guild):
data['channel'] = queries

await self.send_json(payload)

# print(payload)
await asyncio.sleep(2.0)


Expand Down
9 changes: 1 addition & 8 deletions selfcord/api/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,7 @@ async def udp_select(self):
"op": 1,
"d": {
"protocol": "udp",
"codecs": [
{
"name": "opus",
"type": "audio",
"priority": 1000,
"payload_type": 120,
}
],

"data": {"address": self.my_ip, "port": self.my_port, "mode": self.mode},
},
}
Expand Down
1 change: 1 addition & 0 deletions selfcord/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
Messageable,
Callable
)
from .webhooks import Webhook
from .message import Message, MessageAck
from .event_models import PresenceUpdate, MessageAddReaction, MemberListUpdate, CallCreate
11 changes: 11 additions & 0 deletions selfcord/models/channels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Literal
from .message import Message
from .webhooks import Webhook
from .assets import Asset
import random
import asyncio
Expand Down Expand Up @@ -251,6 +252,16 @@ async def trigger_slash(self, cmd: SlashCommand):
data=data
)

async def create_webhook(self, name: str):
json = await self.http.request(
"POST",
f"/channels/{self.id}/webhooks",
json={"name": name}
)
if json is not None:
return Webhook(json, self.bot)


async def typing(self):
await self.http.request(
"POST",
Expand Down
5 changes: 3 additions & 2 deletions selfcord/models/guild.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations
import asyncio
import itertools
from typing import TYPE_CHECKING, Optional, Literal, AsyncGenerator
from .assets import Asset
from .channels import Convert, Messageable
from .message import Message
from .users import Member
from .permissions import Permission

if TYPE_CHECKING:
from ..bot import Bot

Expand Down Expand Up @@ -265,8 +267,7 @@ async def search(


async def get_members(self):
# Doesn't work yet I'm gonna fix
pass
asyncio.create_task(self.bot.gateway.chunk_members(self))

async def delete(self):
await self.http.request(
Expand Down
58 changes: 58 additions & 0 deletions selfcord/models/webhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import annotations
from typing import Optional, TYPE_CHECKING
from .assets import Asset
from .message import Message

if TYPE_CHECKING:
from ..bot import Bot


# TODO: Implement webhooks


class Webhook:
def __init__(self, payload: dict, bot: Bot):
self.bot = bot
self.http = bot.http
self.update(payload)

@property
def url(self) -> str:
return f"https://discord.com/api/webhooks/{self.id}/{self.token}"

@property
def avatar(self) -> Asset:
return Asset(self.id, self.avatar)


def update(self, payload: dict):
self.id = payload.get("id")
self.type = payload.get("type")
self.guild_id = payload.get("guild_id")
self.channel_id = payload.get("channel_id")
self.user = payload.get("user")
self.name = payload.get("name")

self.token = payload.get("token")
self.application_id = payload.get("application_id")
self.source_guild = payload.get("source_guild")
self.source_channel = payload.get("source_channel")

async def delete(self):
await self.http.request(
"DELETE",
f"/webhooks/{self.id}/{self.token}"
)

async def send(self, content: Optional[str] = None):
json = await self.http.request(
"POST",
f"/webhooks/{self.id}/{self.token}",
json={
"content": content,

}
)
if json is not None:
return Message(json, self.bot)

0 comments on commit 2d0aa90

Please sign in to comment.