refactor(bot): rename bot.hear to bot.store
Clearer what it actually does (i.e. record a message in the backlog) and also unlocks that name for a dispatch function where we hear any message and decide what to do with it. Currently that dispatch logic lives inside BotAdapter in main.zig and that is not ideal.
This commit is contained in:
parent
4d1f22194c
commit
958c00ce6f
2 changed files with 7 additions and 7 deletions
12
src/bot.zig
12
src/bot.zig
|
|
@ -216,7 +216,7 @@ test "hear and deinit has no leaks" {
|
||||||
defer bot.deinit();
|
defer bot.deinit();
|
||||||
|
|
||||||
const testMessage = try newTestMessage(allocator, "test");
|
const testMessage = try newTestMessage(allocator, "test");
|
||||||
bot.hear(testMessage);
|
bot.store(testMessage);
|
||||||
|
|
||||||
try std.testing.expectEqual(0, bot.backlog.top);
|
try std.testing.expectEqual(0, bot.backlog.top);
|
||||||
}
|
}
|
||||||
|
|
@ -228,7 +228,7 @@ test "a few hears and deinit has no leaks" {
|
||||||
|
|
||||||
for (0..2) |_| {
|
for (0..2) |_| {
|
||||||
const testMessage = try newTestMessage(std.testing.allocator, "test");
|
const testMessage = try newTestMessage(std.testing.allocator, "test");
|
||||||
bot.hear(testMessage);
|
bot.store(testMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
try std.testing.expectEqual(1, bot.backlog.top);
|
try std.testing.expectEqual(1, bot.backlog.top);
|
||||||
|
|
@ -240,7 +240,7 @@ test "hear wraps" {
|
||||||
|
|
||||||
for (0..1025) |_| {
|
for (0..1025) |_| {
|
||||||
const testMessage = try newTestMessage(std.testing.allocator, "test");
|
const testMessage = try newTestMessage(std.testing.allocator, "test");
|
||||||
bot.hear(testMessage);
|
bot.store(testMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
try std.testing.expectEqual(0, bot.backlog.top);
|
try std.testing.expectEqual(0, bot.backlog.top);
|
||||||
|
|
@ -266,7 +266,7 @@ test "execute substitution" {
|
||||||
|
|
||||||
// hear original message with typo
|
// hear original message with typo
|
||||||
const msg = try newTestMessage(allocator, "What");
|
const msg = try newTestMessage(allocator, "What");
|
||||||
bot.hear(msg);
|
bot.store(msg);
|
||||||
|
|
||||||
// execute substitution
|
// execute substitution
|
||||||
const cmd = UserCommand.init_substitute("jassob", "What", "what", false);
|
const cmd = UserCommand.init_substitute("jassob", "What", "what", false);
|
||||||
|
|
@ -287,7 +287,7 @@ test "execute substitution with no matching needle" {
|
||||||
|
|
||||||
// hear original message
|
// hear original message
|
||||||
const msg = try newTestMessage(std.testing.allocator, "original");
|
const msg = try newTestMessage(std.testing.allocator, "original");
|
||||||
bot.hear(msg);
|
bot.store(msg);
|
||||||
|
|
||||||
// execute substitution
|
// execute substitution
|
||||||
const cmd = UserCommand.init_substitute("jassob", "something else", "weird", false);
|
const cmd = UserCommand.init_substitute("jassob", "something else", "weird", false);
|
||||||
|
|
@ -300,7 +300,7 @@ test "recursive substitutions does not cause issues" {
|
||||||
|
|
||||||
// hear original message
|
// hear original message
|
||||||
const msg = try newTestMessage(std.testing.allocator, "original");
|
const msg = try newTestMessage(std.testing.allocator, "original");
|
||||||
bot.hear(msg);
|
bot.store(msg);
|
||||||
|
|
||||||
// execute substitution
|
// execute substitution
|
||||||
const cmd = UserCommand.init_substitute("jassob", "original", "something else", false);
|
const cmd = UserCommand.init_substitute("jassob", "original", "something else", false);
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ pub const BotAdapter = struct {
|
||||||
msg.targets,
|
msg.targets,
|
||||||
msg.text,
|
msg.text,
|
||||||
) catch |err| return report_error(err);
|
) catch |err| return report_error(err);
|
||||||
self.bot.hear(bot_msg);
|
self.bot.store(bot_msg);
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
.JOIN => |msg| {
|
.JOIN => |msg| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue