Skip to content

Commit 8d8d1bd

Browse files
author
SpongyBacon
committed
Clean up client, new event system
1 parent 9e263f4 commit 8d8d1bd

35 files changed

+459
-544
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
*.iml
3+
target
4+
dependency-reduced-pom.xml

pom.xml

Lines changed: 28 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,38 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>pw.sponges</groupId>
55
<artifactId>botclient</artifactId>
6-
<version>1.0</version>
6+
<version>1.0-SNAPSHOT</version>
7+
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
</properties>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.json</groupId>
17+
<artifactId>json</artifactId>
18+
<version>20141113</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>io.netty</groupId>
22+
<artifactId>netty-all</artifactId>
23+
<version>5.0.0.Alpha2</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.guava</groupId>
27+
<artifactId>guava</artifactId>
28+
<version>19.0</version>
29+
</dependency>
30+
</dependencies>
31+
732
<build>
833
<plugins>
9-
<plugin>
10-
<groupId>org.apache.maven.plugins</groupId>
11-
<artifactId>maven-compiler-plugin</artifactId>
12-
<version>2.3.2</version>
13-
<configuration>
14-
<source>1.8</source>
15-
<target>1.8</target>
16-
</configuration>
17-
</plugin>
18-
<plugin>
19-
<groupId>org.apache.maven.plugins</groupId>
20-
<artifactId>maven-jar-plugin</artifactId>
21-
<version>2.3.2</version>
22-
<configuration>
23-
<archive>
24-
<manifest>
25-
<classpathPrefix>lib/</classpathPrefix>
26-
<addClasspath>false</addClasspath>
27-
</manifest>
28-
<manifestEntries>
29-
<mode>development</mode>
30-
<url>${pom.url}</url>
31-
</manifestEntries>
32-
</archive>
33-
<finalName>BotClient</finalName>
34-
</configuration>
35-
</plugin>
3634
<plugin>
3735
<groupId>org.apache.maven.plugins</groupId>
3836
<artifactId>maven-shade-plugin</artifactId>
39-
<version>2.4.2</version>
37+
<version>2.4.3</version>
4038
<executions>
4139
<execution>
4240
<phase>package</phase>
@@ -48,66 +46,5 @@
4846
</plugin>
4947
</plugins>
5048
</build>
51-
<repositories>
52-
<repository>
53-
<id>EzSkype-mvn-repo</id>
54-
<url>https://raw.github.com/AkHo1ic/EzSkype/mvn-repo/</url>
55-
<snapshots>
56-
<enabled>true</enabled>
57-
<updatePolicy>always</updatePolicy>
58-
</snapshots>
59-
</repository>
60-
<!--repository>
61-
<id>xyz.gghost</id>
62-
<url>http://gghost.xyz/maven/</url>
63-
</repository-->
64-
</repositories>
65-
<dependencies>
66-
<dependency>
67-
<groupId>org.json</groupId>
68-
<artifactId>json</artifactId>
69-
<version>20141113</version>
70-
</dependency>
71-
<dependency>
72-
<groupId>in.kyle</groupId>
73-
<artifactId>EzSkypeEzLife</artifactId>
74-
<version>1.2.8-SNAPSHOT</version>
75-
</dependency>
76-
<!--<dependency>
77-
<groupId>xyz.gghost</groupId>
78-
<artifactId>jdiscord</artifactId>
79-
<version>1.3</version>
80-
<scope>compile</scope>
81-
</dependency>-->
82-
<dependency>
83-
<groupId>org.java-websocket</groupId>
84-
<artifactId>Java-WebSocket</artifactId>
85-
<version>1.3.0</version>
86-
</dependency>
87-
<dependency>
88-
<groupId>org.jsoup</groupId>
89-
<artifactId>jsoup</artifactId>
90-
<version>1.8.1</version>
91-
</dependency>
92-
<dependency>
93-
<groupId>org.apache.commons</groupId>
94-
<artifactId>commons-lang3</artifactId>
95-
<version>3.4</version>
96-
</dependency>
97-
<dependency>
98-
<groupId>pro.zackpollard.telegrambot.api</groupId>
99-
<artifactId>jtelegram-botapi</artifactId>
100-
<version>0.4.5</version>
101-
</dependency>
102-
<dependency>
103-
<groupId>io.netty</groupId>
104-
<artifactId>netty-all</artifactId>
105-
<version>5.0.0.Alpha2</version>
106-
</dependency>
107-
<dependency>
108-
<groupId>com.ullink.slack</groupId>
109-
<artifactId>simpleslackapi</artifactId>
110-
<version>0.5.0</version>
111-
</dependency>
112-
</dependencies>
49+
11350
</project>

src/main/java/pw/sponges/botclient/Bot.java renamed to src/main/java/io/sponges/bot/client/Bot.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package pw.sponges.botclient;
1+
package io.sponges.bot.client;
22

3-
import pw.sponges.botclient.event.framework.EventManager;
4-
import pw.sponges.botclient.messages.Message;
5-
import pw.sponges.botclient.internal.Client;
6-
import pw.sponges.botclient.internal.impl.ClientImpl;
7-
import pw.sponges.botclient.util.Msg;
3+
import io.sponges.bot.client.event.framework.EventBus;
4+
import io.sponges.bot.client.internal.Client;
5+
import io.sponges.bot.client.internal.impl.ClientImpl;
6+
import io.sponges.bot.client.messages.Message;
7+
import io.sponges.bot.client.util.Msg;
88

99
import java.io.IOException;
1010
import java.util.HashMap;
@@ -18,7 +18,7 @@
1818
public class Bot {
1919

2020
private Client client;
21-
private final EventManager eventManager;
21+
private final EventBus eventBus;
2222

2323
private final String clientId;
2424
private Map<String, Object> settings;
@@ -27,8 +27,7 @@ public Bot(String clientId) {
2727
this.clientId = clientId;
2828
this.settings = new HashMap<>();
2929
this.client = new ClientImpl(this);
30-
this.eventManager = new EventManager();
31-
this.eventManager.registerInternalListener(new Listener(this, client));
30+
this.eventBus = new EventBus();
3231
}
3332

3433
public void start() {
@@ -61,8 +60,16 @@ public String getClientId() {
6160
return clientId;
6261
}
6362

64-
public EventManager getEventManager() {
65-
return eventManager;
63+
public Client getClient() {
64+
return client;
65+
}
66+
67+
public void setClient(Client client) {
68+
this.client = client;
69+
}
70+
71+
public EventBus getEventBus() {
72+
return eventBus;
6673
}
6774

6875
public void stop() {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.sponges.bot.client;
2+
3+
import io.sponges.bot.client.event.*;
4+
import io.sponges.bot.client.event.framework.EventBus;
5+
import io.sponges.bot.client.internal.Client;
6+
import io.sponges.bot.client.util.Msg;
7+
import org.json.JSONObject;
8+
9+
public class Listener {
10+
11+
private final Client client;
12+
private final Bot bot;
13+
private final EventBus eventBus;
14+
15+
public Listener(Bot bot, Client client) {
16+
this.client = client;
17+
this.bot = bot;
18+
this.eventBus = bot.getEventBus();
19+
20+
this.eventBus.register(InputEvent.class, this::onInput);
21+
}
22+
23+
private void onInput(InputEvent event) {
24+
if (!event.getInput().contains("{")) {
25+
Msg.warning("Got non json: " + event.getInput());
26+
return;
27+
} else {
28+
Msg.debug("INPUT> " + event.getInput());
29+
}
30+
31+
JSONObject object = new JSONObject(event.getInput());
32+
33+
String type = object.getString("type");
34+
35+
switch (type) {
36+
case "COMMAND": {
37+
eventBus.post(new CommandEvent(object.getString("client-id"), object.getString("room"), object.getString("user"), object.getString("username"), object.getString("response")));
38+
break;
39+
}
40+
41+
case "CHAT": {
42+
eventBus.post(new BridgedChatEvent(object.getString("client-id"), object.getString("source-room"), object.getString("name"), object.getString("room"), object.getString("userid"), object.getString("username"), object.getString("message")));
43+
break;
44+
}
45+
46+
case "STOP": {
47+
Msg.warning("STOPPING!");
48+
try {
49+
client.stop();
50+
System.exit(500);
51+
} catch (InterruptedException e) {
52+
e.printStackTrace();
53+
}
54+
break;
55+
}
56+
57+
case "JOIN": {
58+
eventBus.post(new JoinRoomEvent(object.getString("room")));
59+
break;
60+
}
61+
62+
case "KICK": {
63+
eventBus.post(new KickRequestEvent(object.getString("room"), object.getString("user")));
64+
break;
65+
}
66+
67+
case "RAW": {
68+
eventBus.post(new SendRawRequestEvent(object.getString("room"), object.getString("message")));
69+
break;
70+
}
71+
72+
default: {
73+
Msg.warning("Unknown message type! " + type);
74+
Msg.debug(object.toString());
75+
break;
76+
}
77+
}
78+
}
79+
80+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.sponges.bot.client;
2+
3+
public enum UserRole {
4+
5+
OP, ADMIN, USER;
6+
7+
@Override
8+
public String toString() {
9+
String[][] arr = {
10+
{
11+
"key",
12+
"value"
13+
},
14+
{
15+
"key2",
16+
"value2"
17+
}
18+
};
19+
20+
String[] keys = {
21+
"key",
22+
"key2"
23+
};
24+
25+
String[] values = {
26+
"value",
27+
"value2"
28+
};
29+
30+
return name().toLowerCase();
31+
}
32+
}

src/main/java/pw/sponges/botclient/event/BridgedChatEvent.java renamed to src/main/java/io/sponges/bot/client/event/BridgedChatEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package pw.sponges.botclient.event;
1+
package io.sponges.bot.client.event;
22

3-
import pw.sponges.botclient.event.framework.Event;
3+
import io.sponges.bot.client.event.framework.Event;
44

55
public class BridgedChatEvent extends Event {
66

src/main/java/pw/sponges/botclient/event/CommandEvent.java renamed to src/main/java/io/sponges/bot/client/event/CommandEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package pw.sponges.botclient.event;
1+
package io.sponges.bot.client.event;
22

3-
import pw.sponges.botclient.event.framework.Event;
3+
import io.sponges.bot.client.event.framework.Event;
44

55
public class CommandEvent extends Event {
66

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.sponges.bot.client.event;
2+
3+
import io.sponges.bot.client.event.framework.Event;
4+
5+
public class ConnectEvent extends Event {
6+
}

src/main/java/pw/sponges/botclient/event/InputEvent.java renamed to src/main/java/io/sponges/bot/client/event/InputEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package pw.sponges.botclient.event;
1+
package io.sponges.bot.client.event;
22

3-
import pw.sponges.botclient.event.framework.Event;
3+
import io.sponges.bot.client.event.framework.Event;
44

55
public class InputEvent extends Event {
66

src/main/java/pw/sponges/botclient/event/JoinRoomEvent.java renamed to src/main/java/io/sponges/bot/client/event/JoinRoomEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package pw.sponges.botclient.event;
1+
package io.sponges.bot.client.event;
22

3-
import pw.sponges.botclient.event.framework.Event;
3+
import io.sponges.bot.client.event.framework.Event;
44

55
public class JoinRoomEvent extends Event {
66

0 commit comments

Comments
 (0)