|
| 1 | +<?php |
| 2 | +/* |
| 3 | +the project created by @wizardloop |
| 4 | +*/ |
| 5 | +namespace GetAnyMessage\Handlers; |
| 6 | + |
| 7 | +use GetAnyMessage\Locales\Lang; |
| 8 | +use GetAnyMessage\Storage\Account; |
| 9 | + |
| 10 | +use danog\MadelineProto\EventHandler\Message\PrivateMessage; |
| 11 | +use danog\MadelineProto\EventHandler\SimpleFilter\Incoming; |
| 12 | + |
| 13 | +use Amp\File; |
| 14 | +use function Amp\File\write; |
| 15 | +use function Amp\File\read; |
| 16 | +use function Amp\File\exists; |
| 17 | + |
| 18 | +class Handlers |
| 19 | +{ |
| 20 | + private object $context; |
| 21 | + public function __construct(object $context) { |
| 22 | + $this->context = $context; |
| 23 | + } |
| 24 | + |
| 25 | + public function startHandle(Incoming & PrivateMessage $message): void { |
| 26 | + try{ |
| 27 | + |
| 28 | +if($this->context->isSelfBot()){ |
| 29 | + |
| 30 | + $senderId = $message->senderId; |
| 31 | + $messageid = $message->id; |
| 32 | + |
| 33 | +$lang = (new Lang($this->context))->getUserLang($senderId); |
| 34 | +$translate = (new Lang($this->context))->loadTranslations($lang); |
| 35 | +$welcome = $translate['welcome'] ?? 'welcome'; |
| 36 | +$welcome_button1_txt = $translate['welcome_button1_txt'] ?? '👥 Support Chat'; |
| 37 | +$welcome_button1_data = $translate['welcome_button1_data'] ?? 'https://t.me/GetAnyMessageChat'; |
| 38 | +$welcome_button2_txt = $translate['welcome_button2_txt'] ?? 'Updates Channel 🔔'; |
| 39 | +$welcome_button2_data = $translate['welcome_button2_data'] ?? 'https://t.me/GetAnyMessageUpdates'; |
| 40 | +$welcome_button10_txt = $translate['welcome_button10_txt'] ?? 'Donate 🦾'; |
| 41 | +$welcome_button10_data = $translate['welcome_button10_data'] ?? 'Donate'; |
| 42 | +$source_code_txt = $translate['source_code_txt'] ?? '⭐️ Source Code 🔗'; |
| 43 | +$source_code_url = $translate['source_code_url'] ?? 'https://github.com/WizardLoop/GetAnyMessage'; |
| 44 | + |
| 45 | +$language_name = $translate['language_name'] ?? 'English'; |
| 46 | +$language_flag = $translate['language_flag'] ?? '🇬🇧'; |
| 47 | +$language_button = $language_flag . " " . $language_name; |
| 48 | +$language_data = $translate['language_data'] ?? 'setLanguage'; |
| 49 | + |
| 50 | +$bot_API_markup[] = [['text'=>$welcome_button1_txt,'url'=>$welcome_button1_data],['text'=>$welcome_button2_txt,'url'=>$welcome_button2_data]]; |
| 51 | +$bot_API_markup[] = [['text'=>$welcome_button10_txt,'callback_data'=>$welcome_button10_data]]; |
| 52 | +$bot_API_markup[] = [['text'=>$language_button,'callback_data'=>$language_data]]; |
| 53 | +$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,]; |
| 54 | + |
| 55 | +$inputReplyToMessage = ['_' => 'inputReplyToMessage', 'reply_to_msg_id' => $messageid]; |
| 56 | +$this->context->messages->sendMessage(peer: $message->senderId, |
| 57 | +reply_to: $inputReplyToMessage, |
| 58 | +message: $welcome, |
| 59 | +reply_markup: $bot_API_markup, |
| 60 | +parse_mode: 'HTML', |
| 61 | +effect: 5046509860389126442); |
| 62 | + |
| 63 | + if (!file_exists(__DIR__."/../data")) { |
| 64 | + mkdir(__DIR__."/../data"); |
| 65 | + } |
| 66 | + if (!file_exists(__DIR__."/../data/$senderId")) { |
| 67 | + mkdir(__DIR__."/../data/$senderId"); |
| 68 | + } |
| 69 | + if (file_exists(__DIR__."/../data/$senderId/grs1.txt")) { |
| 70 | + unlink(__DIR__."/../data/$senderId/grs1.txt"); |
| 71 | + } |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | + } catch (\Throwable $e) { |
| 76 | +$inputReplyToMessage = ['_' => 'inputReplyToMessage', 'reply_to_msg_id' => $message->id]; |
| 77 | +$this->context->messages->sendMessage(peer: $message->senderId, |
| 78 | +reply_to: $inputReplyToMessage, |
| 79 | +message: $e->getMessage()); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public function setLanguage(int $senderId, int $msgid): void { |
| 84 | + try{ |
| 85 | +$lang = (new Lang($this->context))->getUserLang($senderId); |
| 86 | +$translate = (new Lang($this->context))->loadTranslations($lang); |
| 87 | +$language_choose = $translate['language_choose'] ?? 'language_choose'; |
| 88 | + |
| 89 | +$languageButtons = (new Lang($this->context))->getLanguageButtons(); |
| 90 | + |
| 91 | +$this->context->messages->editMessage( |
| 92 | +peer: $senderId, |
| 93 | +id: $msgid, |
| 94 | +message: $language_choose, |
| 95 | +reply_markup: $languageButtons, |
| 96 | +parse_mode: 'HTML' |
| 97 | +); |
| 98 | + |
| 99 | + } catch (\Throwable $e) {} |
| 100 | + } |
| 101 | + |
| 102 | + public function backStart(int $senderId, int $msgid): void { |
| 103 | + try{ |
| 104 | +$lang = (new Lang($this->context))->getUserLang($senderId); |
| 105 | +$translate = (new Lang($this->context))->loadTranslations($lang); |
| 106 | +$welcome = $translate['welcome'] ?? 'welcome'; |
| 107 | +$welcome_button1_txt = $translate['welcome_button1_txt'] ?? '👥 Support Chat'; |
| 108 | +$welcome_button1_data = $translate['welcome_button1_data'] ?? 'https://t.me/GetAnyMessageChat'; |
| 109 | +$welcome_button2_txt = $translate['welcome_button2_txt'] ?? 'Updates Channel 🔔'; |
| 110 | +$welcome_button2_data = $translate['welcome_button2_data'] ?? 'https://t.me/GetAnyMessageUpdates'; |
| 111 | +$welcome_button10_txt = $translate['welcome_button10_txt'] ?? 'Donate 🦾'; |
| 112 | +$welcome_button10_data = $translate['welcome_button10_data'] ?? 'Donate'; |
| 113 | +$source_code_txt = $translate['source_code_txt'] ?? '⭐️ Source Code 🔗'; |
| 114 | +$source_code_url = $translate['source_code_url'] ?? 'https://github.com/WizardLoop/GetAnyMessage'; |
| 115 | + |
| 116 | +$language_name = $translate['language_name'] ?? 'English'; |
| 117 | +$language_flag = $translate['language_flag'] ?? '🇬🇧'; |
| 118 | +$language_button = $language_flag . " " . $language_name; |
| 119 | +$language_data = $translate['language_data'] ?? 'setLanguage'; |
| 120 | + |
| 121 | +$bot_API_markup[] = [['text'=>$welcome_button1_txt,'url'=>$welcome_button1_data],['text'=>$welcome_button2_txt,'url'=>$welcome_button2_data]]; |
| 122 | +$bot_API_markup[] = [['text'=>$welcome_button10_txt,'callback_data'=>$welcome_button10_data]]; |
| 123 | +$bot_API_markup[] = [['text'=>$language_button,'callback_data'=>$language_data]]; |
| 124 | +$bot_API_markup = [ 'inline_keyboard'=> $bot_API_markup,]; |
| 125 | + |
| 126 | +$this->context->messages->editMessage( |
| 127 | +peer: $senderId, |
| 128 | +id: $msgid, |
| 129 | +message: $welcome, |
| 130 | +reply_markup: $bot_API_markup, |
| 131 | +parse_mode: 'HTML' |
| 132 | +); |
| 133 | + |
| 134 | +if (file_exists(__DIR__."/../data/$senderId/grs1.txt")) { |
| 135 | +unlink(__DIR__."/../data/$senderId/grs1.txt"); |
| 136 | +} |
| 137 | + |
| 138 | + } catch (\Throwable $e) {} |
| 139 | + } |
| 140 | + |
| 141 | + public function langCommand(Incoming & PrivateMessage $message): void { |
| 142 | + try{ |
| 143 | + |
| 144 | +if($this->context->isSelfBot()){ |
| 145 | + |
| 146 | + $senderId = $message->senderId; |
| 147 | + $messageid = $message->id; |
| 148 | + |
| 149 | +$lang = (new Lang($this->context))->getUserLang($senderId); |
| 150 | +$translate = (new Lang($this->context))->loadTranslations($lang); |
| 151 | +$language_choose = $translate['language_choose'] ?? 'language_choose'; |
| 152 | + |
| 153 | +$languageButtons = (new Lang($this->context))->getLanguageButtons(); |
| 154 | + |
| 155 | +$inputReplyToMessage = ['_' => 'inputReplyToMessage', 'reply_to_msg_id' => $messageid]; |
| 156 | +$this->context->messages->sendMessage(peer: $message->senderId, |
| 157 | +reply_to: $inputReplyToMessage, |
| 158 | +message: $language_choose, |
| 159 | +reply_markup: $languageButtons, |
| 160 | +parse_mode: 'HTML' |
| 161 | +); |
| 162 | +} |
| 163 | + } catch (\Throwable $e) { |
| 164 | +$inputReplyToMessage = ['_' => 'inputReplyToMessage', 'reply_to_msg_id' => $message->id]; |
| 165 | +$this->context->messages->sendMessage(peer: $message->senderId, |
| 166 | +reply_to: $inputReplyToMessage, |
| 167 | +message: $e->getMessage()); |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | +} |
0 commit comments