Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.voicerss.tts. * ;
- import net.bramp.ffmpeg.FFmpeg;
- import net.bramp.ffmpeg.FFmpegExecutor;
- import net.bramp.ffmpeg.FFprobe;
- import net.bramp.ffmpeg.builder.FFmpegBuilder;
- import org.apache.commons.lang.StringEscapeUtils;
- import org.telegram.telegrambots.bots.TelegramLongPollingBot;
- import org.telegram.telegrambots.meta.api.objects.Message;
- import org.telegram.telegrambots.meta.api.objects.Update;
- import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
- import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.sql. * ;
- import java.util. * ;
- import static java.lang.StrictMath.toIntExact;
- public class TTSBot extends TelegramLongPollingBot {
- /* Dichiariamo le variabili globali */
- private InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
- private List < List < InlineKeyboardButton >> rowsInline = new ArrayList < >();
- private List < InlineKeyboardButton > rowInline = new ArrayList < >();
- private List < InlineKeyboardButton > rowInline2 = new ArrayList < >();
- private List < InlineKeyboardButton > rowInline3 = new ArrayList < >();
- private List < InlineKeyboardButton > rowInline4 = new ArrayList < >();
- private List < InlineKeyboardButton > rowInline5 = new ArrayList < >();
- private List < Integer > sendTTSText = new ArrayList < >();
- private List < Integer > sendGlobalPost = new ArrayList < >();
- private MySQLUtils MySQL = new MySQLUtils();
- private Messages msg = new Messages();
- @Override
- public void onUpdateReceived(Update update) {
- String DB_URL = "jdbc:mysql://localhost/ttsbot?useUnicode=true&characterEncoding=utf-8&serverTimezone=" + TimeZone.getDefault().getID();
- String PASS = "FV4qEpQfkNsrpMg6";
- String USER = "root";
- try (
- Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
- Statement stmt = conn.createStatement()) {
- if (update.hasMessage() && update.getMessage().hasText()) {
- /* Dichiariamo le variabili. */
- long chatid = update.getMessage().getChatId();
- long userid = update.getMessage().getFrom().getId();
- String text = update.getMessage().getText();
- if (MySQL.isRegistered(userid)) {
- /* Dichiariamo le variabili. */
- String last_name = null;
- String first_name = StringEscapeUtils.escapeSql(update.getMessage().getFrom().getFirstName());
- String username = null;
- int user_id = Math.toIntExact(userid);
- /* Controlliamo se lastName è null. */
- if (update.getMessage().getFrom().getLastName() != null) {
- last_name = ("'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getLastName()) + "'");
- }
- /* Controlliamo se username è null. */
- if (update.getMessage().getFrom().getUserName() != null) {
- username = "'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getUserName()) + "'";
- }
- MySQL.setInfos(userid, first_name, last_name, username);
- if (update.getMessage().isUserMessage()) {
- if (text.equals("/start")) {
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- if (MySQL.getLanguage(userid).equals("it")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Parla \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Benvenuto nel bot!\n" + "Con questo bot puoi scrivere\n" + "un qualsiasi testo, e ricevere\n" + "un audio in cui il tuo testo\n" + "verrà detto a voce dalla AI!\n" + "\n" + "ℹ️ <i>Utilizza i pulsanti quì sotto.</i>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Welcome to the bot!\n" + "With this bot you can write\n" + "any text, and receive an audio\n" + "where your text will be spoken\n" + "out loud by our AI.\n" + "\n" + "ℹ️ <i>Use the buttons down here.</i>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("not_specified")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech</b> \uD83D\uDD0A\n" + "\n" + "\uD83C\uDDEE\uD83C\uDDF9 <i>Seleziona la tua lingua.</i>\n" + "\n" + "\uD83C\uDDFA\uD83C\uDDF8 <i>Please select your language.</i>", "HTML", markupInline);
- }
- }
- else if (text.equals("/admin") && MySQL.isAdmin(userid)) {
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- sendTTSText.remove(Integer.valueOf(toIntExact(user_id)));
- String sql2 = "SELECT * FROM users WHERE chat_id = " + userid;
- if (MySQL.getLanguage(userid).equals("it")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Utenti \uD83D\uDC65").setCallbackData("manage_users"));
- rowInline.add(new InlineKeyboardButton().setText("Post \uD83D\uDCE8").setCallbackData("globalpost"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Benvenuto nel pannello admin!\n" + "Quì puoi usufruire di molte funzioni\n" + "utili come gestire il database, inviare\n" + "post globali e molto altro ancora.\n" + "\n" + "ℹ️ <i>Utilizza i pulsanti quì sotto.</i>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Users \uD83D\uDC65").setCallbackData("manage_users"));
- rowInline.add(new InlineKeyboardButton().setText("Post \uD83D\uDCE8").setCallbackData("globalpost"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Welcome to the admin panel!\n" + "Here you can use a lot of useful functions\n" + "like manage the database, see the users,\n" + "send global posts and a lot more.\n" + "\n" + "ℹ️ <i>Use the buttons down here.</i>", "HTML", markupInline);
- }
- else {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Users \uD83D\uDC65").setCallbackData("manage_users"));
- rowInline.add(new InlineKeyboardButton().setText("Post \uD83D\uDCE8").setCallbackData("globalpost"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Welcome to the admin panel!\n" + "Here you can use a lot of useful functions\n" + "like manage the database, see the users,\n" + "send global posts and a lot more.\n" + "\n" + "ℹ️ <i>Use the buttons down here.</i>", "HTML", markupInline);
- }
- }
- else if (sendTTSText.contains(toIntExact(userid))) {
- if (MySQL.getLanguage(userid).equals("it")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- VoiceProvider tts = new VoiceProvider("588cf0f182d74e0d8f60a46ed139d0db");
- VoiceParameters params = new VoiceParameters(text, Languages.Italian);
- params.setCodec(AudioCodec.OGG);
- params.setFormat(AudioFormat.Format_48KHZ.AF_48khz_16bit_stereo);
- params.setBase64(false);
- params.setSSML(false);
- params.setRate(0);
- if (text.length() > 1000) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "\uD83D\uDEAB <b>Il testo è troppo lungo.</b>", "HTML", markupInline);
- }
- else {
- try {
- Message msg1 = msg.smMsg(chatid, "\uD83D\uDD0A <b>Creazione audio in corso...</b>", "HTML", null);
- byte[] voice = tts.speech(params);
- Random randomNumber = new Random();
- int random = randomNumber.nextInt(100000000);
- FileOutputStream fos = new FileOutputStream("TextToSpeech_" + random + ".ogg");
- fos.write(voice, 0, voice.length);
- fos.flush();
- fos.close();
- FFmpeg ffmpeg = new FFmpeg("/usr/bin/ffmpeg");
- FFprobe ffprobe = new FFprobe("/usr/bin/ffprobe");
- FFmpegBuilder builder = new FFmpegBuilder()
- .setInput("TextToSpeech_" + random + ".ogg") // Filename, or a FFmpegProbeResult
- .overrideOutputFiles(true) // Override the output if it exists
- .addOutput("TextToSpeech_" + random + "_opus.ogg") // Filename for the destination
- .setAudioChannels(1) // Mono audio
- .setAudioCodec("libopus") // using the aac codec
- .setAudioSampleRate(48_000) // at 48KHz
- .setAudioBitRate(32768) // at 32 kbit/s
- .done();
- FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
- executor.createJob(builder).run();
- File audio = new File("TextToSpeech_" + random + "_opus" + ".ogg");
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro_audio"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.deleteMsg(chatid, msg1.getMessageId());
- msg.sendAudio(chatid, audio, markupInline);
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- VoiceProvider tts = new VoiceProvider("588cf0f182d74e0d8f60a46ed139d0db");
- VoiceParameters params = new VoiceParameters(text, Languages.English_UnitedStates);
- params.setCodec(AudioCodec.OGG);
- params.setFormat(AudioFormat.Format_48KHZ.AF_48khz_16bit_stereo);
- params.setBase64(false);
- params.setSSML(false);
- params.setRate(0);
- if (text.length() > 1000) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "\uD83D\uDEAB <b>Il testo è troppo lungo.</b>", "HTML", markupInline);
- }
- else {
- try {
- Message msg1 = msg.smMsg(chatid, "\uD83D\uDD0A <b>Creazione audio in corso...</b>", "HTML", null);
- byte[] voice = tts.speech(params);
- Random randomNumber = new Random();
- int random = randomNumber.nextInt(100000000);
- FileOutputStream fos = new FileOutputStream("TextToSpeech_" + random + ".ogg");
- fos.write(voice, 0, voice.length);
- fos.flush();
- fos.close();
- FFmpeg ffmpeg = new FFmpeg("/usr/bin/ffmpeg");
- FFprobe ffprobe = new FFprobe("/usr/bin/ffprobe");
- FFmpegBuilder builder = new FFmpegBuilder()
- .setInput("TextToSpeech_" + random + ".ogg") // Filename, or a FFmpegProbeResult
- .overrideOutputFiles(true) // Override the output if it exists
- .addOutput("TextToSpeech_" + random + "_opus.ogg") // Filename for the destination
- .setAudioChannels(1) // Mono audio
- .setAudioCodec("libopus") // using the aac codec
- .setAudioSampleRate(48_000) // at 48KHz
- .setAudioBitRate(32768) // at 32 kbit/s
- .done();
- FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
- executor.createJob(builder).run();
- File audio = new File("TextToSpeech_" + random + "_opus" + ".ogg");
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro_audio"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.deleteMsg(chatid, msg1.getMessageId());
- msg.sendAudio(chatid, audio, markupInline);
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- else if (MySQL.getLanguage(userid).equals("not_specified")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech</b> \uD83D\uDD0A\n" + "\n" + "\uD83C\uDDEE\uD83C\uDDF9 <i>Seleziona la tua lingua.</i>\n" + "\n" + "\uD83C\uDDFA\uD83C\uDDF8 <i>Please select your language.</i>", "HTML", markupInline);
- }
- }
- else if (sendGlobalPost.contains(toIntExact(userid)) && MySQL.isAdmin(userid)) {
- MySQL.sendGlobal(userid, text);
- }
- else if (text.equals("/start change_lang")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech</b> \uD83D\uDD0A\n" + "\n" + "\uD83C\uDDEE\uD83C\uDDF9 <i>Seleziona la tua lingua.</i>\n" + "\n" + "\uD83C\uDDFA\uD83C\uDDF8 <i>Please select your language.</i>", "HTML", markupInline);
- }
- }
- }
- else if (!MySQL.isRegistered(userid)) {
- /* Dichiariamo le variabili. */
- String last_name = null;
- String first_name = StringEscapeUtils.escapeSql(update.getMessage().getFrom().getFirstName());
- String username = null;
- /* Se lastname non è null. */
- if (update.getMessage().getFrom().getLastName() != null) {
- last_name = ("'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getLastName()) + "'");
- }
- /* Se username non è null. */
- if (update.getMessage().getFrom().getUserName() != null) {
- username = "'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getUserName()) + "'";
- }
- /* Creiamo la query. */
- String query = "INSERT INTO users (chat_id, first_name, last_name, username, action, title, type, language) VALUES (" + userid + ", '" + first_name + "', " + last_name + ", " + username + ", 'nessuna', null, 'user', 'not_specified'" + ");";
- /* Eseguiamo la query. */
- stmt.executeUpdate(query);
- if (update.getMessage().isUserMessage()) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(userid, "<b>Text To Speech</b> \uD83D\uDD0A\n" + "\n" + "\uD83C\uDDEE\uD83C\uDDF9 <i>Seleziona la tua lingua.</i>\n" + "\n" + "\uD83C\uDDFA\uD83C\uDDF8 <i>Please select your language.</i>", "HTML", markupInline);
- }
- }
- }
- else if (update.hasCallbackQuery()) {
- String cb_data = update.getCallbackQuery().getData();
- int msgid = toIntExact(update.getCallbackQuery().getMessage().getMessageId());
- long chatid = update.getCallbackQuery().getMessage().getChatId();
- long userid = update.getCallbackQuery().getFrom().getId();
- String query_id = update.getCallbackQuery().getId();
- if (MySQL.isRegistered(userid)) {
- /* Dichiariamo le variabili. */
- String last_name = null;
- String first_name = StringEscapeUtils.escapeSql(update.getCallbackQuery().getFrom().getFirstName());
- String username = null;
- int user_id = Math.toIntExact(userid);
- /* Controlliamo se lastName è null. */
- if (update.getCallbackQuery().getFrom().getLastName() != null) {
- last_name = ("'" + StringEscapeUtils.escapeSql(update.getCallbackQuery().getFrom().getLastName()) + "'");
- }
- /* Controlliamo se username è null. */
- if (update.getCallbackQuery().getFrom().getUserName() != null) {
- username = "'" + StringEscapeUtils.escapeSql(update.getCallbackQuery().getFrom().getUserName()) + "'";
- }
- /* Creiamo la query. */
- String query = "UPDATE users SET first_name='" + first_name + "', last_name=" + last_name + ", username=" + username + " WHERE chat_id=" + user_id;
- /* Eseguiamo la query. */
- stmt.executeUpdate(query);
- }
- /* Se l'utente non è nel db. */
- else if (!MySQL.isRegistered(userid)) {
- /* Dichiariamo le variabili. */
- String last_name = null;
- String first_name = StringEscapeUtils.escapeSql(update.getMessage().getFrom().getFirstName());
- String username = null;
- /* Se lastname non è null. */
- if (update.getMessage().getFrom().getLastName() != null) {
- last_name = ("'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getLastName()) + "'");
- }
- /* Se username non è null. */
- if (update.getMessage().getFrom().getUserName() != null) {
- username = "'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getUserName()) + "'";
- }
- /* Creiamo la query. */
- String query = "INSERT INTO users (chat_id, first_name, last_name, username, action, title, type, language) VALUES (" + userid + ", '" + first_name + "', " + last_name + ", " + username + ", 'nessuna', null, 'user', 'not_specified'" + ");";
- /* Eseguiamo la query. */
- stmt.executeUpdate(query);
- }
- if (cb_data.equals("parla")) {
- if (MySQL.getLanguage(userid).equals("it")) {
- sendTTSText.add(toIntExact(userid));
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCAD <b>Invia ora il testo.</b>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- sendTTSText.add(toIntExact(userid));
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCAD <b>Now send the text.</b>", "HTML", markupInline);
- }
- else {
- sendTTSText.add(toIntExact(userid));
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCAD <b>Invia ora il testo.</b>", "HTML", markupInline);
- }
- }
- else if (cb_data.equals("indietro")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- if (MySQL.getLanguage(userid).equals("it")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Parla ora \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Benvenuto nel bot!\n" + "Con questo bot puoi scrivere\n" + "un qualsiasi testo, e ricevere\n" + "un audio in cui il tuo testo\n" + "verrà detto a voce dalla AI!\n" + "\n" + "ℹ️ <i>Utilizza i pulsanti quì sotto.</i>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Welcome to the bot!\n" + "With this bot you can write\n" + "any text, and receive an audio\n" + "where your text will be spoken\n" + "out loud by our AI.\n" + "\n" + "ℹ️ <i>Use the buttons down here.</i>", "HTML", markupInline);
- }
- }
- else if (cb_data.equals("info")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- if (MySQL.getLanguage(userid).equals("it")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Developer \uD83D\uDDF3").setUrl("https://t.me/Fumaz"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83E\uDD16 <b>Sviluppato da</b> <code>@Fumaz</code>\n\n\uD83D\uDCBB <i>Interamente in Java 8.</i>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Developer \uD83D\uDDF3").setUrl("https://t.me/Fumaz"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83E\uDD16 <b>Developed by</b> <code>@Fumaz</code>\n\n\uD83D\uDCBB <i>Entirely in Java 8.</i>", "HTML", markupInline);
- }
- }
- else if (cb_data.equals("lang_it")) {
- String sql2 = "UPDATE users SET language='it' WHERE chat_id=" + userid;
- stmt.executeUpdate(sql2);
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Parla \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Benvenuto nel bot!\n" + "Con questo bot puoi scrivere\n" + "un qualsiasi testo, e ricevere\n" + "un audio in cui il tuo testo\n" + "verrà detto a voce dalla AI!\n" + "\n" + "ℹ️ <i>Utilizza i pulsanti quì sotto.</i>", "HTML", markupInline);
- }
- else if (cb_data.equals("lang_en")) {
- String sql2 = "UPDATE users SET language='en' WHERE chat_id=" + userid;
- stmt.executeUpdate(sql2);
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Welcome to the bot!\n" + "With this bot you can write\n" + "any text, and receive an audio\n" + "where your text will be spoken\n" + "out loud by our AI.\n" + "\n" + "ℹ️ <i>Use the buttons down here.</i>", "HTML", markupInline);
- }
- else if (cb_data.equals("change_language")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "<b>Text To Speech</b> \uD83D\uDD0A\n" + "\n" + "\uD83C\uDDEE\uD83C\uDDF9 <i>Seleziona la tua lingua.</i>\n" + "\n" + "\uD83C\uDDFA\uD83C\uDDF8 <i>Please select your language.</i>", "HTML", markupInline);
- }
- else if (cb_data.equals("indietro_audio")) {
- msg.replyQuery(query_id);
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- if (MySQL.getLanguage(userid).equals("it")) {
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Parla \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Benvenuto nel bot!\n" + "Con questo bot puoi scrivere\n" + "un qualsiasi testo, e ricevere\n" + "un audio in cui il tuo testo\n" + "verrà detto a voce dalla AI!\n" + "\n" + "ℹ️ <i>Utilizza i pulsanti quì sotto.</i>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
- rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
- rowInline2.clear();
- rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- rowsInline.add(rowInline2);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech \uD83D\uDD0A</b>\n" + "\n" + "Welcome to the bot!\n" + "With this bot you can write\n" + "any text, and receive an audio\n" + "where your text will be spoken\n" + "out loud by our AI.\n" + "\n" + "ℹ️ <i>Use the buttons down here.</i>", "HTML", markupInline);
- }
- else {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
- rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.sm(chatid, "<b>Text To Speech</b> \uD83D\uDD0A\n" + "\n" + "\uD83C\uDDEE\uD83C\uDDF9 <i>Seleziona la tua lingua.</i>\n" + "\n" + "\uD83C\uDDFA\uD83C\uDDF8 <i>Please select your language.</i>", "HTML", markupInline);
- }
- }
- else if (cb_data.equals("manage_users")) {
- sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
- sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
- if (MySQL.getLanguage(userid).equals("it")) {
- String sql3 = "SELECT * FROM users";
- ResultSet rs3 = stmt.executeQuery(sql3);
- String utenti = "";
- int count = 0;
- while (rs3.next()) {
- count++;
- String dbfirst_name = rs3.getString("first_name");
- int dbuserid = rs3.getInt("chat_id");
- if (rs3.getBoolean("blocked")) {
- utenti = utenti + "» <a href='tg://user?id=" + dbuserid + "'>" + dbfirst_name + "</a> [" + dbuserid + "] [BLOCCATO]" + "\n";
- } else {
- utenti = utenti + "» <a href='tg://user?id=" + dbuserid + "'>" + dbfirst_name + "</a> [" + dbuserid + "]" + "\n";
- }
- }
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(userid, msgid, query_id, "\uD83D\uDC65 <b>LISTA UTENTI [" + count + "]</b>\n\n" + utenti, "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- String sql3 = "SELECT * FROM users";
- ResultSet rs3 = stmt.executeQuery(sql3);
- String utenti = "";
- int count = 0;
- while (rs3.next()) {
- count++;
- String dbfirst_name = rs3.getString("first_name");
- int dbuserid = rs3.getInt("chat_id");
- utenti = utenti + "» " + dbfirst_name + " [" + dbuserid + "]" + "\n";
- }
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(userid, msgid, query_id, "\uD83D\uDC65 <b>USERS LIST [" + count + "]</b>\n\n" + utenti, "HTML", markupInline);
- }
- else {
- String sql3 = "SELECT * FROM users";
- ResultSet rs3 = stmt.executeQuery(sql3);
- String utenti = "";
- int count = 0;
- while (rs3.next()) {
- count++;
- String dbfirst_name = rs3.getString("first_name");
- int dbuserid = rs3.getInt("chat_id");
- utenti = utenti + "» " + dbfirst_name + " [" + dbuserid + "]" + "\n";
- }
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(userid, msgid, query_id, "\uD83D\uDC65 <b>USERS LIST [" + count + "]</b>\n\n" + utenti, "HTML", markupInline);
- }
- }
- else if (cb_data.equals("globalpost") && MySQL.isAdmin(userid)) {
- sendGlobalPost.add(toIntExact(userid));
- if (MySQL.getLanguage(userid).equals("it")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCEC <b>Invia ora il testo.</b>", "HTML", markupInline);
- }
- else if (MySQL.getLanguage(userid).equals("en")) {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCEC <b>Now send the text.</b>", "HTML", markupInline);
- }
- else {
- rowInline.clear();
- rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
- rowsInline.clear();
- rowsInline.add(rowInline);
- markupInline.setKeyboard(rowsInline);
- msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCEC <b>Now send the text.</b>", "HTML", markupInline);
- }
- }
- }
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
- /* Se l'utente non è nel db. */
- @Override
- public String getBotUsername() {
- return "TextToSpeechRobot";
- }
- @Override
- public String getBotToken() {
- return "674389619:AAEvDHpm29qZ3aroWNcrHfP6Mxca6RLx0NM";
- }
- }
Add Comment
Please, Sign In to add comment