New innovative programming disciplines, frameworks and products, I create new code.
I am a professional Python developer.
Async Discord API wrapper.
Home Page: https://www.astil.dev/project/hata/
License: Other
I am trying to use a factory pattern and trying to make a create_app function. But I realized that I have to make so many parameters.
We could just make a config class that has the parametert
from hata import Client
import os
class NueConfig:
token = os.getenv('token')
...
Nue = Client.from_class(NueConfig)
# in my use case
def create_app(config, setup_slash=True, setup_commands=True, ...):
client = Client.from_class(config)
if setup_slash:
setup_ext_slash(client)
if setup_commmands:
....
return client
we could also have Client.from_dict()
Factory pattern
Unexpected IndexError
when trying to serialize.
Try to serialize .../hata/ext/solarlink/filters/Equalizer
.
No response
No exception occurs.
Traceback (most recent call last):
File ".../hata/ext/patchouli/module_mapper.py", line 497, in html_extended_with_structure
html_extended, html_extended_structure = html_serialize_docs_extended(self, True, True)
File ".../hata/ext/patchouli/builder_html_extended.py", line 1891, in html_serialize_docs_extended
structure = serializer.structurize()
File ".../hata/ext/patchouli/builder_html_extended.py", line 1574, in structurize
child = section.structurize()
File ".../hata/ext/patchouli/builder_html_extended.py", line 772, in structurize
serializer = serializer_type(unit, path / name)
File ".../hata/ext/patchouli/builder_html_extended.py", line 551, in __init__
parameter_section = ParameterSection(section_content, object_, path)
File ".../hata/ext/patchouli/builder_html_extended.py", line 1259, in __init__
self.extend(section_content)
File ".../hata/ext/patchouli/builder_html_extended.py", line 1289, in extend
self.parameter_sub_sections.append(ParameterSubSection(header, section_content))
File ".../hata/ext/patchouli/builder_html_extended.py", line 1028, in __init__
parameter_name_part = header_contents[0]
IndexError: list index out of range
Hata version: 1.3.4
Scarletio version: 1.0.34
Platform: Linux-5.13.0-1022-aws-x86_64-with-glibc2.2.5
Python implementation: cpython
Python version: 3.8 final
I think a way to change the base URL for endpoints would be a good idea. Because there's things like https://gitlab.com/litecord/litecord which allow people to test their bots out on private discord instances. I think it'd be a neat feature. It'd probably be changed like
Client(base_url="https://discord.com/api")
Obviously, base_url
would be changeable to anything you want. Like a private instance of https://gitlab.com/litecord/litecord
unix_time
can go out of range in windows raising OSError
instead of the expected ValueError
like on linux.
Use windows. (Please don't do that)
N/A
No exception occurs.
Traceback (most recent call last):
File "...\hata\discord\gateway\client_gateway.py", line 357, in _received_message
if parser(client, data) is None:
File "...\hata\discord\events\parsers.py", line 1377, in PRESENCE_UPDATE__OPT
user._update_presence(data)
File "...\hata\discord\user\client_user_base.py", line 777, in _update_presence
new_activities = [create_activity_from_data(activity_data) for activity_data in activity_datas]
File "...\hata\discord\user\client_user_base.py", line 777, in <listcomp>
new_activities = [create_activity_from_data(activity_data) for activity_data in activity_datas]
File "...\hata\discord\activity\utils.py", line 32, in create_activity_from_data
return activity_type.from_data(activity_data)
File "...\hata\discord\activity\activity_rich.py", line 365, in from_data
self._update_attributes(activity_data)
File "...\hata\discord\activity\activity_rich.py", line 397, in _update_attributes
created_at = unix_time_to_datetime(created_at)
File "...\hata\discord\utils.py", line 273, in unix_time_to_datetime
return datetime.utcfromtimestamp(unix_time)
OSError(22, 'Invalid argument')
Python3.9
windows?
(not my pc)
I need a way to store text in the command decorator and need it so I can get it from the case of the command, maybe it could be an extra field in client.events.message_create.commands
? It would be very useful to be able to store text or even a dict about commands, if it can store any data type, that would be preferable since I can easily adapt this to my commands
Patchouli builds broken code blocks.
No response
No response
Every line should appear on a new line.
Line-breaks are missing.
dev
hata try to load opus lib at .venv\\lib\\site-packages\\hata\\discord\\voice\\bin\\libopus-0.x64.dll
instead of .venv\\lib\\site-packages\\hata\\discord\\bin\\libopus-0.x64.dll
No response
from hata.discord.voice.opus import load_opus
load_opus()
the opus lib load correctly
FileNotFoundError("Could not find module '.venv\\lib\\site-packages\\hata\\discord\\voice\\bin\\libopus-0.x64.dll' (or one of its dependencies). Try using the full path with constructor syntax.")
Hata version: 1.1.132
Platform: Windows-7-6.1.7601-SP1
Python implementation: cpython
Python version: 3.8 final
Hata currently is amazing, but it's all in one single repo. I think splitting it up into async
, websockets
, html server
would be a LOT better, because that way people can use your async without downloading everything else, or the same with websockets
. Having multiple projects also makes it easier to update code independent from eachother, so you don't have to change a while file to make one thing work, for example.
Some event handler parameters can be yeeted after fixing up caching.
As an example the guild
parameter of channel_delete
could be made redundant if channel.guild_id
would not be reset to 0
on deletion.
Why are there two different methods which probably does the same thing for embeds?
https://huyanematsu.pythonanywhere.com/docs/hata/discord/embed/Embed
Ex.
Embed.add_footer
Embed.set_footer
There are lots more OwO
Slash command description should only include the first paragraph of documentation allowing other properties of the function to be documented (for example using hdsl) within it's docstring.
Everything after the first double line break should be excluded.
@Client.interactions
async def pepe(
client,
event,
):
"""
hello
Parameters
----------
client : ``Client``
The client who received the event.
event : ``InteractionEvent``
The received interaction event.
"""
return 'a'
Using the description
parameter at registration.
No response
With my code, I decided to try to copy Row only with different components. When I ran copy_with
, it came back with an error. I thought at first this was my code since it was a bit messy at the time. So, I tested it in a different file without running the bot, the same error came back.
The reproduction code below is what the test file included. It would be easier to create a new Row object rather than copying it, but I was mainly messing around with components and seeing what I can do.
No response
from hata import BUILTIN_EMOJIS
from hata.ext.slash import Button, Row
# Paginator buttons
PAGE_FIRST = Button(emoji=BUILTIN_EMOJIS["track_previous"])
PAGE_LAST = Button(emoji=BUILTIN_EMOJIS["track_next"])
PAGE_NEXT = Button(emoji=BUILTIN_EMOJIS["arrow_right"])
PAGE_PREVIOUS = Button(emoji=BUILTIN_EMOJIS["arrow_left"])
PAGE_BUTTONS = Row(PAGE_FIRST, PAGE_PREVIOUS, PAGE_NEXT, PAGE_LAST)
TEST = PAGE_BUTTONS.copy_with(components=[PAGE_FIRST])
copy_with
return the new object with different components.
This error came up:
Traceback (most recent call last):
File "C:\Users\Catzoo Bob\Desktop\Github\discord-channel-bot\bot\test.py", line 12, in <module>
TEST = PAGE_BUTTONS.copy_with(components=[PAGE_FIRST])
File "C:\Users\Catzoo Bob\Desktop\Github\discord-channel-bot\bot\bot-env\lib\site-packages\hata\discord\interaction\components.py", line 658, in copy_with
self = object.__new__(cls)
NameError: name 'cls' is not defined
Hata version: 1.1.101
Platform: Windows-10-10.0.19042-SP0
Python implementation: cpython
Python version: 3.9 final
Interaction has already been acknowledged.
No response
No response
Been Normal
No response
Newest
Nonce doesn't have an attribute for webhooks, and despite my own testing of modified source code (where I've edited nonce into the parameters and added it to the message payload), it doesn't set the nonce for the message. I do not know the cause of this.
Just send a message to a webhook with nonce, I'll upload a fork of Hata that has nonce added to the webhook parameter
await client.webhook_message_create(webhook, "Message", nonce="X")
I expected that nonce should be a valid parameter and should be accessible from other events that return messages (e.g. message_edit)
Original Hata code has no support, my modified Hata fork doesn't register nonce despite it being added to the message payload
Hata version: 1.1.127
Platform: Linux-4.14.180-perf-gaefbc3caa24c-aarch64-with-libc
Python implementation: cpython
Python version: 3.10 final
Ugh what about on_reply_event?
Hello :P
I have an idea for a feature in Hata, I think it would be quite useful to be able to define a check in a decorator, e.g. on_command(permissions=['permission 1', 'permission 2', 'etc'])
, and a way to access it via client.events.commands["name"]["permissions"]
which would be quite nice, it would return a list, and if no permissions were passed, then it would return []
, this would be a nice feature to add, since it simplifies permission checks greatly, so what do you think?
Traceback (most recent call last):
File "/storage/emulated/0/Codes/yametechs/dbot/main.py", line 1, in <module> import hata
File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/__init__.py", line 110, in <module> from .discord import * File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/__init__.py", line 1, in <module> from .activity import * File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/activity/__init__.py", line 3, in <module> from .activity_base import * File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/activity/activity_base.py", line 8, in <module> from ..utils import DATETIME_FORMAT_CODE, DISCORD_EPOCH_START, datetime_to_unix_time, unix_time_to_datetime File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/utils.py", line 331, in <module> UNIX_TIME_MAX = datetime_to_unix_time(DATETIME_MAX) File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/utils.py", line 299, in datetime_to_unix_time return floor(date_time.timestamp() * 1000.0) OverflowError: timestamp out of range for platform time_t```
### Reproduction Steps
pipenv install hata
python
>> import hata
### Reproduction Code
```python
import hata
imports hata
errors
Can't run... it errors
extension files and cogs for the bot.
Creating an ActivityRich, with a custom type_, causes a TypeError.
import hata
hata.ActivityRich('', type_=hata.ACTIVITY_TYPES.custom)
ValueError: `type_` can be any of: 0, 1, 2, 3, 5, got 4.
TypeError: sequence item 0: expected str instance, int found
Hata version: 1.2.14
Scarletio version: 1.0.27
Platform: Windows-10-10.0.19041-SP0
Python implementation: cpython
Python version: 3.9 final
It's hard to navigate around the docs
The search engine of the docs website is kinda strict
(It makes it hard to find certain things)
The other things aren't in the docs website (most people rely on the docs website rather than the github one)
Add a sidebar like where we can see and/or fold other topics.
Don't make it that much strict.
Add the tutorials. Maybe add examples on how to use other useful things. Put everything in one place.
No response
Recreate the whole website maybe on github docs
This issue is the input I took from other people who don't know what exactly hata is yet and my own feedback.
PR-s to improve documentation, docstrings, and examples are welcome.
Contribution for improving 3rd_party_voice_clients.md is welcome.
This is a long term suggestion, but adding AnyIO support to Hata might be a good idea, since then libaries that use a specific library or use AnyIO would also work in Hata. And while Hata async is faster then everything else, this also proves to others how much better it is (also gives you the option to use AnyIO in other projects and use Hata's async)
I'd like to get an easy way to load extensions, since right now we have to do `python
EXTENSION_LOADER = ExtensionLoader(client)
def add_extensions():
async def entry(client, lib):
commands=getattr(lib,'commands',None)
if commands is not None:
client.events.message_create.shortcut.extend(commands)
entry=getattr(lib,'entry',None)
if entry is not None:
if is_coro(entry):
await entry(client)
else:
entry(client)
print(f'{lib.__name__} extension has been loaded!')
async def exit(client, lib):
commands=getattr(lib,'commands',None)
if commands is not None:
client.events.message_create.shortcut.unextend(commands)
exit=getattr(lib,'exit',None)
if exit is not None:
if is_coro(exit):
await exit(client)
else:
exit(client)
print(f'{lib.__name__} extension has been unloaded!')
for filename in os.listdir('./cogs/'):
if filename.endswith('.py'):
module_name='cogs.'+filename[:-3] EXTENSION_LOADER.add(module_name, entry_point=entry, exit_point=exit)
add_extensions()
EXTENSION_LOADER.load_all().syncwrap().wait()which is really annoying and is quite alot to try and remember, for discord.py all we have to do is
python
for file in os.listdir("./cogs/"):
if file.endswith('.py'):
client.load_extension(cogs.file.strip[:-3])which is alot easier to remember, I'd think this would be a nice feature to implement since it'll simplify cog loading alot, for hata you could do
python
client.load_extension("path_of_cog", "the name of the eventlist to load")`
It would be great if there would be an easy way to load all files and directories from a plugin __init__.py
file.
Example code:
mark_as_plugin_root_directory()
Example file system:
plugin_directory
|- __init__.py
|- directory_n
|- file_n.py
No response
Manually import all files & directories from the file's directory.
__init__.py
files stop further files to being loaded in that directory, so manual import is required.__init__.py
files are required for relative imports.ApplicationCommand.__hash__
should work partial instances as well.
Produce hash value based on fields which are allowed for partial application commands.
application_commands = [*{*application_commands}]
Write the logic outside the library.
No response
After f5012b6 plugin dependency tree broke.
Reload a plugin with dependency tree.
No response
Everything works like before.
No response
dev
I'm attempting to use Hata with Fosscord, a reimplementation of the discord API, but currently my program refuses to work correctly due to errors. Here are the errors i have, the first one uses is_bot=False, but the result of the second error keeps is_bot to True
Traceback (most recent call last):
File "/data/data/com.termux/files/home/hata-foss/main.py", line 18, in <module>
acc.start()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/client/client.py", line 14797, in start
return task.sync_wrap().wait()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scarletio-1.0.5-py3.10.egg/scarletio/core/traps/future_sync_wrapper.py", line 392, in wait
return self.result()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scarletio-1.0.5-py3.10.egg/scarletio/core/traps/future_sync_wrapper.py", line 221, in result
raise exception
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/scarletio-1.0.5-py3.10.egg/scarletio/core/traps/task.py", line 480, in _step
result = coroutine.send(None)
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/client/client.py", line 14884, in connect
await self.client_gateway_reshard()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/client/client.py", line 14685, in client_gateway_reshard
new_shard_count = data['shards']
KeyError: 'shards'
Unexpected exception occurred at <Client id=920060660405632105 (partial)>._connect
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/client/client.py", line 14916, in _connect
await self.gateway.run()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/gateway/client_gateway.py", line 172, in run
should_reconnect = await self._poll_event()
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/gateway/client_gateway.py", line 292, in _poll_event
return (await self._received_message(message))
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/hata/discord/gateway/client_gateway.py", line 329, in _received_message
sequence = message['s']
KeyError('s')
If you can reproduce this bug, Please send me a message or open an issue with your code, and with every detail how to reproduce it.
Thanks!
No response
from os import environ
environ['HATA_API_ENDPOINT'] = "https://dev.fosscord.com/api/"
environ['HATA_CDN_ENDPOINT'] = "https://cdn.fosscord.com/"
environ['HATA_DISCORD_ENDPOINT'] = "https://dev.fosscord.com/"
from hata import Client
token = "MY TOKEN"
acc = Client(token, is_bot=False)
@acc.events
async def message_create(client, message):
print(m.author.full_name+': '+m.clean_content)
acc.start()
The bot should connect successfully to the gateway
It failed to run
Hata version: 1.1.127
Platform: Linux-4.14.180-perf-gaefbc3caa24c-aarch64-with-libc
Python implementation: cpython
Python version: 3.10 final
What if I registered a folder then everything made there would be registered too for easier checking and no more looping through a path
Might be a bad idea;
Since I kinda use multiple bots maybe find a way we could separate those? You can set a folder to this bot only.
When trying to implement the example basic voice I cant even let the bot join because AttributeError: 'InteractionEvent' has no attribute '.voice_state'.
run the example code
@Sakuya.interactions(guild = MY_GUILD)
async def join(client, event):
"""Joins to voice channel."""
# Getting the author voice state
voice_state = event.voice_state
if voice_state is None:
return 'You are not at a voice channel!'
# Connecting the client to the same channel, where the user is.
try:
await client.join_voice(voice_state.channel)
except TimeoutError:
# Could not connect.
return 'Timed out meanwhile tried to connect.'
except RuntimeError:
# Not every required library is installed.
return 'The client cannot play voice, some libraries are not loaded.'
# Great success.
return f'Joined to {voice_state.channel.name}'
the bot to join
AttributeError thrown
Hata version: 1.3.53
Scarletio version: 1.0.68
Platform: macOS-14.2.1-arm64-arm-64bit
Python implementation: cpython
Python version: 3.11 final
I think a default help command (similar to Discord.py's help command) would be a good idea. Maybe just to show users how their help command should be structured? The structure would probably be like
CATEGORY:
- Command1 <args> - <description>
- Command2 <args> - <description>
3rd party voice client example is wanted.
A cool hata feature would be the ability to bind objects to an existing object, and depending on what that is, have it be initialised and share the data of the class that an object has been bound to. This would also need a way to detect if the object that is meant to be bound to an object is a class and needs to be initialised, including if it is asynchronous or not.
A bind function could loosely be implemented with a method that accepts 3 parameters. The first being the object being bound to, the second being the target object to bind, and the third being the initialised name of the object.
from hata import User, bind
class Inventory(object):
def __init__(self, parent_self):
self.user = parent_self
self.inv = []
def add_item(self, name):
self.inv.append(name)
def give_user(self, item, recipient):
del self.inv[self.inv.index(item)]
recipient.inventory.add_item(item)
bind(User, Inventory, 'inventory') # Parent object, new class, initialised object name
# Note this is a very bad example. This should also be doable with functions and variables, simply just adding them to the parent object.
While i could simply just keep them separate, it would be more convenient and beneficial to be able to bind related objects together, as they will never be used without eachother.
No response
New contributors don't have anything to work on. So just make some issues which we can contribute to
await client.guild_edit(guild, owner=user)
does not work
owner doesn't take anything yet
Something that'd be pretty nifty would be wrappers around a channel that could be used is stdout
/stderr
/stdin
in Hata. An example would be
hstdout, hstderr, hstdin = get_channel_std(Client, Channel)
That could be used exactly like stdout
/stderr
/stdin
as drop in alternatives for anything else that need std, so redirecting logging to a channel, or a shell like bash
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.