This commit is contained in:
Yuzu 2024-12-05 00:27:38 -05:00
parent a5069e1989
commit 42f6a93245
3 changed files with 34 additions and 76 deletions

View File

@ -10,7 +10,7 @@ A high-performance bleeding edge Discord library in Zig, featuring full API cove
```zig
const Client = @import("discord.zig").Client;
const Shard = @import("discord.zig").Shard;
const Discord = @import("discord.zig").Discord;
const Discord = @import("discord.zig");
const Intents = Discord.Intents;
const std = @import("std");
@ -23,9 +23,7 @@ fn message_create(_: *Shard, message: Discord.Message) void {
}
pub fn main() !void {
var tsa = std.heap.ThreadSafeAllocator{ .child_allocator = std.heap.c_allocator };
var handler = Client.init(tsa.allocator());
var handler = Client.init(allocator);
try handler.start(.{
.token = std.posix.getenv("TOKEN") orelse unreachable,
.intents = Intents.fromRaw(37379),
@ -62,80 +60,14 @@ Contributions are welcome! Please open an issue or pull request if you'd like to
| Task | Status |
|-------------------------------------------------------------|--------|
| stablish good sharding support with buckets | ✅ |
| finish the event coverage roadmap | ✅ |
| use the priority queues for handling ratelimits (half done) | ❌ |
| make the library scalable with a gateway proxy | ❌ |
| get a cool logo | ❌ |
| finish the event coverage roadmap | ❌ |
## event coverage roadmap
## missing events right now
| Event | Support |
|----------------------------------------|---------|
| application_command_permissions_update | ❌ |
| auto_moderation_rule_create | ❌ |
| auto_moderation_rule_update | ❌ |
| auto_moderation_rule_delete | ❌ |
| auto_moderation_action_execution | ❌ |
| channel_create | ❌ |
| channel_update | ❌ |
| channel_delete | ❌ |
| channel_pins_update | ❌ |
| thread_create | ❌ |
| thread_update | ❌ |
| thread_delete | ❌ |
| thread_list_sync | ❌ |
| thread_member_update | ❌ |
| thread_members_update | ❌ |
| guild_audit_log_entry_create | ❌ |
| guild_create | ❌ |
| guild_update | ❌ |
| guild_delete | ❌ |
| guild_ban_add | ❌ |
| guild_ban_remove | ❌ |
| guild_emojis_update | ❌ |
| guild_stickers_update | ❌ |
| guild_integrations_update | ❌ |
| guild_member_add | ❌ |
| guild_member_remove | ❌ |
| guild_member_update | ❌ |
| guild_members_chunk | ❌ |
| guild_role_create | ❌ |
| guild_role_update | ❌ |
| guild_role_delete | ❌ |
| guild_scheduled_event_create | ❌ |
| guild_scheduled_event_update | ❌ |
| guild_scheduled_event_delete | ❌ |
| guild_scheduled_event_user_add | ❌ |
| guild_scheduled_event_user_remove | ❌ |
| integration_create | ❌ |
| integration_update | ❌ |
| integration_delete | ❌ |
| interaction_create | ❌ |
| invite_create | ❌ |
| invite_delete | ❌ |
| message_create: ?*const fn (message: Discord.Message) void | ✅ |
| message_update: ?*const fn (message: Discord.Message) void | ✅ |
| message_delete: ?*const fn (message: Discord.MessageDelete) void | ✅ |
| message_delete_bulk: ?*const fn (message: Discord.MessageDeleteBulk) void | ✅ |
| message_reaction_add | ❌ |
| message_reaction_remove | ❌ |
| message_reaction_remove_all | ❌ |
| message_reaction_remove_emoji | ❌ |
| presence_update | ❌ |
| stage_instance_create | ❌ |
| stage_instance_update | ❌ |
| stage_instance_delete | ❌ |
| typing_start | ❌ |
| user_update | ❌ |
| voice_channel_effect_send | ❌ |
| voice_state_update | ❌ |
| voice_server_update | ❌ |
| webhooks_update | ❌ |
| entitlement_create | ❌ |
| entitlement_update | ❌ |
| entitlement_delete | ❌ |
| message_poll_vote_add | ❌ |
| message_poll_vote_remove | ❌ |
| ready: Discord.Ready | ✅ |
| resumed | ❌ |
| any: []const u8 | ✅ |

View File

@ -258,10 +258,11 @@ pub const Bucket = struct {
pub fn GatewayDispatchEvent(comptime T: type) type {
return struct {
application_command_permissions_update: ?*const fn (save: T, application_command_permissions: Types.ApplicationCommandPermissions) anyerror!void = undefined,
// TODO: implement // auto_moderation_rule_create: null = null,
// TODO: implement // auto_moderation_rule_update: null = null,
// TODO: implement // auto_moderation_rule_delete: null = null,
// TODO: implement // auto_moderation_action_execution: null = null,
auto_moderation_rule_create: ?*const fn (save: T, rule: Types.AutoModerationRule) anyerror!void = undefined,
auto_moderation_rule_update: ?*const fn (save: T, rule: Types.AutoModerationRule) anyerror!void = undefined,
auto_moderation_rule_delete: ?*const fn (save: T, rule: Types.AutoModerationRule) anyerror!void = undefined,
auto_moderation_action_execution: ?*const fn (save: T, action_execution: Types.AutoModerationActionExecution) anyerror!void = undefined,
channel_create: ?*const fn (save: T, chan: Types.Channel) anyerror!void = undefined,
channel_update: ?*const fn (save: T, chan: Types.Channel) anyerror!void = undefined,
/// this isn't send when the channel is not relevant to you
@ -319,6 +320,7 @@ pub fn GatewayDispatchEvent(comptime T: type) type {
typing_start: ?*const fn (save: T, data: Types.TypingStart) anyerror!void = undefined,
/// remember this is only sent when you change your profile yourself/your bot does
user_update: ?*const fn (save: T, user: Types.User) anyerror!void = undefined,
// will do these someday, music is rather pointless at this point in time
// TODO: implement // voice_channel_effect_send: null = null,
// TODO: implement // voice_state_update: null = null,
// TODO: implement // voice_server_update: null = null,

View File

@ -741,6 +741,30 @@ pub fn handleEvent(self: *Self, name: []const u8, payload: []const u8) !void {
if (self.handler.stage_instance_delete) |event| try event(self, stage.value.d.?);
}
if (mem.eql(u8, name, "AUTO_MODERATION_RULE_CREATE")) {
const rule = try zjson.parse(GatewayPayload(Types.AutoModerationRule));
if (self.handler.auto_moderation_rule_create) |event| try event(self, rule.value.d.?);
}
if (mem.eql(u8, name, "AUTO_MODERATION_RULE_UPDATE")) {
const rule = try zjson.parse(GatewayPayload(Types.AutoModerationRule));
if (self.handler.auto_moderation_rule_update) |event| try event(self, rule.value.d.?);
}
if (mem.eql(u8, name, "AUTO_MODERATION_RULE_DELETE")) {
const rule = try zjson.parse(GatewayPayload(Types.AutoModerationRule));
if (self.handler.auto_moderation_rule_delete) |event| try event(self, rule.value.d.?);
}
if (mem.eql(u8, name, "AUTO_MODERATION_ACTION_EXECUTION")) {
const ax = try zjson.parse(GatewayPayload(Types.AutoModerationActionExecution));
if (self.handler.auto_moderation_action_execution) |event| try event(self, ax.value.d.?);
}
if (self.handler.any) |anyEvent|
try anyEvent(self, payload);
}