diff --git a/src/bot.zig b/src/bot.zig index 1124d3c..0694738 100644 --- a/src/bot.zig +++ b/src/bot.zig @@ -269,9 +269,7 @@ test "execute substitution" { bot.hear(msg); // execute substitution - const cmd = UserCommand{ - .substitute = .{ .author = "jassob", .needle = "What", .replacement = "what" }, - }; + const cmd = UserCommand.init_substitute("jassob", "What", "what", false); const response = try bot.execute(&cmd, null, "#test"); // expect response matching the correct message @@ -292,9 +290,7 @@ test "execute substitution with no matching needle" { bot.hear(msg); // execute substitution - const cmd = UserCommand{ - .substitute = .{ .author = "jassob", .needle = "something else", .replacement = "weird" }, - }; + const cmd = UserCommand.init_substitute("jassob", "something else", "weird", false); try std.testing.expectError(Error.NoMessage, bot.execute( &cmd, null, diff --git a/src/commands.zig b/src/commands.zig index cff4b98..b16f3ef 100644 --- a/src/commands.zig +++ b/src/commands.zig @@ -9,6 +9,15 @@ pub const UserCommand = union(enum) { /// !help help: void, + pub fn init_substitute(author: []const u8, needle: []const u8, replacement: []const u8, all: bool) UserCommand { + return .{ .substitute = .{ + .author = author, + .needle = needle, + .replacement = replacement, + .all = all, + } }; + } + pub fn parse(nick: []const u8, text: []const u8) ?UserCommand { const original = Parser.init(text); if (original.consume_str("!help")) |_| { @@ -38,14 +47,7 @@ pub const UserCommand = union(enum) { return null; } parser, const correction = result.?; - return .{ - .substitute = .{ - .author = nick, - .needle = typo, - .replacement = correction, - .all = false, - }, - }; + return .init_substitute(nick, typo, correction, false); } return null; }