Skip to content

Commit

Permalink
Fix /welcome not saving reply_markup
Browse files Browse the repository at this point in the history
and use keyboard constructor from api utilities

Signed-off-by: Yan Minari <yangm97@gmail.com>
  • Loading branch information
yangm97 committed Sep 30, 2018
1 parent dcf6192 commit e5f5fe6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lua/groupbutler/plugins/welcome.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local locale = require "groupbutler.languages"
local i18n = locale.translate
local null = require "groupbutler.null"
local api_err = require "groupbutler.api_errors"
local api_u = require "telegram-bot-api.utilities"

local _M = {}

Expand Down Expand Up @@ -96,10 +97,9 @@ local function get_reply_markup(self, msg, text)

if is_on(self, msg.chat.id, "Welbut") then
if not reply_markup then
reply_markup = {inline_keyboard={}}
reply_markup = api_u.InlineKeyboardMarkup:new()
end
local line = {{text = i18n("Read the rules"), url = u:deeplink_constructor(msg.chat.id, "rules")}}
table.insert(reply_markup.inline_keyboard, line)
reply_markup:row({text = i18n("Read the rules"), url = u:deeplink_constructor(msg.chat.id, "rules")})
end

return reply_markup, new_text
Expand Down Expand Up @@ -200,7 +200,7 @@ function _M:onTextMessage(blocks)
new_text = new_text:gsub('$rules', u:deeplink_constructor(msg.chat.id, 'rules'))

red:hset(hash, 'type', 'custom')
red:hset(hash, 'content', new_text)
red:hset(hash, 'content', input)

local ok, err = msg:send_reply(new_text, "Markdown", reply_markup)
if not ok then
Expand Down
6 changes: 3 additions & 3 deletions lua/groupbutler/utilities.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local config = require "groupbutler.config"
local api_err = require "groupbutler.api_errors"
local api_u = require "telegram-bot-api.utilities"
local locale = require "groupbutler.languages"
local log = require "groupbutler.logging"
local null = require "groupbutler.null"
Expand Down Expand Up @@ -416,12 +417,11 @@ end
function _M:reply_markup_from_text(text) -- luacheck: ignore 212
local clean_text = text
local n = 0
local reply_markup = {inline_keyboard={}}
local reply_markup = api_u.InlineKeyboardMarkup:new()
for label, url in text:gmatch("{{(.-)}{(.-)}}") do
clean_text = clean_text:gsub('{{'..label:escape_magic()..'}{'..url:escape_magic()..'}}', '')
if label and url and n < 3 then
local line = {{text = label, url = url}}
table.insert(reply_markup.inline_keyboard, line)
reply_markup:row({text = label, url = url})
end
n = n + 1
end
Expand Down

0 comments on commit e5f5fe6

Please sign in to comment.