chore(bot.zig): add join admin command
Allows an admin to request the bot to join a channel.
This commit is contained in:
parent
7690c8b46d
commit
edb0727dda
1 changed files with 15 additions and 0 deletions
15
src/bot.zig
15
src/bot.zig
|
|
@ -56,6 +56,8 @@ pub const Parser = struct {
|
|||
pub const AdminCommand = union(enum) {
|
||||
backlog: struct { history: u16 },
|
||||
status: void,
|
||||
join: struct { channel: []const u8 },
|
||||
err: struct { message: []const u8 },
|
||||
|
||||
pub fn parse(text: []const u8) ?AdminCommand {
|
||||
const original = Parser.init(text);
|
||||
|
|
@ -63,6 +65,12 @@ pub const AdminCommand = union(enum) {
|
|||
if (command.consume_str("status")) |_| {
|
||||
return .status;
|
||||
}
|
||||
if (command.consume_str("join").?.consume_char(' ')) |join| {
|
||||
if (join.rest[0] != '#') {
|
||||
return .{ .err = .{ .message = "channels must start with \"#\"" } };
|
||||
}
|
||||
return .{ .join = .{ .channel = join.rest } };
|
||||
}
|
||||
if (command.consume_str("backlog")) |backlog| {
|
||||
const history = std.fmt.parseInt(u16, backlog.rest, 10) catch |err| {
|
||||
std.debug.print("failed to parse int ('{s}') with error: {}\n", .{ backlog.rest, err });
|
||||
|
|
@ -209,6 +217,10 @@ pub const Bot = struct {
|
|||
);
|
||||
return .{ .PRIVMSG = .{ .targets = targets, .prefix = prefix, .text = msg } };
|
||||
},
|
||||
.join => |msg| {
|
||||
std.log.debug("received join request: channel \"{s}\"", .{msg.channel});
|
||||
return .{ .JOIN = .{ .prefix = prefix, .channels = msg.channel } };
|
||||
},
|
||||
.backlog => |backlog| {
|
||||
if (self.top == self.bottom) {
|
||||
return Error.NoMessage;
|
||||
|
|
@ -229,6 +241,9 @@ pub const Bot = struct {
|
|||
};
|
||||
} else return Error.NoMessage;
|
||||
},
|
||||
.err => |err| {
|
||||
return .{ .PRIVMSG = .{ .targets = targets, .prefix = prefix, .text = err.message } };
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue