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
1 change: 1 addition & 0 deletions cordslite/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'cordslite.core.Members': ('core.html#members', 'cordslite/core.py'),
'cordslite.core.Members._repr_html_': ('core.html#members._repr_html_', 'cordslite/core.py'),
'cordslite.core.Message': ('core.html#message', 'cordslite/core.py'),
'cordslite.core.Message.__init__': ('core.html#message.__init__', 'cordslite/core.py'),
'cordslite.core.Message.__repr__': ('core.html#message.__repr__', 'cordslite/core.py'),
'cordslite.core.Message.attachments': ('core.html#message.attachments', 'cordslite/core.py'),
'cordslite.core.Message.channel': ('core.html#message.channel', 'cordslite/core.py'),
Expand Down
10 changes: 9 additions & 1 deletion cordslite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from fastcore.utils import *
from nacl.bindings import crypto_aead_xchacha20poly1305_ietf_decrypt as xchacha_decrypt

import asyncio,ffmpeg,httpx,json,opuslib_next,os,random,socket,time
import asyncio,ffmpeg,httpx,json,opuslib_next,os,random,re,socket,time
import websockets.asyncio.client

# %% ../nbs/00_core.ipynb #d9e0f6cf
Expand Down Expand Up @@ -86,6 +86,14 @@ async def get_channel(self:DiscordClient, channel_id):

# %% ../nbs/00_core.ipynb #461bcb8b
class Message(DiscordObject):
def __init__(self, data, client):
super().__init__(data, client)
self.raw_content = self.content
mentions = {m['id']: m['username'] for m in data.get('mentions', [])}
self.data['content'] = re.sub( r'<@!?(\d+)>',
lambda m: f"@{mentions.get(m.group(1), 'unknown')}",
self.content)

def __repr__(self):
author = self.author['username']
preview = self.content[:30] + '...' if len(self.content) > 30 else self.content
Expand Down
42 changes: 32 additions & 10 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"from fastcore.utils import *\n",
"from nacl.bindings import crypto_aead_xchacha20poly1305_ietf_decrypt as xchacha_decrypt\n",
"\n",
"import asyncio,ffmpeg,httpx,json,opuslib_next,os,random,socket,time\n",
"import asyncio,ffmpeg,httpx,json,opuslib_next,os,random,re,socket,time\n",
"import websockets.asyncio.client"
]
},
Expand Down Expand Up @@ -355,10 +355,30 @@
"execution_count": null,
"id": "461bcb8b",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "IndentationError",
"evalue": "unexpected indent (2441870440.py, line 6)",
"output_type": "error",
"traceback": [
" \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 6\u001b[39m",
"\u001b[31m \u001b[39m\u001b[31mself.data['content'] = re.sub( r'<@!?(\\d+)>',\u001b[39m",
" ^",
"\u001b[31mIndentationError\u001b[39m\u001b[31m:\u001b[39m unexpected indent"
]
}
],
"source": [
"#| export\n",
"class Message(DiscordObject):\n",
" def __init__(self, data, client):\n",
" super().__init__(data, client)\n",
" self.raw_content = self.content\n",
" mentions = {m['id']: m['username'] for m in data.get('mentions', [])}\n",
" self.data['content'] = re.sub( r'<@!?(\\d+)>',\n",
" lambda m: f\"@{mentions.get(m.group(1), 'unknown')}\",\n",
" self.content)\n",
"\n",
" def __repr__(self): \n",
" author = self.author['username']\n",
" preview = self.content[:30] + '...' if len(self.content) > 30 else self.content\n",
Expand Down Expand Up @@ -402,14 +422,14 @@
{
"data": {
"text/html": [
"<table class=\"prose\"><thead><tr><th>ID</th><th>Author</th><th>Content</th><th>Date</th></tr></thead><tbody><tr><td>1473452262922911961</td><td>nate.dawgg</td><td>howdy!</td><td>2026-02-17</td></tr><tr><td>1473455165708435556</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473455208284684320</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473468026882887823</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473468028950675577</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr></tbody></table>"
"<table class=\"prose\"><thead><tr><th>ID</th><th>Author</th><th>Content</th><th>Date</th></tr></thead><tbody><tr><td>1473455208284684320</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473468026882887823</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473468028950675577</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473468409684426845</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473468411853148376</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr></tbody></table>"
],
"text/plain": [
"[Message(id=1473452262922911961, author='nate.dawgg', content='howdy!'),\n",
" Message(id=1473455165708435556, author='DBuddy', content='Hi, from Solveit!'),\n",
" Message(id=1473455208284684320, author='DBuddy', content='Here is a file!'),\n",
"[Message(id=1473455208284684320, author='DBuddy', content='Here is a file!'),\n",
" Message(id=1473468026882887823, author='DBuddy', content='Hi, from Solveit!'),\n",
" Message(id=1473468028950675577, author='DBuddy', content='Here is a file!')]"
" Message(id=1473468028950675577, author='DBuddy', content='Here is a file!'),\n",
" Message(id=1473468409684426845, author='DBuddy', content='Hi, from Solveit!'),\n",
" Message(id=1473468411853148376, author='DBuddy', content='Here is a file!')]"
]
},
"execution_count": null,
Expand Down Expand Up @@ -466,10 +486,12 @@
{
"data": {
"text/html": [
"<table class=\"prose\"><thead><tr><th>ID</th><th>Author</th><th>Content</th><th>Date</th></tr></thead><tbody><tr><td>1473468028950675577</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473468026882887823</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473455208284684320</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473455165708435556</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473452262922911961</td><td>nate.dawgg</td><td>howdy!</td><td>2026-02-17</td></tr></tbody></table>"
"<table class=\"prose\"><thead><tr><th>ID</th><th>Author</th><th>Content</th><th>Date</th></tr></thead><tbody><tr><td>1473468411853148376</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473468409684426845</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473468028950675577</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473468026882887823</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473455208284684320</td><td>DBuddy</td><td>Here is a file!</td><td>2026-02-17</td></tr><tr><td>1473455165708435556</td><td>DBuddy</td><td>Hi, from Solveit!</td><td>2026-02-17</td></tr><tr><td>1473452262922911961</td><td>nate.dawgg</td><td>howdy!</td><td>2026-02-17</td></tr></tbody></table>"
],
"text/plain": [
"[Message(id=1473468028950675577, author='DBuddy', content='Here is a file!'),\n",
"[Message(id=1473468411853148376, author='DBuddy', content='Here is a file!'),\n",
" Message(id=1473468409684426845, author='DBuddy', content='Hi, from Solveit!'),\n",
" Message(id=1473468028950675577, author='DBuddy', content='Here is a file!'),\n",
" Message(id=1473468026882887823, author='DBuddy', content='Hi, from Solveit!'),\n",
" Message(id=1473455208284684320, author='DBuddy', content='Here is a file!'),\n",
" Message(id=1473455165708435556, author='DBuddy', content='Hi, from Solveit!'),\n",
Expand Down Expand Up @@ -523,7 +545,7 @@
{
"data": {
"text/plain": [
"Message(id=1473468409684426845, author='DBuddy', content='Hi, from Solveit!')"
"Message(id=1473720714816393372, author='DBuddy', content='Hi, from Solveit!')"
]
},
"execution_count": null,
Expand Down
Loading