Skip to content

Commit

Permalink
bot - group - membership improve and texts
Browse files Browse the repository at this point in the history
  • Loading branch information
grandmotivator committed May 17, 2023
1 parent a54cddd commit d6c7a12
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 72 deletions.
14 changes: 14 additions & 0 deletions messages/ru/bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
'BEGIN' => 'НАЧАТЬ',
'Commands' => 'Команды',
'Available commands' => 'Доступные команды',
'Available commands in groups' => 'Доступные команды в группах',
'Available commands in groups (as a reply to another message)' => 'Доступные команды в группах (в виде ответа на другое сообщение)',
'Available commands in this group' => 'Доступные команды в этой группе',
'Available commands in this group (as a reply to another message)' => 'Доступные команды в этой группе (в виде ответа на другое сообщение)',
'Greeting' => 'Приветствие',
'Help' => 'Справка',
'Menu' => 'Меню',
Expand Down Expand Up @@ -191,6 +195,9 @@
'Only the owner of the group can configure the list of administrators who have access to the settings of this group' => 'Только владелец группы может настраивать список администраторов которые имеют доступ к настройкам этой группы',
'Administrators who can manage the group' => 'Администраторы, которые могут управлять этой группой',
'Administrators' => 'Администраторы',
'delete a member\'s message, send a personal notification about violation of group rules' => 'удалить сообщение участника, отправить персональное уведомление о нарушении правил группы',
'delete a member\'s message, send a personal notification about violation of group rules, mute the member in the group' => 'удалить сообщение участника, отправить персональное уведомление о нарушении правил группы, заглушить участника в группе',
'delete a member\'s message, send a personal notification about violation of group rules, ban the member in the group' => 'удалить сообщение участника, отправить персональное уведомление о нарушении правил группы, забанить участника в группе',
'Add phrase' => 'Добавить фразу',
'Main menu' => 'В главное меню',
'Slow Mode' => 'Медленный режим',
Expand Down Expand Up @@ -225,6 +232,8 @@
'Send any date in format «YYYY-MM-DD» to change the date' => 'Отправьте любую дату в формате «YYYY-MM-DD», чтобы изменить дату',
'Tag for members' => 'Тег для участников',
'Send a tag for members' => 'Отправьте тег для участников',
'list of premium members' => 'список премиум участников',
'premium members with intro' => 'премиум участники с интро',
'Note' => 'Заметка',
'Send a note' => 'Отправьте заметку',
'Tariff, price' => 'Тариф, цена',
Expand Down Expand Up @@ -581,6 +590,9 @@
'Your verification is valid until' => 'Ваша верификация действительна до',
'Verification is valid until' => 'Верификация действительна до',
'Verification date' => 'Дата верификации',
'Verification end date' => 'Дата окончания верификации',
'Membership date' => 'Дата членства',
'Membership end date' => 'Дата окончания членства',
'Your premium membership is valid until {0}' => 'Ваше премиум членство действительно до {0}',
'Your premium membership is valid until' => 'Ваше премиум членство действительно до',
'Premium membership is valid until' => 'Премиум членство действительно до',
Expand Down Expand Up @@ -656,6 +668,8 @@
'Financial gifts for this group' => 'Финансовые подарки для этой группы',
'Financial thanks for this group' => 'Финансовая благодарность для этой группы',
'Financial thanks for this member' => 'Финансовая благодарность для этого участника',
'send financial gifts for a group' => 'отправить финансовые подарки для группы',
'send financial thanks for a member' => 'отправить финансовую благодарность для участника',
'Preparation' => 'Подготовка',
'Confirmation' => 'Подтверждение',
'Send a number of gifts' => 'Отправьте количество подарков',
Expand Down
6 changes: 5 additions & 1 deletion modules/bot/config/actions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// add new values to the end
// erase instead deleting 'actionName' -> ''
// erase instead deleting 'actionName' => ''
// so that the index is not violated
return [
'view',
Expand Down Expand Up @@ -106,4 +106,8 @@
'pay_for_membership',
'renew_membership',
'transaction',
'set_member_membership_date',
'set_member_verification_date',
'delete_member_membership_date',
'delete_member_verification_date',
];
2 changes: 1 addition & 1 deletion modules/bot/config/controllers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// add new values to the end
// erase instead deleting 'controllerName' -> ''
// erase instead deleting 'controllerName' => ''
// so that the index is not violated
return [
'start',
Expand Down
2 changes: 1 addition & 1 deletion modules/bot/config/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'/help(@<botname:[\w_]+bot>)?( <message:.+>)?' => 'hello/index',
'/reload(@<botname:[\w_]+bot>)?( <message:.+>)?' => 'refresh/index',
'/norepeat(@<botname:[\w_]+bot>)?( <message:.+>)?' => 'repeat/off',
'/(thanks|gift|donation|charity|reward|present)(@<botname:[\w_]+bot>)?( <message:.+>)?' => 'tip/index',
'/(thank|thanks|gift|gifts|donation|charity|reward|present|tips)(@<botname:[\w_]+bot>)?( <message:.+>)?' => 'tip/index',
'/<controller:\w+>__<action:\w+>(@<botname:[\w_]+bot>)?(\?<query:(&?\w+=[^&]*)*>)?( <message:.+>)?' => '<controller>/<action>',
'/<controller:\w+>(@<botname:[\w_]+bot>)?(\?<query:(&?\w+=[^&]*)*>)?( <message:.+>)?' => '<controller>/index',
],
Expand Down
3 changes: 3 additions & 0 deletions modules/bot/controllers/privates/ChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public function actionView($chatId = null)
'visible' => (bool)$chat->getUsername(),
],
],
],
[
'disablePreview' => true,
]
)
->build();
Expand Down
90 changes: 35 additions & 55 deletions modules/bot/controllers/privates/GroupMembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ public function actionIndex($id = null)
'text' => Yii::t('bot', 'Tag for members'),
],
],
[
[
'callback_data' => self::createRoute('send-group-message', [
'id' => $chat->id,
]),
'text' => Emoji::SEND . ' ' . Yii::t('bot', 'Send new message to the group'),
'visible' => $chat->getPremiumChatMembers()->exists(),
],
],
[
[
'callback_data' => GroupController::createRoute('view', [
Expand Down Expand Up @@ -344,9 +335,7 @@ public function actionMember($id = null)
->build();
}

$this->getState()->setInputRoute(self::createRoute('input-member-date', [
'id' => $member->id,
]));
$this->getState()->clearInputRoute();

return $this->getResponseBuilder()
->editMessageTextOrSendMessage(
Expand Down Expand Up @@ -393,10 +382,18 @@ public function actionMember($id = null)
],
[
[
'callback_data' => self::createRoute('set-member-verification_date', [
'callback_data' => self::createRoute('set-member-membership-date', [
'id' => $member->id,
]),
'text' => Yii::t('bot', 'Membership end date'),
],
],
[
[
'callback_data' => self::createRoute('set-member-verification-date', [
'id' => $member->id,
]),
'text' => Yii::t('bot', 'Verification date'),
'text' => Yii::t('bot', 'Verification end date'),
],
],
[
Expand All @@ -411,7 +408,7 @@ public function actionMember($id = null)
'text' => Emoji::MENU,
],
[
'callback_data' => self::createRoute('delete-member-date', [
'callback_data' => self::createRoute('delete-member-membership-date', [
'id' => $member->id,
]),
'text' => Emoji::DELETE,
Expand All @@ -422,11 +419,11 @@ public function actionMember($id = null)
->build();
}

/**
* @param int $id ChatMember->id
* @return array
*/
public function actionInputMemberDate($id = null)
/**
* @param int $id ChatMember->id
* @return array
*/
public function actionSetMemberMembershipDate($id = null)
{
$member = ChatMember::findOne($id);

Expand All @@ -444,6 +441,10 @@ public function actionInputMemberDate($id = null)
->build();
}

$this->getState()->setInputRoute(self::createRoute('set-member-membership-date', [
'id' => $member->id,
]));

if ($this->getUpdate()->getMessage()) {
if ($text = $this->getUpdate()->getMessage()->getText()) {
$dateValidator = new DateValidator();
Expand All @@ -460,7 +461,19 @@ public function actionInputMemberDate($id = null)
}

return $this->getResponseBuilder()
->answerCallbackQuery()
->editMessageTextOrSendMessage(
$this->render('set-member-membership-date'),
[
[
[
'callback_data' => self::createRoute('member', [
'id' => $member->id,
]),
'text' => Emoji::BACK,
],
],
]
)
->build();
}

Expand Down Expand Up @@ -532,7 +545,7 @@ public function actionSetMemberVerificationDate($id = null)
* @param int $id ChatMember->id
* @return array
*/
public function actionDeleteMemberDate($id = null)
public function actionDeleteMemberMembershipDate($id = null)
{
$member = ChatMember::findOne($id);

Expand Down Expand Up @@ -979,37 +992,4 @@ public function actionSetMemberTariffDaysBalance($id = null)
)
->build();
}

/**
* @param int $id Chat->id
* @return array
*/
public function actionSendGroupMessage($id = null)
{
$chat = Chat::findOne($id);

if (!isset($chat) || !$chat->isGroup()) {
return $this->getResponseBuilder()
->answerCallbackQuery()
->build();
}

$thisChat = $this->chat;
$module = Yii::$app->getModule('bot');
$module->setChat($chat);
$response = $module->runAction('premium-members/index');
$module->setChat($thisChat);

if ($response) {
return $this->getResponseBuilder()
->answerCallbackQuery(
$this->render('../alert-ok')
)
->build();
}

return $this->getResponseBuilder()
->answerCallbackQuery()
->build();
}
}
16 changes: 8 additions & 8 deletions modules/bot/controllers/privates/GroupPublisherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,26 +320,26 @@ public function actionPost($id = null)
],
[
[
'callback_data' => self::createRoute('set-time', [
'callback_data' => self::createRoute('set-text', [
'id' => $post->id,
]),
'text' => Yii::t('bot', 'Time of day') . ': ' . $post->getTimeOfDay(),
'text' => Yii::t('app', 'Text'),
],
],
[
[
'callback_data' => self::createRoute('set-skip-days', [
'callback_data' => self::createRoute('set-time', [
'id' => $post->id,
]),
'text' => Yii::t('bot', 'Skip days') . ': ' . $post->getSkipDays(),
'text' => Yii::t('bot', 'Time of day') . ': ' . $post->getTimeOfDay(),
],
],
[
[
'callback_data' => self::createRoute('set-text', [
'callback_data' => self::createRoute('set-skip-days', [
'id' => $post->id,
]),
'text' => Yii::t('app', 'Text'),
'text' => Yii::t('bot', 'Skip days') . ': ' . $post->getSkipDays(),
],
],
[
Expand Down Expand Up @@ -573,8 +573,8 @@ public function actionSetText($id = null)
if ($text = MessageWithEntitiesConverter::toHtml($this->getUpdate()->getMessage())) {
$post->text = $text;

if ($post->validate('text')) {
$post->save(false);
if ($post->validate('text') && $post->save(false)) {
return $this->actionPost($post->id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/bot/views/privates/channel/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?php endforeach; ?>
<br/>
<i><?= Yii::t('bot', 'Only the owner of the channel can configure the list of administrators who have access to the settings of this channel') ?>.</i><br/>
<br/>
————<br/>
<?= Yii::t('bot', 'Timezone') ?>: <?= TimeHelper::getNameByOffset($chat->timezone) ?><br/>
<?php if ($currency = $chat->currency) : ?>
<?= Yii::t('bot', 'Currency') ?>: <?= $currency->code . ' - ' . $currency->name ?><br/>
Expand Down
4 changes: 4 additions & 0 deletions modules/bot/views/privates/group-membership/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
<br/>
<?= Yii::t('bot', 'Tag for members') ?>: <?= $chat->membership_tag ?><br/>
<?php endif; ?>
————<br/>
<?= Yii::t('bot', 'Available commands in this group') ?>:<br/>
<code>/premium_members</code> - <?= Yii::t('bot', 'list of premium members') ?>. <i><?= Yii::t('bot', 'Sorted by user rank') ?>.</i><br/>
<code>/premium_members__intro</code> - <?= Yii::t('bot', 'premium members with intro') ?>. <i><?= Yii::t('bot', 'Sorted by user rank') ?>.</i><br/>
2 changes: 0 additions & 2 deletions modules/bot/views/privates/group-membership/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@
<br/>
<?= Yii::t('bot', 'Verification is valid until') ?>: <?= $chatMember->limiter_date ?><br/>
<?php endif; ?>
————<br/>
<?= Yii::t('bot', 'Send any date in format «YYYY-MM-DD» to change the date') ?>.<br/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<b><?= Yii::t('bot', 'Send a date in format «YYYY-MM-DD»') ?>:</b>

Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<b><?= Yii::t('bot', 'Send a note') ?>:</b>
<b><?= Yii::t('bot', 'Send a note') ?>:</b><br/>
<br/>
<i><?= Yii::t('bot', 'Only you see this information') ?>.</i><br/>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<b><?= Yii::t('bot', 'Send any date in format «YYYY-MM-DD» to change the date') ?>:</b>
<b><?= Yii::t('bot', 'Send a date in format «YYYY-MM-DD»') ?>:</b>

6 changes: 6 additions & 0 deletions modules/bot/views/privates/group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
<?= Yii::t('bot', 'Turn on the folowing permissions for the bot') ?>:<br/>
<?= Yii::t('bot', 'to delete messages') ?>.<br/>
<?= Yii::t('bot', 'to ban users') ?>.<br/>
————<br/>
<?= Yii::t('bot', 'Available commands in groups') ?>:<br/>
<code>/tip</code> - <?= Yii::t('bot', 'send financial gifts for a group') ?>.<br/>
<br/>
<?= Yii::t('bot', 'Available commands in groups (as a reply to another message)') ?>:<br/>
<code>/tip</code> - <?= Yii::t('bot', 'send financial thanks for a member') ?>.<br/>
7 changes: 6 additions & 1 deletion modules/bot/views/privates/group/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
<?php endforeach; ?>
<br/>
<i><?= Yii::t('bot', 'Only the owner of the group can configure the list of administrators who have access to the settings of this group') ?>.</i><br/>
<br/>
————<br/>
<?= Yii::t('bot', 'Timezone') ?>: <?= TimeHelper::getNameByOffset($chat->timezone) ?><br/>
<?php if ($currency = $chat->currency) : ?>
<?= Yii::t('bot', 'Currency') ?>: <?= $currency->code . ' - ' . $currency->name ?><br/>
<?php endif; ?>
<br/>
<?= Yii::t('bot', 'Public link to view information about the group'); ?>: <?= $chat->getLink() ?><br/>
————<br/>
<?= Yii::t('bot', 'Available commands in this group (as a reply to another message)') ?>:<br/>
<code>/warn</code> - <?= Yii::t('bot', 'delete a member\'s message, send a personal notification about violation of group rules') ?>.<br/>
<code>/mute</code> - <?= Yii::t('bot', 'delete a member\'s message, send a personal notification about violation of group rules, mute the member in the group') ?>.<br/>
<code>/ban</code> - <?= Yii::t('bot', 'delete a member\'s message, send a personal notification about violation of group rules, ban the member in the group') ?>.<br/>

0 comments on commit d6c7a12

Please sign in to comment.