diff options
| author | 2024-07-26 17:50:08 +0300 | |
|---|---|---|
| committer | 2024-07-26 17:50:08 +0300 | |
| commit | 665e22036439a84e61ad28329dccf201af274923 (patch) | |
| tree | 84ace178e80505e702970910ff36b818b998a2b4 /src/Bot.zig | |
| parent | Missed this (diff) | |
| download | ukkobot-665e22036439a84e61ad28329dccf201af274923.tar.gz ukkobot-665e22036439a84e61ad28329dccf201af274923.tar.xz ukkobot-665e22036439a84e61ad28329dccf201af274923.zip | |
Send a different GIF when bot gets added
Diffstat (limited to 'src/Bot.zig')
| -rw-r--r-- | src/Bot.zig | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/Bot.zig b/src/Bot.zig index 49c5df3..adfafef 100644 --- a/src/Bot.zig +++ b/src/Bot.zig | |||
| @@ -19,6 +19,7 @@ uri_path_data: ArrayList(u8), | |||
| 19 | poweron: bool = true, | 19 | poweron: bool = true, |
| 20 | server_header_buffer: [4096]u8 = undefined, | 20 | server_header_buffer: [4096]u8 = undefined, |
| 21 | username: ?[]const u8 = null, | 21 | username: ?[]const u8 = null, |
| 22 | id: ?i64 = null, | ||
| 22 | 23 | ||
| 23 | pub fn init(allocator: Allocator, config: Config) !Bot { | 24 | pub fn init(allocator: Allocator, config: Config) !Bot { |
| 24 | var uri_path_data = try ArrayList(u8).initCapacity(allocator, 5 + config.bot_token.len); | 25 | var uri_path_data = try ArrayList(u8).initCapacity(allocator, 5 + config.bot_token.len); |
| @@ -54,8 +55,20 @@ pub inline fn editMessageText_(self: *Bot, args: types.EditMessageTextParams) !v | |||
| 54 | (try self.editMessageText(args)).deinit(); | 55 | (try self.editMessageText(args)).deinit(); |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 58 | pub inline fn getId(self: *Bot) !i64 { | ||
| 59 | if (self.id) |id| return id; | ||
| 60 | (try self.getMe()).deinit(); | ||
| 61 | return self.id.?; | ||
| 62 | } | ||
| 63 | |||
| 57 | pub inline fn getMe(self: *Bot) !Parsed(types.User) { | 64 | pub inline fn getMe(self: *Bot) !Parsed(types.User) { |
| 58 | return self.get(types.User, "getMe", null); | 65 | const user = try self.get(types.User, "getMe", null); |
| 66 | errdefer user.deinit(); | ||
| 67 | |||
| 68 | self.id = user.value.id; | ||
| 69 | self.username = try self.allocator.dupe(u8, user.value.username.?); | ||
| 70 | |||
| 71 | return user; | ||
| 59 | } | 72 | } |
| 60 | 73 | ||
| 61 | pub inline fn getMyName(self: *Bot, args: types.GetMyNameParams) !Parsed(types.BotName) { | 74 | pub inline fn getMyName(self: *Bot, args: types.GetMyNameParams) !Parsed(types.BotName) { |
| @@ -68,9 +81,7 @@ pub inline fn getUpdates(self: *Bot, args: types.GetUpdatesParams) !Parsed([]typ | |||
| 68 | 81 | ||
| 69 | pub inline fn getUsername(self: *Bot) ![]const u8 { | 82 | pub inline fn getUsername(self: *Bot) ![]const u8 { |
| 70 | if (self.username) |username| return username; | 83 | if (self.username) |username| return username; |
| 71 | const user = try self.getMe(); | 84 | (try self.getMe()).deinit(); |
| 72 | defer user.deinit(); | ||
| 73 | self.username = user.value.username; | ||
| 74 | return self.username.?; | 85 | return self.username.?; |
| 75 | } | 86 | } |
| 76 | 87 | ||