chore: simplify code
This commit is contained in:
parent
798721d59d
commit
4fc4ff16c0
@ -158,16 +158,12 @@ pub const SelectMenu = union(MessageComponentTypes) {
|
|||||||
@panic("coulnd't match against non-object type");
|
@panic("coulnd't match against non-object type");
|
||||||
|
|
||||||
switch (value.object.get("type") orelse @panic("couldn't find property `type`")) {
|
switch (value.object.get("type") orelse @panic("couldn't find property `type`")) {
|
||||||
.number => |num| switch (num) {
|
.number => |num| return switch (@as(MessageComponentTypes, @enumFromInt(num.integer))) {
|
||||||
.integer => |int| return switch (@as(MessageComponentTypes, @enumFromInt(int))) {
|
|
||||||
.SelectMenu => .{ .SelectMenu = try zjson.parseInto(SelectMenuString, allocator, value) },
|
.SelectMenu => .{ .SelectMenu = try zjson.parseInto(SelectMenuString, allocator, value) },
|
||||||
.SelectMenuUsers => .{ .SelectMenuUsers = try zjson.parseInto(SelectMenuUsers, allocator, value) },
|
.SelectMenuUsers => .{ .SelectMenuUsers = try zjson.parseInto(SelectMenuUsers, allocator, value) },
|
||||||
.SelectMenuRoles => .{ .SelectMenuRoles = try zjson.parseInto(SelectMenuRoles, allocator, value) },
|
.SelectMenuRoles => .{ .SelectMenuRoles = try zjson.parseInto(SelectMenuRoles, allocator, value) },
|
||||||
.SelectMenuUsersAndRoles => .{ .SelectMenuUsersAndRoles = try zjson.parseInto(SelectMenuUsersAndRoles, allocator, value) },
|
.SelectMenuUsersAndRoles => .{ .SelectMenuUsersAndRoles = try zjson.parseInto(SelectMenuUsersAndRoles, allocator, value) },
|
||||||
.SelectMenuChannels => .{ .SelectMenuChannels = try zjson.parseInto(SelectMenuChannels, allocator, value) },
|
.SelectMenuChannels => .{ .SelectMenuChannels = try zjson.parseInto(SelectMenuChannels, allocator, value) },
|
||||||
else => unreachable,
|
|
||||||
},
|
|
||||||
else => unreachable,
|
|
||||||
},
|
},
|
||||||
else => @panic("got type but couldn't match against non enum member `type`"),
|
else => @panic("got type but couldn't match against non enum member `type`"),
|
||||||
}
|
}
|
||||||
@ -216,8 +212,7 @@ pub const MessageComponent = union(MessageComponentTypes) {
|
|||||||
@panic("coulnd't match against non-object type");
|
@panic("coulnd't match against non-object type");
|
||||||
|
|
||||||
switch (value.object.get("type") orelse @panic("couldn't find property `type`")) {
|
switch (value.object.get("type") orelse @panic("couldn't find property `type`")) {
|
||||||
.number => |num| switch (num) {
|
.number => |num| return switch (@as(MessageComponentTypes, @enumFromInt(num.integer))) {
|
||||||
.integer => |int| return switch (@as(MessageComponentTypes, @enumFromInt(int))) {
|
|
||||||
.ActionRow => .{ .ActionRow = try zjson.parseInto([]MessageComponent, allocator, value) },
|
.ActionRow => .{ .ActionRow = try zjson.parseInto([]MessageComponent, allocator, value) },
|
||||||
.Button => .{ .Button = try zjson.parseInto(Button, allocator, value) },
|
.Button => .{ .Button = try zjson.parseInto(Button, allocator, value) },
|
||||||
.SelectMenu => .{ .SelectMenu = try zjson.parseInto(SelectMenuString, allocator, value) },
|
.SelectMenu => .{ .SelectMenu = try zjson.parseInto(SelectMenuString, allocator, value) },
|
||||||
@ -227,10 +222,7 @@ pub const MessageComponent = union(MessageComponentTypes) {
|
|||||||
.SelectMenuUsersAndRoles => .{ .SelectMenuUsersAndRoles = try zjson.parseInto(SelectMenuUsersAndRoles, allocator, value) },
|
.SelectMenuUsersAndRoles => .{ .SelectMenuUsersAndRoles = try zjson.parseInto(SelectMenuUsersAndRoles, allocator, value) },
|
||||||
.SelectMenuChannels => .{ .SelectMenuChannels = try zjson.parseInto(SelectMenuChannels, allocator, value) },
|
.SelectMenuChannels => .{ .SelectMenuChannels = try zjson.parseInto(SelectMenuChannels, allocator, value) },
|
||||||
},
|
},
|
||||||
else => unreachable,
|
|
||||||
},
|
|
||||||
else => @panic("got type but couldn't match against non enum member `type`"),
|
else => @panic("got type but couldn't match against non enum member `type`"),
|
||||||
}
|
}
|
||||||
unreachable;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user