├── oldVersion ├── id ├── src │ ├── main │ │ └── java │ │ │ ├── packages │ │ │ └── inutile │ │ │ │ ├── Image.java │ │ │ │ ├── Propic.java │ │ │ │ ├── ClassiInutile.java │ │ │ │ └── Push.java │ │ │ ├── reloaded │ │ │ └── convintobot │ │ │ │ ├── tResponse │ │ │ │ ├── Response.java │ │ │ │ ├── Inline.java │ │ │ │ └── Commands.java │ │ │ │ ├── Live.java │ │ │ │ ├── Info.java │ │ │ │ ├── ExceptionAlert.java │ │ │ │ ├── Download.java │ │ │ │ ├── Youtube.java │ │ │ │ ├── Settings.java │ │ │ │ ├── Phrase.java │ │ │ │ ├── FileO.java │ │ │ │ └── Main.java │ │ │ ├── asd │ │ │ └── it │ │ │ └── TetrisReich │ │ │ └── bot │ │ │ └── TestBot │ │ │ ├── Download.java │ │ │ ├── Chan.java │ │ │ ├── Clive.java │ │ │ ├── Jar.java │ │ │ ├── Startup.java │ │ │ ├── FileO.java │ │ │ ├── App.java │ │ │ └── MyRunnable.java │ └── test │ │ └── java │ │ └── it │ │ └── TetrisReich │ │ └── bot │ │ └── TestBot │ │ └── AppTest.java ├── target │ ├── classes │ │ ├── packages │ │ │ └── inutile │ │ │ │ ├── Image.class │ │ │ │ ├── Push.class │ │ │ │ ├── Propic.class │ │ │ │ └── ClassiInutile.class │ │ ├── META-INF │ │ │ ├── MANIFEST.MF │ │ │ └── maven │ │ │ │ ├── reloaded │ │ │ │ └── convintobot │ │ │ │ │ ├── pom.properties │ │ │ │ │ └── pom.xml │ │ │ │ └── it.TetrisReich.bot │ │ │ │ └── TestBot │ │ │ │ ├── pom.properties │ │ │ │ └── pom.xml │ │ ├── reloaded │ │ │ └── convintobot │ │ │ │ ├── FileO.class │ │ │ │ ├── Info.class │ │ │ │ ├── Live.class │ │ │ │ ├── Main.class │ │ │ │ ├── Phrase.class │ │ │ │ ├── Download.class │ │ │ │ ├── Settings.class │ │ │ │ ├── Youtube.class │ │ │ │ ├── ExceptionAlert.class │ │ │ │ └── tResponse │ │ │ │ ├── Inline.class │ │ │ │ ├── Commands.class │ │ │ │ └── Response.class │ │ ├── it │ │ │ └── TetrisReich │ │ │ │ └── bot │ │ │ │ └── TestBot │ │ │ │ ├── App.class │ │ │ │ ├── Chan.class │ │ │ │ ├── Clive.class │ │ │ │ ├── FileO.class │ │ │ │ ├── Jar.class │ │ │ │ ├── Startup.class │ │ │ │ ├── Download.class │ │ │ │ └── MyRunnable.class │ │ └── asd │ └── test-classes │ │ └── it │ │ └── TetrisReich │ │ └── bot │ │ └── TestBot │ │ └── AppTest.class ├── nullconfig.json ├── pom.xml └── ZombiHunter.java ├── newVersion ├── web │ ├── logo.png │ ├── scelto.jpg │ ├── BerlinSansFB.ttf │ ├── acceptSub.html │ └── redirect.html ├── code │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── .project │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── reloaded │ │ │ └── convintobot │ │ │ ├── tResponse │ │ │ ├── Response.java │ │ │ ├── Inline.java │ │ │ └── Commands.java │ │ │ ├── Format.java │ │ │ ├── LiveNotification.java │ │ │ ├── Chats.java │ │ │ ├── ExceptionAlert.java │ │ │ ├── Live.java │ │ │ ├── Youtube.java │ │ │ ├── Info.java │ │ │ ├── GroupUser.java │ │ │ ├── Twitch.java │ │ │ ├── Download.java │ │ │ ├── FileO.java │ │ │ ├── Phrase.java │ │ │ └── Settings.java │ ├── .classpath │ └── pom.xml └── commands │ ├── twverify.json │ ├── twitch.json │ ├── last.json │ ├── ping.json │ ├── github.json │ ├── admin.json │ ├── news.json │ ├── stat.json │ ├── subMessages.json │ ├── help.json │ ├── start.json │ └── sub.json └── README.md /oldVersion/id: -------------------------------------------------------------------------------- 1 | https://youtu.be/GefvLSjzepk -------------------------------------------------------------------------------- /newVersion/web/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/newVersion/web/logo.png -------------------------------------------------------------------------------- /newVersion/web/scelto.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/newVersion/web/scelto.jpg -------------------------------------------------------------------------------- /newVersion/web/BerlinSansFB.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/newVersion/web/BerlinSansFB.ttf -------------------------------------------------------------------------------- /oldVersion/src/main/java/packages/inutile/Image.java: -------------------------------------------------------------------------------- 1 | package packages.inutile; 2 | 3 | public class Image { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/packages/inutile/Propic.java: -------------------------------------------------------------------------------- 1 | package packages.inutile; 2 | 3 | public class Propic { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /newVersion/code/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /oldVersion/target/classes/packages/inutile/Image.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/packages/inutile/Image.class -------------------------------------------------------------------------------- /oldVersion/target/classes/packages/inutile/Push.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/packages/inutile/Push.class -------------------------------------------------------------------------------- /oldVersion/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Luca 3 | Build-Jdk: 1.8.0_72 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /oldVersion/target/classes/packages/inutile/Propic.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/packages/inutile/Propic.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/FileO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/FileO.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Info.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Live.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Live.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Main.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Phrase.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Phrase.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Download.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Download.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Settings.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Settings.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/Youtube.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/Youtube.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/App.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/Chan.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/Chan.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/Clive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/Clive.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/FileO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/FileO.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/Jar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/Jar.class -------------------------------------------------------------------------------- /oldVersion/target/classes/packages/inutile/ClassiInutile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/packages/inutile/ClassiInutile.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/Startup.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/Startup.class -------------------------------------------------------------------------------- /newVersion/code/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/Download.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/Download.class -------------------------------------------------------------------------------- /oldVersion/target/classes/it/TetrisReich/bot/TestBot/MyRunnable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/it/TetrisReich/bot/TestBot/MyRunnable.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/ExceptionAlert.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/ExceptionAlert.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/tResponse/Inline.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/tResponse/Inline.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/tResponse/Commands.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/tResponse/Commands.class -------------------------------------------------------------------------------- /oldVersion/target/classes/reloaded/convintobot/tResponse/Response.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/classes/reloaded/convintobot/tResponse/Response.class -------------------------------------------------------------------------------- /oldVersion/target/test-classes/it/TetrisReich/bot/TestBot/AppTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stranck/ConvintoBot/HEAD/oldVersion/target/test-classes/it/TetrisReich/bot/TestBot/AppTest.class -------------------------------------------------------------------------------- /newVersion/commands/twverify.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 0, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "6" 9 | ], 10 | "args" : { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /newVersion/commands/twitch.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "%twitch%" 9 | ], 10 | "args" : { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /newVersion/commands/last.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "%lastvideo%" 9 | ], 10 | "args" : { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /oldVersion/target/classes/META-INF/maven/reloaded/convintobot/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Tue Feb 28 11:32:44 CET 2017 3 | version=0.0.1-SNAPSHOT 4 | groupId=reloaded 5 | m2e.projectName=TestBot 6 | m2e.projectLocation=C\:\\Users\\Luca\\workspace\\TestBot 7 | artifactId=convintobot 8 | -------------------------------------------------------------------------------- /oldVersion/target/classes/META-INF/maven/it.TetrisReich.bot/TestBot/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Fri Feb 24 17:18:04 CET 2017 3 | version=0.0.1-SNAPSHOT 4 | groupId=it.TetrisReich.bot 5 | m2e.projectName=TestBot 6 | m2e.projectLocation=C\:\\Users\\Luca\\workspace\\TestBot 7 | artifactId=TestBot 8 | -------------------------------------------------------------------------------- /newVersion/commands/ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "Pong", 9 | "Peng", 10 | "Non so come rispondere." 11 | ], 12 | "args" : { 13 | "pang" : 1, 14 | "pung" : 2 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /newVersion/commands/github.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "Vuoi vedere quale convinzione si cela tra i miei codici?\nBene, premi qui!" 9 | ], 10 | "args" : { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /oldVersion/src/main/java/packages/inutile/ClassiInutile.java: -------------------------------------------------------------------------------- 1 | package packages.inutile; 2 | 3 | public class ClassiInutile { 4 | //public class ClasseInutile { 5 | 6 | public static Image propic(Propic my){ 7 | 8 | 9 | return null; 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | } 24 | 25 | 26 | 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /newVersion/commands/admin.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 0, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : true, 6 | "responseData" : { 7 | "response" : [ 8 | "1", 9 | "2", 10 | "3", 11 | "4", 12 | "5" 13 | ], 14 | "args" : { 15 | "force" : 0, 16 | "reload" : 1, 17 | "file" : 2, 18 | "program" : 3, 19 | "html" : 4 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /newVersion/commands/news.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 4, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : false, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "Qui sotto il canale con tutte le news del mio creatore!" 9 | ], 10 | "args" : { 11 | }, 12 | "inline" : [ 13 | [ 14 | { 15 | "type" : 0, 16 | "text" : "Click me >.<", 17 | "data" : "https://t.me/MultychatNews" 18 | } 19 | ] 20 | ] 21 | } 22 | } -------------------------------------------------------------------------------- /oldVersion/nullconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "gToken" : "INSERIT YOUR GOOGLE APIS TOKEN HERE", 3 | "tToken" : "INSERIT YOUR TELEGRAM TOKEN HERE", 4 | "id" : "INSERIT YOUR CHANNEL ID HERE", 5 | "chat" : "INSERIT THE CHAT ID HERE", 6 | "botName" : "INSERIT THE NAME OF YOUR BOT HERE", 7 | "admins" : [ 8 | "INSERIT THE TELEGRAM ACCOUNT ID OF YOUR FIRST ADMIN HERE", 9 | "INSERIT THE TELEGRAM ACCOUNT ID OF YOUR SECOND ADMIN HERE", 10 | "...", 11 | ] 12 | } -------------------------------------------------------------------------------- /newVersion/web/acceptSub.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Please wait 5 | 6 | 7 |

Please wait

8 |

If you're stuck here, please try again. If the problem persists, try from a different browser.

9 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /newVersion/code/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TestBot 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /newVersion/commands/stat.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : true, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "ALL STAT ARE ONLY OF THIS SESSION!!!\n\nPhrase status: %phraseStatus%\nChannel id: %id%\nChat id: %chat%\nBot name: %botName%\nDefault directory: %dir%\nUptime: %uptime%\nVersion: %version%\n\nProgrammed by Stranck.", 9 | "STATS:\nPhrase status: %phraseStatus%\nChannel id: %id%\nChat id: %chat%\nBot name: %botName%\nDefault directory: %dir%\nUptime: %uptime%\nVersion: %version%\n" 10 | ], 11 | "args" : { 12 | "low" : 1 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/tResponse/Response.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot.tResponse; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.json.JSONObject; 6 | 7 | public class Response { 8 | 9 | private ArrayList response = new ArrayList(); 10 | private JSONObject args; 11 | 12 | public void addResponse(String r){ 13 | response.add(r); 14 | } 15 | 16 | public void setResponse(ArrayList r){ 17 | response = r; 18 | } 19 | public void setArgs(JSONObject a){ 20 | args = a; 21 | } 22 | 23 | public ArrayList getResponse(){ 24 | return response; 25 | } 26 | public JSONObject getArgs(){ 27 | return args; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/tResponse/Response.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot.tResponse; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.json.JSONObject; 6 | 7 | public class Response { 8 | 9 | private ArrayList response = new ArrayList(); 10 | private JSONObject args; 11 | 12 | public void addResponse(String r){ 13 | response.add(r); 14 | } 15 | 16 | public void setResponse(ArrayList r){ 17 | response = r; 18 | } 19 | public void setArgs(JSONObject a){ 20 | args = a; 21 | } 22 | 23 | public ArrayList getResponse(){ 24 | return response; 25 | } 26 | public JSONObject getArgs(){ 27 | return args; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /newVersion/commands/subMessages.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : true, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "why u do diz", 9 | "Caricamento dei dati del tuo canale in corso. Attendere prego...", 10 | "Fatto! Stato attuale: %sub%\n\nUsa il pulsante qui sotto per entrare nel gruppo ufficiale di %twitchUser% :D", 11 | "Si è verificato un problema... Sicuro di essere abbonato?\n\nSe credi si tratti di un errore, riprova, oppure contattami su Telegram", 12 | 13 | ], 14 | "args" : { 15 | "loading" : 1, 16 | "done" : 2, 17 | "error" : 3 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /oldVersion/src/main/java/packages/inutile/Push.java: -------------------------------------------------------------------------------- 1 | package packages.inutile; 2 | 3 | import org.apache.commons.lang3.ArrayUtils; 4 | 5 | public class Push { 6 | /*public Live[] push(Live[] array, Live push) { 7 | Live[] longer = new Live[array.length + 1]; 8 | for (int i = 0; i < array.length; i++) longer[i] = array[i]; 9 | longer[array.length] = push; 10 | return longer; 11 | } 12 | public Live[] removeIndex(Live[] array, int remove){ 13 | return ArrayUtils.removeElement(array, remove); 14 | } 15 | public String[] shift(String[] array, String shift){ 16 | String[] shifted = new String[array.length]; 17 | shifted[0] = shift; 18 | for(int i = 1; i < shifted.length; i++) shifted[i] = array[i - 1]; 19 | return shifted; 20 | }*/ 21 | } 22 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Format.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.logging.Formatter; 6 | import java.util.logging.LogRecord; 7 | 8 | public class Format extends Formatter{ 9 | 10 | public Format() { 11 | super(); 12 | } 13 | 14 | @Override 15 | public String format(final LogRecord record){ 16 | return "[" + time("dd/MM/yyyy-HH:mm:ss") + "][" + record.getLevel() + "]\t" + record.getMessage().replaceAll("\n", "") + "\n"; 17 | } 18 | 19 | private String time(String format) { 20 | SimpleDateFormat sdfDate = new SimpleDateFormat(format); 21 | Date now = new Date(); 22 | String strDate = sdfDate.format(now); 23 | return strDate; 24 | } 25 | } -------------------------------------------------------------------------------- /newVersion/code/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/Live.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | public class Live { 4 | private String id, title; 5 | private int type, messageId; 6 | public Live(String name, String liveId, int videoType, int mId){ 7 | title = name; 8 | id = liveId; 9 | type = videoType; 10 | messageId = mId; 11 | //if(type==2) upcoming = true; 12 | } 13 | 14 | public void setType(int videoType){ 15 | type = videoType; 16 | } 17 | 18 | public int getMessageId(){ 19 | return messageId; 20 | } 21 | public int getType(){ 22 | return type; 23 | } 24 | public String getId(){ 25 | return id; 26 | } 27 | public String getTitle(){ 28 | return title; 29 | } 30 | //public boolean stillupcoming(int type){ //0 = live stopped, 2 = still live, 3 = switch from upcoming to live, 4 = still upcoming 31 | ////} 32 | } 33 | -------------------------------------------------------------------------------- /oldVersion/src/test/java/it/TetrisReich/bot/TestBot/AppTest.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/LiveNotification.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import com.pengrad.telegrambot.TelegramBot; 4 | import com.pengrad.telegrambot.request.DeleteMessage; 5 | import com.pengrad.telegrambot.request.SendMessage; 6 | import com.pengrad.telegrambot.response.SendResponse; 7 | 8 | public class LiveNotification implements Runnable { 9 | 10 | private TelegramBot bot; 11 | private String title, chat, f; 12 | 13 | public LiveNotification(TelegramBot b, String p, String t, String c){ 14 | bot = b; 15 | f = p; 16 | title = t; 17 | chat = c; 18 | } 19 | 20 | public void run() { 21 | try { 22 | SendResponse sr = bot.execute(new SendMessage(chat, f + "\n" + title)); 23 | Main.wait(1500); 24 | bot.execute(new DeleteMessage(chat, 25 | sr.message().messageId())); 26 | 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | Main.ea.alert(e); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/tResponse/Inline.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot.tResponse; 2 | 3 | import com.pengrad.telegrambot.model.request.InlineKeyboardButton; 4 | 5 | public class Inline { 6 | private String text, data; 7 | private byte type; //0 = url, 1 = callBackData, 2 = callBackGame, 3 = switchInlineQuery, 4 = switchInlineQueryCurrentChat 8 | 9 | public Inline(String t, String d, int i){ 10 | text = t; 11 | data = d; 12 | type = (byte) i; 13 | } 14 | 15 | public InlineKeyboardButton getButton(){ 16 | switch(type){ 17 | case 0: return new InlineKeyboardButton(text).url(data); 18 | case 1: return new InlineKeyboardButton(text).callbackData(data); 19 | case 2: return new InlineKeyboardButton(text).callbackGame(data); 20 | case 3: return new InlineKeyboardButton(text).switchInlineQuery(data); 21 | case 4: return new InlineKeyboardButton(text).switchInlineQueryCurrentChat(data); 22 | } 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /newVersion/commands/help.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : true, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "Salve! Benvenuto in %botName% :D\n 9 | Questo bot ha il compito di condividere tutti i nuovi video di chivuoitu sul canale telegram sempre di chivuoitu, in questo caso %chat%.\n 10 | \nEcco qui una piccola lista di comandi:\n 11 | /last per ottenere l'ultimo mio video.\n 12 | /github per ottenere il link di github contenente il mio codice.\n 13 | /start o /help per visualizzare questo messaggio.\n 14 | /news per ricevere le notizie su questo ed altri bot del mio creatore.\n 15 | /stat per vedere le statistiche della sessione corrente del bot.\n\n 16 | Per bug report, maggiori informazioni o se vuoi usarmi per il tuo canale youtube contattami per email qui: public.stranck@gmail.com", 17 | "Come mi hai scoperto? D:" 18 | ], 19 | "args" : { 20 | "testsegreto" : 1 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /newVersion/commands/start.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 1, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : true, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "Salve! Benvenuto in %botName% :D\n 9 | Questo bot ha il compito di condividere tutti i nuovi video di chivuoitu sul canale telegram sempre di chivuoitu, in questo caso %chat%.\n 10 | \nEcco qui una piccola lista di comandi:\n 11 | /last per ottenere l'ultimo mio video.\n 12 | /github per ottenere il link di github contenente il mio codice.\n 13 | /start o /help per visualizzare questo messaggio.\n 14 | /news per ricevere le notizie su questo ed altri bot del mio creatore.\n 15 | /stat per vedere le statistiche della sessione corrente del bot.\n\n 16 | Per bug report, maggiori informazioni o se vuoi usarmi per il tuo canale youtube contattami per email qui: public.stranck@gmail.com", 17 | "Come mi hai scoperto? D:" 18 | ], 19 | "args" : { 20 | "testsegreto" : 1 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /newVersion/code/.classpath: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /newVersion/code/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | reloaded 6 | convintobot 7 | 2.0.0 8 | jar 9 | 10 | convintobot 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | com.github.pengrad 20 | java-telegram-bot-api 21 | 3.1.0 22 | 23 | 24 | org.json 25 | json 26 | 20171018 27 | 28 | 29 | 30 | org.apache.httpcomponents 31 | httpclient 32 | 4.5.3 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/asd: -------------------------------------------------------------------------------- 1 | String server = "www.myserver.com"; 2 | int port = 21; 3 | String user = "user"; 4 | String pass = "pass"; 5 | 6 | FTPClient ftpClient = new FTPClient(); 7 | try { 8 | 9 | ftpClient.connect(server, port); 10 | ftpClient.login(user, pass); 11 | ftpClient.enterLocalPassiveMode(); 12 | ftpClient.setFileType(FTP.BINARY_FILE_TYPE); 13 | 14 | 15 | String remoteFile1 = "/test/video.mp4"; 16 | File downloadFile1 = new File("D:/Downloads/video.mp4"); 17 | OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1)); 18 | boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1); 19 | outputStream1.close(); 20 | if (success) { 21 | System.out.println("File #1 has been downloaded successfully."); 22 | } 23 | 24 | } catch (IOException ex) { 25 | System.out.println("Error: " + ex.getMessage()); 26 | ex.printStackTrace(); 27 | } finally { 28 | try { 29 | if (ftpClient.isConnected()) { 30 | ftpClient.logout(); 31 | ftpClient.disconnect(); 32 | } 33 | } catch (IOException ex) { 34 | ex.printStackTrace(); 35 | } 36 | } 37 | 38 | 39 | 40 | 41 | commons-net 42 | commons-net 43 | 3.3 44 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/Info.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import org.json.JSONObject; 4 | 5 | public class Info { 6 | private String id, type, name; 7 | 8 | public void update(int n, Settings s){ 9 | while(true){ //this gibe me cancer 10 | try { 11 | JSONObject data = new JSONObject(Download.dwn(s.getGoogleApiFullUrl(n + 1))).getJSONArray("items").getJSONObject(n); 12 | JSONObject snippet = data.getJSONObject("snippet"); 13 | id = data.getJSONObject("id").getString("videoId"); 14 | type = snippet.getString("liveBroadcastContent"); 15 | name = snippet.getString("title"); 16 | return; 17 | } catch (Exception e) { 18 | Main.ea.alert(e); 19 | Main.wait(5000); 20 | } 21 | } 22 | } 23 | 24 | public String getVideoType(String id, Settings s){ 25 | while(true){ 26 | try{ 27 | return new JSONObject(Download.dwn(s.getUrlVideoType(id))).getJSONArray("items").getJSONObject(0).getJSONObject("snippet").getString("liveBroadcastContent"); 28 | }catch(Exception e){ 29 | Main.ea.alert(e); 30 | Main.wait(5000); 31 | } 32 | } 33 | } 34 | 35 | public String getVideoId(){ 36 | return id; 37 | } 38 | public String getVideoType(){ 39 | return type; 40 | } 41 | public String getVideoName(){ 42 | return name; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /oldVersion/target/classes/asd: -------------------------------------------------------------------------------- 1 | String server = "www.myserver.com"; 2 | int port = 21; 3 | String user = "user"; 4 | String pass = "pass"; 5 | 6 | FTPClient ftpClient = new FTPClient(); 7 | try { 8 | 9 | ftpClient.connect(server, port); 10 | ftpClient.login(user, pass); 11 | ftpClient.enterLocalPassiveMode(); 12 | ftpClient.setFileType(FTP.BINARY_FILE_TYPE); 13 | 14 | 15 | String remoteFile1 = "/test/video.mp4"; 16 | File downloadFile1 = new File("D:/Downloads/video.mp4"); 17 | OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1)); 18 | boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1); 19 | outputStream1.close(); 20 | if (success) { 21 | System.out.println("File #1 has been downloaded successfully."); 22 | } 23 | 24 | } catch (IOException ex) { 25 | System.out.println("Error: " + ex.getMessage()); 26 | ex.printStackTrace(); 27 | } finally { 28 | try { 29 | if (ftpClient.isConnected()) { 30 | ftpClient.logout(); 31 | ftpClient.disconnect(); 32 | } 33 | } catch (IOException ex) { 34 | ex.printStackTrace(); 35 | } 36 | } 37 | 38 | 39 | 40 | 41 | commons-net 42 | commons-net 43 | 3.3 44 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Chats.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | public class Chats { 4 | private boolean pin, pinNotification, twitch, youtube, onUpcoming, onStop, repeat; 5 | private String chat, lessSpamMethod; 6 | 7 | public Chats(String c, String lsm, boolean p, boolean ou, boolean os, boolean r){ 8 | chat = c; 9 | lessSpamMethod = lsm; 10 | pin = p; 11 | onUpcoming = ou; 12 | onStop = os; 13 | repeat = r; 14 | } 15 | 16 | public void setIfYoutube(boolean b){ 17 | youtube = b; 18 | } 19 | public void setIfTwitch(boolean b){ 20 | twitch = b; 21 | } 22 | public void setPiNotification(boolean b){ 23 | pinNotification = b; 24 | } 25 | 26 | public String getChatId(){ 27 | return chat; 28 | } 29 | public String getLessSpamMethod(){ 30 | return lessSpamMethod; 31 | } 32 | public boolean getIfRepeat(){ 33 | return repeat; 34 | } 35 | public boolean getIfNotificationOnUpcoming(){ 36 | return onUpcoming; 37 | } 38 | public boolean getIfNotificationOnStop(){ 39 | return onStop; 40 | } 41 | public boolean getIfYoutube(){ 42 | return youtube; 43 | } 44 | public boolean getIfTwitch(){ 45 | return twitch; 46 | } 47 | public boolean getIfPin(){ 48 | return pin; 49 | } 50 | public boolean getPinNotification(){ 51 | return pinNotification; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/ExceptionAlert.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.util.ArrayList; 6 | 7 | import com.pengrad.telegrambot.TelegramBot; 8 | import com.pengrad.telegrambot.request.SendMessage; 9 | 10 | import reloaded.convintobot.tResponse.Commands; 11 | 12 | public class ExceptionAlert { 13 | private Info i = new Info(); 14 | private TelegramBot bot; 15 | private Commands last; 16 | 17 | public ExceptionAlert(TelegramBot b, ArrayList c){ 18 | i.update(0, Main.st); 19 | bot = b; 20 | for(Commands cmd : c){ 21 | if(cmd.isThisCommand("/stat")) last = cmd; 22 | } 23 | } 24 | 25 | public void alert(Exception e){ 26 | 27 | try{ 28 | e.printStackTrace(); 29 | bot.execute(new SendMessage("-169611331", "An exception occurred\n\n" + last.getString("/stat low", Main.st, i) + "\nException data:\n" + getThrow(e))); 30 | System.out.println("FATTO"); 31 | }catch(Exception sfiga){ //qui sarebbe il classisco "unexpected error occured while displaying an unexpected error" 32 | Main.wait(5000); 33 | alert(sfiga); 34 | } 35 | 36 | } 37 | 38 | private String getThrow(Exception e){ 39 | 40 | StringWriter sw = new StringWriter(); 41 | PrintWriter pw = new PrintWriter(sw); 42 | e.printStackTrace(pw); 43 | return sw.toString(); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/tResponse/Inline.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot.tResponse; 2 | 3 | import java.io.IOException; 4 | 5 | import com.pengrad.telegrambot.model.request.InlineKeyboardButton; 6 | 7 | import reloaded.convintobot.Info; 8 | import reloaded.convintobot.Main; 9 | import reloaded.convintobot.Phrase; 10 | import reloaded.convintobot.Settings; 11 | import reloaded.convintobot.Twitch; 12 | 13 | public class Inline { 14 | private String text, data; 15 | private byte type; //0 = url, 1 = callBackData, 2 = callBackGame, 3 = switchInlineQuery, 4 = switchInlineQueryCurrentChat 16 | 17 | public Inline(String t, String d, int i){ 18 | text = t; 19 | data = d; 20 | type = (byte) i; 21 | } 22 | 23 | public InlineKeyboardButton getButton(Info i, Phrase f, Twitch t, Settings s, String id) throws IOException{ 24 | String nText = Main.replaceRuntimeData(text, i, f, t, s, id), nData = Main.replaceRuntimeData(data, i, f, t, s, id); 25 | switch(type){ 26 | case 0: return new InlineKeyboardButton(nText).url(nData); 27 | case 1: return new InlineKeyboardButton(nText).callbackData(nData); 28 | case 2: return new InlineKeyboardButton(nText).callbackGame(nData); 29 | case 3: return new InlineKeyboardButton(nText).switchInlineQuery(nData); 30 | case 4: return new InlineKeyboardButton(nText).switchInlineQueryCurrentChat(nData); 31 | } 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /oldVersion/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | reloaded 6 | convintobot 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | convintobot 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | com.github.pengrad 20 | java-telegram-bot-api 21 | 2.1.4 22 | 23 | 24 | 25 | junit 26 | junit 27 | 3.8.1 28 | test 29 | 30 | 31 | org.json 32 | json 33 | 20160212 34 | 35 | 36 | org.apache.commons 37 | commons-lang3 38 | 3.5 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/Download.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.net.ConnectException; 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | 12 | public class Download { 13 | public static String dwn(String apii) throws ConnectException, InvocationTargetException{ 14 | boolean first = false; 15 | String check = null; 16 | URL url; 17 | InputStream is = null; 18 | BufferedReader br; 19 | String line; 20 | try { 21 | url = new URL(apii); 22 | is = url.openStream(); 23 | br = new BufferedReader(new InputStreamReader(is)); 24 | while ((line = br.readLine()) != null) { 25 | if(!first){ 26 | check = line; 27 | first = true; 28 | } else check = check + line; 29 | } 30 | } catch (MalformedURLException mue) { 31 | Main.ea.alert(mue); 32 | } catch (IOException ioe) { 33 | Main.ea.alert(ioe); 34 | } finally { 35 | try { 36 | if (is != null) is.close(); 37 | } catch (IOException ioe) {} 38 | } 39 | if(Main.link){ 40 | Main.logger("\n\nCheck: " + apii); 41 | Main.logger(check + "\n"); 42 | } 43 | return check; 44 | } 45 | } -------------------------------------------------------------------------------- /oldVersion/target/classes/META-INF/maven/reloaded/convintobot/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | reloaded 6 | convintobot 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | convintobot 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | com.github.pengrad 20 | java-telegram-bot-api 21 | 2.1.4 22 | 23 | 24 | 25 | junit 26 | junit 27 | 3.8.1 28 | test 29 | 30 | 31 | org.json 32 | json 33 | 20160212 34 | 35 | 36 | org.apache.commons 37 | commons-lang3 38 | 3.5 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /oldVersion/target/classes/META-INF/maven/it.TetrisReich.bot/TestBot/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | it.TetrisReich.bot 6 | TestBot 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | TestBot 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | com.github.pengrad 20 | java-telegram-bot-api 21 | 2.1.4 22 | 23 | 24 | 25 | junit 26 | junit 27 | 3.8.1 28 | test 29 | 30 | 31 | org.json 32 | json 33 | 20160212 34 | 35 | 36 | org.apache.commons 37 | commons-lang3 38 | 3.5 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/it/TetrisReich/bot/TestBot/Download.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.net.ConnectException; 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | import it.TetrisReich.bot.TestBot.App; 12 | 13 | public class Download { 14 | public static String dwn(String apii) throws ConnectException, InvocationTargetException{ 15 | boolean first = false; 16 | String check = null; 17 | URL url; 18 | InputStream is = null; 19 | BufferedReader br; 20 | String line; 21 | try { 22 | url = new URL(apii); 23 | is = url.openStream(); 24 | br = new BufferedReader(new InputStreamReader(is)); 25 | while ((line = br.readLine()) != null) { 26 | if(!first){ 27 | check = line; 28 | first = true; 29 | } else check = check + line; 30 | } 31 | } catch (MalformedURLException mue) { 32 | mue.printStackTrace(); 33 | } catch (IOException ioe) { 34 | ioe.printStackTrace(); 35 | } finally { 36 | try { 37 | if (is != null) is.close(); 38 | } catch (IOException ioe) {} 39 | } 40 | if(App.link&&!App.secret){ 41 | App.logger("\n\nCheck: " + apii); 42 | App.logger(check + "\n"); 43 | } 44 | return check; 45 | } 46 | } -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/ExceptionAlert.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.util.ArrayList; 6 | 7 | import com.pengrad.telegrambot.TelegramBot; 8 | import com.pengrad.telegrambot.request.SendMessage; 9 | 10 | import reloaded.convintobot.tResponse.Commands; 11 | 12 | public class ExceptionAlert { 13 | private Info i = new Info(); 14 | private TelegramBot bot; 15 | private Commands stat; 16 | private Twitch t = new Twitch(); 17 | private Phrase f; 18 | 19 | public ExceptionAlert(TelegramBot b, ArrayList c, Phrase ph){ 20 | bot = b; 21 | f = ph; 22 | for(Commands cmd : c){ 23 | if(cmd.isThisCommand("/stat", Main.st.getUser(), Main.st)) { 24 | stat = cmd; 25 | break; 26 | } 27 | } 28 | } 29 | 30 | public void alert(Exception e){ 31 | 32 | try{ 33 | //e.printStackTrace(); 34 | bot.execute(new SendMessage("-169611331", "An exception occurred\n\n" + stat.getString("/stat low", Main.st, i, t, f, "") + "\nException data:\n" + getThrow(e))); 35 | }catch(Exception sfiga){ //qui sarebbe il classisco "unexpected error occured while displaying an unexpected error" 36 | //Main.wait(5000); 37 | sfiga.printStackTrace(); 38 | } 39 | 40 | } 41 | 42 | private String getThrow(Exception e){ 43 | 44 | StringWriter sw = new StringWriter(); 45 | PrintWriter pw = new PrintWriter(sw); 46 | e.printStackTrace(pw); 47 | return sw.toString(); 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/it/TetrisReich/bot/TestBot/Chan.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.Random; 7 | 8 | //import org.apache.commons.lang3.StringEscapeUtils; 9 | 10 | import it.TetrisReich.bot.TestBot.App; 11 | 12 | public class Chan { 13 | public static String chan() throws IOException{ 14 | if(!FileO.exist("programmed")){ 15 | if(!App.textEsist) if(App.inLive) return "In live ora:"; else return "Nuovo video:"; 16 | Random generator = new Random(); 17 | int rand; 18 | if(App.inLive) rand = generator.nextInt(App.lf); else rand = generator.nextInt(App.vf); 19 | boolean toke = false; 20 | try(BufferedReader br = new BufferedReader(new FileReader("text"))) { 21 | String line; 22 | while ((line = br.readLine()) != null) { 23 | String esc = line; 24 | if(App.inLive){ 25 | if(toke) if(rand==0) return esc; else rand--; 26 | if(line.equalsIgnoreCase("_")) toke = true; 27 | } else { 28 | if(rand==0) return esc; 29 | rand--; 30 | } 31 | } 32 | }} else {String s = FileO.aL("programmed", false); FileO.delater("programmed"); return s;} 33 | return null; 34 | } 35 | public static void chanSP() throws IOException{ 36 | boolean toke = false; 37 | try(BufferedReader br = new BufferedReader(new FileReader("text"))) { 38 | for(String line; (line = br.readLine()) != null; ) { 39 | if(line.equalsIgnoreCase("_")) toke = true; else {if(toke) App.lf++; else App.vf++;} 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Live.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | public class Live { 4 | private String id, title, mText; 5 | private int type; 6 | private int[] messageId; 7 | private long notificationCycle, liveOffline; 8 | 9 | public Live(String name, String liveId, String s, int videoType, int[] mId){ 10 | title = name; 11 | id = liveId; 12 | type = videoType; 13 | messageId = mId; 14 | mText = s; 15 | //if(type==2) upcoming = true; 16 | } 17 | 18 | public void setType(int videoType){ 19 | type = videoType; 20 | } 21 | public void setNotificationCycle(long n){ 22 | notificationCycle = n; 23 | } 24 | public void setLiveOffline(long n){ 25 | liveOffline = n; 26 | } 27 | 28 | public int[] getMessageId(){ 29 | return messageId; 30 | } 31 | public int getType(){ 32 | return type; 33 | } 34 | public long getNotificationCycle(){ 35 | return notificationCycle; 36 | } 37 | public long getLiveOffline(){ 38 | return liveOffline; 39 | } 40 | public String getId(){ 41 | return id; 42 | } 43 | public String getTitle(){ 44 | return title; 45 | } 46 | public String getMText(){ 47 | return mText; 48 | } 49 | 50 | public String toString(){ 51 | return "Live{" 52 | + "id=" + id + ", " 53 | + "title='" + title + "', " 54 | + "type='" + type + "', " 55 | + "messageId='" + messageId + "'," 56 | + "offlineFrom='" + liveOffline + "'," 57 | + "notificationCycle='" + notificationCycle + "'" 58 | + "}"; 59 | } 60 | //public boolean stillupcoming(int type){ //0 = live stopped, 2 = still live, 3 = switch from upcoming to live, 4 = still upcoming 61 | ////} 62 | } 63 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/Youtube.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONObject; 7 | 8 | public class Youtube { 9 | private ArrayList oldVideoIds = new ArrayList(); 10 | private boolean forceNewVideo = false; 11 | 12 | public void initialize(Settings s){ 13 | Main.loggerL("Inizialazing youtube object... "); 14 | 15 | while(true){ 16 | try{ 17 | //System.out.println("START"); 18 | JSONObject obj = new JSONObject(Download.dwn(s.getGoogleApiFullUrl(16))); 19 | //System.out.println("END"); 20 | JSONArray arr = obj.getJSONArray("items"); 21 | for(int i = 0; i < arr.length(); i++) oldVideoIds.add(arr.getJSONObject(i).getJSONObject("id").getString("videoId")); 22 | //System.out.println("DONE"); 23 | break; 24 | }catch(Exception e){ 25 | Main.ea.alert(e); 26 | Main.wait(5000); 27 | } 28 | } 29 | 30 | if(!FileO.exist("last.ini")) { 31 | FileO.newFile("last.ini"); 32 | FileO.writer("thisisatest@uItXIawwf8k@0", "last.ini"); 33 | } 34 | Main.logger("Done!"); 35 | } 36 | 37 | //vado a magnà 38 | 39 | public void forceVideoUpdate(boolean b){ 40 | forceNewVideo = b; 41 | } 42 | 43 | public boolean newVideo(String id){ 44 | if(forceNewVideo) { 45 | forceNewVideo = false; 46 | return true; 47 | } 48 | if(!oldVideoIds.contains(id)){ 49 | oldVideoIds.remove(0); 50 | oldVideoIds.add(id); 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | public ArrayList getOldVideoIds(){ 57 | return oldVideoIds; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Youtube.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONObject; 7 | 8 | public class Youtube { 9 | private ArrayList oldVideoIds = new ArrayList(); 10 | private boolean forceNewVideo = false, forceNoVideo = false; 11 | 12 | public void initialize(Settings s){ 13 | Main.LOGGER.config("Inizialazing youtube object"); 14 | 15 | while(true){ 16 | try{ 17 | JSONObject obj = new JSONObject(Download.dwn(s.getGoogleApiFullUrl(16))); 18 | JSONArray arr = obj.getJSONArray("items"); 19 | for(int i = 0; i < arr.length(); i++) oldVideoIds.add(arr.getJSONObject(i).getJSONObject("id").getString("videoId")); 20 | break; 21 | }catch(Exception e){ 22 | Main.ea.alert(e); 23 | Main.wait(5000); 24 | } 25 | } 26 | 27 | if(!FileO.exist("last.ini")) { 28 | FileO.newFile("last.ini"); 29 | FileO.writer("thisisatest@S0vzZBxXRB4@0", "last.ini"); 30 | } 31 | } 32 | 33 | //vado a magnà 34 | 35 | public void forceNoUpdate(boolean b){ 36 | forceNoVideo = b; 37 | } 38 | public void forceVideoUpdate(boolean b){ 39 | forceNewVideo = b; 40 | } 41 | 42 | public boolean newVideo(String id){ 43 | 44 | if(forceNewVideo) { 45 | forceNewVideo = false; 46 | return true; 47 | } 48 | 49 | if(!oldVideoIds.contains(id)){ 50 | oldVideoIds.remove(oldVideoIds.size() - 1); 51 | oldVideoIds.add(0, id); 52 | 53 | if(!forceNoVideo) return true; 54 | forceNoVideo = false; 55 | } 56 | return false; 57 | } 58 | 59 | public ArrayList getOldVideoIds(){ 60 | return oldVideoIds; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ConvintoBot 2 | This Bot sends notifications to your Telegram Channel when a new YouTube video is uploaded (or made public). 3 | 4 | With the last update it also include optional Twitch notifications for Live Streaming and the awesome **Subscribers Group Manager** function! 5 | 6 | ###### This bot is really old, and its code it's absolutely shit. I started writing it when I first met OOP. It needs a complete rewrite, maybe using my personal [TelegramBot's java framework](https://github.com/stranck/BaseTgBot) but I don't have enough time. Btw I'm adding instagram support. [DM me](www.stranck.ovh) for more info about its functionalities 7 | 8 | Youtube functionalities showcase (Made for Google's api review): https://youtu.be/lrXVcAQ6jUw 9 | 10 | ## Changelog 11 | 12 | **2017-08-23** 13 | 14 | * **Added "Group Manager" Support:** 15 | * Automatically Check if a user in the private telegram group is a subscriber 16 | * Send private notifications to users to remind them to renew their subscription 17 | * Automatically Kick a user after 2 days if his subscription is expired 18 | * New users can join the group (without being able to see the public link) through the bot, which will automatically check the status of subscription. Users have to log into Twitch through the BOT. 19 | 20 | * **Added Twitch Live Notifications Support** 21 | 22 | 23 | Made by Stranck: https://stranck.ovh 24 | 25 | ZombieBest's (https://youtube.com/c/ZombieBestOfficial) Telegram Channel: https://telegram.me/ZombieTheBest 26 | 27 | If you want to try the BOT Login Screen for the ZombieBest's Subscriber Private Group (in Italian): https://goo.gl/jZRuA6 28 | 29 | 30 | 31 | ## Libraries used: 32 | 33 | org.json 34 | 35 | com.pengrad.telegrambot 36 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Info.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONObject; 5 | 6 | public class Info { 7 | private String id = "", type = "", name = ""; 8 | 9 | public void update(int n, Settings s){ 10 | while(true){ //this gibe me cancer 11 | try { 12 | JSONObject data = new JSONObject(Download.dwn(s.getGoogleApiFullUrl(n + 1))).getJSONArray("items").getJSONObject(n); 13 | JSONObject snippet = data.getJSONObject("snippet"); 14 | id = data.getJSONObject("id").getString("videoId"); 15 | type = snippet.getString("liveBroadcastContent"); 16 | name = snippet.getString("title"); 17 | return; 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | Main.ea.alert(e); 21 | Main.wait(5000); 22 | } 23 | } 24 | } 25 | 26 | public String getVideoType(String id, Settings s){ 27 | String ret = ""; 28 | while(ret.equals("")){ 29 | try{ 30 | JSONArray items = new JSONObject(Download.dwn(s.getUrlVideoType(id))).getJSONArray("items"); 31 | if(items.length() > 0) 32 | ret = items.getJSONObject(0).getJSONObject("snippet").getString("liveBroadcastContent"); 33 | else 34 | ret = "none"; 35 | }catch(Exception e){ 36 | Main.ea.alert(e); 37 | Main.wait(5000); 38 | } 39 | } 40 | return ret; 41 | } 42 | 43 | public String getVideoId(){ 44 | return id; 45 | } 46 | public String getVideoType(){ 47 | return type; 48 | } 49 | public String getVideoName(){ 50 | return name; 51 | } 52 | 53 | public void set(String i, String t, String n){ 54 | id = i; 55 | name = n; 56 | type = t; 57 | } 58 | 59 | public String toString(){ 60 | return "Info{" 61 | + "id=" + id + ", " 62 | + "title='" + name + "', " 63 | + "type='" + type + "'" 64 | + "}"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/GroupUser.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.io.File; 4 | 5 | public class GroupUser { 6 | private String id; 7 | private long expireDate; 8 | private boolean alreadyNotified = false, expiredNotified = false, banned = false; 9 | 10 | public GroupUser(String userId, String data){ 11 | id = userId; 12 | if(data.length() > 0){ 13 | String[] sp = data.split(";"); 14 | expireDate = Long.valueOf(sp[0]); 15 | alreadyNotified = Boolean.valueOf(sp[1]); 16 | expiredNotified = Boolean.valueOf(sp[2]); 17 | } else { 18 | banned = true; 19 | } 20 | } 21 | 22 | public GroupUser(String userId, long ms){ 23 | id = userId; 24 | expireDate = ms; 25 | save(); 26 | } 27 | 28 | public boolean checkIfNotify(Settings st){ 29 | return st.getIfNotifyBefore() && (System.currentTimeMillis() > expireDate - st.getNotifyBeforeDelay()) && !alreadyNotified; 30 | } 31 | public boolean checkIfExpired(){ 32 | return (System.currentTimeMillis() > expireDate) && !expiredNotified; 33 | } 34 | public boolean checkIfTimedOut(Settings st){ 35 | return (System.currentTimeMillis() > (expireDate + st.getKeepInGroupDelay())) || !st.getIfKeepInGroup(); 36 | } 37 | 38 | public void save(){ 39 | FileO.writer(String.valueOf(expireDate) + ";" + alreadyNotified + ";" + expiredNotified, "sub" + File.separator + id); 40 | } 41 | public void deletea(){ 42 | FileO.delater("sub" + File.separator + id); 43 | } 44 | 45 | public String getId(){ 46 | return id; 47 | } 48 | public int getNumericId(){ 49 | return Integer.parseInt(id); 50 | } 51 | public long getExpireDate(){ 52 | return expireDate; 53 | } 54 | public boolean isBanned(){ 55 | return banned; 56 | } 57 | public void setId(String s){ 58 | id = s; 59 | } 60 | public void setExpireDate(long l){ 61 | expireDate = l; 62 | } 63 | public void setIfAlreadyNotified(boolean b){ 64 | alreadyNotified = b; 65 | } 66 | public void setIfExpiredIsNotified(boolean b){ 67 | expiredNotified = b; 68 | } 69 | public void ban(){ 70 | banned = true; 71 | FileO.writer("", "sub" + File.separator + id); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /newVersion/commands/sub.json: -------------------------------------------------------------------------------- 1 | { 2 | "commandType" : 4, 3 | "randomResponse" : false, 4 | "DisableWebPagePreview" : true, 5 | "admin" : false, 6 | "responseData" : { 7 | "response" : [ 8 | "Stato attuale: %sub%\n\nUsa il pulsante qui sotto per collegare il tuo account twitch e aggiornare il tuo abbonamento.\nA fine procedura, se sei abbonato, potrai entrare nel gruppo ufficiale di %twitchUser%!", 9 | "Non sei registrato al bot!\nHai 24 ore di tempo per collegare il tuo account twitch prima di essere kickato dal gruppo.\nSe sei abbonato, clicca il pulsante sotto e completa la procedura per poter riaver accesso al gruppo.", 10 | "Sei stato kickato dal gruppo poiché il tuo abbonamento è scaduto\nSe vuoi rientrare, non esitare a subbarti di nuovo!\n\nUna volta che hai fatto, usa il pulsante qui sotto per aggiornare i tuoi dati", 11 | "Il tuo abbonamento è scaduto. Se non lo rinnoverai, verrai presto kickato dal gruppo!\n\nUna volta che hai fatto, usa il pulsante qui sotto per aggiornare i tuoi dati", 12 | "Il tuo abbonamento sta per scadere! Rinnovalo, se vuoi rimanere nel gruppo!\n\nUna volta che hai fatto, usa il pulsante qui sotto per aggiornare i tuoi dati" 13 | ], 14 | "args" : { 15 | "new" : 1, 16 | "kicked" : 2, 17 | "expired" : 3, 18 | "notify" : 4 19 | }, 20 | "inline" : [ 21 | [ 22 | { 23 | "type" : 0, 24 | "text" : "Collega!", 25 | "data" : "%tLoginURL%#token=%twToken%&bot_user=%botUsername%&lang=%lang%" 26 | } 27 | ], 28 | [ 29 | { 30 | "type" : 0, 31 | "text" : "Collega!", 32 | "data" : "%tLoginURL%#token=%twToken%&bot_user=%botUsername%&lang=%lang%" 33 | } 34 | ], 35 | [ 36 | { 37 | "type" : 0, 38 | "text" : "Collega!", 39 | "data" : "%tLoginURL%#token=%twToken%&bot_user=%botUsername%&lang=%lang%" 40 | } 41 | ], 42 | [ 43 | { 44 | "type" : 0, 45 | "text" : "Collega!", 46 | "data" : "%tLoginURL%#token=%twToken%&bot_user=%botUsername%&lang=%lang%" 47 | } 48 | ], 49 | [ 50 | { 51 | "type" : 0, 52 | "text" : "Collega!", 53 | "data" : "%tLoginURL%#token=%twToken%&bot_user=%botUsername%&lang=%lang%" 54 | } 55 | ] 56 | ] 57 | } 58 | } -------------------------------------------------------------------------------- /oldVersion/src/main/java/it/TetrisReich/bot/TestBot/Clive.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import it.TetrisReich.bot.TestBot.Download; 4 | 5 | import java.lang.reflect.InvocationTargetException; 6 | import java.net.ConnectException; 7 | 8 | import org.json.JSONArray; 9 | import org.json.JSONException; 10 | import org.json.JSONObject; 11 | 12 | import it.TetrisReich.bot.TestBot.App; 13 | 14 | public class Clive extends Thread{ 15 | public static boolean incoming = false; 16 | public static void checkInLive() throws JSONException, InvocationTargetException{ 17 | try{ 18 | if(incoming)checkUpcoming(); 19 | App.loggerL("Checking if Live is finished: "); 20 | JSONObject obj = new JSONObject(Download.dwn(App.threadst1)); 21 | JSONArray arr = obj.getJSONArray("items"); 22 | obj = arr.getJSONObject(0); 23 | if(obj.getJSONObject("snippet").getString("liveBroadcastContent").equals("none")){ 24 | App.liveEnd = "" + 25 | FileO.toHtml(obj.getJSONObject("snippet").getJSONObject("localized").getString("title")) 26 | + ""; 27 | App.liveFinish = 1; 28 | App.logger("false"); 29 | } else { 30 | App.logger("true"); 31 | App.liveFinish = 2; 32 | } 33 | }catch(ConnectException | JSONException e){ 34 | e.printStackTrace(); 35 | } 36 | } 37 | public static boolean checkUpcoming() throws ConnectException, JSONException, InvocationTargetException{ 38 | try{ 39 | JSONObject obj = new JSONObject(Download.dwn(App.threadst1)); 40 | JSONArray arr = obj.getJSONArray("items"); 41 | obj = arr.getJSONObject(0); 42 | if(incoming&&obj.getJSONObject("snippet").getString("liveBroadcastContent").equals("live")){ 43 | App.cristoEVenuto = true; 44 | incoming = false; 45 | App.liveEnd = FileO.toHtml(obj.getJSONObject("snippet") 46 | .getJSONObject("localized").getString("title")); 47 | return false; 48 | } 49 | if(obj.getJSONObject("snippet").getString("liveBroadcastContent").equals("upcoming")){ 50 | incoming = true; 51 | return true; 52 | } 53 | return false; 54 | } catch(ConnectException | JSONException e){ 55 | e.printStackTrace(); 56 | try{ 57 | Thread.sleep(1000); 58 | } catch(InterruptedException ex){ 59 | Thread.currentThread().interrupt(); 60 | } 61 | return checkUpcoming(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Twitch.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONObject; 5 | 6 | public class Twitch { 7 | private boolean goneOnline = true, forceClipUpdate; 8 | private int[] messageId; 9 | private long liveOffline, notificationCycle; 10 | private String title = "", game = "", mText = ""; 11 | 12 | public Twitch(){} 13 | 14 | public Twitch(Settings st){ 15 | Main.LOGGER.config("Initializing Twitch object"); 16 | try{ 17 | if(st.getIfTwitch()){ 18 | st.loadTwitchUserId(); 19 | JSONObject stream = Download.twitchOld("channels/" + st.getTwitchUserID()); //FARE IN MODO CHE SI PRECARICHI VECCHI TITLE E GAME 20 | //System.out.println(stream.toString()); 21 | title = stream.getString("status"); 22 | game = stream.getString("game"); 23 | } 24 | } catch(Exception e) {e.printStackTrace();} 25 | } 26 | 27 | public int checkLive(Settings st) throws Exception{ 28 | JSONArray stream = Download.twitch(st.getTwitchUrl(0)).getJSONArray("data"); 29 | 30 | int ret = 0; //0 = offline; 1 = gone offline; 2 = online; 3 = gone online; 31 | 32 | if(stream.length() > 0 && st.checkTwtichLiveType(stream.getJSONObject(0).getString("type"))) { 33 | if(goneOnline) { 34 | JSONObject data = stream.getJSONObject(0); 35 | notificationCycle = System.currentTimeMillis(); 36 | goneOnline = false; 37 | game = getNameFromId(data.getString("game_id")); 38 | title = data.getString("title"); 39 | ret = 3; 40 | } else ret = 2; 41 | liveOffline = System.currentTimeMillis(); 42 | } else if(!goneOnline && System.currentTimeMillis() - liveOffline > st.getOfflineDelay()) { 43 | goneOnline = true; 44 | ret = 1; 45 | } 46 | 47 | return ret; 48 | } 49 | private String getNameFromId(String id) throws Exception{ 50 | return Download.twitch("games?id=" + id).getString("name"); 51 | } 52 | 53 | public String getMText(){ 54 | return mText; 55 | } 56 | public String getGame(){ 57 | return game; 58 | } 59 | public String getTitle(){ 60 | return title; 61 | } 62 | public int[] getMessageId(){ 63 | return messageId; 64 | } 65 | public long getNotificationCycle(){ 66 | return notificationCycle; 67 | } 68 | public boolean getIfInLive(){ 69 | return !goneOnline; 70 | } 71 | public boolean getClipUpdate(){ 72 | return forceClipUpdate; 73 | } 74 | 75 | public void setClipUpdate(boolean b){ 76 | forceClipUpdate = b; 77 | } 78 | public void setMText(String s){ 79 | mText = s; 80 | } 81 | public void setMessageId(int[] n){ 82 | messageId = n; 83 | } 84 | public void setNotificationCycle(long n){ 85 | notificationCycle = n; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /oldVersion/ZombiHunter.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.ZombieHunterBot; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.List; 7 | import java.util.Random; 8 | 9 | import com.pengrad.telegrambot.TelegramBot; 10 | import com.pengrad.telegrambot.TelegramBotAdapter; 11 | import com.pengrad.telegrambot.model.Message; 12 | import com.pengrad.telegrambot.model.Update; 13 | import com.pengrad.telegrambot.request.GetUpdates; 14 | import com.pengrad.telegrambot.request.SendAudio; 15 | import com.pengrad.telegrambot.request.SendPhoto; 16 | import com.pengrad.telegrambot.response.GetUpdatesResponse; 17 | 18 | public class App{ 19 | public static int[] oldId = new int[128]; 20 | public static final String[] url = reader("urls.txt").split(";"); 21 | public static final String[] aud = reader("audi.txt").split(";"); 22 | public static void main(String[] args){ 23 | empty(); 24 | TelegramBot bot = TelegramBotAdapter.build(args[0]); 25 | boolean b = true; 26 | Random generator = new Random(); 27 | System.out.println("Bot started. " + args[0]); 28 | while(true){try{ 29 | GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates()); 30 | List updates = updatesResponse.updates(); 31 | for(Update update : updates) { 32 | Message msg = update.message(); 33 | if(!isIn(update.updateId())){ 34 | if(b) {empty(); b = false;} 35 | add(update.updateId()); 36 | if(msg.text().equalsIgnoreCase("/armi")||msg.text().equalsIgnoreCase("/start armi")){ 37 | int r = generator.nextInt(url.length); 38 | bot.execute(new SendPhoto(msg.chat().id(), url[r])); 39 | System.out.println("Request weapon: " + url[r]); 40 | } 41 | if(msg.text().equalsIgnoreCase("/song")||msg.text().equalsIgnoreCase("/start song")){ 42 | int r = generator.nextInt(aud.length); 43 | bot.execute(new SendAudio(msg.chat().id(), aud[r])); 44 | System.out.println("Request song: " + aud[r]); 45 | } 46 | } else b = true; 47 | System.out.println("[" + update.updateId() + "]" + msg.chat().id().toString() + "> "+ msg.text()); 48 | } 49 | try{ 50 | Thread.sleep(300); 51 | } catch(InterruptedException ex){ 52 | Thread.currentThread().interrupt(); 53 | }}catch(NullPointerException e) {e.printStackTrace();} 54 | } 55 | } 56 | public static void add(int n){ 57 | for(int i=0;i admins = new ArrayList(); 14 | public boolean loadSettings(long sTime){ 15 | try { 16 | if(!FileO.exist("config.json")){ 17 | Main.logger("File \"config.json\" not found."); 18 | FileO.newFile("config.json"); 19 | FileO.writer("{", "config.json"); 20 | FileO.addWrite("config.json", " \"gToken\" : \"INSERIT YOUR GOOGLE APIS TOKEN HERE\","); 21 | FileO.addWrite("config.json", " \"tToken\" : \"INSERIT YOUR TELEGRAM TOKEN HERE\","); 22 | FileO.addWrite("config.json", " \"id\" : \"INSERIT YOUR CHANNEL ID HERE\","); 23 | FileO.addWrite("config.json", " \"chat\" : \"INSERIT THE CHAT ID HERE\","); 24 | FileO.addWrite("config.json", " \"botName\" : \"INSERIT THE NAME OF YOUR BOT HERE\","); 25 | FileO.addWrite("config.json", " \"admins\" : ["); 26 | FileO.addWrite("config.json", " \"INSERIT THE TELEGRAM ACCOUNT ID OF YOUR FIRST ADMIN HERE\","); 27 | FileO.addWrite("config.json", " \"INSERIT THE TELEGRAM ACCOUNT ID OF YOUR SECOND ADMIN HERE\","); 28 | FileO.addWrite("config.json", " \"...\""); 29 | FileO.addWrite("config.json", " ]"); 30 | FileO.addWrite("config.json", "}"); 31 | Main.logger("File \"config.json\" created. Edit your settings and then turn on again the bot."); 32 | return false; 33 | } 34 | 35 | Main.loggerL("Loading configs... "); 36 | JSONObject config = new JSONObject(FileO.allLine("config.json")); 37 | gToken = config.getString("gToken"); 38 | tToken = config.getString("tToken"); 39 | id = config.getString("id"); 40 | chat = config.getString("chat"); 41 | botName = config.getString("botName"); 42 | startTime = sTime; 43 | Main.logger("done"); 44 | 45 | dir = System.getProperty("user.dir") + File.separator; 46 | 47 | JSONArray admin = config.getJSONArray("admins"); 48 | for(int i = 0; i < admin.length(); i++) admins.add(admin.getString(i)); 49 | 50 | } catch (Exception e) { 51 | Main.ea.alert(e); 52 | return false; 53 | } 54 | return true; 55 | } 56 | public ArrayList getAdmins(){ 57 | return admins; 58 | } 59 | public String getBotName(){ 60 | return botName; 61 | } 62 | public String getChatId(){ 63 | return chat; 64 | } 65 | public String getChannelId(){ 66 | return id; 67 | } 68 | public String getTelegramToken(){ 69 | return tToken; 70 | } 71 | public String getGoogleToken(){ 72 | return gToken; 73 | } 74 | public String getDefaultDirectory(){ 75 | return dir; 76 | } 77 | public boolean getPhraseStatus(){ 78 | return phraseStatus; 79 | } 80 | public void setPhraseStatus(boolean status){ 81 | phraseStatus = status; 82 | } 83 | public void removeDirectory(){ 84 | dir = ""; 85 | } 86 | public String getGoogleApiFullUrl(int n){ 87 | return "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=" + id + "&order=date&type=video&key=" + gToken + "&maxResults=" + n; 88 | } 89 | public String getUrlVideoType(String id){ 90 | return "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + id + "&maxResults=1&key=" + gToken; 91 | } 92 | public String getUpTime(){ 93 | long estimatedTime = (System.currentTimeMillis() - startTime) / 1000; 94 | int hours = (int) estimatedTime / 3600; 95 | int secs = (int) estimatedTime - hours * 3600; 96 | int mins = secs / 60; 97 | secs = secs - mins * 60; 98 | return hours + ":" + mins + ":" + secs; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/Phrase.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Random; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONObject; 8 | 9 | public class Phrase { 10 | private ArrayList videoPhrase = new ArrayList(), livePhrase = new ArrayList(), upcomingPhrase = new ArrayList(), terminedPhrase = new ArrayList(); 11 | 12 | public boolean initialize(){ 13 | //System.out.println(!FileO.exist("phrases.json")); 14 | if(!FileO.exist("phrases.json")){ 15 | Main.logger("\"phrases.json\" not foud. If you wanna use your own phrases create this file in the same directory of the .jar and write in it in this method:\n" 16 | + "{\n " 17 | + " \"video\" : [\n" 18 | + " \"phrase for new video 1\",\n" 19 | + " \"phrase for new video 2\",\n" 20 | + " \"...\"\n" 21 | + " ],\n" 22 | + " \"live\" : [\n" 23 | + " \"phrase for new live 1\",\n" 24 | + " \"phrase for new live 2\",\n" 25 | + " \"...\"\n" 26 | + " ],\n" 27 | + " \"upcoming\" : [\n" 28 | + " \"phrase for new upcoming live 1\",\n" 29 | + " \"phrase for new upcoming live 2\",\n" 30 | + " \"...\"\n" 31 | + " ],\n" 32 | + " \"termined\" : [\n" 33 | + " \"phrase when a live is termined 1\",\n" 34 | + " \"phrase when a live is termined 2\",\n" 35 | + " \"...\"\n" 36 | + " ]\n" 37 | + "}"); 38 | return false; 39 | } 40 | 41 | Main.loggerL("Initialazing phrase... "); 42 | 43 | try { //bot.execute(new EditMessageText(st.getChatId(), l.get(liveIndex).getMessageId(), 44 | String json = FileO.allLine("phrases.json"); 45 | 46 | JSONArray videoPhrases = new JSONObject(json).getJSONArray("video"); 47 | JSONArray livePhrases = new JSONObject(json).getJSONArray("live"); 48 | JSONArray upcomingPhrases = new JSONObject(json).getJSONArray("upcoming"); 49 | JSONArray terminedPhrases = new JSONObject(json).getJSONArray("termined"); 50 | 51 | for(int i = 0; i < videoPhrases.length(); i++) videoPhrase.add(videoPhrases.getString(i)); 52 | for(int i = 0; i < livePhrases.length(); i++) livePhrase.add(livePhrases.getString(i)); 53 | for(int i = 0; i < upcomingPhrases.length(); i++) upcomingPhrase.add(upcomingPhrases.getString(i)); 54 | for(int i = 0; i < terminedPhrases.length(); i++) terminedPhrase.add(terminedPhrases.getString(i)); 55 | 56 | Main.logger("Done!"); 57 | return true; 58 | 59 | } catch (Exception e) { 60 | Main.logger("Error while loading \"phrases.json\": "); 61 | Main.ea.alert(e); 62 | } 63 | return false; 64 | } 65 | 66 | public ArrayList getAllPhrases(int type){ 67 | try{ 68 | switch(type){ 69 | case 0: return videoPhrase; 70 | case 1: return livePhrase; 71 | case 2: return upcomingPhrase; 72 | case 3: return terminedPhrase; 73 | } 74 | }catch(Exception e){ 75 | Main.logger("Error while getting phrases:"); 76 | Main.ea.alert(e); 77 | } 78 | return null; 79 | } 80 | public String getSinglePhrases(int type, Settings s){ 81 | if(s.getPhraseStatus()) { 82 | switch(type){ 83 | case 0: return "Nuovo video:"; 84 | case 1: return "In live ora:"; 85 | case 2: return "[Live programmata]"; 86 | case 3: return "[Live terminata]"; 87 | } 88 | } else { 89 | Random r = new Random(); 90 | switch(type){ 91 | case 0: return videoPhrase.get(r.nextInt(videoPhrase.size())); 92 | case 1: return livePhrase.get(r.nextInt(livePhrase.size())); 93 | case 2: return upcomingPhrase.get(r.nextInt(upcomingPhrase.size())); 94 | case 3: return terminedPhrase.get(r.nextInt(terminedPhrase.size())); 95 | } 96 | } 97 | return null; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/it/TetrisReich/bot/TestBot/Jar.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedReader; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.net.ConnectException; 10 | import java.net.URL; 11 | import java.net.URLConnection; 12 | 13 | public class Jar { 14 | static Jar thisInstance; 15 | public static String url; 16 | public static boolean update() throws ConnectException, InvocationTargetException { 17 | System.out.println("Checking for version update: "); 18 | String[] res = Download.dwn("http://stranckutilies.altervista.org/version").split(";");; 19 | if(!res[0].equalsIgnoreCase(App.version)) { 20 | App.logger("true"); 21 | url = "http://www.mediafire.com/download/"+res[1]+"/YoutubeBot.jar"; 22 | new Jar(); 23 | System.out.println("\nRESTARTING FOR BOT UPDATE!!!"); 24 | return true; 25 | } 26 | App.logger("false"); 27 | return false; 28 | } 29 | public Jar() 30 | { 31 | otherthread(); 32 | } 33 | public void otherthread() 34 | { 35 | navigate(url,"downloadedFromMediafire"); 36 | // navigate("http://www.mediafire.com/download/j7e4wh6hbdhdj84/Minecraft+1.5.2-+C.H.T.zip","mediafire"); 37 | } 38 | private void navigate(String url,String sufix) 39 | { 40 | try 41 | { 42 | String downloadLink = fetchDownloadLink(getUrlSource(url)); 43 | saveUrl(downloadLink,sufix); 44 | } catch (Exception e) 45 | { 46 | e.printStackTrace(); 47 | } 48 | 49 | } 50 | public void saveUrl(final String urlString,String sufix) throws Exception 51 | { 52 | App.loggerL("Downloading..."); 53 | String filename = urlString.substring(urlString.lastIndexOf("/")+1, urlString.lastIndexOf("."))+urlString.substring(urlString.lastIndexOf("."), urlString.length()); 54 | BufferedInputStream in = null; 55 | FileOutputStream fout = null; 56 | try { 57 | in = new BufferedInputStream(new URL(urlString).openStream()); 58 | fout = new FileOutputStream(filename); 59 | 60 | final byte data[] = new byte[1024]; 61 | int count; 62 | while ((count = in.read(data, 0, 1024)) != -1) 63 | { 64 | fout.write(data, 0, count); 65 | } 66 | } finally { 67 | if (in != null) { 68 | in.close(); 69 | } 70 | if (fout != null) { 71 | fout.close(); 72 | } 73 | } 74 | App.logger("Success!"); 75 | } 76 | private static String getUrlSource(String url) throws IOException 77 | { 78 | App.loggerL("Connecting..."); 79 | URL yahoo = new URL(url); 80 | URLConnection yc = yahoo.openConnection(); 81 | BufferedReader in = new BufferedReader(new InputStreamReader( 82 | yc.getInputStream(), "UTF-8")); 83 | String inputLine; 84 | String total=""; 85 | while ((inputLine = in.readLine()) != null) 86 | total+=inputLine; 87 | in.close(); 88 | 89 | return total; 90 | } 91 | private static String fetchDownloadLink(String str) 92 | { 93 | App.logger("Fetching download link"); 94 | try { 95 | String regex = "(?=\\<)|(?<=\\>)"; 96 | String data[] = str.split(regex); 97 | String found = "NOTFOUND"; 98 | for (String dat : data) { 99 | if (dat.contains("DLP_mOnDownload(this)")) { 100 | found = dat; 101 | break; 102 | } 103 | } 104 | String wentthru = found.substring(found.indexOf("href=\"") + 6); 105 | wentthru = wentthru.substring(0, wentthru.indexOf("\"")); 106 | return wentthru; 107 | } catch (Exception e) 108 | { 109 | e.printStackTrace(); 110 | return "ERROR"; 111 | } 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/tResponse/Commands.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot.tResponse; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.Random; 6 | 7 | import org.json.JSONArray; 8 | import org.json.JSONObject; 9 | 10 | import com.pengrad.telegrambot.TelegramBot; 11 | import com.pengrad.telegrambot.model.Update; 12 | import com.pengrad.telegrambot.model.request.InlineKeyboardButton; 13 | import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; 14 | import com.pengrad.telegrambot.model.request.ParseMode; 15 | import com.pengrad.telegrambot.request.SendAudio; 16 | import com.pengrad.telegrambot.request.SendMessage; 17 | import com.pengrad.telegrambot.request.SendPhoto; 18 | 19 | import reloaded.convintobot.FileO; 20 | import reloaded.convintobot.Info; 21 | import reloaded.convintobot.Main; 22 | import reloaded.convintobot.Settings; 23 | 24 | 25 | public class Commands { 26 | private int commandType; //0 = bot operation; 1 = text; 2 = pic; 3 = song; 4 inline = keyboard; 27 | private boolean randomResponse, webPagePreview, onlyAdmin; 28 | private String command; 29 | private Response response = new Response(); // /test a 30 | ArrayList inline = new ArrayList(); 31 | 32 | public Commands(String cmd){ 33 | try{ 34 | JSONObject data = new JSONObject(FileO.allLine("commands" + File.separator + cmd + ".json")); 35 | 36 | commandType = data.getInt("commandType"); 37 | randomResponse = data.getBoolean("randomResponse"); 38 | webPagePreview = data.getBoolean("DisableWebPagePreview"); 39 | onlyAdmin = data.getBoolean("admin"); 40 | command = "/" + cmd; 41 | 42 | JSONObject json = data.getJSONObject("responseData"); 43 | JSONArray rsp = json.getJSONArray("response"); 44 | for(int i = 0; i < rsp.length(); i++) response.addResponse(rsp.getString(i)); 45 | response.setArgs(json.getJSONObject("args")); 46 | 47 | if(commandType == 4) { 48 | JSONArray il = json.getJSONArray("inline"); 49 | for(int i = 0; i < il.length(); i++) 50 | inline.add(new Inline(il.getJSONObject(i).getString("text"), il.getJSONObject(i).getString("data"), il.getJSONObject(i).getInt("type"))); 51 | } 52 | 53 | }catch(Exception e){ 54 | Main.logger("Error while loading command " + cmd); 55 | e.printStackTrace(); 56 | } 57 | } 58 | 59 | public boolean isThisCommand(String cmd){ 60 | try{ 61 | return cmd.split("\\s+")[0].equalsIgnoreCase(command) || ("/start" + cmd.split("\\s+")[1]).equalsIgnoreCase(command); 62 | }catch(Exception e){} 63 | return false; 64 | } 65 | public int commandExecute(String cmd, TelegramBot bot, Update update, Settings st, Info i, boolean admin){ 66 | try{ 67 | String send = getString(cmd, st, i); 68 | 69 | if((onlyAdmin==admin)||admin) 70 | switch(commandType){ 71 | case 0: { 72 | return Integer.parseInt(send); 73 | } 74 | case 1: { 75 | bot.execute(new SendMessage(update.message().chat().id().toString(), send).parseMode(ParseMode.HTML).disableWebPagePreview(webPagePreview)); 76 | break; 77 | } 78 | case 2: { 79 | bot.execute(new SendPhoto(update.message().chat().id().toString(), send)); 80 | break; 81 | } 82 | case 3: { 83 | bot.execute(new SendAudio(update.message().chat().id().toString(), send)); 84 | break; 85 | } 86 | case 4: { 87 | ArrayList ikb = new ArrayList(); 88 | for(Inline in : inline) ikb.add(in.getButton()); 89 | bot.execute(new SendMessage(update.message().chat().id().toString(), send).replyMarkup(new InlineKeyboardMarkup(ikb.toArray(new InlineKeyboardButton[ikb.size()])))); 90 | } 91 | } 92 | }catch(Exception e){Main.logger("" + e);} 93 | return 0; 94 | } 95 | 96 | public String getString(String cmd, Settings st, Info i){ 97 | String sp[] = cmd.split("\\s+"); 98 | Random r = new Random(); 99 | String send; 100 | 101 | if(!randomResponse) 102 | if(sp.length > 1) send = response.getResponse().get(response.getArgs().getInt(sp[1])); 103 | else send = response.getResponse().get(0); 104 | else send = response.getResponse().get(r.nextInt(response.getResponse().size())); 105 | return send 106 | .replaceAll("%phraseStatus%", String.valueOf(st.getPhraseStatus())) 107 | .replaceAll("%gToken%", st.getGoogleToken()) 108 | .replaceAll("%tToken%", st.getTelegramToken()) 109 | .replaceAll("%id%", st.getChannelId()) 110 | .replaceAll("%chat%", st.getChatId()) 111 | .replaceAll("%botName%", st.getBotName()) 112 | .replaceAll("%dir%", st.getDefaultDirectory()) 113 | .replaceAll("%uptime%", st.getUpTime()) 114 | .replaceAll("%lastvideo%", last(i)) 115 | .replaceAll("%version%", Main.version); 116 | } 117 | 118 | private String last(Info i){ 119 | String ret; 120 | switch(i.getVideoType()){ 121 | case"live": ret = "In live ora:"; 122 | case"upcoming": ret = "Live programmata:"; 123 | default: ret = "Video:"; 124 | } 125 | return ret + "\n" + Main.convertToLink(i.getVideoId(), i.getVideoName()); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Download.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Map.Entry; 6 | 7 | /*import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.InputStreamReader; 11 | import java.net.URL;*/ 12 | 13 | import org.apache.http.HttpEntity; 14 | import org.apache.http.HttpResponse; 15 | import org.apache.http.NameValuePair; 16 | import org.apache.http.client.HttpClient; 17 | import org.apache.http.client.config.RequestConfig; 18 | import org.apache.http.client.entity.UrlEncodedFormEntity; 19 | import org.apache.http.client.methods.HttpGet; 20 | import org.apache.http.client.methods.HttpPost; 21 | import org.apache.http.impl.client.HttpClients; 22 | import org.apache.http.util.EntityUtils; 23 | import org.json.JSONObject; 24 | 25 | public class Download { 26 | 27 | public static final int TIMEOUT = 4000; 28 | private static HttpClient client = HttpClients.custom().build(); 29 | private static final RequestConfig PARAMS = RequestConfig.custom() 30 | .setConnectionRequestTimeout(TIMEOUT) 31 | .setConnectTimeout(TIMEOUT) 32 | .setSocketTimeout(TIMEOUT).build(); 33 | /*public static String dwn(String apii) throws Exception{ 34 | Main.LOGGER.finest("Check: " + apii); 35 | String check = ""; 36 | InputStream is = null; 37 | BufferedReader br; 38 | String line; 39 | is = new URL(apii).openStream(); 40 | br = new BufferedReader(new InputStreamReader(is)); 41 | while ((line = br.readLine()) != null) { 42 | //if(line.isEmpty()) break; 43 | check += line; 44 | } 45 | try { 46 | if (is != null) is.close(); 47 | } catch (IOException ioe) {} 48 | Main.LOGGER.finest(check); 49 | return check; 50 | }*/ 51 | public static String dwn(String apii) throws Exception{ 52 | //Main.LOGGER.finest("Check: " + apii); 53 | String s = dwn(apii, null); 54 | //Main.LOGGER.finest(s); 55 | //System.out.println(s); 56 | return s; 57 | } 58 | 59 | /*public static void asd(String api){ 60 | final HttpParams httpParams = new BasicHttpParams(); 61 | HttpConnectionParams.setConnectionTimeout(httpParams, 30000); 62 | httpClient = new DefaultHttpClient(httpParams); 63 | HttpResponse httpResponse = httpClient.execute(httpGet); 64 | }*/ 65 | public static String post(String url, ArrayList params) throws Exception{ 66 | HttpPost httppost = new HttpPost(url); 67 | httppost.setConfig(PARAMS); 68 | httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); 69 | HttpResponse response = client.execute(httppost); 70 | HttpEntity entity = response.getEntity(); 71 | if (entity != null) { 72 | String s = EntityUtils.toString(entity); 73 | Main.LOGGER.finest(s); 74 | return s; 75 | } 76 | 77 | return null; 78 | } 79 | 80 | public static String dwn(String api, HashMap headers) throws Exception{ 81 | //System.out.println("FREE: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024)); 82 | Main.LOGGER.finest("GET: " + api); 83 | HttpGet get = new HttpGet(api); 84 | //if(headerName != null && headerValue != null) 85 | // get.setHeader(headerName, headerValue); 86 | if(headers != null) 87 | for (Entry h : headers.entrySet()) { 88 | get.setHeader(h.getKey(), h.getValue()); 89 | } 90 | get.setConfig(PARAMS); 91 | HttpResponse responseGet = client.execute(get); 92 | HttpEntity resEntityGet = responseGet.getEntity(); 93 | Main.LOGGER.finest("downloaded"); 94 | if (resEntityGet != null) { 95 | //do something with the response 96 | String s = EntityUtils.toString(resEntityGet); 97 | get.releaseConnection(); 98 | EntityUtils.consume(resEntityGet); 99 | Main.LOGGER.finest(s); 100 | return s; 101 | } 102 | return null; 103 | } 104 | 105 | public static JSONObject twitchOAuth(String method, String oauth) throws Exception{ 106 | HashMap headers = new HashMap(); 107 | headers.put("Authorization", "Bearer " + oauth); 108 | return new JSONObject(dwn("https://api.twitch.tv/helix/" + method, headers)); 109 | } 110 | public static JSONObject twitchOldOauth(String method, String oauth) throws Exception{ 111 | HashMap headers = new HashMap(); 112 | headers.put("Client-ID", Main.st.getTwitchToken()); 113 | headers.put("Accept", "application/vnd.twitchtv.v5+json"); 114 | headers.put("Authorization", "OAuth " + oauth); 115 | return new JSONObject(dwn("https://api.twitch.tv/kraken/" + method, headers)); 116 | } 117 | public static JSONObject twitchOld(String method) throws Exception{ 118 | HashMap headers = new HashMap(); 119 | headers.put("Client-ID", Main.st.getTwitchToken()); 120 | headers.put("Accept", "application/vnd.twitchtv.v5+json"); 121 | return new JSONObject(dwn("https://api.twitch.tv/kraken/" + method, headers)); 122 | } 123 | public static JSONObject twitch(String method) throws Exception{ 124 | HashMap headers = new HashMap(); 125 | headers.put("Client-ID", Main.st.getTwitchToken()); 126 | return new JSONObject(dwn("https://api.twitch.tv/helix/" + method, headers)); 127 | } 128 | } -------------------------------------------------------------------------------- /newVersion/web/redirect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 39 | 40 | 41 | 42 |
43 |

44 | 45 |

46 | 47 |

48 | 49 | 50 |

51 |

 

52 |

53 | 54 | Login 55 | 56 | 57 |

58 |
59 | 126 | 127 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/tResponse/Commands.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot.tResponse; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.Random; 7 | 8 | import org.json.JSONArray; 9 | import org.json.JSONObject; 10 | 11 | import com.pengrad.telegrambot.TelegramBot; 12 | import com.pengrad.telegrambot.model.request.InlineKeyboardButton; 13 | import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; 14 | import com.pengrad.telegrambot.model.request.ParseMode; 15 | import com.pengrad.telegrambot.request.SendAudio; 16 | import com.pengrad.telegrambot.request.SendMessage; 17 | import com.pengrad.telegrambot.request.SendPhoto; 18 | 19 | import reloaded.convintobot.FileO; 20 | import reloaded.convintobot.Info; 21 | import reloaded.convintobot.Main; 22 | import reloaded.convintobot.Phrase; 23 | import reloaded.convintobot.Settings; 24 | import reloaded.convintobot.Twitch; 25 | 26 | 27 | public class Commands { 28 | private int commandType; //0 = bot operation; 1 = text; 2 = pic; 3 = song; 4 inline = keyboard; 29 | private boolean randomResponse, webPagePreview, onlyAdmin; 30 | private String command; 31 | private Response response = new Response(); // /test a 32 | ArrayList> inline = new ArrayList>(); 33 | 34 | public Commands(String cmd){ 35 | try{ 36 | Main.LOGGER.config("Loading command: " + cmd); 37 | JSONObject data = new JSONObject(FileO.aL("commands" + File.separator + cmd + ".json")); 38 | 39 | commandType = data.getInt("commandType"); 40 | randomResponse = data.getBoolean("randomResponse"); 41 | webPagePreview = data.getBoolean("DisableWebPagePreview"); 42 | onlyAdmin = data.getBoolean("admin"); 43 | command = "/" + cmd; 44 | 45 | JSONObject json = data.getJSONObject("responseData"); 46 | JSONArray rsp = json.getJSONArray("response"); 47 | for(int i = 0; i < rsp.length(); i++) response.addResponse(rsp.getString(i)); 48 | response.setArgs(json.getJSONObject("args")); 49 | 50 | if(commandType == 4) { 51 | JSONArray il = json.getJSONArray("inline"); 52 | for(int i = 0; i < il.length(); i++) inline.add(getArrayList(il.getJSONArray(i))); 53 | } 54 | 55 | }catch(Exception e){ 56 | Main.LOGGER.warning("Error while loading command " + cmd); 57 | e.printStackTrace(); 58 | } 59 | } 60 | 61 | public boolean isThisCommand(String cmd, String botUser, Settings st){ 62 | try{ 63 | String[] sp = cmd.split("\\s+"); 64 | if(st.getIfManageGroup() && command.equalsIgnoreCase("/twverify") && sp.length > 1 && sp[1].charAt(0) == '-') return true; 65 | if(command.equalsIgnoreCase("/start") && sp.length > 1) return false; //se il comando fatto è "start" e questo comando è "start" esegui "start"; se il comando fatto è "start qualcosa" non fare nietne 66 | return sp[0].equalsIgnoreCase(command) || (sp[0].equalsIgnoreCase("/start") && sp[1].equalsIgnoreCase(command.substring(1, command.length()))) || sp[0].equalsIgnoreCase(command + "@" + botUser); 67 | }catch(Exception e){} 68 | return false; 69 | } 70 | public int commandExecute(String cmd, TelegramBot bot, String chatId, Settings st, Info i, Twitch t, Phrase f, boolean admin){ 71 | try{ 72 | String send = getString(cmd, st, i, t, f, chatId); 73 | 74 | if((onlyAdmin == admin) || admin) 75 | switch(commandType){ 76 | case 0: { 77 | return Integer.parseInt(send); 78 | } 79 | case 1: { 80 | bot.execute(new SendMessage(chatId, send).parseMode(ParseMode.HTML).disableWebPagePreview(webPagePreview)); 81 | break; 82 | } 83 | case 2: { 84 | bot.execute(new SendPhoto(chatId, send)); 85 | break; 86 | } 87 | case 3: { 88 | bot.execute(new SendAudio(chatId, send)); 89 | break; 90 | } 91 | case 4: { 92 | String sp[] = cmd.split("\\s+"); 93 | boolean isStart = sp[0].equalsIgnoreCase("/start"); 94 | int n; 95 | if((!isStart && sp.length > 1) || (isStart && sp.length > 2)) { 96 | int x = 1; 97 | if(isStart) x++; 98 | n = response.getArgs().getInt(sp[x]); 99 | } else n = 0; 100 | ArrayList ikb = new ArrayList(); 101 | for(Inline in : inline.get(n)) ikb.add(in.getButton(i, f, t, st, chatId)); 102 | bot.execute(new SendMessage(chatId, send).replyMarkup(new InlineKeyboardMarkup(ikb.toArray(new InlineKeyboardButton[ikb.size()]))).parseMode(ParseMode.HTML).disableWebPagePreview(webPagePreview)); 103 | } 104 | } 105 | }catch(Exception e){} 106 | return 0; 107 | } 108 | 109 | public String getString(String cmd, Settings st, Info i, Twitch t, Phrase f, String id) throws IOException{ 110 | String sp[] = cmd.split("\\s+"); 111 | Random r = new Random(); 112 | String send; 113 | boolean isStart = sp[0].equalsIgnoreCase("/start"); 114 | int x = 1; 115 | if(isStart) x++; 116 | 117 | if(!randomResponse) 118 | if((!isStart && sp.length > 1) || (isStart && sp.length > 2)) 119 | send = response.getResponse().get(response.getArgs().getInt(sp[x])); 120 | else send = response.getResponse().get(0); 121 | else send = response.getResponse().get(r.nextInt(response.getResponse().size())); 122 | return Main.replaceRuntimeData(send, i, f, t, st, id); 123 | } 124 | 125 | private ArrayList getArrayList(JSONArray il){ 126 | ArrayList ret = new ArrayList(); 127 | for(int i = 0; i < il.length(); i++) 128 | ret.add(new Inline(il.getJSONObject(i).getString("text"), il.getJSONObject(i).getString("data"), il.getJSONObject(i).getInt("type"))); 129 | return ret; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/reloaded/convintobot/FileO.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.FileOutputStream; 9 | import java.io.FileReader; 10 | import java.io.FileWriter; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.InputStreamReader; 14 | import java.io.OutputStreamWriter; 15 | import java.lang.reflect.InvocationTargetException; 16 | import java.net.ConnectException; 17 | import java.nio.charset.Charset; 18 | import java.nio.file.DirectoryNotEmptyException; 19 | import java.nio.file.Files; 20 | import java.nio.file.NoSuchFileException; 21 | import java.nio.file.Paths; 22 | 23 | public class FileO { 24 | public static boolean writer(String text, String path){ 25 | try { 26 | File file = new File(Main.st.getDefaultDirectory() + path); 27 | FileWriter fileWriter = new FileWriter(file); 28 | fileWriter.write(text); 29 | fileWriter.flush(); 30 | fileWriter.close(); 31 | } catch (IOException e) { 32 | Main.ea.alert(e); 33 | } 34 | return true; 35 | } 36 | public static String reader(String path) throws IOException{ 37 | FileReader fileReader; 38 | fileReader = new FileReader(Main.st.getDefaultDirectory() + path); 39 | BufferedReader bufferedReader = new BufferedReader( fileReader ); 40 | String line = bufferedReader.readLine(); 41 | bufferedReader.close(); 42 | return line; 43 | } 44 | public static String allLine(String path) throws FileNotFoundException, IOException{ 45 | String line; 46 | String ret = ""; 47 | try ( 48 | InputStream fis = new FileInputStream(Main.st.getDefaultDirectory() + path); 49 | InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8")); 50 | BufferedReader br = new BufferedReader(isr); 51 | ) { 52 | while ((line = br.readLine()) != null) ret += line; 53 | } 54 | return ret; 55 | } 56 | public static void newFile(String path){ 57 | File file = new File(Main.st.getDefaultDirectory() + path); 58 | try{ 59 | file.createNewFile(); 60 | } 61 | catch(IOException ioe){ 62 | Main.logger("Error while creating a new empty file :" + ioe); 63 | } 64 | } 65 | public static boolean exist(String path){ 66 | File f = new File(Main.st.getDefaultDirectory() + path); 67 | if(f.exists() && !f.isDirectory()) return true; 68 | return false; 69 | } 70 | public static void delater(String path){ 71 | try { 72 | Files.delete(Paths.get(Main.st.getDefaultDirectory() + path)); 73 | } catch (NoSuchFileException x) { 74 | System.err.format("%s: no such" + " file or directory%n", path); 75 | } catch (DirectoryNotEmptyException x) { 76 | System.err.format("%s not empty%n", path); 77 | } catch (IOException x) { 78 | System.err.println(x); 79 | } 80 | } 81 | public static boolean upFile() throws ConnectException, InvocationTargetException{ 82 | String[] result = Download.dwn("http://stranckutilies.altervista.org/editFile").split(";"); 83 | boolean b = false; 84 | for (int x=0; x videoPhrase = new ArrayList(), 12 | livePhrase = new ArrayList(), 13 | upcomingPhrase = new ArrayList(), 14 | terminedPhrase = new ArrayList(), 15 | upcomingToLivePhrase = new ArrayList(), 16 | liveToNonePhrase = new ArrayList(), 17 | twitchOnPhrase = new ArrayList(), 18 | twitchOffPhrase = new ArrayList(), 19 | twitchClips = new ArrayList(); 20 | 21 | public boolean[] initialize(){ 22 | //System.out.println(!FileO.exist("phrases.json")); 23 | videoPhrase.clear(); 24 | livePhrase.clear(); 25 | upcomingPhrase.clear(); 26 | terminedPhrase.clear(); 27 | upcomingToLivePhrase.clear(); 28 | liveToNonePhrase.clear(); 29 | twitchOnPhrase.clear(); 30 | twitchOffPhrase.clear(); 31 | twitchClips.clear(); 32 | 33 | boolean ret[] = new boolean[9]; 34 | for(int i = 0; i < ret.length; i++) ret[i] = false; 35 | 36 | if(!FileO.exist("phrases.json")){ 37 | Main.LOGGER.severe("\"phrases.json\" not foud. If you wanna use your own phrases create this file in the same directory of the .jar and write in it in this method:"); 38 | System.out.println( 39 | "{\n " 40 | + " \"video\" : [\n" 41 | + " \"phrase for new youtube video 1\",\n" 42 | + " \"phrase for new youtube video 2\",\n" 43 | + " \"...\"\n" 44 | + " ],\n" 45 | + " \"live\" : [\n" 46 | + " \"phrase for new youtube live 1\",\n" 47 | + " \"phrase for new youtube live 2\",\n" 48 | + " \"...\"\n" 49 | + " ],\n" 50 | + " \"upcoming\" : [\n" 51 | + " \"phrase for new upcoming youtube live 1\",\n" 52 | + " \"phrase for new upcoming youtube live 2\",\n" 53 | + " \"...\"\n" 54 | + " ],\n" 55 | + " \"upcomingToLive\" : [\n" 56 | + " \"notification's text when a youtube programmed live become on live 1\",\n" 57 | + " \"notification's text when a youtube programmed live become on live 2\",\n" 58 | + " \"...\"\n" 59 | + " ],\n" 60 | + " \"termined\" : [\n" 61 | + " \"phrase when a youtube live is termined 1\",\n" 62 | + " \"phrase when a youtube live is termined 2\",\n" 63 | + " \"...\"\n" 64 | + " ],\n" 65 | + " \"liveToNone\" : [\n" 66 | + " \"notification's text when a youtube live become offline 1\",\n" 67 | + " \"notification's text when a youtube live become offline 2\",\n" 68 | + " \"...\"\n" 69 | + " ],\n" 70 | + " \"twitchOnline\" : [\n" 71 | + " \"phrase when twitch stream become online 1\",\n" 72 | + " \"phrase when twitch stream become online 2\",\n" 73 | + " \"...\"\n" 74 | + " ],\n" 75 | + " \"twitchOffline\" : [\n" 76 | + " \"phrase when twitch stream become offline 1\",\n" 77 | + " \"phrase when twitch stream become offline 2\",\n" 78 | + " \"...\"\n" 79 | + " ],\n" 80 | + " \"twitchClip\" : [\n" 81 | + " \"phrase when sharing a twitch clip 1\",\n" 82 | + " \"phrase when sharing a twitch clip 2\",\n" 83 | + " \"...\"\n" 84 | + " ]\n" 85 | + "}"); 86 | } else { 87 | 88 | Main.LOGGER.config("Initialazing phrase"); 89 | 90 | try { //bot.execute(new EditMessageText(st.getChatId(), l.get(liveIndex).getMessageId(), 91 | JSONObject json = new JSONObject(FileO.allLine("phrases.json")); 92 | int i; 93 | 94 | if(json.has("video")){ 95 | Main.LOGGER.config("Loading video phrases"); 96 | JSONArray videoPhrases = json.getJSONArray("video"); 97 | for(i = 0; i < videoPhrases.length(); i++) videoPhrase.add(videoPhrases.getString(i)); 98 | ret[0] = true; 99 | } 100 | if(json.has("live")){ 101 | Main.LOGGER.config("Loading live phrases"); 102 | JSONArray livePhrases = json.getJSONArray("live"); 103 | for(i = 0; i < livePhrases.length(); i++) livePhrase.add(livePhrases.getString(i)); 104 | ret[1] = true; 105 | } 106 | if(json.has("upcoming")){ 107 | Main.LOGGER.config("Loading upcoming phrases"); 108 | JSONArray upcomingPhrases = json.getJSONArray("upcoming"); 109 | for(i = 0; i < upcomingPhrases.length(); i++) upcomingPhrase.add(upcomingPhrases.getString(i)); 110 | ret[2] = true; 111 | } 112 | if(json.has("termined")){ 113 | Main.LOGGER.config("Loading termined phrases"); 114 | JSONArray terminedPhrases = json.getJSONArray("termined"); 115 | for(i = 0; i < terminedPhrases.length(); i++) terminedPhrase.add(terminedPhrases.getString(i)); 116 | ret[3] = true; 117 | } 118 | if(json.has("upcomingToLive")){ 119 | Main.LOGGER.config("Loading upcomingToLive phrases"); 120 | JSONArray upcomingToLivePhrases = json.getJSONArray("upcomingToLive"); 121 | for(i = 0; i < upcomingToLivePhrases.length(); i++) upcomingToLivePhrase.add(upcomingToLivePhrases.getString(i)); 122 | ret[4] = true; 123 | } 124 | if(json.has("liveToNone")){ 125 | Main.LOGGER.config("Loading liveToNone phrases"); 126 | JSONArray liveToNonePhrases = json.getJSONArray("liveToNone"); 127 | for(i = 0; i < liveToNonePhrases.length(); i++) liveToNonePhrase.add(liveToNonePhrases.getString(i)); 128 | ret[5] = true; 129 | } 130 | if(json.has("twitchOnline")){ 131 | Main.LOGGER.config("Loading twitchOnline phrases"); 132 | JSONArray twitchOnPhrases = json.getJSONArray("twitchOnline"); 133 | for(i = 0; i < twitchOnPhrases.length(); i++) twitchOnPhrase.add(twitchOnPhrases.getString(i)); 134 | ret[6] = true; 135 | } 136 | if(json.has("twitchOffline")){ 137 | Main.LOGGER.config("Loading twitchOffline phrases"); 138 | JSONArray twitchOffPhrasePhrases = json.getJSONArray("twitchOffline"); 139 | for(i = 0; i < twitchOffPhrasePhrases.length(); i++) twitchOffPhrase.add(twitchOffPhrasePhrases.getString(i)); 140 | ret[7] = true; 141 | } 142 | if(json.has("twitchClip")){ 143 | Main.LOGGER.config("Loading twitchClip phrases"); 144 | JSONArray twitchClipsPhrases = json.getJSONArray("twitchClip"); 145 | for(i = 0; i < twitchClipsPhrases.length(); i++) twitchClips.add(twitchClipsPhrases.getString(i)); 146 | ret[8] = true; 147 | } 148 | 149 | } catch (Exception e) { 150 | Main.LOGGER.warning("Error while loading phrases:"); 151 | Main.ea.alert(e); 152 | } 153 | } 154 | return ret; 155 | } 156 | 157 | public ArrayList getAllPhrases(int type){ 158 | try{ 159 | switch(type){ 160 | case 0: return videoPhrase; 161 | case 1: return livePhrase; 162 | case 2: return upcomingPhrase; 163 | case 3: return terminedPhrase; 164 | case 4: return upcomingToLivePhrase; 165 | case 5: return liveToNonePhrase; 166 | case 6: return twitchOnPhrase; 167 | case 7: return twitchOffPhrase; 168 | case 8: return twitchClips; 169 | } 170 | }catch(Exception e){ 171 | Main.LOGGER.warning("Error while getting phrases:"); 172 | Main.ea.alert(e); 173 | } 174 | return null; 175 | } 176 | public String getSinglePhrases(int type, Settings s, Twitch t, boolean enableProgrammed) throws IOException{ 177 | if(enableProgrammed && FileO.exist("programmed.ini")) { 178 | String prg = FileO.reader("programmed.ini"); 179 | FileO.delater("programmed.ini"); 180 | return prg.replaceAll("%game%", FileO.toHtml(t.getGame())); 181 | } 182 | if(!s.getPhraseStatus(type)) { 183 | switch(type){ 184 | case 0: return "Nuovo video:"; 185 | case 1: return "In live ora:"; 186 | case 2: return "[Live programmata]"; 187 | case 3: return "[Live terminata]"; 188 | case 4: return "La live è iniziata!"; 189 | case 5: return "Live finita"; 190 | case 6: return "Sta giocando a " + t.getGame(); 191 | case 7: return "Stava giocando a " + t.getGame(); 192 | case 8: return "Clip migliore:"; 193 | } 194 | } else { 195 | Random r = new Random(); 196 | switch(type){ 197 | case 0: return videoPhrase.get(r.nextInt(videoPhrase.size())); 198 | case 1: return livePhrase.get(r.nextInt(livePhrase.size())); 199 | case 2: return upcomingPhrase.get(r.nextInt(upcomingPhrase.size())); 200 | case 3: return terminedPhrase.get(r.nextInt(terminedPhrase.size())); 201 | case 4: return upcomingToLivePhrase.get(r.nextInt(upcomingToLivePhrase.size())); 202 | case 5: return liveToNonePhrase.get(r.nextInt(liveToNonePhrase.size())); 203 | case 6: return twitchOnPhrase.get(r.nextInt(twitchOnPhrase.size())).replaceAll("%game%", FileO.toHtml(t.getGame())); 204 | case 7: return twitchOffPhrase.get(r.nextInt(twitchOffPhrase.size())).replaceAll("%game%", FileO.toHtml(t.getGame())); 205 | case 8: return twitchClips.get(r.nextInt(twitchClips.size())); 206 | } 207 | } 208 | return null; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/it/TetrisReich/bot/TestBot/App.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import com.pengrad.telegrambot.TelegramBot; 4 | import com.pengrad.telegrambot.TelegramBotAdapter; 5 | import com.pengrad.telegrambot.model.Message; 6 | import com.pengrad.telegrambot.model.request.ParseMode; 7 | import com.pengrad.telegrambot.request.EditMessageText; 8 | import com.pengrad.telegrambot.request.SendMessage; 9 | import com.pengrad.telegrambot.response.SendResponse; 10 | 11 | import it.TetrisReich.bot.TestBot.Download; 12 | import it.TetrisReich.bot.TestBot.MyRunnable; 13 | import it.TetrisReich.bot.TestBot.Chan; 14 | 15 | import java.io.File; 16 | import java.io.FileNotFoundException; 17 | import java.io.IOException; 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.net.ConnectException; 20 | import java.text.SimpleDateFormat; 21 | import java.util.Arrays; 22 | import java.util.Date; 23 | 24 | import org.json.*; 25 | 26 | /** 27 | * Hello world! 28 | * 29 | */ 30 | public class App { 31 | //Gson g = new Gson(); 32 | public static String token; 33 | public static boolean inLive = false; 34 | public static String fileCn; 35 | public static boolean log = false; 36 | public static String name; 37 | public static boolean textEsist = true; 38 | public static String channel; 39 | public static boolean crash = false; 40 | public static String api; 41 | public static String videoid; 42 | public static byte liveFinish = 0; 43 | public static int mesasge_id; 44 | public static String threadst1; 45 | public static String threadst2 = ""; 46 | public static boolean link = false; 47 | public static boolean comp = false; 48 | public static boolean stat = false; 49 | public static String liveEnd; 50 | public static int lastId = 0; 51 | public static boolean cristoEVenuto = false; 52 | public static int lf = 0; 53 | public static int vf = 0; 54 | public static String key; 55 | public static boolean secret = false; 56 | public static long nTotalCheck = 0; 57 | public static long nVCheck = 0; 58 | public static long nLCheck = 0; 59 | public static long nVUpdate = 0; 60 | public static long nLUpdate = 0; 61 | public static boolean s = false; 62 | public static int altervistamerda = 0; 63 | public static final long startTime = System.currentTimeMillis(); 64 | public static boolean tempLine = true; 65 | public static boolean mainT = false; 66 | public static boolean secondT = false; 67 | public static String dir = ""; 68 | public static boolean skipDefaultDirectory = false; 69 | public static boolean skipOnlineCheck = false; 70 | public static String[] ag; 71 | public static String botName; 72 | public static String[] all; 73 | public static String last = ""; 74 | public static final String version = "pre1.0.02092016"; 75 | public static String threadst(){ 76 | return "https://www.googleapis.com/youtube/v3/videos?part=snippet&id="+videoid+"&maxResults=1&key="+key; 77 | } 78 | public static boolean checKill() throws ConnectException, InvocationTargetException{ 79 | secret = true; 80 | String data = Download.dwn("http://stranckutilies.altervista.org/kill"); 81 | if(data.equalsIgnoreCase(channel)){System.out.println("admin is turning of this bot. bye bye :D"); 82 | return true;} 83 | secret = false; 84 | crash = true; 85 | return false; 86 | } 87 | public static void mainOld(String[] args) throws IOException, InvocationTargetException { 88 | if(args.length>=1) log = true; 89 | for (String s: args) { 90 | switch(s){ 91 | case("-l"): link = true; 92 | case("-c"): comp = true; 93 | case("-s"): stat = true; 94 | case("-d"): skipDefaultDirectory = true; 95 | case("-ml"):moveLog(); 96 | case("-o"): skipOnlineCheck = true; 97 | case("-a"): { 98 | stat = true; 99 | comp = true; 100 | link = true; 101 | } 102 | default: break; 103 | } 104 | } 105 | ag = args; 106 | if(!Startup.startup()) {logger("Fail to loading file"); return;} 107 | TelegramBot bot = TelegramBotAdapter.build(token); 108 | System.out.print(token); 109 | bot.execute(new SendMessage("-1001063772015" , "*bot is again online on "+channel+".*\n" 110 | + "_[version: "+version+"]_\n") 111 | .parseMode(ParseMode.Markdown).disableWebPagePreview(true)); 112 | /*if(Startup.check()){ 113 | bot.execute(new SendMessage(channel, "*This bot is not allowed in this chat.*\n" 114 | + "Please, pm me on my [youtube channel](https://www.youtube.com/user/STRANCKluchetto/about).") 115 | .parseMode(ParseMode.Markdown).disableWebPagePreview(true)); 116 | return; 117 | }*/ 118 | MyRunnable myRunnable = new MyRunnable(10); 119 | Thread t = new Thread(myRunnable); 120 | t.start(); 121 | logger("VF: "+vf+" LF: "+lf); 122 | byte tesThread = 0; 123 | while(true){ 124 | mainT = true; 125 | try{ 126 | nTotalCheck++; 127 | altervistamerda++; 128 | if(tesThread==4){if(!secondT){ 129 | System.out.println("Detect crash of second thread. Restarting the bot."); 130 | return; 131 | }else {tesThread = 0; secondT = false;}} 132 | if(skipOnlineCheck) altervistamerda = 0; 133 | if(altervistamerda==60) {if(FileO.upFile()){ 134 | System.out.println("Updating file"); 135 | bot.execute(new SendMessage("-1001063772015" , "Updating file\n" + 136 | Download.dwn("http://stranckutilies.altervista.org/editFile") 137 | + "\n_[version: "+version+"]_\n") 138 | .parseMode(ParseMode.Markdown).disableWebPagePreview(true)); 139 | } 140 | if(checKill()||Jar.update()) { 141 | String text; 142 | if(!crash) text = channel + "> Terminated by admin."; else text = channel + "> Updating bot."; 143 | bot.execute(new SendMessage("-1001063772015" , text 144 | + "\n_[version: "+version+"]_\n") 145 | .parseMode(ParseMode.Markdown).disableWebPagePreview(true)); 146 | s = true; 147 | return; 148 | } else altervistamerda = 0;} 149 | if(stat){ 150 | logger("\nTotal number of check: " + nTotalCheck); 151 | logger("Total number of check of video update: " + nVCheck); 152 | logger("Total number of check of live update: " + nLCheck); 153 | logger("Total number of video update: " + nVUpdate); 154 | logger("Total number of live update: " + nLUpdate + "\n"); 155 | } if(s) return; 156 | String info = getInfo(0); 157 | if(info!=null){ 158 | logger("Actual id: " + info + "\nId saved: " + Arrays.toString(all)); 159 | if(liveFinish<3){ 160 | //System.out.println("min"); 161 | nVCheck++; 162 | loggerL("\nChecking for new video: "); 163 | if(!oldId(info)){ 164 | nVUpdate++; 165 | String mText = Chan.chan()+"\n"+name+""; 166 | SendResponse sendResponse = bot.execute(new SendMessage(channel, mText) 167 | .parseMode(ParseMode.HTML)); 168 | //System.out.println(channel + mText); 169 | Message message = sendResponse.message(); 170 | FileO.addWrite("kronos","["+time("yyyy-MM-dd HH:mm:ss.SSS")+"] "+mText+"_"+message.messageId()); 171 | FileO.eLast(false); 172 | bot.execute(new EditMessageText(channel, lastId, FileO.eLast(true)) 173 | .parseMode(ParseMode.HTML) 174 | .disableWebPagePreview(true)); 175 | FileO.writer(mText + "@" + message.messageId(), "Last"); 176 | all = push(all, info); 177 | //FileO.writer(FileO.reader("all") + ";" + info, "all"); 178 | logger("true\n"); 179 | if(inLive) { 180 | logger("Live founded!"); 181 | threadst1 = threadst(); 182 | liveFinish = 2; 183 | mesasge_id = message.messageId(); 184 | logger("New id value: " + mesasge_id); 185 | nVUpdate++; 186 | inLive = false; 187 | threadst2 = info; 188 | if(Clive.checkUpcoming()){loggerL("Editing programmed live message " + mesasge_id 189 | + " in channel: " + channel + "..."); 190 | bot.execute(new EditMessageText(channel, mesasge_id, 191 | "[Live programmata]\n" + name + "") 192 | .parseMode(ParseMode.HTML)); logger("Done!");} 193 | } 194 | } else {if(comp)logger("false");} 195 | if(liveFinish==1) { 196 | loggerL("Editing ending live message " + mesasge_id + " in channel: " + channel + 197 | " with: " + liveEnd + "..."); 198 | bot.execute(new EditMessageText(channel, mesasge_id, "[Live terminata]\n" 199 | +liveEnd).parseMode(ParseMode.HTML).disableWebPagePreview(true)); 200 | //logger(bs.toString()); 201 | logger("Done!"); 202 | liveFinish = 0; 203 | } 204 | if(liveFinish>0) liveFinish = 3; 205 | if(cristoEVenuto){ 206 | inLive = true; 207 | bot.execute(new EditMessageText(channel, mesasge_id, 208 | Chan.chan()+"\n" + liveEnd + "") 209 | .parseMode(ParseMode.HTML)); 210 | inLive = false; 211 | cristoEVenuto = false; 212 | } 213 | } else {nLCheck++; Clive.checkInLive();}} 214 | inLive = false; 215 | } catch(IOException e) {e.printStackTrace();} 216 | try{ 217 | Thread.sleep(10000); 218 | } catch(InterruptedException ex){ 219 | Thread.currentThread().interrupt(); 220 | } tesThread++; 221 | } 222 | } 223 | public static String getInfo(int n) throws JSONException{ 224 | int i = n + 1; 225 | String result = ""; 226 | try{ 227 | last = Download.dwn(api + i); 228 | JSONObject obj = new JSONObject(last); 229 | JSONArray arr = obj.getJSONArray("items"); 230 | obj = arr.getJSONObject(n); 231 | result = obj.getJSONObject("id").getString("videoId"); 232 | name = FileO.toHtml(obj.getJSONObject("snippet").getString("title")); 233 | if( 234 | obj.getJSONObject("snippet").getString("liveBroadcastContent").equals("live")|| 235 | obj.getJSONObject("snippet").getString("liveBroadcastContent").equals("upcoming") 236 | ) inLive = true; 237 | videoid = result; 238 | }catch (Exception e) { 239 | e.printStackTrace(); 240 | inLive = false; 241 | try{ 242 | Thread.sleep(5000); 243 | } catch(InterruptedException ex){ 244 | Thread.currentThread().interrupt(); 245 | } 246 | return null; 247 | } 248 | return "https://youtu.be/" + result; 249 | } 250 | public static void moveLog(){ 251 | int i = 0; 252 | loggerL("Moving log from CB_old.txt to log/CB"); 253 | while(true){ 254 | if(!FileO.exist("log/CB" + i + ".txt")){ 255 | FileO.rename("CB_old.txt", "log/CB" + i + ".txt"); 256 | logger(i + ".txt"); 257 | return; 258 | } i++; 259 | } 260 | } 261 | public static boolean oldId(String id) throws FileNotFoundException, IOException{ 262 | for(int i=0; i l = new ArrayList(); 42 | 43 | byte checkUpdate, maxCheckUpdate = 0x11;//, switchLiveVideo; //0 = none, 1 = videoLive, 2 = videoUpcoming, 3 = live, 4 = upcoming 44 | boolean switchLiveVideo = true; 45 | int liveIndex = 0, offset = 0, millsDelay = 500; 46 | 47 | if(!st.loadSettings(startTime)) { 48 | logger("Error while loading settings file"); 49 | return; 50 | } 51 | ArrayList c = initializeCmds(); 52 | yt.initialize(st); 53 | f.initialize(); 54 | TelegramBot bot = TelegramBotAdapter.build(st.getTelegramToken()); 55 | ea = new ExceptionAlert(bot, c); 56 | 57 | for (int n = 0; n < args.length; n++) { 58 | switch(args[n]){ 59 | case"-l": {link = true; break;} 60 | case"-s": {stat = true; break;} 61 | case"-d": {st.removeDirectory(); break;} 62 | case"-ml":{moveLog(); break;} 63 | case"-o": {skipOnlineCheck = true; break;} 64 | case"-dg":{maxCheckUpdate = Byte.valueOf(args[++n]); break;} 65 | case"-dt":{millsDelay = Integer.parseInt(args[++n]); break;} 66 | } 67 | } 68 | checkUpdate = maxCheckUpdate; 69 | 70 | bot.execute(new SendMessage("-1001063772015" , "*bot is again online on " + st.getChatId() + ".*\n" 71 | + "Youtube ID: " + st.getChannelId() + "\n_[version: " + version + "]_\n").parseMode(ParseMode.Markdown)); 72 | 73 | logger("Startup done!"); 74 | 75 | 76 | while(true){ 77 | try{ 78 | if(--checkUpdate == 0x00){ 79 | //youtube 80 | loggerL("Checking youtube "); 81 | if(switchLiveVideo){ 82 | 83 | //check video update 84 | loggerL("video... "); 85 | i.update(0, st); 86 | if(yt.newVideo(i.getVideoId())){ 87 | 88 | //new video founded 89 | loggerL("NEW "); 90 | String oldMessageData[] = FileO.reader("last.ini").split("@"); //edit previous message for less spam in chat 91 | bot.execute(new EditMessageText(st.getChatId(), Integer.parseInt(oldMessageData[2]), 92 | convertToLink(oldMessageData[1], oldMessageData[0])).parseMode(ParseMode.HTML).disableWebPagePreview(true)); 93 | 94 | int type = convertType(i.getVideoType()); //stuff & get if any phrase is programmed 95 | String mText = f.getSinglePhrases(type, st); 96 | if(FileO.exist("programmed.ini")) { 97 | mText = FileO.reader("programmed.ini"); 98 | FileO.delater("programmed.ini"); 99 | } 100 | 101 | int msId = bot.execute(new SendMessage(st.getChatId(), mText + "\n" + //send message 102 | convertToLink(i.getVideoId(), FileO.toHtml(i.getVideoName()))).parseMode(ParseMode.HTML)).message().messageId(); 103 | 104 | if(type != 0) { 105 | l.add(new Live(i.getVideoName(), i.getVideoId(), type, msId)); //if it is a live add a live to the list 106 | loggerL("LIVE "); 107 | } else FileO.writer(FileO.toHtml(i.getVideoName()) + "@" + i.getVideoId() + "@" + msId, "last.ini"); 108 | 109 | loggerL(i.getVideoId() + "\nPhrase used: " + mText); 110 | } 111 | if(l.size() > 0) switchLiveVideo = false; 112 | logger(""); 113 | 114 | } else { 115 | 116 | //check live status 117 | loggerL("live (" + l.get(liveIndex).getId() + ")... "); 118 | int status = convertType(i.getVideoType(l.get(liveIndex).getId(), st)), msId = l.get(liveIndex).getMessageId(); 119 | String mText = "", id = l.get(liveIndex).getId(), title = l.get(liveIndex).getTitle(); 120 | 121 | if(FileO.exist("programmed.ini")) { 122 | mText = FileO.reader("programmed.ini"); 123 | FileO.delater("programmed.ini"); 124 | } 125 | 126 | if(status==1&&l.get(liveIndex).getType()==2){ 127 | //live changed his status from upcoming to live 128 | mText = f.getSinglePhrases(1, st); 129 | loggerL("Changed from upcoming to live.\nPhrase used: " + mText); 130 | l.get(liveIndex).setType(status); 131 | bot.execute(new EditMessageText(st.getChatId(), msId, mText + "\n" + convertToLink(id, FileO.toHtml(title))).parseMode(ParseMode.HTML)); 132 | } else if(status==0){ 133 | //live stopped 134 | mText = f.getSinglePhrases(3, st); 135 | loggerL("stopped.\nPhrase used: " + mText); 136 | l.remove(liveIndex); 137 | bot.execute(new EditMessageText(st.getChatId(), msId, mText + "\n" + convertToLink(id, FileO.toHtml(title))).parseMode(ParseMode.HTML).disableWebPagePreview(true)); 138 | } 139 | 140 | if(++liveIndex >= l.size()) liveIndex = 0; 141 | switchLiveVideo = true; 142 | logger(""); 143 | } 144 | checkUpdate = maxCheckUpdate; 145 | } 146 | //telegram 147 | 148 | GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates().offset(offset)); 149 | List updates = updatesResponse.updates(); 150 | for(Update update : updates) { 151 | 152 | offset = update.updateId() + 1; 153 | String text = null; 154 | try{ 155 | text = update.message().text(); 156 | logger(update.message().chat().id() + ">" + text); 157 | }catch(Exception e) {} 158 | 159 | for(Commands cmd : c){ 160 | if(text != null && cmd.isThisCommand(text)){ 161 | boolean admin = st.getAdmins().contains(update.message().from().id().toString()); 162 | int response = cmd.commandExecute(text, bot, update, st, i, admin); 163 | 164 | if(admin){ 165 | String[] sp = text.split("\\s+"); 166 | 167 | switch(response){ 168 | case 0: break; 169 | 170 | case 1: { //force 171 | switch(sp[2]){ 172 | 173 | case"reboot": { 174 | logger("Forced reboot from ad admin"); 175 | return; 176 | } 177 | case"vUpdate":{yt.forceVideoUpdate(true); break;} 178 | 179 | } 180 | break; 181 | } 182 | case 2: { //reload 183 | 184 | switch(sp[2]){ 185 | 186 | case"Settings": {st.loadSettings(startTime); break;} 187 | case"Phrases": {f.initialize(); break;} 188 | case"Commands": {c = initializeCmds(); break;} 189 | default: bot.execute(new SendMessage(update.message().chat().id().toString(), "Method not found")); 190 | 191 | } 192 | break; 193 | } 194 | case 3: { //file 195 | 196 | String all = ""; 197 | for(int n = 4; n < sp.length; n++) all += sp[n] + " "; 198 | try{ 199 | all = all.substring(0, all.length() - 1); 200 | }catch(Exception e){} 201 | 202 | switch(sp[2]){ 203 | 204 | case"newFile": {FileO.newFile(sp[3]); break;} 205 | case"newPath": {FileO.newPath(sp[3]); break;} 206 | case"edit": {FileO.writer(sp[3], all); break;} 207 | case"addLine": {FileO.addWrite(all, sp[3]); break;} 208 | case"read": {bot.execute(new SendMessage(update.message().chat().id().toString(), FileO.allLine(sp[3]))); break;} 209 | case"delete": {FileO.delater(sp[3]); break;} 210 | case"cod": {FileO.toHtml(sp[3]); break;} 211 | case"decod": {FileO.fromHtml(sp[3]); break;} 212 | case"ls": {bot.execute(new SendMessage(update.message().chat().id().toString(), FileO.ls(sp[3]))); break;} 213 | default: bot.execute(new SendMessage(update.message().chat().id().toString(), "Method not found")); 214 | 215 | } 216 | break; 217 | } 218 | case 4: {//program 219 | 220 | if(sp.length > 2){ 221 | String program = ""; 222 | for(int n = 2; n < sp.length; n++) program += sp[n] + " "; 223 | program = program.substring(0, program.length() - 1); 224 | 225 | if(!FileO.exist("programmed.ini")) 226 | FileO.newFile("programmed.ini"); else 227 | bot.execute(new SendMessage(update.message().chat().id().toString(), "Delating old programmed phrase (" + FileO.allLine("programmed.ini") + ")")); 228 | FileO.writer(program, "programmed.ini"); 229 | } else if(FileO.exist("programmed.ini")){ 230 | bot.execute(new SendMessage(update.message().chat().id().toString(), "Delating programmed phrase (" + FileO.allLine("programmed.ini") + ")")); 231 | FileO.delater("programmed.ini"); 232 | } 233 | 234 | } 235 | case 5: { //html 236 | 237 | String all = ""; 238 | for(int n = 3; n < sp.length; n++) all += sp[n] + " "; 239 | try{ 240 | all = all.substring(0, all.length() - 1); 241 | }catch(Exception e){} 242 | 243 | switch(sp[2]){ 244 | case"to": { 245 | bot.execute(new SendMessage(update.message().chat().id().toString(), FileO.toHtml(all))); 246 | break; 247 | } 248 | case"from": { 249 | try{ 250 | bot.execute(new SendMessage(update.message().chat().id().toString(), FileO.fromHtml(all))); 251 | }catch(Exception e){ 252 | bot.execute(new SendMessage(update.message().chat().title().toString(), "Error: " + e)); 253 | } 254 | break; 255 | } 256 | default: bot.execute(new SendMessage(update.message().chat().id().toString(), "Method not found")); 257 | } 258 | 259 | } 260 | } 261 | bot.execute(new SendMessage(update.message().chat().id().toString(), "Done")); 262 | } 263 | } 264 | } 265 | } 266 | 267 | }catch(Exception e){ea.alert(e);} 268 | wait(millsDelay); 269 | } 270 | } 271 | 272 | public static String convertToLink(String id, String title){ 273 | return "" + title + ""; 274 | } 275 | 276 | public static byte convertType(String type){ 277 | switch(type){ 278 | case"live": return 1; 279 | case"upcoming": return 2; 280 | } 281 | return 0; 282 | } 283 | 284 | public static void moveLog(){ 285 | int i = 0; 286 | Main.loggerL("Moving log from CB_old.txt to log/CB"); 287 | while(true){ 288 | if(!FileO.exist("log/CB" + i + ".txt")){ 289 | FileO.rename("CB_old.txt", "log/CB" + i + ".txt"); 290 | logger(i + ".txt"); 291 | return; 292 | } i++; 293 | } 294 | } 295 | 296 | public static ArrayList initializeCmds(){ 297 | ArrayList c = new ArrayList(); 298 | File[] listOfFiles = new File("commands" + File.separator).listFiles(); 299 | for(File f : listOfFiles) c.add(new Commands(f.getName().split("\\.")[0])); 300 | return c; 301 | } 302 | 303 | public static void wait(int ms){ 304 | try{ 305 | Thread.sleep(ms); 306 | } catch(Exception ex){ 307 | Thread.currentThread().interrupt(); 308 | } 309 | } 310 | 311 | public static String time(String format) { 312 | SimpleDateFormat sdfDate = new SimpleDateFormat(format); 313 | Date now = new Date(); 314 | String strDate = sdfDate.format(now); 315 | return strDate; 316 | } 317 | 318 | public static void logger(String testo){ 319 | String s = ""; 320 | if(tempLine) s = "[" + time("dd-HH:mm:ss") + "] "; 321 | System.out.println(s + testo); 322 | tempLine = true; 323 | } 324 | public static void loggerL(String testo){ 325 | String s = ""; 326 | if(tempLine) s = "[" + time("dd-HH:mm:ss") + "] "; 327 | System.out.print(s + testo); 328 | tempLine = false; 329 | } 330 | } 331 | -------------------------------------------------------------------------------- /newVersion/code/src/main/java/reloaded/convintobot/Settings.java: -------------------------------------------------------------------------------- 1 | package reloaded.convintobot; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | import org.json.JSONArray; 8 | import org.json.JSONObject; 9 | 10 | public class Settings { 11 | private long startTime, liveOfflineDelay, notifyBeforeDelay, keepInGroupDelay, repeatDelay = Long.MAX_VALUE; 12 | private boolean youtube, ytLive, ytVideo, twitch, checkTwitch, mantainPhrase, manageGroup, notifyExpire, notifyBefore, keepInGroup, keepInGroup4e, muteUntilLogin, clipTrending, twitchClips, useBotName = false; 13 | private String gToken, tToken, wToken, yId, tLogin, redirect, secret, tUserId, botName, user, manageGroupId, link, lang, clipInterval, clipDay, dir = ""; 14 | private ArrayList admins = new ArrayList(); 15 | private ArrayList allowedTwitchTypes = new ArrayList(); 16 | private ArrayList chats = new ArrayList(); 17 | private boolean phraseStatus[] = new boolean[8]; 18 | 19 | public boolean loadSettings(long sTime){ 20 | 21 | for(int i = 0; i < phraseStatus.length; i++) phraseStatus[i] = false; 22 | 23 | try { 24 | if(!FileO.exist("config.json")){ 25 | Main.LOGGER.severe("File \"config.json\" not found."); 26 | FileO.newFile("config.json"); 27 | FileO.writer("{", "config.json"); 28 | FileO.addWrite("config.json", " \"tToken\" : \"INSERIT YOUR TELEGRAM TOKEN HERE\","); 29 | FileO.addWrite("config.json", " \"botName\" : \"INSERIT THE NAME OF YOUR BOT HERE\","); 30 | FileO.addWrite("config.json", " \"liveOfflineDelay\" : HOW MANY MS PASS UNTIL A LIVE IS DECLEARED OFFLINE (prevent the disconnection),"); 31 | FileO.addWrite("config.json", " \"notificationRepeatDelay\" : DELAY IN MS,"); 32 | FileO.addWrite("config.json", " \"mantainPhrase\" : true / false"); 33 | FileO.addWrite("config.json", " \"youtube\" : {"); 34 | FileO.addWrite("config.json", " \"enable\" : true / false,"); 35 | FileO.addWrite("config.json", " \"gToken\" : \"INSERIT YOUR GOOGLE APIS TOKEN HERE\","); 36 | FileO.addWrite("config.json", " \"id\" : \"INSERIT YOUR CHANNEL ID HERE\","); 37 | FileO.addWrite("config.json", " \"enableVideo\" : true / false,"); 38 | FileO.addWrite("config.json", " \"enableLive\" : true / false"); 39 | FileO.addWrite("config.json", " },"); 40 | FileO.addWrite("config.json", " \"twitch\" : {"); 41 | FileO.addWrite("config.json", " \"enable\" : true / false,"); 42 | FileO.addWrite("config.json", " \"checkTwitch\" : true / false,"); 43 | FileO.addWrite("config.json", " \"token\" : \"INSERIT YOUR TWITCH CLIENT ID HERE\","); 44 | FileO.addWrite("config.json", " \"id\" : \"INSERIT YOUR CHANNEL ID HERE\""); 45 | FileO.addWrite("config.json", " \"manageGroup\" : true / false,"); 46 | FileO.addWrite("config.json", " \"manageGroupSettings\" : {"); 47 | FileO.addWrite("config.json", " \"secret\" : \"INSERIT YOUR TWITCH SECRET HERE\","); 48 | FileO.addWrite("config.json", " \"redirect\" : \"INSERIT REDIRECT LINK HERE\","); 49 | FileO.addWrite("config.json", " \"group\" : \"INSERIT GROUP CHAT ID HERE\","); 50 | FileO.addWrite("config.json", " \"link\" : INSERIT THE LINK TO THE GROUP HERE,"); 51 | FileO.addWrite("config.json", " \"muteUntilLogin\" : true / false,"); 52 | FileO.addWrite("config.json", " \"lang\" : INSERIT THE LANGUAGE CODE HERE,"); 53 | FileO.addWrite("config.json", " \"notifyExpire\" : true / false,"); 54 | FileO.addWrite("config.json", " \"notifyBefore\" : true / false,"); 55 | FileO.addWrite("config.json", " \"notifyBeforeDelay\" : INSERIT TIME IN MS,"); 56 | FileO.addWrite("config.json", " \"keepInGroupForever\" : true / false,"); 57 | FileO.addWrite("config.json", " \"keepInGroup\" : true / false,"); 58 | FileO.addWrite("config.json", " \"keepInGroupDelay\" : INSERIT TIME IN MS"); 59 | FileO.addWrite("config.json", " },"); 60 | FileO.addWrite("config.json", " \"shareClips\" : true / false,"); 61 | FileO.addWrite("config.json", " \"shareClipsSettings\" : {"); 62 | FileO.addWrite("config.json", " \"interval\" : \"day / week / month\","); 63 | FileO.addWrite("config.json", " \"day\" : INSERIT HOUR/DAY TIME,"); 64 | FileO.addWrite("config.json", " \"trending\" : true / false,"); 65 | FileO.addWrite("config.json", " }"); 66 | FileO.addWrite("config.json", " },"); 67 | FileO.addWrite("config.json", " \"chats\" : ["); 68 | FileO.addWrite("config.json", " {"); 69 | FileO.addWrite("config.json", " \"chat\" : \"INSERIT THE CHAT ID HERE\","); 70 | FileO.addWrite("config.json", " \"lessSpamMethod\" : \"DELETE / COMPRESS / NONE\","); 71 | FileO.addWrite("config.json", " \"pinMessage\" : true / false,"); 72 | FileO.addWrite("config.json", " \"disablePinNotification\" : true / false,"); 73 | FileO.addWrite("config.json", " \"twitch\" : true / false,"); 74 | FileO.addWrite("config.json", " \"youtube\" : true / false,"); 75 | FileO.addWrite("config.json", " \"liveNotification\" : {"); 76 | FileO.addWrite("config.json", " \"onUpcoming\" : true / false,"); 77 | FileO.addWrite("config.json", " \"onStop\" : true / false,"); 78 | FileO.addWrite("config.json", " \"repeat\" : true / false"); 79 | FileO.addWrite("config.json", " }"); 80 | FileO.addWrite("config.json", " }"); 81 | FileO.addWrite("config.json", " ],"); 82 | FileO.addWrite("config.json", " \"admins\" : ["); 83 | FileO.addWrite("config.json", " \"INSERIT THE TELEGRAM ACCOUNT ID OF YOUR FIRST ADMIN HERE\","); 84 | FileO.addWrite("config.json", " \"INSERIT THE TELEGRAM ACCOUNT ID OF YOUR SECOND ADMIN HERE\","); 85 | FileO.addWrite("config.json", " \"...\""); 86 | FileO.addWrite("config.json", " ]"); 87 | FileO.addWrite("config.json", "}"); 88 | Main.LOGGER.severe("File \"config.json\" created. Edit your settings and then turn on again the bot."); 89 | return false; 90 | } 91 | 92 | Main.LOGGER.config("Loading configs"); 93 | JSONObject config = new JSONObject(FileO.allLine("config.json")); 94 | tToken = config.getString("tToken"); 95 | liveOfflineDelay = config.getLong("liveOfflineDelay"); 96 | mantainPhrase = config.getBoolean("mantainPhrase"); 97 | 98 | JSONObject ytObj = config.getJSONObject("youtube"); 99 | if(ytObj.getBoolean("enable")){ 100 | youtube = true; 101 | gToken = ytObj.getString("gToken"); 102 | yId = ytObj.getString("id"); 103 | ytVideo = ytObj.getBoolean("enableVideo"); 104 | ytLive = ytObj.getBoolean("enableLive"); 105 | } 106 | JSONObject twObj = config.getJSONObject("twitch"); 107 | if(twObj.getBoolean("enable")){ 108 | twitch = true; 109 | wToken = twObj.getString("token"); 110 | tLogin = twObj.getString("id"); 111 | //tUserId = getTwitchUserId(); 112 | checkTwitch = twObj.getBoolean("checkTwitch"); 113 | if(twObj.has("allowedTypes")){ 114 | JSONArray types = twObj.getJSONArray("allowedTypes"); 115 | for(int i = 0; i < types.length(); i++) 116 | allowedTwitchTypes.add(types.getString(i)); 117 | } 118 | manageGroup = twObj.getBoolean("manageGroup"); 119 | if(manageGroup) { 120 | JSONObject mgObj = twObj.getJSONObject("manageGroupSettings"); 121 | secret = mgObj.getString("secret"); 122 | redirect = mgObj.getString("redirect"); 123 | manageGroupId = mgObj.getString("group"); 124 | link = mgObj.getString("link"); 125 | muteUntilLogin = mgObj.getBoolean("muteUntilLogin"); 126 | lang = mgObj.getString("lang"); 127 | notifyExpire = mgObj.getBoolean("notifyExpire"); 128 | notifyBefore = mgObj.getBoolean("notifyBefore"); 129 | if(notifyBefore) notifyBeforeDelay = mgObj.getLong("notifyBeforeDelay"); 130 | keepInGroup4e = mgObj.getBoolean("keepInGroupForever"); 131 | if(!keepInGroup4e){ 132 | keepInGroup = mgObj.getBoolean("keepInGroup"); 133 | if(keepInGroup) keepInGroupDelay = mgObj.getLong("keepInGroupDelay"); 134 | } 135 | } 136 | twitchClips = twObj.getBoolean("shareClips"); 137 | if(twitchClips){ 138 | JSONObject clipObj = twObj.getJSONObject("shareClipsSettings"); 139 | clipInterval = clipObj.getString("interval"); 140 | if(!clipInterval.equalsIgnoreCase("day") && !clipInterval.equalsIgnoreCase("week") && !clipInterval.equalsIgnoreCase("month")) { 141 | Main.LOGGER.severe(clipObj.getString("interval") + ": Interval not valid"); 142 | return false; 143 | } 144 | clipDay = clipObj.getString("day"); 145 | clipTrending = clipObj.getBoolean("trending"); 146 | } 147 | } 148 | if(config.has("botName")) botName = config.getString("botName"); else { 149 | useBotName = true; 150 | Main.LOGGER.config("Using telegram bot name"); 151 | } 152 | 153 | startTime = sTime; 154 | dir = System.getProperty("user.dir") + File.separator; 155 | 156 | JSONArray admin = config.getJSONArray("admins"); 157 | admins.clear(); 158 | for(int i = 0; i < admin.length(); i++) admins.add(admin.getString(i)); 159 | 160 | boolean rd = false; 161 | chats.clear(); 162 | JSONArray arr = config.getJSONArray("chats"); 163 | for(int i = 0; i < arr.length(); i++){ 164 | Main.LOGGER.config("Loading settings for chat [" + i + "]"); 165 | JSONObject chat = arr.getJSONObject(i); 166 | 167 | String lessSpamMethod = chat.getString("lessSpamMethod"); 168 | if(!lessSpamMethod.equalsIgnoreCase("DELETE") && !lessSpamMethod.equalsIgnoreCase("COMPRESS") && !lessSpamMethod.equalsIgnoreCase("NONE") && !lessSpamMethod.equalsIgnoreCase("NOWEBPREVIEW")) { 169 | Main.LOGGER.severe(lessSpamMethod + ": lessSpamMethod not valid."); 170 | return false; 171 | } 172 | JSONObject liveNotification = chat.getJSONObject("liveNotification"); 173 | Chats c = new Chats(chat.getString("chat"), lessSpamMethod, chat.getBoolean("pinMessage"), liveNotification.getBoolean("onUpcoming"), liveNotification.getBoolean("onStop"), liveNotification.getBoolean("repeat")); 174 | if(twitch) c.setIfTwitch(chat.getBoolean("twitch")); 175 | if(youtube) c.setIfYoutube(chat.getBoolean("youtube")); 176 | 177 | if(c.getIfPin()) c.setPiNotification(chat.getBoolean("disablePinNotification")); 178 | if(c.getIfRepeat()) rd = true; 179 | chats.add(c); 180 | } 181 | if(rd) repeatDelay = config.getLong("notificationRepeatDelay"); 182 | 183 | } catch (Exception e) { 184 | e.printStackTrace(); 185 | return false; 186 | } 187 | return true; 188 | } 189 | 190 | public ArrayList getAdmins(){ 191 | return admins; 192 | } 193 | public String getBotName(){ 194 | return botName; 195 | } 196 | public String getChannelId(){ 197 | return yId; 198 | } 199 | public String getTelegramToken(){ 200 | return tToken; 201 | } 202 | public String getGoogleToken(){ 203 | return gToken; 204 | } 205 | public String getDefaultDirectory(){ 206 | return dir; 207 | } 208 | public String getUser(){ 209 | return user; 210 | } 211 | public String getTwitchToken(){ 212 | return wToken; 213 | } 214 | public String getTwitchChannel(){ 215 | return tLogin; 216 | } 217 | public String getTwitchUserID(){ 218 | return tUserId; 219 | } 220 | public String getManageGroupId(){ 221 | return manageGroupId; 222 | } 223 | public String getGroupLink(){ 224 | return link; 225 | } 226 | public String getLoginPageLang(){ 227 | return lang; 228 | } 229 | public String getClipInterval(){ 230 | return clipInterval; 231 | } 232 | public String getClipDay(){ 233 | return clipDay; 234 | } 235 | public String getTSecret(){ 236 | return secret; 237 | } 238 | public String getRedirectURL(){ 239 | return redirect + "acceptSub"; 240 | } 241 | public String getLoginURL(){ 242 | return redirect; 243 | } 244 | public boolean getPhraseStatus(int type){ 245 | return phraseStatus[type]; 246 | } 247 | public boolean[] getPhraseStatus(){ 248 | return phraseStatus; 249 | } 250 | public boolean getWhatBotName(){ 251 | return useBotName; 252 | } 253 | public boolean getIfYoutube(){ 254 | return youtube; 255 | } 256 | public boolean getIfTwitch(){ 257 | return twitch; 258 | } 259 | public boolean getMantainPhrase(){ 260 | return mantainPhrase; 261 | } 262 | public boolean getIfYoutubeVideo(){ 263 | return ytVideo; 264 | } 265 | public boolean getIfYoutubeLive(){ 266 | return ytLive; 267 | } 268 | public boolean getIfManageGroup(){ 269 | return manageGroup; 270 | } 271 | public boolean getIfNotifyExpire(){ 272 | return notifyExpire; 273 | } 274 | public boolean getIfNotifyBefore(){ 275 | return notifyBefore; 276 | } 277 | public boolean getIfKeepInGroup(){ 278 | return keepInGroup; 279 | } 280 | public boolean getIfKeepInGroupForever(){ 281 | return keepInGroup4e; 282 | } 283 | public boolean getIfMuteUntilLogin(){ 284 | return muteUntilLogin; 285 | } 286 | public boolean getIfCheckTwitch(){ 287 | return checkTwitch; 288 | } 289 | public boolean getIfShareClips(){ 290 | return twitchClips; 291 | } 292 | public boolean getIfClipTrending(){ 293 | return clipTrending; 294 | } 295 | public long getOfflineDelay(){ 296 | return liveOfflineDelay; 297 | } 298 | public long getRepeatDelay(){ 299 | return repeatDelay; 300 | } 301 | public long getNotifyBeforeDelay(){ 302 | return notifyBeforeDelay; 303 | } 304 | public long getKeepInGroupDelay(){ 305 | return keepInGroupDelay; 306 | } 307 | public ArrayList getChats(){ 308 | return chats; 309 | } 310 | public void setPhraseStatus(boolean[] status){ 311 | phraseStatus = status; 312 | } 313 | public void removeDirectory(){ 314 | dir = ""; 315 | } 316 | public void setUser(String usr){ 317 | user = usr; 318 | } 319 | public void setBotName(String name){ 320 | botName = name; 321 | } 322 | public boolean checkTwtichLiveType(String type){ 323 | if(allowedTwitchTypes.size() == 0) return true; 324 | for(String s : allowedTwitchTypes) 325 | if(type.equals(s)) 326 | return true; 327 | return false; 328 | } 329 | public String getGoogleApiFullUrl(int n){ 330 | return "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=" + yId + "&order=date&type=video&key=" + gToken + "&maxResults=" + n; 331 | } 332 | public String getUrlVideoType(String id){ 333 | return "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + id + "&maxResults=1&key=" + gToken; 334 | } 335 | public String getTwitchUrl(int option){ 336 | String method = ""; 337 | switch(option){ 338 | case 0: {method = "streams"; break;} 339 | case 1: {method = "channels"; break;} 340 | } 341 | return method + "?user_login=" + tLogin; 342 | } 343 | public String getTwitchClickableTitle(String title){ 344 | return "" + FileO.toHtml(title) + ""; 345 | } 346 | public String getUpTime(){ 347 | return Main.remainTime(startTime); 348 | } 349 | public String getChatsId(){ 350 | String[] s = new String[chats.size()]; 351 | for(int i = 0; i < s.length; i++) s[i] = chats.get(i).getChatId(); 352 | return Arrays.toString(s); 353 | } 354 | public void loadTwitchUserId() throws Exception{ 355 | tUserId = Download.twitch("users?login=" + getTwitchChannel()) 356 | .getJSONArray("data") 357 | .getJSONObject(0) 358 | .getString("id"); 359 | } 360 | } 361 | -------------------------------------------------------------------------------- /oldVersion/src/main/java/it/TetrisReich/bot/TestBot/MyRunnable.java: -------------------------------------------------------------------------------- 1 | package it.TetrisReich.bot.TestBot; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | import java.io.OutputStreamWriter; 10 | import java.lang.reflect.InvocationTargetException; 11 | import java.net.SocketTimeoutException; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | import org.json.JSONArray; 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | 19 | import com.pengrad.telegrambot.TelegramBot; 20 | import com.pengrad.telegrambot.TelegramBotAdapter; 21 | import com.pengrad.telegrambot.model.Message; 22 | import com.pengrad.telegrambot.model.Update; 23 | import com.pengrad.telegrambot.model.request.InlineKeyboardButton; 24 | import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; 25 | import com.pengrad.telegrambot.model.request.ParseMode; 26 | import com.pengrad.telegrambot.request.GetUpdates; 27 | import com.pengrad.telegrambot.request.SendMessage; 28 | import com.pengrad.telegrambot.response.GetUpdatesResponse; 29 | 30 | public class MyRunnable implements Runnable { 31 | 32 | private int var; 33 | 34 | public MyRunnable(int var) { 35 | this.var = var; 36 | } 37 | 38 | public void run() { 39 | boolean b = false; 40 | if(b) System.out.println(var); //solo per togliere il warn 41 | int offset = 0; 42 | TelegramBot bot = TelegramBotAdapter.build(App.token); 43 | long command = 0; 44 | long cUpdates = 0; 45 | long nUpdates = 0; 46 | byte tesThread = 0; 47 | boolean parse = false; 48 | boolean crash = false; 49 | while(true){ 50 | App.secondT = true; 51 | try{ 52 | Thread.sleep(1000); 53 | } catch(InterruptedException ex){ 54 | Thread.currentThread().interrupt(); 55 | } 56 | try{//try{ 57 | GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates().offset(offset)); 58 | List updates = updatesResponse.updates(); 59 | for(Update update : updates) { 60 | nUpdates++; 61 | offset = update.updateId() + 1; 62 | Message message = update.message(); 63 | App.logger(message.chat().id().toString() + "> " + message.text()); 64 | if(message.text().equalsIgnoreCase("/start")||message.text().equalsIgnoreCase("/help")){ 65 | App.logger(message.chat().id().toString() + "> Request start/help page"); 66 | bot.execute(new SendMessage(message.chat().id().toString(), 67 | "Salve! Benvenuto in " + App.botName + " :D\n" 68 | + "Questo bot ha il compito di condividere tutti i nuovi video di chivuoitu " 69 | + "sul canale telegram sempre di chivuoitu, in questo caso "+App.channel+".\n" 70 | + "\nEcco qui una piccola lista di comandi:\n" 71 | + "/last per ottenere l'ultimo mio video.\n" 72 | + "/github per ottenere il link di github del mio codice.\n" 73 | + "/start o /help per visualizzare questo messaggio.\n" 74 | + "/news per ricevere le notizie su questo ed altri bot del mio creatore.\n " 75 | + "/stat per vedere le statistiche della sessione corrente del bot.\n\n" 76 | + "Per bug report, maggiori informazioni o se vuoi usarmi per il " 77 | + "tuo canale youtube contattami per email qui: public.stranck@gmail.com" 78 | ).parseMode(ParseMode.Markdown).disableWebPagePreview(true)); 79 | if(message.chat().id().toString().equals("50731050")||App.checkAdm(message.chat().id())){ 80 | bot.execute(new SendMessage(message.chat().id().toString(), 81 | "Admin commands:\n" 82 | + "/program [text]: Set a specific description for the next video update\n" 83 | + "/ping: pong.\n" 84 | + "/force\n" 85 | + " reboot: Terminate reboot for restart\n" 86 | + " vUpdate: Forcing a video update modifying the file \"id\"\n" 87 | + " startup: Redo the startup metod\n" 88 | + " version: check for kill the bot, version, edit file\n" 89 | + " crash: crash the bot with ArrayIndexOutOfBoundsException\n" 90 | + "/file\n" 91 | + " new [file name]: create a file with certain name\n" 92 | + " edit [file name] [text]: overwrite the file content " 93 | + "with specified text\n" 94 | + " addLine [file name] [text]: add at the last line " 95 | + "of the file the text specified\n" 96 | + " read [file name]: read the content of the file\n" 97 | + " delate [file name]: delate the specified file\n" 98 | + " html [on|off]: activate/deactivate the html parsing for /file read\n" 99 | + " cod [file name]: encode the file contnent in html\n" 100 | + " decod [file name]: decode the file contnent from html\n" 101 | + " ls [path]: get list of all files in the select path. Use '.' for default" 102 | )); 103 | } 104 | command++; 105 | } 106 | if(message.text().equalsIgnoreCase("/github")){ 107 | bot.execute(new SendMessage(message.chat().id().toString(), 108 | "Vuoi vedere quale convinzione si cela tra i miei codici?\n" 109 | +"Bene, [premi qui!](https://github.com/stranck/ConvintoBot)") 110 | .parseMode(ParseMode.Markdown)); 111 | App.logger(message.chat().id().toString()+"> Request github link"); 112 | command++; 113 | } 114 | if(message.text().equalsIgnoreCase("/ping")){ 115 | bot.execute(new SendMessage(message.chat().id().toString(), "Pong")); 116 | App.logger(message.chat().id().toString()+"> Request ping"); 117 | command++; 118 | } 119 | if(message.text().equalsIgnoreCase("/news")){ 120 | String news = "http://telegram.me/MultyChatNews"; 121 | bot.execute(new SendMessage(message.chat().id().toString(), 122 | "Qui sotto il canale con tutte le news!").replyMarkup(new InlineKeyboardMarkup( 123 | new InlineKeyboardButton[]{ 124 | new InlineKeyboardButton("Click me >.<").url(news), 125 | }))); 126 | App.logger(message.chat().id().toString()+"> Request news channel"); 127 | } 128 | if(message.text().equalsIgnoreCase("/stat")){ 129 | command++; 130 | long estimatedTime = System.currentTimeMillis() - App.startTime; 131 | estimatedTime = estimatedTime/1000; 132 | int hours = (int) estimatedTime / 3600; 133 | int remainder = (int) estimatedTime - hours * 3600; 134 | int mins = remainder / 60; 135 | remainder = remainder - mins * 60; 136 | int secs = remainder; 137 | int n = 60 - App.altervistamerda; 138 | int nTime = n * 5; 139 | bot.execute(new SendMessage(message.chat().id().toString(), 140 | "ALL STAT ARE ONLY OF THIS SESSION!!!\n" + 141 | "\n\nStat of main thread:\n--------\n" + 142 | "Total number of check: "+ App.nTotalCheck + "\n"+ 143 | "Total number of check of video update: " + App.nVCheck + "\n"+ 144 | "Total number of check of live update: " + App.nLCheck + "\n" + 145 | "Total number of video update: " + App.nVUpdate + "\n" + 146 | "Total number of live update: " + App.nLUpdate + "\n" + 147 | "\n\nStat of second thread:\n--------\n" + 148 | "Actual offset: " + offset + "\n" + 149 | "Actual messageId: " + message.messageId() + "\n" + 150 | "Total number of checkUpdates: " + cUpdates + "\n" + 151 | "Total number of Updates: " + nUpdates + "\n" + 152 | "Total numeber of know command: " + command + "\n" + 153 | "\n\nGeneral\n--------\n" + 154 | "Bot online for channel: " + App.channel + "\n" + 155 | "Bot version: " + App.version + "\n" + 156 | "Next check for a new version: " + n + " (About " + nTime + "sec+-5)\n" + 157 | "Location: " + App.dir + "\n" + 158 | "Startup argouments: " + Arrays.toString(App.ag) + "\n" + 159 | "Name: " + App.botName + "\n" + 160 | "Uptime: "+hours+":"+mins+":"+secs+"(From "+App.startTime+")\n\n"+ 161 | "Programmed by Stranck" 162 | ).parseMode(ParseMode.HTML).disableWebPagePreview(true)); 163 | App.logger(message.chat().id().toString()+"> Request stat page"); 164 | } 165 | if(message.text().equalsIgnoreCase("/last")){ 166 | try{ 167 | JSONObject obj = new JSONObject(App.last); 168 | JSONArray arr = obj.getJSONArray("items"); 169 | obj = arr.getJSONObject(0); 170 | String type = "Video:"; 171 | switch(obj.getJSONObject("snippet").getString("liveBroadcastContent")){ 172 | case "live": {type = "In live ora:"; break;} 173 | case "upcoming": {type = "Live programmata:"; break;} 174 | default: break; 175 | } 176 | System.out.println(type + "\n" 178 | + FileO.toHtml(obj.getJSONObject("snippet").getString("title")) 179 | + ""); 180 | bot.execute(new SendMessage(message.chat().id().toString(), 181 | type + "\n" 183 | + FileO.toHtml(obj.getJSONObject("snippet").getString("title")) 184 | + "").parseMode(ParseMode.HTML)); 185 | //System.out.println(br.description()); 186 | } catch (NullPointerException | JSONException e) { 187 | e.printStackTrace(); 188 | bot.execute(new SendMessage("An error occurred, please retry later.", 189 | message.chat().id().toString())); 190 | } 191 | App.logger(message.chat().id().toString()+"> Request last video"); 192 | command++; 193 | } 194 | try{ 195 | if(message.chat().id().toString().equals("50731050")||App.checkAdm(message.chat().id())){ 196 | String[] sp = message.text().split("\\s+"); 197 | if(sp[0].equalsIgnoreCase("/program")){ 198 | if(sp.length==1){ 199 | if(FileO.exist("programmed")) FileO.delater("programmed"); 200 | App.logger(message.chat().id().toString() + "> Delating programmed message"); 201 | bot.execute(new SendMessage(message.chat().id().toString(), 202 | "Programmed message delated")); 203 | } else{ 204 | FileO.newFile("programmed"); 205 | String text = ""; 206 | for(int i=1;i Programming message:\n" + text); 210 | command++; 211 | } 212 | } 213 | if(sp[0].equalsIgnoreCase("/force")){ 214 | App.loggerL(message.chat().id().toString() + "> Forcing "); 215 | if(sp[1].equalsIgnoreCase("reboot")) { 216 | App.loggerL("reboot."); 217 | bot.execute(new SendMessage(message.chat().id().toString(), "Forcing reboot.")); 218 | bot.execute(new SendMessage("-1001063772015", "Reboot forced by an admin." 219 | + "\n_[version: "+App.version+"]_\n").parseMode(ParseMode.Markdown)); 220 | int o = offset; 221 | Download.dwn("https://api.telegram.org/bot"+App.token+"/getUpdates?offset="+o+ 222 | "&limit=1"); 223 | App.s = true; return; 224 | } 225 | if(sp[1].equalsIgnoreCase("vUpdate")) { 226 | App.loggerL("video update."); 227 | String s = ""; 228 | do{ 229 | s = App.getInfo(0);// App.loggerL("DUIASODASISDISA."); 230 | }while(s==null); 231 | //System.out.println(Arrays.toString(App.all)); 232 | //App.loggerL("ASDDDDDDDDDDD"); 233 | App.all = App.remove(App.all, s); 234 | //System.out.println(Arrays.toString(App.all)); 235 | //App.loggerL("DIOCANEEEEEEEEEEEEEEEEEEEE"); 236 | bot.execute(new SendMessage(message.chat().id().toString(), 237 | "Forcing video update.")); 238 | } 239 | if(sp[1].equalsIgnoreCase("startup")) { 240 | System.out.print("startup with"); 241 | String s = ""; 242 | if(Startup.startup()) s = " no"; 243 | App.loggerL(s + " error/s."); 244 | bot.execute(new SendMessage(message.chat().id().toString(), 245 | "Forced startup with" + s + " error/s.")); 246 | } 247 | if(sp[1].equalsIgnoreCase("version")){ 248 | App.loggerL("version update."); 249 | App.altervistamerda = 59; 250 | bot.execute(new SendMessage(message.chat().id().toString(), 251 | "Forcing version update.")); 252 | } 253 | if(sp[1].equalsIgnoreCase("crash")){ 254 | App.loggerL("crash."); 255 | bot.execute(new SendMessage(message.chat().id().toString(), 256 | "Forcing crash.")); 257 | int o = offset; 258 | Download.dwn("https://api.telegram.org/bot"+App.token+"/getUpdates?offset="+o+ 259 | "&limit=1"); 260 | crash = true; 261 | } 262 | App.logger(""); 263 | command++; 264 | } 265 | if(sp[0].equalsIgnoreCase("/file")){ 266 | App.loggerL(message.chat().id().toString() + "> File "); 267 | if(sp[1].equalsIgnoreCase("read")){ 268 | App.loggerL("read " + sp[2]); 269 | if(parse){ 270 | bot.execute(new SendMessage(message.chat().id().toString(),FileO.aL(sp[2],true)) 271 | .parseMode(ParseMode.HTML).disableWebPagePreview(true)); 272 | } else { 273 | bot.execute(new SendMessage(message.chat().id().toString(), FileO.aL(sp[2],true)) 274 | .disableWebPagePreview(true));} 275 | } 276 | if(sp[1].equalsIgnoreCase("delate")){ 277 | App.loggerL("delate " + sp[2]); 278 | FileO.delater(sp[2]); 279 | } 280 | if(sp[1].equalsIgnoreCase("new")){ 281 | App.loggerL("new " + sp[2]); 282 | FileO.newFile(sp[2]); 283 | } 284 | if(sp[1].equalsIgnoreCase("edit")){ 285 | App.loggerL("edit " + sp[2] + " with " + sp[3]); 286 | FileO.writer(sp[3], sp[2]); 287 | } 288 | if(sp[1].equalsIgnoreCase("addLine")){ 289 | App.loggerL("Adding line " + sp[3] + " to " + sp[2]); 290 | FileO.addWrite(sp[2], sp[3]); 291 | } 292 | if(sp[1].equalsIgnoreCase("ls")){ 293 | bot.execute(new SendMessage(message.chat().id().toString(), FileO.ls(sp[2]))); 294 | } 295 | if(sp[1].equalsIgnoreCase("html")){ 296 | App.loggerL("parsing mode: "); 297 | if(sp[2].equalsIgnoreCase("on")){ parse = true; App.loggerL("on");} 298 | if(sp[2].equalsIgnoreCase("off")){ parse = false; App.loggerL("off");} 299 | } 300 | if(sp[1].equalsIgnoreCase("cod")){ 301 | File fout = new File("temp"); 302 | try (BufferedReader br = new BufferedReader(new FileReader(App.dir+sp[2]))) { 303 | FileOutputStream fos = new FileOutputStream(fout); 304 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); 305 | String line; 306 | while ((line = br.readLine()) != null) { 307 | bw.write(FileO.toHtml(line)); 308 | bw.newLine(); 309 | } 310 | bw.close(); 311 | } 312 | FileO.delater(sp[2]); 313 | fout.renameTo(new File(App.dir+sp[2])); 314 | } 315 | if(sp[1].equalsIgnoreCase("decod")){ 316 | File fout = new File("temp"); 317 | try (BufferedReader br = new BufferedReader(new FileReader(App.dir+sp[2]))) { 318 | FileOutputStream fos = new FileOutputStream(fout); 319 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); 320 | String line; 321 | while ((line = br.readLine()) != null) { 322 | bw.write(FileO.fromHtml(line)); 323 | bw.newLine(); 324 | } 325 | bw.close(); 326 | } 327 | FileO.delater(sp[2]); 328 | fout.renameTo(new File(App.dir+sp[2])); 329 | } 330 | App.logger(""); 331 | bot.execute(new SendMessage(message.chat().id().toString(), "Done!")); 332 | command++; 333 | } 334 | } 335 | }catch(ArrayIndexOutOfBoundsException e){} catch (IOException e){} catch (InvocationTargetException e) { 336 | // TODO Auto-generated catch block 337 | e.printStackTrace(); 338 | } 339 | } 340 | cUpdates++; 341 | }catch(SocketTimeoutException | NullPointerException e){e.printStackTrace();} 342 | catch(RuntimeException | IOException e){e.printStackTrace();} 343 | 344 | tesThread++; 345 | if(App.s) return; if(tesThread==32){if(!App.mainT){ 346 | System.out.println("Detect crash of main thread. Restarting the bot."); 347 | return; 348 | }else{tesThread=0;App.mainT=false;}} 349 | if(crash) crash(); 350 | } 351 | } 352 | public static void crash(){ 353 | int i[] = new int[1]; 354 | System.out.println(i[8]); 355 | } 356 | } --------------------------------------------------------------------------------