chore: implement initial bot with substitute command
This commit introduces a Bot struct which is the main type of this project. The Bot holds a backlog of messages to be able to update a typo in a message and so on. So far there is no IRC/TLS implementation, it is only the base logic.
This commit is contained in:
parent
00d2cf3c69
commit
6449a7de2d
6 changed files with 361 additions and 43 deletions
41
src/main.zig
41
src/main.zig
|
|
@ -3,25 +3,26 @@ const zigeru = @import("zigeru");
|
|||
|
||||
pub fn main() !void {
|
||||
// Prints to stderr, ignoring potential errors.
|
||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||
try zigeru.bufferedPrint();
|
||||
}
|
||||
|
||||
test "simple test" {
|
||||
const gpa = std.testing.allocator;
|
||||
var list: std.ArrayList(i32) = .empty;
|
||||
defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
|
||||
try list.append(gpa, 42);
|
||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||
}
|
||||
|
||||
test "fuzz example" {
|
||||
const Context = struct {
|
||||
fn testOne(context: @This(), input: []const u8) anyerror!void {
|
||||
_ = context;
|
||||
// Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
|
||||
try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
|
||||
}
|
||||
const message = zigeru.bot.Message{
|
||||
.author = "Jassob",
|
||||
.timestamp = 12345,
|
||||
.content = "All your base are belong to us.\n",
|
||||
};
|
||||
try std.testing.fuzz(Context{}, Context.testOne, .{});
|
||||
|
||||
var gpa = std.heap.DebugAllocator(.{}){};
|
||||
var bot = zigeru.bot.Bot.new(gpa.allocator());
|
||||
bot.hear(message);
|
||||
const command = zigeru.bot.Command{
|
||||
.substitute = .{
|
||||
.author = "Jassob",
|
||||
.needle = "base",
|
||||
.replacement = "codebase",
|
||||
},
|
||||
};
|
||||
const result = try bot.execute(&command);
|
||||
switch (result) {
|
||||
.post_message => |msg| {
|
||||
std.debug.print("{s}", .{msg.content});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue