|
|
@@ -9,6 +9,8 @@ use App\Models\User;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
+use Telegram\Bot\Api;
|
|
|
+use Telegram\Bot\Exceptions\TelegramSDKException;
|
|
|
|
|
|
class UserService extends BaseService
|
|
|
{
|
|
|
@@ -108,13 +110,44 @@ class UserService extends BaseService
|
|
|
return ['chat_id' => $chatId, 'text' => "✅ 游戏ID设置成功\n游戏ID:{$gameId}"];
|
|
|
}
|
|
|
|
|
|
- public static function getLanguages($chatId, $language)
|
|
|
+ /**
|
|
|
+ * @param Api $telegram
|
|
|
+ * @param $data
|
|
|
+ * @param $chatId
|
|
|
+ * @param $firstName
|
|
|
+ * @param $messageId
|
|
|
+ * @return void
|
|
|
+ * @throws TelegramSDKException
|
|
|
+ */
|
|
|
+ public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
|
|
|
+ {
|
|
|
+ $pattern = "/^setLanguage@@.*$/";
|
|
|
+ if (preg_match($pattern, $data)) {
|
|
|
+ $language = preg_replace('/^setLanguage@@/', '', $data);
|
|
|
+ $res = UserService::setLanguage($chatId, $language, $messageId);
|
|
|
+ $telegram->editMessageText($res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function setLanguage($chatId, $language, $messageId): array
|
|
|
+ {
|
|
|
+ $userInfo = self::findOne(['member_id' => $chatId]);
|
|
|
+ $userInfo->language = $language;
|
|
|
+ $userInfo->save();
|
|
|
+ return [
|
|
|
+ 'chat_id' => $chatId,
|
|
|
+ 'text' => lang("语言设置成功"),
|
|
|
+ 'message_id' => $messageId,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getLanguages($chatId): array
|
|
|
{
|
|
|
$keyboard = [
|
|
|
[['text' => lang('en'), 'callback_data' => "setLanguage@@en"]],
|
|
|
[['text' => lang('zh'), 'callback_data' => "setLanguage@@zh"]],
|
|
|
[['text' => lang('vi'), 'callback_data' => "setLanguage@@vi"]],
|
|
|
- [ ['text' => lang('❌取消'), 'callback_data' => "message@@close"]],
|
|
|
+ [['text' => lang('❌取消'), 'callback_data' => "message@@close"]],
|
|
|
];
|
|
|
return [
|
|
|
'chat_id' => $chatId,
|