-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBMnuCommand.php
153 lines (132 loc) · 4.8 KB
/
BMnuCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\Command;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Entities\InlineKeyboardButton;
use Longman\TelegramBot\Funciones;
use Longman\TelegramBot\Entities\InputMedia\InputMediaPhoto;
require_once __DIR__ . '/../Funciones/BMnu.php';
use BMenu\BMnu;
error_reporting(E_ALL);
class BmnuCommand extends UserCommand
{
protected $name = 'Bmnu';
protected $description = 'Menu';
protected $usage = '/Bmnu';
protected $version = '0.1.0';
public function armar_menu($CAT='PRIN',$actual=0,$item_id=0)
{
$actual = intval($actual) ; //Este es el numero de item que hay que incrementar/decrementar
$prox = $actual + 1;
$ant = $actual - 1;
$proxd = $actual + 3;
$antd = $actual - 3;
switch($CAT)
{
case 'PRIN';
/* Menu Principal de Pizzeria */
$MENU=new BMnu($CAT);
$MENU->setTit('Principal');
$MENU->setCols(array(1,2,3,2,3));
$MENU->setRet('');
$MENU->add_btn( 'Weather',"pag;PZA;0");
$MENU->add_btn( $MENU->emoji('U+2699').' Preferences','bmnu;CFG');
break;
case 'PZA';
/* Menu de Pizzas */
$MENU=new BMnu($CAT);
$MENU->setTit('Weather Bot');
$MENU->setCols(array(3,3,2,1));
$MENU->setRet('PRIN');
$MENU->actual_item = $actual;
$MENU->item_id = $item_id;
$MENU->add_btn( '< ',"pag;$CAT;$ant");
$MENU->add_btn( 'Now',"pag;$CAT;0");
$MENU->add_btn( '> ',"pag;$CAT;$prox");
$MENU->add_btn( '<< ',"pag;$CAT;$antd");
$MENU->add_btn( 'City','cmd;gps');
$MENU->add_btn( '>> ',"pag;$CAT;$proxd");
break;
case 'CFG';
/* Menu Principal de Pizzeria */
$MENU=new BMnu($CAT);
$MENU->setTit('Actualizá tus datos');
$MENU->setCols(array(3,2,1,3,2,3));
$MENU->setRet('PRIN');
//$MENU->add_btn( 'Web','login_url;https://redengo.com/pizza/check_authorization.php');
//$MENU->add_btn( 'DashBoard','login_url;https://redengo.com/pizza/dash/check_authorization.php');
$MENU->add_btn( $MENU->emj_satellite.' Position','cmd;gps');
//$MENU->add_btn( 'Ayuda','cmd;ayudapza');
break;
default;
/* Menu Principal de Pizzeria */
$MENU=new BMnu('PRIN');
$MENU->setTit('Principal');
$MENU->setCols(array(1,2,3,2,3));
$MENU->setRet('');
$MENU->add_btn( 'Weather',"pag;PZA;0");
$MENU->add_btn( $MENU->emoji('U+2699').' Configuracion','bmnu;CFG');
break;
/*$MENU=new BMnu($CAT);
$MENU->setTit('Errror llamando al menu con '.$CAT);
$MENU->setCols(array(1,1,2,2,3));
$MENU->setRet('PRIN');
$MENU->add_btn( 'ir al menu principal','bmnu;PRIN');
$MENU->add_btn( 'ERROR'.$CAT,'cmd:help');
*/
break;
}
return $MENU;
}
public function execute()
{
if ($this->getCallbackQuery() !== null) {
//$message = $update->getMessage();
$message = $this->getCallbackQuery()->getMessage();
$chat =$this->getCallbackQuery()->getMessage()->getChat();
$user = $chat;
$chat_id = $this->getCallbackQuery()->getMessage()->getChat()->getId();
$user_id = $chat_id;
$text = trim($message->getText(true));
}
else
{
$message = $this->getMessage() ?: $this->getEditedMessage();
$chat = $message->getChat();
$user = $message->getFrom();
$chat_id = $chat->getId();
$user_id = $user->getId();
$text = trim($message->getText(true));
}
$M = ($text == '') ? 'PRIN' : $text; //Trae el text del ultimo getMessage, no sirve
//$M = 'PZA';
$update = $this->getUpdate();
$data = [
'chat_id' => $chat_id,
'parse_mode' => 'HTML',
];
$data['disable_web_page_preview'] = false;
$MENU = $this->armar_menu($M,1);
$MENU->actual_item = 1;
//Funciones::debug_a_admins_php( 'yo', $MENU->show());
$data['text'] = '*'.$MENU->getTit().'*' . $this->getTelegram()->getBotId() ;
//$imgurl="https://redengo.com/bots/pizzero/imagenes/logo_ancho.png";
$imgurl=__DIR__.'/../imagenes/weather/owm.png';
$data['parse_mode']='HTML';
$data['caption']= 'Select an option ';
$data['photo'] = Request::encodeFile($imgurl);
$data['reply_markup']= $MENU->show();
$data['media'] = new InputMediaPhoto([
'type' => 'photo',
'caption' => 'Principal mnu',
'parse_mode' => 'HTML',
'media' => Request::encodeFile($imgurl),
]);
//return Request::editMessageMedia($data);
//return Request::sendMessage($data);
return Request::sendPhoto($data);
}
}
?>