Guest User

Untitled

a guest
Feb 2nd, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.17 KB | None | 0 0
  1. import com.voicerss.tts. * ;
  2. import net.bramp.ffmpeg.FFmpeg;
  3. import net.bramp.ffmpeg.FFmpegExecutor;
  4. import net.bramp.ffmpeg.FFprobe;
  5. import net.bramp.ffmpeg.builder.FFmpegBuilder;
  6. import org.apache.commons.lang.StringEscapeUtils;
  7. import org.telegram.telegrambots.bots.TelegramLongPollingBot;
  8. import org.telegram.telegrambots.meta.api.objects.Message;
  9. import org.telegram.telegrambots.meta.api.objects.Update;
  10. import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
  11. import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
  12.  
  13. import java.io.File;
  14. import java.io.FileOutputStream;
  15. import java.sql. * ;
  16. import java.util. * ;
  17.  
  18. import static java.lang.StrictMath.toIntExact;
  19.  
  20. public class TTSBot extends TelegramLongPollingBot {
  21.  
  22. /* Dichiariamo le variabili globali */
  23. private InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
  24. private List < List < InlineKeyboardButton >> rowsInline = new ArrayList < >();
  25. private List < InlineKeyboardButton > rowInline = new ArrayList < >();
  26. private List < InlineKeyboardButton > rowInline2 = new ArrayList < >();
  27. private List < InlineKeyboardButton > rowInline3 = new ArrayList < >();
  28. private List < InlineKeyboardButton > rowInline4 = new ArrayList < >();
  29. private List < InlineKeyboardButton > rowInline5 = new ArrayList < >();
  30. private List < Integer > sendTTSText = new ArrayList < >();
  31. private List < Integer > sendGlobalPost = new ArrayList < >();
  32. private MySQLUtils MySQL = new MySQLUtils();
  33. private Messages msg = new Messages();
  34.  
  35. @Override
  36. public void onUpdateReceived(Update update) {
  37.  
  38. String DB_URL = "jdbc:mysql://localhost/ttsbot?useUnicode=true&characterEncoding=utf-8&serverTimezone=" + TimeZone.getDefault().getID();
  39. String PASS = "FV4qEpQfkNsrpMg6";
  40. String USER = "root";
  41.  
  42. try (
  43. Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
  44. Statement stmt = conn.createStatement()) {
  45.  
  46. if (update.hasMessage() && update.getMessage().hasText()) {
  47.  
  48. /* Dichiariamo le variabili. */
  49. long chatid = update.getMessage().getChatId();
  50. long userid = update.getMessage().getFrom().getId();
  51. String text = update.getMessage().getText();
  52.  
  53. if (MySQL.isRegistered(userid)) {
  54.  
  55. /* Dichiariamo le variabili. */
  56. String last_name = null;
  57. String first_name = StringEscapeUtils.escapeSql(update.getMessage().getFrom().getFirstName());
  58. String username = null;
  59. int user_id = Math.toIntExact(userid);
  60.  
  61. /* Controlliamo se lastName è null. */
  62. if (update.getMessage().getFrom().getLastName() != null) {
  63. last_name = ("'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getLastName()) + "'");
  64. }
  65.  
  66. /* Controlliamo se username è null. */
  67. if (update.getMessage().getFrom().getUserName() != null) {
  68. username = "'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getUserName()) + "'";
  69. }
  70.  
  71. MySQL.setInfos(userid, first_name, last_name, username);
  72.  
  73. if (update.getMessage().isUserMessage()) {
  74.  
  75. if (text.equals("/start")) {
  76.  
  77. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  78.  
  79. if (MySQL.getLanguage(userid).equals("it")) {
  80.  
  81. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  82.  
  83. rowInline.clear();
  84. rowInline.add(new InlineKeyboardButton().setText("Parla \uD83D\uDCE2").setCallbackData("parla"));
  85. rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
  86.  
  87. rowInline2.clear();
  88. rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
  89.  
  90. rowsInline.clear();
  91. rowsInline.add(rowInline);
  92. rowsInline.add(rowInline2);
  93.  
  94. markupInline.setKeyboard(rowsInline);
  95. 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);
  96. }
  97. else if (MySQL.getLanguage(userid).equals("en")) {
  98. rowInline.clear();
  99. rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
  100. rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
  101.  
  102. rowInline2.clear();
  103. rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
  104.  
  105. rowsInline.clear();
  106. rowsInline.add(rowInline);
  107. rowsInline.add(rowInline2);
  108.  
  109. markupInline.setKeyboard(rowsInline);
  110. 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);
  111. }
  112. else if (MySQL.getLanguage(userid).equals("not_specified")) {
  113. rowInline.clear();
  114. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
  115. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
  116.  
  117. rowsInline.clear();
  118. rowsInline.add(rowInline);
  119.  
  120. markupInline.setKeyboard(rowsInline);
  121. 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);
  122. }
  123. }
  124. else if (text.equals("/admin") && MySQL.isAdmin(userid)) {
  125. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  126. sendTTSText.remove(Integer.valueOf(toIntExact(user_id)));
  127. String sql2 = "SELECT * FROM users WHERE chat_id = " + userid;
  128.  
  129. if (MySQL.getLanguage(userid).equals("it")) {
  130.  
  131. rowInline.clear();
  132. rowInline.add(new InlineKeyboardButton().setText("Utenti \uD83D\uDC65").setCallbackData("manage_users"));
  133. rowInline.add(new InlineKeyboardButton().setText("Post \uD83D\uDCE8").setCallbackData("globalpost"));
  134.  
  135. rowInline2.clear();
  136. rowInline2.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  137.  
  138. rowsInline.clear();
  139. rowsInline.add(rowInline);
  140. rowsInline.add(rowInline2);
  141.  
  142. markupInline.setKeyboard(rowsInline);
  143. 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);
  144. }
  145. else if (MySQL.getLanguage(userid).equals("en")) {
  146. rowInline.clear();
  147. rowInline.add(new InlineKeyboardButton().setText("Users \uD83D\uDC65").setCallbackData("manage_users"));
  148. rowInline.add(new InlineKeyboardButton().setText("Post \uD83D\uDCE8").setCallbackData("globalpost"));
  149.  
  150. rowInline2.clear();
  151. rowInline2.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  152.  
  153. rowsInline.clear();
  154. rowsInline.add(rowInline);
  155. rowsInline.add(rowInline2);
  156.  
  157. markupInline.setKeyboard(rowsInline);
  158. 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);
  159. }
  160. else {
  161. rowInline.clear();
  162. rowInline.add(new InlineKeyboardButton().setText("Users \uD83D\uDC65").setCallbackData("manage_users"));
  163. rowInline.add(new InlineKeyboardButton().setText("Post \uD83D\uDCE8").setCallbackData("globalpost"));
  164.  
  165. rowInline2.clear();
  166. rowInline2.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  167.  
  168. rowsInline.clear();
  169. rowsInline.add(rowInline);
  170. rowsInline.add(rowInline2);
  171.  
  172. markupInline.setKeyboard(rowsInline);
  173. 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);
  174. }
  175. }
  176. else if (sendTTSText.contains(toIntExact(userid))) {
  177. if (MySQL.getLanguage(userid).equals("it")) {
  178. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  179.  
  180. VoiceProvider tts = new VoiceProvider("588cf0f182d74e0d8f60a46ed139d0db");
  181.  
  182. VoiceParameters params = new VoiceParameters(text, Languages.Italian);
  183. params.setCodec(AudioCodec.OGG);
  184. params.setFormat(AudioFormat.Format_48KHZ.AF_48khz_16bit_stereo);
  185. params.setBase64(false);
  186. params.setSSML(false);
  187. params.setRate(0);
  188.  
  189. if (text.length() > 1000) {
  190.  
  191. rowInline.clear();
  192. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  193.  
  194. rowsInline.clear();
  195. rowsInline.add(rowInline);
  196.  
  197. markupInline.setKeyboard(rowsInline);
  198. msg.sm(chatid, "\uD83D\uDEAB <b>Il testo è troppo lungo.</b>", "HTML", markupInline);
  199. }
  200. else {
  201. try {
  202.  
  203. Message msg1 = msg.smMsg(chatid, "\uD83D\uDD0A <b>Creazione audio in corso...</b>", "HTML", null);
  204.  
  205. byte[] voice = tts.speech(params);
  206.  
  207. Random randomNumber = new Random();
  208. int random = randomNumber.nextInt(100000000);
  209.  
  210. FileOutputStream fos = new FileOutputStream("TextToSpeech_" + random + ".ogg");
  211. fos.write(voice, 0, voice.length);
  212. fos.flush();
  213. fos.close();
  214.  
  215. FFmpeg ffmpeg = new FFmpeg("/usr/bin/ffmpeg");
  216. FFprobe ffprobe = new FFprobe("/usr/bin/ffprobe");
  217.  
  218. FFmpegBuilder builder = new FFmpegBuilder()
  219.  
  220. .setInput("TextToSpeech_" + random + ".ogg") // Filename, or a FFmpegProbeResult
  221. .overrideOutputFiles(true) // Override the output if it exists
  222.  
  223. .addOutput("TextToSpeech_" + random + "_opus.ogg") // Filename for the destination
  224.  
  225. .setAudioChannels(1) // Mono audio
  226. .setAudioCodec("libopus") // using the aac codec
  227. .setAudioSampleRate(48_000) // at 48KHz
  228. .setAudioBitRate(32768) // at 32 kbit/s
  229.  
  230. .done();
  231.  
  232. FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
  233.  
  234. executor.createJob(builder).run();
  235.  
  236. File audio = new File("TextToSpeech_" + random + "_opus" + ".ogg");
  237.  
  238. rowInline.clear();
  239. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro_audio"));
  240.  
  241. rowsInline.clear();
  242. rowsInline.add(rowInline);
  243.  
  244. markupInline.setKeyboard(rowsInline);
  245.  
  246. msg.deleteMsg(chatid, msg1.getMessageId());
  247. msg.sendAudio(chatid, audio, markupInline);
  248. }
  249. catch(Exception e) {
  250. e.printStackTrace();
  251. }
  252. }
  253. }
  254. else if (MySQL.getLanguage(userid).equals("en")) {
  255. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  256.  
  257. VoiceProvider tts = new VoiceProvider("588cf0f182d74e0d8f60a46ed139d0db");
  258.  
  259. VoiceParameters params = new VoiceParameters(text, Languages.English_UnitedStates);
  260. params.setCodec(AudioCodec.OGG);
  261. params.setFormat(AudioFormat.Format_48KHZ.AF_48khz_16bit_stereo);
  262. params.setBase64(false);
  263. params.setSSML(false);
  264. params.setRate(0);
  265.  
  266. if (text.length() > 1000) {
  267.  
  268. rowInline.clear();
  269. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  270.  
  271. rowsInline.clear();
  272. rowsInline.add(rowInline);
  273.  
  274. markupInline.setKeyboard(rowsInline);
  275. msg.sm(chatid, "\uD83D\uDEAB <b>Il testo è troppo lungo.</b>", "HTML", markupInline);
  276. }
  277. else {
  278. try {
  279.  
  280. Message msg1 = msg.smMsg(chatid, "\uD83D\uDD0A <b>Creazione audio in corso...</b>", "HTML", null);
  281.  
  282. byte[] voice = tts.speech(params);
  283.  
  284. Random randomNumber = new Random();
  285. int random = randomNumber.nextInt(100000000);
  286.  
  287. FileOutputStream fos = new FileOutputStream("TextToSpeech_" + random + ".ogg");
  288. fos.write(voice, 0, voice.length);
  289. fos.flush();
  290. fos.close();
  291.  
  292. FFmpeg ffmpeg = new FFmpeg("/usr/bin/ffmpeg");
  293. FFprobe ffprobe = new FFprobe("/usr/bin/ffprobe");
  294.  
  295. FFmpegBuilder builder = new FFmpegBuilder()
  296.  
  297. .setInput("TextToSpeech_" + random + ".ogg") // Filename, or a FFmpegProbeResult
  298. .overrideOutputFiles(true) // Override the output if it exists
  299.  
  300. .addOutput("TextToSpeech_" + random + "_opus.ogg") // Filename for the destination
  301.  
  302. .setAudioChannels(1) // Mono audio
  303. .setAudioCodec("libopus") // using the aac codec
  304. .setAudioSampleRate(48_000) // at 48KHz
  305. .setAudioBitRate(32768) // at 32 kbit/s
  306.  
  307. .done();
  308.  
  309. FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
  310.  
  311. executor.createJob(builder).run();
  312.  
  313. File audio = new File("TextToSpeech_" + random + "_opus" + ".ogg");
  314.  
  315. rowInline.clear();
  316. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro_audio"));
  317.  
  318. rowsInline.clear();
  319. rowsInline.add(rowInline);
  320.  
  321. markupInline.setKeyboard(rowsInline);
  322.  
  323. msg.deleteMsg(chatid, msg1.getMessageId());
  324. msg.sendAudio(chatid, audio, markupInline);
  325.  
  326. }
  327. catch(Exception e) {
  328. e.printStackTrace();
  329. }
  330. }
  331. }
  332. else if (MySQL.getLanguage(userid).equals("not_specified")) {
  333. rowInline.clear();
  334. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
  335. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
  336.  
  337. rowsInline.clear();
  338. rowsInline.add(rowInline);
  339.  
  340. markupInline.setKeyboard(rowsInline);
  341. 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);
  342. }
  343. }
  344. else if (sendGlobalPost.contains(toIntExact(userid)) && MySQL.isAdmin(userid)) {
  345. MySQL.sendGlobal(userid, text);
  346. }
  347. else if (text.equals("/start change_lang")) {
  348. rowInline.clear();
  349. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
  350. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
  351.  
  352. rowsInline.clear();
  353. rowsInline.add(rowInline);
  354.  
  355. markupInline.setKeyboard(rowsInline);
  356. 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);
  357. }
  358. }
  359. }
  360. else if (!MySQL.isRegistered(userid)) {
  361.  
  362. /* Dichiariamo le variabili. */
  363. String last_name = null;
  364. String first_name = StringEscapeUtils.escapeSql(update.getMessage().getFrom().getFirstName());
  365. String username = null;
  366.  
  367. /* Se lastname non è null. */
  368. if (update.getMessage().getFrom().getLastName() != null) {
  369. last_name = ("'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getLastName()) + "'");
  370. }
  371.  
  372. /* Se username non è null. */
  373. if (update.getMessage().getFrom().getUserName() != null) {
  374. username = "'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getUserName()) + "'";
  375. }
  376.  
  377. /* Creiamo la query. */
  378. 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'" + ");";
  379.  
  380. /* Eseguiamo la query. */
  381. stmt.executeUpdate(query);
  382.  
  383. if (update.getMessage().isUserMessage()) {
  384. rowInline.clear();
  385. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
  386. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
  387.  
  388. rowsInline.clear();
  389. rowsInline.add(rowInline);
  390.  
  391. markupInline.setKeyboard(rowsInline);
  392. 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);
  393. }
  394. }
  395. }
  396. else if (update.hasCallbackQuery()) {
  397.  
  398. String cb_data = update.getCallbackQuery().getData();
  399. int msgid = toIntExact(update.getCallbackQuery().getMessage().getMessageId());
  400. long chatid = update.getCallbackQuery().getMessage().getChatId();
  401. long userid = update.getCallbackQuery().getFrom().getId();
  402. String query_id = update.getCallbackQuery().getId();
  403.  
  404. if (MySQL.isRegistered(userid)) {
  405.  
  406. /* Dichiariamo le variabili. */
  407. String last_name = null;
  408. String first_name = StringEscapeUtils.escapeSql(update.getCallbackQuery().getFrom().getFirstName());
  409. String username = null;
  410. int user_id = Math.toIntExact(userid);
  411.  
  412. /* Controlliamo se lastName è null. */
  413. if (update.getCallbackQuery().getFrom().getLastName() != null) {
  414. last_name = ("'" + StringEscapeUtils.escapeSql(update.getCallbackQuery().getFrom().getLastName()) + "'");
  415. }
  416.  
  417. /* Controlliamo se username è null. */
  418. if (update.getCallbackQuery().getFrom().getUserName() != null) {
  419. username = "'" + StringEscapeUtils.escapeSql(update.getCallbackQuery().getFrom().getUserName()) + "'";
  420. }
  421.  
  422. /* Creiamo la query. */
  423. String query = "UPDATE users SET first_name='" + first_name + "', last_name=" + last_name + ", username=" + username + " WHERE chat_id=" + user_id;
  424.  
  425. /* Eseguiamo la query. */
  426. stmt.executeUpdate(query);
  427. }
  428.  
  429. /* Se l'utente non è nel db. */
  430. else if (!MySQL.isRegistered(userid)) {
  431.  
  432. /* Dichiariamo le variabili. */
  433. String last_name = null;
  434. String first_name = StringEscapeUtils.escapeSql(update.getMessage().getFrom().getFirstName());
  435. String username = null;
  436.  
  437. /* Se lastname non è null. */
  438. if (update.getMessage().getFrom().getLastName() != null) {
  439. last_name = ("'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getLastName()) + "'");
  440. }
  441.  
  442. /* Se username non è null. */
  443. if (update.getMessage().getFrom().getUserName() != null) {
  444. username = "'" + StringEscapeUtils.escapeSql(update.getMessage().getFrom().getUserName()) + "'";
  445. }
  446.  
  447. /* Creiamo la query. */
  448. 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'" + ");";
  449.  
  450. /* Eseguiamo la query. */
  451. stmt.executeUpdate(query);
  452.  
  453. }
  454.  
  455. if (cb_data.equals("parla")) {
  456.  
  457. if (MySQL.getLanguage(userid).equals("it")) {
  458. sendTTSText.add(toIntExact(userid));
  459.  
  460. rowInline.clear();
  461. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  462.  
  463. rowsInline.clear();
  464. rowsInline.add(rowInline);
  465.  
  466. markupInline.setKeyboard(rowsInline);
  467. msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCAD <b>Invia ora il testo.</b>", "HTML", markupInline);
  468. }
  469. else if (MySQL.getLanguage(userid).equals("en")) {
  470. sendTTSText.add(toIntExact(userid));
  471.  
  472. rowInline.clear();
  473. rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  474.  
  475. rowsInline.clear();
  476. rowsInline.add(rowInline);
  477.  
  478. markupInline.setKeyboard(rowsInline);
  479. msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCAD <b>Now send the text.</b>", "HTML", markupInline);
  480. }
  481. else {
  482. sendTTSText.add(toIntExact(userid));
  483.  
  484. rowInline.clear();
  485. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  486.  
  487. rowsInline.clear();
  488. rowsInline.add(rowInline);
  489.  
  490. markupInline.setKeyboard(rowsInline);
  491. msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCAD <b>Invia ora il testo.</b>", "HTML", markupInline);
  492. }
  493. }
  494. else if (cb_data.equals("indietro")) {
  495. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  496. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  497.  
  498. if (MySQL.getLanguage(userid).equals("it")) {
  499. rowInline.clear();
  500. rowInline.add(new InlineKeyboardButton().setText("Parla ora \uD83D\uDCE2").setCallbackData("parla"));
  501. rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
  502.  
  503. rowInline2.clear();
  504. rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
  505.  
  506. rowsInline.clear();
  507. rowsInline.add(rowInline);
  508. rowsInline.add(rowInline2);
  509.  
  510. markupInline.setKeyboard(rowsInline);
  511. 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);
  512. }
  513. else if (MySQL.getLanguage(userid).equals("en")) {
  514. rowInline.clear();
  515. rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
  516. rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
  517.  
  518. rowInline2.clear();
  519. rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
  520.  
  521. rowsInline.clear();
  522. rowsInline.add(rowInline);
  523. rowsInline.add(rowInline2);
  524.  
  525. markupInline.setKeyboard(rowsInline);
  526. 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);
  527. }
  528. }
  529. else if (cb_data.equals("info")) {
  530. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  531. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  532.  
  533. if (MySQL.getLanguage(userid).equals("it")) {
  534. rowInline.clear();
  535. rowInline.add(new InlineKeyboardButton().setText("Developer \uD83D\uDDF3").setUrl("https://t.me/Fumaz"));
  536. rowInline2.clear();
  537. rowInline2.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  538.  
  539. rowsInline.clear();
  540. rowsInline.add(rowInline);
  541. rowsInline.add(rowInline2);
  542.  
  543. markupInline.setKeyboard(rowsInline);
  544. 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);
  545. }
  546. else if (MySQL.getLanguage(userid).equals("en")) {
  547. rowInline.clear();
  548. rowInline.add(new InlineKeyboardButton().setText("Developer \uD83D\uDDF3").setUrl("https://t.me/Fumaz"));
  549. rowInline2.clear();
  550. rowInline2.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  551.  
  552. rowsInline.clear();
  553. rowsInline.add(rowInline);
  554. rowsInline.add(rowInline2);
  555.  
  556. markupInline.setKeyboard(rowsInline);
  557. 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);
  558. }
  559. }
  560. else if (cb_data.equals("lang_it")) {
  561. String sql2 = "UPDATE users SET language='it' WHERE chat_id=" + userid;
  562.  
  563. stmt.executeUpdate(sql2);
  564.  
  565. rowInline.clear();
  566. rowInline.add(new InlineKeyboardButton().setText("Parla \uD83D\uDCE2").setCallbackData("parla"));
  567. rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
  568.  
  569. rowInline2.clear();
  570. rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
  571.  
  572. rowsInline.clear();
  573. rowsInline.add(rowInline);
  574. rowsInline.add(rowInline2);
  575.  
  576. markupInline.setKeyboard(rowsInline);
  577. 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);
  578. }
  579. else if (cb_data.equals("lang_en")) {
  580. String sql2 = "UPDATE users SET language='en' WHERE chat_id=" + userid;
  581.  
  582. stmt.executeUpdate(sql2);
  583.  
  584. rowInline.clear();
  585. rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
  586. rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
  587.  
  588. rowInline2.clear();
  589. rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
  590.  
  591. rowsInline.clear();
  592. rowsInline.add(rowInline);
  593. rowsInline.add(rowInline2);
  594.  
  595. markupInline.setKeyboard(rowsInline);
  596. 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);
  597. }
  598. else if (cb_data.equals("change_language")) {
  599. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  600. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  601.  
  602. rowInline.clear();
  603. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
  604. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
  605.  
  606. rowsInline.clear();
  607. rowsInline.add(rowInline);
  608.  
  609. markupInline.setKeyboard(rowsInline);
  610. 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);
  611. }
  612. else if (cb_data.equals("indietro_audio")) {
  613. msg.replyQuery(query_id);
  614. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  615.  
  616. if (MySQL.getLanguage(userid).equals("it")) {
  617.  
  618. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  619.  
  620. rowInline.clear();
  621. rowInline.add(new InlineKeyboardButton().setText("Parla \uD83D\uDCE2").setCallbackData("parla"));
  622. rowInline.add(new InlineKeyboardButton().setText("Lingua \uD83C\uDDEE\uD83C\uDDF9").setCallbackData("change_language"));
  623.  
  624. rowInline2.clear();
  625. rowInline2.add(new InlineKeyboardButton().setText("Info sul bot \uD83D\uDCE6").setCallbackData("info"));
  626.  
  627. rowsInline.clear();
  628. rowsInline.add(rowInline);
  629. rowsInline.add(rowInline2);
  630.  
  631. markupInline.setKeyboard(rowsInline);
  632. 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);
  633. }
  634. else if (MySQL.getLanguage(userid).equals("en")) {
  635. rowInline.clear();
  636. rowInline.add(new InlineKeyboardButton().setText("Talk \uD83D\uDCE2").setCallbackData("parla"));
  637. rowInline.add(new InlineKeyboardButton().setText("Language \uD83C\uDDFA\uD83C\uDDF8").setCallbackData("change_language"));
  638.  
  639. rowInline2.clear();
  640. rowInline2.add(new InlineKeyboardButton().setText("Bot infos \uD83D\uDCE6").setCallbackData("info"));
  641.  
  642. rowsInline.clear();
  643. rowsInline.add(rowInline);
  644. rowsInline.add(rowInline2);
  645.  
  646. markupInline.setKeyboard(rowsInline);
  647. 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);
  648. }
  649. else {
  650. rowInline.clear();
  651. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDEE\uD83C\uDDF9").setCallbackData("lang_it"));
  652. rowInline.add(new InlineKeyboardButton().setText("\uD83C\uDDFA\uD83C\uDDF8").setCallbackData("lang_en"));
  653.  
  654. rowsInline.clear();
  655. rowsInline.add(rowInline);
  656.  
  657. markupInline.setKeyboard(rowsInline);
  658. 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);
  659. }
  660. }
  661. else if (cb_data.equals("manage_users")) {
  662. sendGlobalPost.remove(Integer.valueOf(toIntExact(userid)));
  663. sendTTSText.remove(Integer.valueOf(toIntExact(userid)));
  664.  
  665. if (MySQL.getLanguage(userid).equals("it")) {
  666. String sql3 = "SELECT * FROM users";
  667.  
  668. ResultSet rs3 = stmt.executeQuery(sql3);
  669.  
  670. String utenti = "";
  671. int count = 0;
  672. while (rs3.next()) {
  673. count++;
  674. String dbfirst_name = rs3.getString("first_name");
  675. int dbuserid = rs3.getInt("chat_id");
  676.  
  677. if (rs3.getBoolean("blocked")) {
  678. utenti = utenti + "» <a href='tg://user?id=" + dbuserid + "'>" + dbfirst_name + "</a> [" + dbuserid + "] [BLOCCATO]" + "\n";
  679. } else {
  680. utenti = utenti + "» <a href='tg://user?id=" + dbuserid + "'>" + dbfirst_name + "</a> [" + dbuserid + "]" + "\n";
  681. }
  682. }
  683.  
  684. rowInline.clear();
  685. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  686.  
  687. rowsInline.clear();
  688. rowsInline.add(rowInline);
  689.  
  690. markupInline.setKeyboard(rowsInline);
  691.  
  692. msg.cb_reply(userid, msgid, query_id, "\uD83D\uDC65 <b>LISTA UTENTI [" + count + "]</b>\n\n" + utenti, "HTML", markupInline);
  693. }
  694. else if (MySQL.getLanguage(userid).equals("en")) {
  695. String sql3 = "SELECT * FROM users";
  696.  
  697. ResultSet rs3 = stmt.executeQuery(sql3);
  698.  
  699. String utenti = "";
  700. int count = 0;
  701. while (rs3.next()) {
  702. count++;
  703. String dbfirst_name = rs3.getString("first_name");
  704. int dbuserid = rs3.getInt("chat_id");
  705.  
  706. utenti = utenti + "» " + dbfirst_name + " [" + dbuserid + "]" + "\n";
  707. }
  708.  
  709. rowInline.clear();
  710. rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  711.  
  712. rowsInline.clear();
  713. rowsInline.add(rowInline);
  714.  
  715. markupInline.setKeyboard(rowsInline);
  716.  
  717. msg.cb_reply(userid, msgid, query_id, "\uD83D\uDC65 <b>USERS LIST [" + count + "]</b>\n\n" + utenti, "HTML", markupInline);
  718. }
  719. else {
  720. String sql3 = "SELECT * FROM users";
  721.  
  722. ResultSet rs3 = stmt.executeQuery(sql3);
  723.  
  724. String utenti = "";
  725. int count = 0;
  726. while (rs3.next()) {
  727. count++;
  728. String dbfirst_name = rs3.getString("first_name");
  729. int dbuserid = rs3.getInt("chat_id");
  730.  
  731. utenti = utenti + "» " + dbfirst_name + " [" + dbuserid + "]" + "\n";
  732. }
  733.  
  734. rowInline.clear();
  735. rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  736.  
  737. rowsInline.clear();
  738. rowsInline.add(rowInline);
  739.  
  740. markupInline.setKeyboard(rowsInline);
  741.  
  742. msg.cb_reply(userid, msgid, query_id, "\uD83D\uDC65 <b>USERS LIST [" + count + "]</b>\n\n" + utenti, "HTML", markupInline);
  743. }
  744. }
  745. else if (cb_data.equals("globalpost") && MySQL.isAdmin(userid)) {
  746. sendGlobalPost.add(toIntExact(userid));
  747.  
  748. if (MySQL.getLanguage(userid).equals("it")) {
  749. rowInline.clear();
  750. rowInline.add(new InlineKeyboardButton().setText("Indietro ↩️").setCallbackData("indietro"));
  751.  
  752. rowsInline.clear();
  753. rowsInline.add(rowInline);
  754.  
  755. markupInline.setKeyboard(rowsInline);
  756. msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCEC <b>Invia ora il testo.</b>", "HTML", markupInline);
  757. }
  758. else if (MySQL.getLanguage(userid).equals("en")) {
  759. rowInline.clear();
  760. rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  761.  
  762. rowsInline.clear();
  763. rowsInline.add(rowInline);
  764.  
  765. markupInline.setKeyboard(rowsInline);
  766. msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCEC <b>Now send the text.</b>", "HTML", markupInline);
  767. }
  768. else {
  769. rowInline.clear();
  770. rowInline.add(new InlineKeyboardButton().setText("Back ↩️").setCallbackData("indietro"));
  771.  
  772. rowsInline.clear();
  773. rowsInline.add(rowInline);
  774.  
  775. markupInline.setKeyboard(rowsInline);
  776. msg.cb_reply(chatid, msgid, query_id, "\uD83D\uDCEC <b>Now send the text.</b>", "HTML", markupInline);
  777. }
  778. }
  779. }
  780. } catch(SQLException e) {
  781. e.printStackTrace();
  782. }
  783. }
  784. /* Se l'utente non è nel db. */
  785.  
  786. @Override
  787. public String getBotUsername() {
  788. return "TextToSpeechRobot";
  789. }
  790.  
  791. @Override
  792. public String getBotToken() {
  793. return "674389619:AAEvDHpm29qZ3aroWNcrHfP6Mxca6RLx0NM";
  794. }
  795. }
Add Comment
Please, Sign In to add comment