diff options
| author | 2025-08-03 12:54:12 +0300 | |
|---|---|---|
| committer | 2025-08-03 12:54:12 +0300 | |
| commit | e5185f65051f881bf61e88542a1acd4957f8383b (patch) | |
| tree | a030a8b32cd13ed6a7d9ed736f8fc626501c2749 /src/Bot.zig | |
| parent | Moved inline bot handling to a new file (diff) | |
| download | ukkobot-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.zig | 9 |
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; | |||
| 6 | const ArrayList = std.ArrayList; | 6 | const ArrayList = std.ArrayList; |
| 7 | const Bot = @This(); | 7 | const Bot = @This(); |
| 8 | const Config = @import("Config.zig"); | 8 | const Config = @import("Config.zig"); |
| 9 | const DB = @import("DB.zig"); | ||
| 9 | const HttpClient = std.http.Client; | 10 | const HttpClient = std.http.Client; |
| 10 | const HttpMethod = std.http.Method; | 11 | const HttpMethod = std.http.Method; |
| 11 | const Parsed = std.json.Parsed; | 12 | const Parsed = std.json.Parsed; |
| @@ -14,6 +15,7 @@ const Uri = std.Uri; | |||
| 14 | allocator: Allocator, | 15 | allocator: Allocator, |
| 15 | http_client: HttpClient, | 16 | http_client: HttpClient, |
| 16 | config: Config, | 17 | config: Config, |
| 18 | db: *DB, | ||
| 17 | base_uri: Uri = Uri.parse("https://api.telegram.org/") catch unreachable, | 19 | base_uri: Uri = Uri.parse("https://api.telegram.org/") catch unreachable, |
| 18 | uri_path_data: ArrayList(u8), | 20 | uri_path_data: ArrayList(u8), |
| 19 | poweron: bool = true, | 21 | poweron: bool = true, |
| @@ -21,7 +23,7 @@ server_header_buffer: [4096]u8 = undefined, | |||
| 21 | username: ?[]const u8 = null, | 23 | username: ?[]const u8 = null, |
| 22 | id: ?i64 = null, | 24 | id: ?i64 = null, |
| 23 | 25 | ||
| 24 | pub fn init(allocator: Allocator, config: Config) !Bot { | 26 | pub 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 | ||
| 53 | pub inline fn answerCallbackQuery(self: *Bot, args: types.AnswerCallbackQueryParams) !void { | ||
| 54 | (try self.post(bool, "answerCallbackQuery", args)).deinit(); | ||
| 55 | } | ||
| 56 | |||
| 50 | pub inline fn deleteMessage(self: *Bot, args: types.DeleteMessageParams) !void { | 57 | pub 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 | } |