diff options
| author | 2024-08-27 00:39:59 +0800 | |
|---|---|---|
| committer | 2024-08-27 00:39:59 +0800 | |
| commit | b5e3e16842bd6e163d7d32f60c621a4dc6b655eb (patch) | |
| tree | 0e62e260ccbbc84824298b90dcb045b42435fc97 /src | |
| parent | Retry the HTTP calls occasionally (diff) | |
| download | ukkobot-b5e3e16842bd6e163d7d32f60c621a4dc6b655eb.tar.gz ukkobot-b5e3e16842bd6e163d7d32f60c621a4dc6b655eb.tar.xz ukkobot-b5e3e16842bd6e163d7d32f60c621a4dc6b655eb.zip | |
Do some extra user input validation
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 15 |
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 @@ | |||
| 1 | const types = @import("types.zig"); | ||
| 2 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const types = @import("types.zig"); | ||
| 3 | const utils = @import("utils.zig"); | ||
| 3 | 4 | ||
| 4 | const Allocator = std.mem.Allocator; | 5 | const Allocator = std.mem.Allocator; |
| 5 | const ArrayList = std.ArrayList; | 6 | const 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, |