broadside 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- broadside-0.1.0/LICENSE +8 -0
- broadside-0.1.0/PKG-INFO +24 -0
- broadside-0.1.0/README.md +3 -0
- broadside-0.1.0/broadside/__init__.py +5 -0
- broadside-0.1.0/broadside/bot.py +59 -0
- broadside-0.1.0/broadside/context.py +4 -0
- broadside-0.1.0/broadside/gateway.py +37 -0
- broadside-0.1.0/broadside.egg-info/PKG-INFO +24 -0
- broadside-0.1.0/broadside.egg-info/SOURCES.txt +12 -0
- broadside-0.1.0/broadside.egg-info/dependency_links.txt +1 -0
- broadside-0.1.0/broadside.egg-info/requires.txt +1 -0
- broadside-0.1.0/broadside.egg-info/top_level.txt +1 -0
- broadside-0.1.0/pyproject.toml +22 -0
- broadside-0.1.0/setup.cfg +4 -0
broadside-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
Copyright 1985 Sabisa
|
|
3
|
+
|
|
4
|
+
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:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
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.
|
broadside-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: broadside
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: broadside bot thingy
|
|
5
|
+
Author: Sabisa
|
|
6
|
+
License:
|
|
7
|
+
Copyright 1985 Sabisa
|
|
8
|
+
|
|
9
|
+
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:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
Project-URL: Homepage, https://scm.socket775.xyz/Sabisascm/broadside.py
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: websockets==10.1
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# broadside.py
|
|
23
|
+
|
|
24
|
+
python bot
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
from .gateway import Gateway
|
|
3
|
+
from .context import Context
|
|
4
|
+
|
|
5
|
+
class Bot:
|
|
6
|
+
def __init__(self, ws_url, username, prefix="!"):
|
|
7
|
+
self.ws_url = ws_url
|
|
8
|
+
self.username = username
|
|
9
|
+
self.prefix = prefix
|
|
10
|
+
|
|
11
|
+
self.commands = {}
|
|
12
|
+
self.events = {}
|
|
13
|
+
|
|
14
|
+
self.gateway = Gateway(self)
|
|
15
|
+
|
|
16
|
+
def command(self, name=None):
|
|
17
|
+
def decorator(func):
|
|
18
|
+
cmd_name = name or func.__name__
|
|
19
|
+
self.commands[cmd_name] = func
|
|
20
|
+
return func
|
|
21
|
+
return decorator
|
|
22
|
+
|
|
23
|
+
def event(self, func):
|
|
24
|
+
self.events[func.__name__] = func
|
|
25
|
+
return func
|
|
26
|
+
|
|
27
|
+
async def send(self, content):
|
|
28
|
+
await self.gateway.send({
|
|
29
|
+
"username": self.username,
|
|
30
|
+
"content": content
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
async def _dispatch(self, event, *args):
|
|
34
|
+
if event in self.events:
|
|
35
|
+
await self.events[event](*args)
|
|
36
|
+
|
|
37
|
+
async def _handle_message(self, message):
|
|
38
|
+
if message.get("username") == self.username:
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
await self._dispatch("on_message", message)
|
|
42
|
+
|
|
43
|
+
content = message.get("content", "")
|
|
44
|
+
if not content.startswith(self.prefix):
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
parts = content[len(self.prefix):].split()
|
|
48
|
+
if not parts:
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
name = parts[0]
|
|
52
|
+
args = parts[1:]
|
|
53
|
+
|
|
54
|
+
if name in self.commands:
|
|
55
|
+
ctx = Context(self, message)
|
|
56
|
+
await self.commands[name](ctx, *args)
|
|
57
|
+
|
|
58
|
+
async def run(self):
|
|
59
|
+
await self.gateway.connect()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import websockets
|
|
2
|
+
import json
|
|
3
|
+
import asyncio
|
|
4
|
+
class Gateway:
|
|
5
|
+
def __init__(self, bot):
|
|
6
|
+
self.bot = bot
|
|
7
|
+
self.ws = None
|
|
8
|
+
|
|
9
|
+
async def connect(self):
|
|
10
|
+
print(f"connecting to {self.bot.ws_url} with name {self.bot.username}")
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
self.ws = await websockets.connect(self.bot.ws_url)
|
|
14
|
+
|
|
15
|
+
await self.bot._dispatch("on_connect")
|
|
16
|
+
|
|
17
|
+
asyncio.create_task(self._heartbeat())
|
|
18
|
+
await self.listen()
|
|
19
|
+
except Exception as e:
|
|
20
|
+
print(f"failed to connect: {e}")
|
|
21
|
+
|
|
22
|
+
async def _heartbeat(self):
|
|
23
|
+
while True:
|
|
24
|
+
try:
|
|
25
|
+
await asyncio.sleep(20)
|
|
26
|
+
await self.ws.send(json.dumps({"_ping": 1}))
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"heartbeat failed: {e}")
|
|
29
|
+
break
|
|
30
|
+
|
|
31
|
+
async def listen(self):
|
|
32
|
+
async for raw in self.ws:
|
|
33
|
+
data = json.loads(raw)
|
|
34
|
+
await self.bot._handle_message(data)
|
|
35
|
+
|
|
36
|
+
async def send(self, payload):
|
|
37
|
+
await self.ws.send(json.dumps(payload))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: broadside
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: broadside bot thingy
|
|
5
|
+
Author: Sabisa
|
|
6
|
+
License:
|
|
7
|
+
Copyright 1985 Sabisa
|
|
8
|
+
|
|
9
|
+
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:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
Project-URL: Homepage, https://scm.socket775.xyz/Sabisascm/broadside.py
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: websockets==10.1
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# broadside.py
|
|
23
|
+
|
|
24
|
+
python bot
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
broadside/__init__.py
|
|
5
|
+
broadside/bot.py
|
|
6
|
+
broadside/context.py
|
|
7
|
+
broadside/gateway.py
|
|
8
|
+
broadside.egg-info/PKG-INFO
|
|
9
|
+
broadside.egg-info/SOURCES.txt
|
|
10
|
+
broadside.egg-info/dependency_links.txt
|
|
11
|
+
broadside.egg-info/requires.txt
|
|
12
|
+
broadside.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
websockets==10.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
broadside
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "broadside"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "broadside bot thingy"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name="Sabisa" }
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
license = { file = "LICENSE" }
|
|
16
|
+
|
|
17
|
+
dependencies = [
|
|
18
|
+
"websockets==10.1",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://scm.socket775.xyz/Sabisascm/broadside.py"
|