Skip to content

Commit

Permalink
add setup for bot group inviter
Browse files Browse the repository at this point in the history
  • Loading branch information
grandmotivator committed Sep 25, 2023
1 parent 36f7898 commit e9cb9a4
Show file tree
Hide file tree
Showing 34 changed files with 464 additions and 146 deletions.
2 changes: 0 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Use widgets and helpers to prevent duplication and copying of code. Widgets and

### File Structure

### File Structure

- [`/modules/bot`](/modules/bot)
- [`/components`](/modules/bot/components) - Main bot components responsible for its functionality.
- [`/actions`](/modules/bot/components/actions) - Actions shared among some controllers.
Expand Down
9 changes: 8 additions & 1 deletion messages/ru/bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
'deletes messages by members that exceed the allowed posting frequency' => 'удаляет сообщения участников, которые превышают разрешенную частоту публикаций',
'Limit of messages per member per day' => 'Лимит сообщений на одного участника в день',
'Limit of messages' => 'Лимит сообщений',
'today' => 'сегодня',
'Send a maximum number of messages per member per day' => 'Отправьте максимальное количество сообщений на одного участника в день',
'Send a maximum number of messages for this member per day to change the value' => 'Отправьте максимальное количество сообщений для этого участника в день чтобы изменить значение',
'Members with exceptions' => 'Участники с исключениями',
Expand Down Expand Up @@ -536,7 +537,7 @@
'Your premium membership is valid until {0}' => 'Ваше премиум членство действительно до {0}',
'Your premium membership is valid until' => 'Ваше премиум членство действительно до',
'Premium membership is valid until' => 'Премиум членство действительно до',
'Public link for reviews from other group members' => 'Публичная ссылка для отзывов от других участников группы',
'Public personal link for reviews from other group members' => 'Публичная ссылка для отзывов от других участников группы',
'Member status' => 'Статус участника',
'Members status' => 'Статус участников',
'Intro' => 'Интро',
Expand Down Expand Up @@ -651,4 +652,10 @@
'Publisher' => 'Публикатор',
'sends posts to the group at the specified time' => 'отправляет обьявления в группу в заданное время',
'Next publish' => 'Следующая публикация',
'Inviter' => 'Пригласитель',
'pays rewards to members for adding new members to the group' => 'выплачивает вознаграждения участникам за добавление новых участников в группу',
'Rewards are paid from the wallet of the group creator for each new member' => 'Вознаграждения выплачиваются с кошелька создателя группы за каждого нового участника',
'Reward amount' => 'Сумма вознаграждения',
'Send a reward amount for adding a new member to the group' => 'Отправьте сумму вознаграждения за добавление нового участника в группу',
'Reward amount for adding a new member to the group' => 'Сумма вознаграждения за добавление нового участника в группу',
];
10 changes: 10 additions & 0 deletions models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ class Setting extends ActiveRecord
'default' => 1,
'min' => 0,
],
'active_bot_group_inviter_quantity_value_per_one_rating' => [
'type' => 'float',
'default' => 1,
'more' => 0,
],
'active_bot_group_inviter_min_quantity_value_per_one_user' => [
'type' => 'integer',
'default' => 1,
'min' => 0,
],
'company_quantity_value_per_one_rating' => [
'type' => 'float',
'default' => 1,
Expand Down
6 changes: 6 additions & 0 deletions models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use app\components\Converter;
use app\components\helpers\Html;
use app\components\helpers\TimeHelper;
use app\helpers\Number;
use app\models\queries\ContactQuery;
use app\models\queries\UserQuery;
Expand Down Expand Up @@ -1152,4 +1153,9 @@ public function getWalletsWithPositiveBalance()
->andWhere(['>', Wallet::tableName() . '.amount', 0])
->orderByCurrencyCode();
}

public function getTimezoneName()
{
return TimeHelper::getNameByOffset($this->timezone);
}
}
4 changes: 3 additions & 1 deletion modules/bot/components/helpers/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Emoji
public const ADD = '➕';
public const BACK = '🔙';
public const DELETE = '🗑';
public const EDIT = '️';
public const EDIT = '🖊️';
public const END = '🔚';
public const LANGUAGE = '🌐';
public const MENU = '📱';
Expand Down Expand Up @@ -47,7 +47,9 @@ class Emoji
public const SOON = '🔜';
public const NEW1 = '🆕';
public const LIST = '📖';
public const ITEMS = '🗂';
public const GIFT = '🎁';
public const EYE = '👁‍🗨';
public const THANKS = '🙏';
public const SWITCH = '🔀';
}
13 changes: 13 additions & 0 deletions modules/bot/config/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,17 @@
'set_member_verification_date',
'delete_member_membership_date',
'delete_member_verification_date',
'whitelist_word_list',
'whitelist_word_view_list',
'whitelist_word_view',
'whitelist_word_enter',
'blacklist_word_list',
'blacklist_word_view_list',
'blacklist_word_view',
'blacklist_word_enter',
'set_intro_text',
'set_reward_amount',
'input_reward_amount',
'input_tag',
'input_messages_limit',
];
2 changes: 1 addition & 1 deletion modules/bot/config/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'',
'',
'group_membership',
'',
'group_inviter',
'group_slow_mode',
'channel',
'group',
Expand Down
17 changes: 13 additions & 4 deletions modules/bot/controllers/privates/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@ public function actionView($chatId = null)
'callback_data' => GroupTimezoneController::createRoute('index', [
'id' => $chat->id,
]),
'text' => Yii::t('bot', 'Timezone'),
'text' => Emoji::EDIT . ' ' . Yii::t('bot', 'Timezone') . ': ' . $chat->getTimezoneName(),
],
],
[
[
[
'callback_data' => GroupLanguageController::createRoute('index', [
'id' => $chat->id,
]),
'text' => Yii::t('bot', 'Language'),
'text' => Emoji::EDIT . ' ' . Yii::t('bot', 'Language') . (($language = $chat->language) ? ': ' . strtoupper($language->code) : ''),
],
],
[
[
'callback_data' => GroupCurrencyController::createRoute('index', [
'id' => $chat->id,
]),
'text' => Yii::t('bot', 'Currency'),
'text' => Emoji::EDIT . ' ' . Yii::t('bot', 'Currency') . (($currency = $chat->currency) ? ': ' . $currency->code : ''),
],
],
[
Expand Down Expand Up @@ -206,6 +206,15 @@ public function actionView($chatId = null)
'text' => ($chat->isMembershipOn() ? Emoji::STATUS_ON : Emoji::STATUS_OFF) . ' ' . Yii::t('bot', 'Membership'),
],
],
[
[
'callback_data' => GroupInviterController::createRoute('index', [
'id' => $chat->id,
]),
'text' => ($chat->isInviterOn() ? Emoji::STATUS_ON : Emoji::STATUS_OFF) . ' ' . Yii::t('bot', 'Inviter'),
'visible' => $chatMember->isCreator(),
],
],
[
[
'callback_data' => GroupPublisherController::createRoute('index', [
Expand Down
55 changes: 37 additions & 18 deletions modules/bot/controllers/privates/GroupGuestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public function actionView($id = null)

$buttons[] = [
[
'callback_data' => self::createRoute('input-intro-text', [
'callback_data' => self::createRoute('set-intro-text', [
'id' => $chatMember->id,
]),
'text' => Yii::t('bot', 'My public intro'),
'text' => Emoji::EDIT . ' ' . Yii::t('bot', 'My public intro'),
],
];

Expand Down Expand Up @@ -176,7 +176,7 @@ public function actionView($id = null)
* @param int $id ChatMember->id
* @return array
*/
public function actionInputIntroText($id = null)
public function actionSetIntroText($id = null)
{
$chatMember = ChatMember::findOne($id);

Expand All @@ -190,23 +190,9 @@ public function actionInputIntroText($id = null)
'id' => $chatMember->id,
]));

if ($this->getUpdate()->getMessage()) {
if ($text = MessageWithEntitiesConverter::toHtml($this->getUpdate()->getMessage())) {
$chatMember->intro = $text;

if ($chatMember->validate('intro')) {
$chatMember->save(false);

return $this->runAction('view', [
'id' => $chatMember->getChatId(),
]);
}
}
}

return $this->getResponseBuilder()
->editMessageTextOrSendMessage(
$this->render('input-intro-text', [
$this->render('set-intro-text', [
'chatMember' => $chatMember,
]),
[
Expand All @@ -233,6 +219,39 @@ public function actionInputIntroText($id = null)
->build();
}

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

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

if ($this->getUpdate()->getMessage()) {
if ($text = MessageWithEntitiesConverter::toHtml($this->getUpdate()->getMessage())) {
$chatMember->intro = $text;

if ($chatMember->validate('intro')) {
$chatMember->save(false);

return $this->runAction('view', [
'id' => $chatMember->getChatId(),
]);
}
}
}

return $this->getResponseBuilder()
->answerCallbackQuery()
->build();
}

/**
* @param int $id ChatMember->id
* @return array
Expand Down
Loading

0 comments on commit e9cb9a4

Please sign in to comment.