summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2024-08-27 00:39:59 +0800
committerGravatar Uko Kokņevičs2024-08-27 00:39:59 +0800
commitb5e3e16842bd6e163d7d32f60c621a4dc6b655eb (patch)
tree0e62e260ccbbc84824298b90dcb045b42435fc97 /src/main.zig
parentRetry the HTTP calls occasionally (diff)
downloadukkobot-b5e3e16842bd6e163d7d32f60c621a4dc6b655eb.tar.gz
ukkobot-b5e3e16842bd6e163d7d32f60c621a4dc6b655eb.tar.xz
ukkobot-b5e3e16842bd6e163d7d32f60c621a4dc6b655eb.zip
Do some extra user input validation
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig
index 04d4055..544b105 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,5 +1,6 @@
1const types = @import("types.zig");
2const std = @import("std"); 1const std = @import("std");
2const types = @import("types.zig");
3const utils = @import("utils.zig");
3 4
4const Allocator = std.mem.Allocator; 5const Allocator = std.mem.Allocator;
5const ArrayList = std.ArrayList; 6const ArrayList = std.ArrayList;
@@ -198,16 +199,16 @@ fn onTextMessage(bot: *Bot, msg: types.Message, text: []const u8) !void {
198 }, 199 },
199 }); 200 });
200 } else if (std.ascii.startsWithIgnoreCase(text, "big ")) { 201 } else if (std.ascii.startsWithIgnoreCase(text, "big ")) {
201 var output = try bot.allocator.alloc(u8, text.len + 3); 202 var output = ArrayList(u8).init(bot.allocator);
202 defer bot.allocator.free(output); 203 defer output.deinit();
203 204
204 std.mem.copyForwards(u8, output, "<b>"); 205 try output.appendSlice("<b>");
205 _ = std.ascii.upperString(output[3..], text[4..]); 206 try utils.escapeXml(output.writer(), text[4..]);
206 std.mem.copyForwards(u8, output[output.len - 4 ..], "</b>"); 207 try output.appendSlice("</b>");
207 208
208 try bot.sendMessage_(.{ 209 try bot.sendMessage_(.{
209 .chat_id = msg.chat.id, 210 .chat_id = msg.chat.id,
210 .text = output, 211 .text = output.items,
211 .parse_mode = .html, 212 .parse_mode = .html,
212 .reply_parameters = .{ 213 .reply_parameters = .{
213 .message_id = msg.message_id, 214 .message_id = msg.message_id,