migrate to TelegramAPI version 0.0.2, updated pom.xml

This commit is contained in:
mrbesen 2019-05-20 19:12:50 +02:00
parent 0b3faf8839
commit 7713dcf56f
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
3 changed files with 37 additions and 21 deletions

21
YoutubeCrawler.iml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.11" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.protobuf:protobuf-java:2.6.0" level="project" />
<orderEntry type="library" name="Maven: TelegramAPI:TelegramAPI:0.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:20.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20180130" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.11.1" level="project" />
</component>
</module>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>YoutubeCrawler</groupId>
<artifactId>YoutubeCrawler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
@ -18,6 +18,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
@ -60,6 +61,8 @@
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
@ -75,7 +78,7 @@
<dependency>
<groupId>TelegramAPI</groupId>
<artifactId>TelegramAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2</version>
</dependency>
</dependencies>
</project>

View File

@ -11,19 +11,17 @@ import org.apache.log4j.Logger;
import de.mrbesen.telegram.MessageBuilder;
import de.mrbesen.telegram.TelegramAPI;
import de.mrbesen.telegram.commands.JSONCommandHandler;
import de.mrbesen.telegram.event.EventHandler;
import de.mrbesen.telegram.event.EventListener;
import de.mrbesen.telegram.event.events.UserSendMessageEvent;
import de.mrbesen.telegram.log.Log4JLog;
import de.mrbesen.telegram.objects.TMessage;
import de.mrbesen.telegram.objects.TUser;
public class Main implements JSONCommandHandler, EventListener{
public class Main implements JSONCommandHandler {
private ArrayList<Integer> admins = new ArrayList<>();//userids of admins
private ArrayList<Long> admins = new ArrayList<>();//userids of admins
private String adminstr = null;
private long setadminstr = -1;
private static String abc = "abcdefghijklmnopqrstuvwxyz";//used for random string generation
private static final String abc = "abcdefghijklmnopqrstuvwxyz";//used for random string generation
private Logger log = Logger.getLogger(this.getClass().getName());
private TelegramAPI tapi;
private Thread mainthread;
@ -71,12 +69,8 @@ public class Main implements JSONCommandHandler, EventListener{
//starting BOT API
tapi = new TelegramAPI(Config.prop.getProperty("telegramapi.key"));
tapi.getCommandManager().registerCommand("random", this);
tapi.getCommandManager().registerCommand("admin", this);
tapi.getCommandManager().registerCommand("stats", this);
tapi.getCommandManager().registerCommand("stop", this);
tapi.getCommandManager().registerCommand("profiler", this);
tapi.getEventManager().registerEvent(this);
tapi.getCommandManager().registerCommand( this);
tapi.getEventManager().registerEvent(UserSendMessageEvent.class, this::onAdmin);
tapi.setHelpText("Send the command /random to get a random video.");
tapi.setUpdateInterval(2000);
tapi.setLog(new Log4JLog());
@ -90,7 +84,7 @@ public class Main implements JSONCommandHandler, EventListener{
String line = scan.nextLine().trim();
if(!line.isEmpty()) {
try {
admins.add(Integer.parseInt(line));
admins.add(Long.parseLong(line));
} catch(NumberFormatException e) {
e.printStackTrace();
}
@ -164,7 +158,7 @@ public class Main implements JSONCommandHandler, EventListener{
public boolean onCommand(TUser sender, String cmd, String[] args, TMessage json) {
if(cmd.startsWith("random")) {
String ytid = cra.getDB().getRandom();
int chatid = json.getChatID();
long chatid = json.getChatID();
tapi.sendMessage(new MessageBuilder().setAsync().setText("https://youtube.com/watch?v=" + ytid).setReciver(chatid).build());
@ -208,7 +202,7 @@ public class Main implements JSONCommandHandler, EventListener{
}
public void broadcastAdmin(String msg) {
for(int admin : admins) {
for(long admin : admins) {
if(admin != 0) {
MessageBuilder mb = new MessageBuilder().setAsync().setText(msg).setReciver(admin);
tapi.sendMessage(mb.build());
@ -216,7 +210,7 @@ public class Main implements JSONCommandHandler, EventListener{
}
}
private String getRandomStr(int length) {
private static String getRandomStr(int length) {
Random rand = new Random();
String out = "";
for(int i = 0; i < length; i++) {
@ -225,8 +219,8 @@ public class Main implements JSONCommandHandler, EventListener{
return out;
}
@EventHandler
public void onAdmin(UserSendMessageEvent e) {
public void onAdmin(Object event) {
UserSendMessageEvent e = (UserSendMessageEvent) event;
if(adminstr != null && setadminstr > 0) {
if(e.getMessage() != null && (System.currentTimeMillis() - setadminstr) / 1000 < 60) {
if(e.getMessage().getText() != null) {
@ -241,6 +235,4 @@ public class Main implements JSONCommandHandler, EventListener{
}
}
}
}