summaryrefslogtreecommitdiff
path: root/src/Bot.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-08-03 12:54:12 +0300
committerGravatar Uko Kokņevičs2025-08-03 12:54:12 +0300
commite5185f65051f881bf61e88542a1acd4957f8383b (patch)
treea030a8b32cd13ed6a7d9ed736f8fc626501c2749 /src/Bot.zig
parentMoved inline bot handling to a new file (diff)
downloadukkobot-e5185f65051f881bf61e88542a1acd4957f8383b.tar.gz
ukkobot-e5185f65051f881bf61e88542a1acd4957f8383b.tar.xz
ukkobot-e5185f65051f881bf61e88542a1acd4957f8383b.zip
Move bot configuration to SQL land
Diffstat (limited to 'src/Bot.zig')
-rw-r--r--src/Bot.zig9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Bot.zig b/src/Bot.zig
index b0eb972..fb91b3f 100644
--- a/src/Bot.zig
+++ b/src/Bot.zig
@@ -6,6 +6,7 @@ const Allocator = std.mem.Allocator;
6const ArrayList = std.ArrayList; 6const ArrayList = std.ArrayList;
7const Bot = @This(); 7const Bot = @This();
8const Config = @import("Config.zig"); 8const Config = @import("Config.zig");
9const DB = @import("DB.zig");
9const HttpClient = std.http.Client; 10const HttpClient = std.http.Client;
10const HttpMethod = std.http.Method; 11const HttpMethod = std.http.Method;
11const Parsed = std.json.Parsed; 12const Parsed = std.json.Parsed;
@@ -14,6 +15,7 @@ const Uri = std.Uri;
14allocator: Allocator, 15allocator: Allocator,
15http_client: HttpClient, 16http_client: HttpClient,
16config: Config, 17config: Config,
18db: *DB,
17base_uri: Uri = Uri.parse("https://api.telegram.org/") catch unreachable, 19base_uri: Uri = Uri.parse("https://api.telegram.org/") catch unreachable,
18uri_path_data: ArrayList(u8), 20uri_path_data: ArrayList(u8),
19poweron: bool = true, 21poweron: bool = true,
@@ -21,7 +23,7 @@ server_header_buffer: [4096]u8 = undefined,
21username: ?[]const u8 = null, 23username: ?[]const u8 = null,
22id: ?i64 = null, 24id: ?i64 = null,
23 25
24pub fn init(allocator: Allocator, config: Config) !Bot { 26pub fn init(allocator: Allocator, config: Config, db: *DB) !Bot {
25 var uri_path_data = try ArrayList(u8).initCapacity(allocator, 5 + config.bot_token.len); 27 var uri_path_data = try ArrayList(u8).initCapacity(allocator, 5 + config.bot_token.len);
26 errdefer uri_path_data.deinit(); 28 errdefer uri_path_data.deinit();
27 29
@@ -35,6 +37,7 @@ pub fn init(allocator: Allocator, config: Config) !Bot {
35 .allocator = allocator, 37 .allocator = allocator,
36 }, 38 },
37 .config = config, 39 .config = config,
40 .db = db,
38 .uri_path_data = uri_path_data, 41 .uri_path_data = uri_path_data,
39 }; 42 };
40} 43}
@@ -47,6 +50,10 @@ pub fn deinit(self: *Bot) void {
47 self.* = undefined; 50 self.* = undefined;
48} 51}
49 52
53pub inline fn answerCallbackQuery(self: *Bot, args: types.AnswerCallbackQueryParams) !void {
54 (try self.post(bool, "answerCallbackQuery", args)).deinit();
55}
56
50pub inline fn deleteMessage(self: *Bot, args: types.DeleteMessageParams) !void { 57pub inline fn deleteMessage(self: *Bot, args: types.DeleteMessageParams) !void {
51 (try self.post(bool, "deleteMessage", args)).deinit(); 58 (try self.post(bool, "deleteMessage", args)).deinit();
52} 59}