Skip to content

Commit

Permalink
Added reminders management.
Browse files Browse the repository at this point in the history
Now reminders can be deleted.
  • Loading branch information
Francesco Tarantino committed Jul 6, 2017
1 parent d808f7d commit fa9695d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 20 deletions.
113 changes: 96 additions & 17 deletions bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
$callback = $update["callback_query"]["data"];

if($callback){
$chatID = $update["callback_query"]["chat"]["id"];
$chatID = $update["callback_query"]["message"]["chat"]["id"];
$userID = $update["callback_query"]["from"]["id"];
$msgid = $update["callback_query"]["message"]["message_id"];
} else if($inline){
$msg = $update["inline_query"]["query"];
$userID = $update["inline_query"]["from"]["id"];
Expand Down Expand Up @@ -191,7 +192,7 @@
"callback_data" => "edit-" . $json['result']['message_id'] . "-0"));
$menu[] = array(array(
"text" => $lang['remindme'],
"callback_data" => "remindme-" . $data[1] . "-" . $i), array(
"callback_data" => "reminder-" . $data[1] . "-" . $i), array(
"text" => $lang['date'],
"callback_data" => "retrodate-" . $data[1] . "-" . $i));
}
Expand Down Expand Up @@ -220,7 +221,7 @@
"callback_data" => "edit-" . $json['result']['message_id'] . "-0"));
$menu[] = array(array(
"text" => $lang['remindme'],
"callback_data" => "remindme-" . $data[1] . "-" . $i), array(
"callback_data" => "reminder-" . $data[1] . "-" . $i), array(
"text" => $lang['date'],
"callback_data" => "retrodate-" . $data[1] . "-" . $i));
} else {
Expand All @@ -236,7 +237,7 @@
"callback_data" => "edit-" . $json['result']['message_id'] . "-0"));
$menu[] = array(array(
"text" => $lang['remindme'],
"callback_data" => "remindme-" . $data[1] . "-" . $i), array(
"callback_data" => "reminder-" . $data[1] . "-" . $i), array(
"text" => $lang['date'],
"callback_data" => "retrodate-" . $data[1] . "-" . $i));
}
Expand Down Expand Up @@ -266,23 +267,99 @@
$text = $lang['deleted'];
} else if($data[0] == "confdeleteallno"){
$text = $lang['cancelled'];
} else if ($data[0] == "reminder") {
$text = $set[$data[2]]['memo'];
$menur[] = array(array(
"text" => $lang['add'],
"callback_data" => "remindme-" . $data[1] . "-" . $data[2]
));
$query = "SELECT * FROM BNoteBot_reminder WHERE memoid = '" . $set[$data[2]]['id'] . "' ORDER by timestamp DESC";
if($result = $dbuser->query($query)){
if($result->num_rows > 0){
$counter = 1;
while ($row = $result->fetch_assoc()) {
$reminders = $reminders . $counter . ". " . date($dateformatnosec, $row["timestamp"]) . "\n";
$counter++;
}
$reminders = $lang['uhareminders'] . "\n" . $reminders . "\n";
if ($userID == "31507896") $menur[] = array(array(
"text" => $lang['delete'],
"callback_data" => "deletereminder-" . $data[1] . "-" . $set[$data[2]]['id'] . "-" . $data[2]
));
}
}
if ($data[3] == "em") {
em($userID, $msgid, $lang['reminderman'] . "\n\n" . $reminders, $menur, true);
} else {
sm($userID, $lang['reminderman'] . "\n\n" . $reminders, $menur, 'HTML', false, false, false, true);
}
} else if($data[0] == "remindme"){
$text = $set[$data[2]]['memo'];
$dbuser->query("UPDATE BNoteBot_user SET status='addremind-" . $data[2] . "' WHERE userID='$userID'");
$menur[] = array($lang['remindmetut']);
$menur[] = array($lang['cancel']);
$query = "SELECT * FROM BNoteBot_reminder WHERE memoid = '" . $set[$data[2]]['id'] . "' ORDER by timestamp DESC";
if($result = $dbuser->query($query)){
if($result->num_rows > 0){
$counter = 1;
while ($row = $result->fetch_assoc()) {
$reminders = $reminders . $counter . ". " . date($dateformatnosec, $row["timestamp"]) . "\n";
$counter++;
}
$reminders = "\n\n" . $lang['uhareminders'] . "\n" . $reminders . "\n";
}
em($userID, $msgid, $lang['reminderman']);
sm($userID, $lang['remindmetxt'], $menur);
} else if($data[0] == "deletereminder"){
$query = "SELECT * FROM BNoteBot_reminder WHERE memoid = '" . $data[2] . "' ORDER by timestamp DESC";
if($result = $dbuser->query($query)){
if($result->num_rows > 0){
$counter = 1;
while ($row = $result->fetch_assoc()) {
$reminders = $reminders . $counter . ". " . date($dateformatnosec, $row["timestamp"]) . "\n";
$menur[] = array(array(
"text" => "$counter",
"callback_data" => "deletenreminder-" . $data[1] . "-" . $row["id"] . "-" . $data[3] . "-" . $data[2]
));
$counter++;
}
}
}
$menur[] = array(array(
"text" => $lang['deleteall'],
"callback_data" => "deleteallreminders-" . $data[1] . "-" . $data[2]
));
$menur[] = array(array(
"text" => $lang['back'],
"callback_data" => "reminder-" . $data[1] . "-" . $data[3] . "-em"
));
em($userID, $msgid, $lang['deletereminder'] . "\n\n" . $reminders, $menur, true);
} elseif ($data[0] == "deleteallreminders") {
$dbuser->query("DELETE FROM BNoteBot_reminder WHERE memoid = " . $data[2]);
$menur[] = array(array(
"text" => $lang['back'],
"callback_data" => "reminder-" . $data[1] . "-" . $data[2] . "-em"
));
em($userID, $msgid, $lang['noreminder'], $menur, true);
} elseif ($data[0] == "deletenreminder") {
$dbuser->query("DELETE FROM BNoteBot_reminder WHERE id = " . $data[2]);
$textalert = $lang['deletedreminder'];
$alert = true;
$query = "SELECT * FROM BNoteBot_reminder WHERE memoid = '" . $data[4] . "' ORDER by timestamp DESC";
if($result = $dbuser->query($query)){
if($result->num_rows > 0){
$counter = 1;
while ($row = $result->fetch_assoc()) {
$reminders = $reminders . $counter . ". " . date($dateformatnosec, $row["timestamp"]) . "\n";
$menur[] = array(array(
"text" => "$counter",
"callback_data" => "deletenreminder-" . $data[1] . "-" . $row["id"]
));
$counter++;
}
$menur[] = array(array(
"text" => $lang['back'],
"callback_data" => "reminder-" . $data[1] . "-" . $data[3] . "-em"
));
em($userID, $msgid, $lang['deletereminder'] . "\n\n" . $reminders, $menur, true);
} else {
$menur[] = array(array(
"text" => $lang['back'],
"callback_data" => "reminder-" . $data[1] . "-" . $data[3] . "-em"
));
em($userID, $msgid, $lang['noreminder'], $menur, true);
}
sm($userID, $reminders . $lang['remindmetxt'], $menur);
}
} else if($data[0] == "retrodate"){
$text = $set[$data[2]]['memo'];
$dbuser->query("UPDATE BNoteBot_user SET status='retrodate-" . $data[2] . "' WHERE userID='$userID'");
Expand Down Expand Up @@ -480,7 +557,7 @@
"callback_data" => "edit-" . $json['result']['message_id'] . "-0"));
$menu[] = array(array(
"text" => $lang['remindme'],
"callback_data" => "remindme-" . $json['result']['message_id'] . "-0"), array(
"callback_data" => "reminder-" . $json['result']['message_id'] . "-0"), array(
"text" => $lang['date'],
"callback_data" => "retrodate-" . $json['result']['message_id'] . "-0"));
em($chatID, $json['result']['message_id'], $text, $menu, true);
Expand Down Expand Up @@ -517,7 +594,9 @@
inlinemodeset($chatID, $lang, $invertmemodata);
break;
default:
sm($chatID, $lang['messagenovalid']);
if ($update["message"]) {
sm($chatID, $lang['messagenovalid']);
}
break;
}
}
Expand Down
11 changes: 9 additions & 2 deletions lang/message.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
$lang['thanksfeedback'] = "Thanks for the feedback! \xE2\x9C\x85";
$lang['onlytxt'] = "Bot supports only text for now.";
$lang['github'] = "GitHub \xF0\x9F\x93\x82";

$lang['remindme'] = "Remind me \xF0\x9F\x95\x92";
//Missing in message.pt.php
$lang['remindme'] = "Reminder \xF0\x9F\x95\x92";
$lang['remindmetxt'] = "When you want to remember this note? \xF0\x9F\x95\x92";
$lang['remindersaved'] = "Reminder saved! \xE2\x9C\x85";
$lang['remindmetut'] = "How to write the date \xF0\x9F\x93\x85";
Expand All @@ -67,4 +67,11 @@
$lang['supportme'] = "Support Me \xF0\x9F\x92\x9A";
$lang['supportmetext'] = "My bots are free and without advertisement, you can support me by making a little donation with PayPal or BitCoin and voting my bot on @StoreBot. Thank you so much \xF0\x9F\x92\x9A";
$lang['opensource'] = "This bot is open source under GPL 3.0 License, you can find the code on GitHub.";
//Missing in message.pt.php and message.ru.php
$lang['reminderman'] = "Reminder management \xF0\x9F\x95\x92";
$lang['add'] = "Add \xE2\x9E\x95";
$lang['deletereminder'] = "Choose which reminder to delete \xE2\x9D\x8C:";
$lang['deletedreminder'] = "Deleted reminder! \xE2\x9D\x8C";
$lang['noreminder'] = "You don't have any reminder! \xF0\x9F\x95\x92";
$lang['deleteall'] = "Delete everything \xE2\x9D\x8C";
?>
8 changes: 7 additions & 1 deletion lang/message.it.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$lang['feedback'] = "Feedback \xF0\x9F\x93\xAB";
$lang['feedbacktext'] = "\xF0\x9F\x93\xAB - Se il Bot ha problemi o vuoi suggerirmi qualcosa, scrivimi in chat (@franci22) o inviami un messaggio adesso:";
$lang['thanksfeedback'] = "Grazie per il feedback! \xE2\x9C\x85";
$lang['remindme'] = "Ricordamelo \xF0\x9F\x95\x92";
$lang['remindme'] = "Promemoria \xF0\x9F\x95\x92";
$lang['remindmetxt'] = "Quando ti devo ricordare questa nota? \xF0\x9F\x95\x92";
$lang['remindmetut'] = "Come scrivere la data \xF0\x9F\x93\x85";
$lang['remindmeformat'] = "Devi scrivere la data in questo modo: GG.mm.AAAA hh:mm
Expand All @@ -66,4 +66,10 @@
$lang['supportmetext'] = "I miei Bot sono gratuiti e privi di pubblicità, puoi supportarmi facendo una piccola donazione via PayPal o BitCoin, iscrivendoti al mio canale (@franci22channel) e votando il Bot su @StoreBot. Grazie \xF0\x9F\x92\x9A";
$lang['github'] = "GitHub \xF0\x9F\x93\x82";
$lang['opensource'] = "Questo Bot è open source sotto licenza GPL 3.0, puoi trovarne il codice completo su GitHub.";
$lang['reminderman'] = "Gestione promemoria \xF0\x9F\x95\x92";
$lang['add'] = "Aggiungi \xE2\x9E\x95";
$lang['deletereminder'] = "Scegli quale promemoria eliminare \xE2\x9D\x8C:";
$lang['deletedreminder'] = "Promemoria eliminato! \xE2\x9D\x8C";
$lang['noreminder'] = "Non hai nessun promemoria! \xF0\x9F\x95\x92";
$lang['deleteall'] = "Elimina tutti \xE2\x9D\x8C";
?>

0 comments on commit fa9695d

Please sign in to comment.