| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- use Modern::Perl;
- use utf8;
- use Mojo::Base -strict, -async_await, -signatures;
- use Data::Dumper;
- our $client;
- our $fsa;
- our $abon_client;
- sub __
- {
- @_;
- }
- ##############################################
- our $commands = [
- {command=>"help", name=>__("Помощь"), description=>__("Список доступных команд"), hide_in_kb=>1},
- {command=>"info", name=>__("Информация"), description=>__("Информация о пользователе")},
- {command=>"balance", name=>__("Баланс"), description=>__("Проверка баланса")},
- {command=>"service", name=>__("Сервисы"), description=>__("Подключенные сервисы")},
- {command=>"credit", name=>__("Кредит"), description=>__("Установка кредита")},
- {command=>"logout", name=>__("Выход"), description=>__("Выход")},
- ];
- ##############################################
- sub command_help($chatid, $uid, $rest)
- {
- my @list = map { "<b>/$_->{command}</b> " . _($_->{description}) } @$commands;
- notify($chatid, join("\n", @list), $rest);
- }
- sub command_start($chatid, $uid, $from)
- {
- set_new_state("");
- }
- sub command_logout($chatid, $uid, $rest)
- {
- notify($chatid, _("Благодарим за использование нашего бота"));
- $client->del("client", "/client/$uid/telegram");
- if (my $err = $client->error)
- {
- report($chatid, $err);
- }
- $fsa->notes(uid => undef);
- set_new_state("logged_out");
- }
- async sub command_balance
- {
- my ($chatid, $uid, $rest) = @_;
- my $money = await $abon_client->get_p($chatid, "client", "/client/$uid/money?human=1");
- my $cur = $money->{human};
-
- my @lines = (
- sprintf("<u>%s:</u> <b>%.2f $cur</b> (%s %.2f $cur + %s %.2f $cur) ",
- _("Ваш баланс"), $money->{balance}, ("депозит"), $money->{deposit}, _("кредит"), $money->{credit}),
- );
-
- push @lines, sprintf("<u>%s:</u> %s", _("Оплачено до"), format_date($money->{last_day})) if $money->{last_day} ne "-";
- push @lines, sprintf("<u>%s:</u> %d%%", _("Скидка"), $money->{reduction}) if $money->{reduction};
- push @lines, sprintf("<u>%s:</u> <b>%.2f $cur</b> %s (%s)",
- _("Последнее снятие"), $money->{last_withdrawal}->{sum}, format_time($money->{last_withdrawal}->{date}), $money->{last_withdrawal}->{comment})
- if $money->{last_withdrawal}->{sum};
- push @lines, sprintf("<u>%s:</u> <b>%.2f $cur</b> %s", _("Последний платеж"), $money->{last_payment}->{sum}, format_time($money->{last_payment}->{date}))
- if $money->{last_payment}->{sum};
- for (keys %{ $money->{accounts} })
- {
- push @lines, sprintf("<u>%s:</u> <b>%.2f $cur</b>", $_, $money->{accounts}->{$_});
- }
-
- reply($rest, @lines);
- }
- async sub command_info
- {
- my ($chatid, $uid, $rest) = @_;
- my $client = await $abon_client->get_p($chatid, "client", "/client/$uid");
- reply($rest,
- sprintf("<u>%s</u>: %d", _("Лицевой счет"), $client->{uid}),
- sprintf("<u>%s</u>: %s", _("Логин"), $client->{login}),
- sprintf("<u>%s</u>: %s", _("ФИО"), $client->{fio}),
- sprintf("<u>%s</u>: %s", _("Адрес"), $client->{address}),
- sprintf("<u>%s</u>: %s", _("Телефон"), $client->{phone}),
- );
- }
- async sub command_credit
- {
- my ($chatid, $uid, $rest) = @_;
- my $money = await $abon_client->get_p($chatid, "client", "/client/$uid/money?human=1");
- if ($money->{credit} > 0)
- {
- return reply($rest, sprintf("%s <b>%.2f %s</b>", _("У вас уже установлен кредит"), $money->{credit}, $money->{human}));
- }
-
- reply_with($rest, {
- inline_menu => [[
- { text=>_("Я согласен с условиями"), callback_data=>"/set-credit" },
- ]],
- },
- _("Вы можете самостоятельно установить кредит на два дня"),
- _("<b>Ограничения</b>: только для физических лиц, продлевать кредит повторно до оплаты нельзя. При следующей оплате кредит будет погашен"),
- );
- }
- async sub command_set_credit
- {
- my ($chatid, $uid, $rest) = @_;
- my $res = await $abon_client->post_p($chatid, "client", "/client/$uid/credit", {human=>1});
- return reply($rest, _("Кредит не имеет смысла для бесплатных тарифных планов")) if $res->{credit} == 0;
-
- await reply($rest,
- sprintf("%s <b>%.2f %s</b>", _("Установлен кредит "), $res->{credit}, $res->{human}),
- "",
- );
-
- command_balance($chatid, $uid, $rest);
- }
- =cut
- $VAR1 = [
- {
- 'tariff' => {
- 'monthly' => '0',
- 'dayly' => '0',
- 'entity' => 1000,
- 'speed' => 0,
- 'name_ru' => "\x{414}\x{43b}\x{44f} \x{441}\x{43e}\x{442}\x{440}\x{443}\x{434}\x{43d}\x{438}\x{43a}\x{43e}\x{432} MOL"
- },
- 'name' => 'pppoe',
- 'name_ru' => 'PPPoE',
- 'entity' => 32320,
- 'disabled' => 0
- },
- {
- 'tariff' => {
- 'speed' => 0,
- 'name_ru' => "\x{414}\x{43b}\x{44f} \x{441}\x{43e}\x{442}\x{440}\x{443}\x{434}\x{43d}\x{438}\x{43a}\x{43e}\x{432} MOL",
- 'entity' => 1000,
- 'monthly' => '0',
- 'dayly' => '0'
- },
- 'name' => 'ipoe',
- 'entity' => 17,
- 'name_ru' => 'IPoE',
- 'disabled' => 0
- }
- ];
- =cut
- async sub command_service
- {
- my ($chatid, $uid, $rest) = @_;
-
- my $res = await $abon_client->get_p($chatid, "client", "/client/$uid/service?human=1&as-array=1");
- my @list = map { sprintf("<u>%s:</u> %s (%s '%s')", $_->{name_ru}, format_wd($_->{tariff}, $_->{human}), _("тариф"), $_->{tariff}->{name_ru}) }
- grep { !$_->{disabled} } @$res;
-
- reply($rest, @list);
- };
- sub format_wd($rec, $cur)
- {
- return _("бесплатно") if $rec->{dayly} == 0 && $rec->{monthly} == 0;
- my $m = sprintf("<b>%.2f $cur</b> %s", $rec->{monthly}, _("в месяц")) if $rec->{monthly} != 0;
- my $d = sprintf("<b>%.2f $cur</b> %s", $rec->{dayly}, _("в месяц")) if $rec->{dayly} != 0;
- return ("$m + $d") if $m && $d;
- return $m if $m;
- return $d if $d;
- }
- ################################################
- sub parse_error
- {
- my $e = shift;
- return $e unless ref $e;
-
- return "$e->{code} $e->{message} $e->{body}";
- }
- 1;
- # что будет, если, к примеру, установка кредита вернет ошибку?
- # сервисы
- # перевод денег
|