diff --git a/examples/reply-bot.zig b/examples/reply-bot.zig index 6229ae4..9ca96b3 100644 --- a/examples/reply-bot.zig +++ b/examples/reply-bot.zig @@ -35,8 +35,8 @@ fn processEvent(event: zCord.Gateway.Event) !void { else => {}, .message_create => { const paths = try event.data.pathMatch(struct { - @"channel_id": zCord.Snowflake(.channel), - @"content": std.BoundedArray(u8, 0x1000), + channel_id: zCord.Snowflake(.channel), + content: std.BoundedArray(u8, 0x1000), }); if (std.mem.eql(u8, paths.content.constSlice(), "Hello")) { diff --git a/src/Gateway.zig b/src/Gateway.zig index fbb9b46..ab8a7d7 100644 --- a/src/Gateway.zig +++ b/src/Gateway.zig @@ -135,15 +135,15 @@ fn connect(self: *Gateway) !void { defer self.wz.flushReader() catch |err| { flush_error = err; }; - errdefer |err| log.info("{}", .{stream.debugInfo()}); + errdefer log.info("{}", .{stream.debugInfo()}); const root = try stream.root(); const paths = try root.pathMatch(struct { - @"op": u8, + op: u8, @"d.heartbeat_interval": u32, }); - if (paths.@"op" != @enumToInt(discord.Gateway.Opcode.hello)) { + if (paths.op != @enumToInt(discord.Gateway.Opcode.hello)) { return error.MalformedHelloResponse; } @@ -183,27 +183,27 @@ fn connect(self: *Gateway) !void { defer self.wz.flushReader() catch |err| { flush_error = err; }; - errdefer |err| log.info("{}", .{stream.debugInfo()}); + errdefer log.info("{}", .{stream.debugInfo()}); const root = try stream.root(); // TODO: possibly "rewind" this to allow data reconsumption const paths = try root.pathMatch(struct { - @"t": std.BoundedArray(u8, 0x100), - @"s": ?u32, - @"op": u8, + t: std.BoundedArray(u8, 0x100), + s: ?u32, + op: u8, @"d.session_id": std.BoundedArray(u8, 0x100), @"d.user.username": std.BoundedArray(u8, 0x100), @"d.user.discriminator": std.BoundedArray(u8, 0x100), }); - if (!std.mem.eql(u8, paths.@"t".constSlice(), "READY")) { + if (!std.mem.eql(u8, paths.t.constSlice(), "READY")) { return error.MalformedIdentify; } - if (paths.@"op" != @enumToInt(discord.Gateway.Opcode.dispatch)) { + if (paths.op != @enumToInt(discord.Gateway.Opcode.dispatch)) { return error.MalformedIdentify; } - if (paths.@"s") |seq| { + if (paths.s) |seq| { self.seq = seq; } @@ -347,7 +347,7 @@ fn recvEventNoReconnect(self: *Gateway) !Event { const gateway_event = self.processEvent(self.wz.reader()) catch |err| switch (err) { error.ConnectionReset, error.InvalidSession => |e| return e, else => { - log.warn("Process chunks failed: {s}", .{err}); + log.warn("Process chunks failed: {s}", .{@errorName(err)}); continue; }, }; @@ -416,7 +416,7 @@ fn processEvent(self: *Gateway, reader: anytype) !?Event { } }, else => { - log.info("Unhandled {} -- {s}", .{ op, name }); + log.info("Unhandled {} -- {?}", .{ op.?, name }); match.value.debugDump(std.io.getStdErr().writer()) catch {}; }, } diff --git a/src/Gateway/Heartbeat.zig b/src/Gateway/Heartbeat.zig index 9447638..b74f1fa 100644 --- a/src/Gateway/Heartbeat.zig +++ b/src/Gateway/Heartbeat.zig @@ -49,7 +49,7 @@ pub fn send(self: Heartbeat, msg: Message) void { pub const CallbackHandler = struct { context: *anyopaque, - func: fn (ctx: *anyopaque, msg: Message) void, + func: *const fn (ctx: *anyopaque, msg: Message) void, }; const ThreadHandler = struct { diff --git a/cacert.pem b/src/cacert.pem similarity index 100% rename from cacert.pem rename to src/cacert.pem diff --git a/src/https.zig b/src/https.zig index 98db983..90ba985 100644 --- a/src/https.zig +++ b/src/https.zig @@ -4,7 +4,7 @@ const iguanaTLS = @import("iguanaTLS"); const util = @import("util.zig"); pub const root_ca = struct { - const pem = @embedFile("../cacert.pem"); + const pem = @embedFile("cacert.pem"); var cert_chain: ?iguanaTLS.x509.CertificateChain = null; /// Initializes the bundled root certificates diff --git a/src/main.zig b/src/main.zig index 169c8f1..af11a93 100644 --- a/src/main.zig +++ b/src/main.zig @@ -12,6 +12,6 @@ pub const util = @import("util.zig"); pub const root_ca = https.root_ca; pub const Snowflake = discord.Snowflake; -test "" { +test { std.testing.refAllDecls(@This()); } diff --git a/src/util.zig b/src/util.zig index 01d74d7..0710ec5 100644 --- a/src/util.zig +++ b/src/util.zig @@ -112,7 +112,7 @@ pub const TimeoutStream = struct { return .{ .context = self }; } - const PollFdEvents = std.meta.fieldInfo(std.os.pollfd, .events).field_type; + const PollFdEvents = std.meta.fieldInfo(std.os.pollfd, .events).type; fn pollWait(self: TimeoutStream, events: PollFdEvents) !void { if (self.expiration) |expiration| { var polling = [_]std.os.pollfd{.{ diff --git a/zig.mod b/zig.mod index 292d6fa..2db429a 100644 --- a/zig.mod +++ b/zig.mod @@ -6,4 +6,5 @@ description: Zig ⚡ Discord API with zero allocations in the critical path dependencies: - src: git https://github.com/truemedian/wz - src: git https://github.com/truemedian/hzzp - - src: git https://github.com/marler8997/iguanaTLS + - src: git https://github.com/nektro/iguanaTLS + - src: git https://github.com/fengb/zasp