feat(eventsub): implement (shared-chat-)ban (#5985)
This commit is contained in:
@@ -55,12 +55,6 @@ def _is_trivially_copyable(type: clang.cindex.Type) -> bool:
|
||||
return _is_chrono_like_type(type)
|
||||
|
||||
|
||||
def _has_no_fields(type: clang.cindex.Type) -> bool:
|
||||
for _ in type.get_fields():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@dataclass
|
||||
class VariantType:
|
||||
name: str
|
||||
@@ -179,7 +173,7 @@ class Member:
|
||||
VariantType(
|
||||
name=name,
|
||||
trivial=_is_trivially_copyable(inner),
|
||||
empty=_has_no_fields(inner),
|
||||
empty=inner.get_size() <= 1,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
import logging
|
||||
|
||||
@@ -20,6 +20,7 @@ class Struct:
|
||||
self.comment_commands = CommentCommands()
|
||||
self.inner_root: str = ""
|
||||
self.namespace = namespace
|
||||
self.base: Optional[str] = None
|
||||
|
||||
@property
|
||||
def full_name(self) -> str:
|
||||
@@ -48,3 +49,8 @@ class Struct:
|
||||
|
||||
def apply_comment_commands(self, comment_commands: CommentCommands) -> None:
|
||||
self.inner_root = comment_commands.inner_root
|
||||
|
||||
def validate(self) -> None:
|
||||
assert not (self.base and self.members), (
|
||||
f"Unsupported: Struct {self.name} has both a base class as well as additional members"
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<{{struct.full_name}}> /* tag */, const boost::json::value &{%- if struct.members|length -%}jvRoot{%- else -%}/* jvRoot */{%- endif -%})
|
||||
boost::json::try_value_to_tag<{{struct.full_name}}> /* tag */, const boost::json::value &{%- if struct.members|length or struct.base -%}jvRoot{%- else -%}/* jvRoot */{%- endif -%})
|
||||
{
|
||||
{% if struct.inner_root %}
|
||||
if (!jvRoot.is_object())
|
||||
@@ -24,6 +24,12 @@ boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invo
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
{% elif struct.base %}
|
||||
auto base = boost::json::try_value_to<{{struct.base}}>(jvRoot);
|
||||
if (base.has_error())
|
||||
{
|
||||
return base.error();
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
{% for field in struct.members %}
|
||||
@@ -56,6 +62,9 @@ boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invo
|
||||
{%- elif field.member_type == MemberType.VARIANT -%}
|
||||
{% include 'initializer-variant.tmpl' indent content %}
|
||||
{%- endif -%}
|
||||
{% endfor %}
|
||||
{% endfor -%}
|
||||
{%- if struct.base %}
|
||||
std::move(*base)
|
||||
{% endif -%}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class Walker:
|
||||
for child in node.get_children():
|
||||
self.handle_node(child, new_struct, None)
|
||||
|
||||
new_struct.validate()
|
||||
self.structs.append(new_struct)
|
||||
|
||||
return True
|
||||
@@ -83,6 +84,11 @@ class Walker:
|
||||
self.namespace = self.namespace[:-1]
|
||||
return True
|
||||
|
||||
case CursorKind.CXX_BASE_SPECIFIER:
|
||||
assert struct
|
||||
struct.base = node.type.spelling
|
||||
return False
|
||||
|
||||
case CursorKind.FUNCTION_DECL:
|
||||
# Ignore function declarations
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user