docs(main): add comments to functions and types
This commit is contained in:
parent
b72d584996
commit
7d444204ef
1 changed files with 19 additions and 0 deletions
19
src/main.zig
19
src/main.zig
|
|
@ -49,6 +49,16 @@ pub const Adapter = struct {
|
||||||
callbackFn: *const fn (*anyopaque, zircon.Message) ?zircon.Message,
|
callbackFn: *const fn (*anyopaque, zircon.Message) ?zircon.Message,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// BotAdapter is the closure that we register in zircon as the
|
||||||
|
/// message callback.
|
||||||
|
///
|
||||||
|
/// Whenever a message is received by the zircon client it will invoke
|
||||||
|
/// BotAdapter.callback (through some indirection) with the received
|
||||||
|
/// message.
|
||||||
|
///
|
||||||
|
/// The main responsibility of BotAdapter is to serve as the
|
||||||
|
/// translation layer between our own internal types and the zircon
|
||||||
|
/// IRC types.
|
||||||
pub const BotAdapter = struct {
|
pub const BotAdapter = struct {
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
@ -64,6 +74,14 @@ pub const BotAdapter = struct {
|
||||||
self.bot.deinit();
|
self.bot.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// callback gets called for every message that we receive.
|
||||||
|
///
|
||||||
|
/// This is where we can extend the bot to support more types of
|
||||||
|
/// messages if needed.
|
||||||
|
///
|
||||||
|
/// See
|
||||||
|
/// - https://modern.ircdocs.horse/, for what kinds of messages exists in the IRC protocol documentation,
|
||||||
|
/// - https://github.com/Jassob/zircon/blob/main/src/message.zig, for zircon documentation.
|
||||||
pub fn callback(self: *BotAdapter, message: zircon.Message) ?zircon.Message {
|
pub fn callback(self: *BotAdapter, message: zircon.Message) ?zircon.Message {
|
||||||
switch (message) {
|
switch (message) {
|
||||||
.PRIVMSG => |msg| {
|
.PRIVMSG => |msg| {
|
||||||
|
|
@ -97,6 +115,7 @@ pub const BotAdapter = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// report errors as private message to admin channel.
|
||||||
fn reportError(err: Error) zircon.Message {
|
fn reportError(err: Error) zircon.Message {
|
||||||
const err_msg = switch (err) {
|
const err_msg = switch (err) {
|
||||||
Error.NoMessage => "no matching message",
|
Error.NoMessage => "no matching message",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue