-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 108a4da
Showing
6 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Eclipse stuff | ||
.project | ||
.classpath | ||
.settings/* | ||
|
||
# IDE Junk | ||
/bin | ||
*.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.gmail.inverseconduit</groupId> | ||
<artifactId>javabot</artifactId> | ||
<version>0.0.1</version> | ||
<build> | ||
<plugins> | ||
<!-- This will build a JAR that contains all dependencies inside of it. --> | ||
<!-- To build, run: mvn clean compile assembly:single --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.gmail.inverseconduit.JavaBot</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.findbugs</groupId> | ||
<artifactId>jsr305</artifactId> | ||
<version>LATEST</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>fluent-hc</artifactId> | ||
<version>4.3.5</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/gmail/inverseconduit/ConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// CLASS CREATED 2014/10/19 AT 4:41:32 P.M. | ||
// ConnectionManager.java by Unihedron | ||
package com.gmail.inverseconduit; | ||
|
||
/** | ||
* Manages the connection to the chat room.<br> | ||
* ConnectionManager @ com.gmail.inverseconduit | ||
* | ||
* @author Unihedron<<a href="mailto:vincentyification@gmail.com" | ||
* >vincentyification@gmail.com</a>> | ||
*/ | ||
interface ConnectionManager { | ||
|
||
void establishConnection(); | ||
|
||
boolean login(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// CLASS CREATED 2014/10/19 AT 4:41:58 P.M. | ||
// JavaBot.java by Unihedron | ||
package com.gmail.inverseconduit; | ||
|
||
/** | ||
* Procrastination: I'll fix this javadoc comment later.<br> | ||
* JavaBot @ com.gmail.inverseconduit | ||
* | ||
* @author Unihedron<<a href="mailto:vincentyification@gmail.com" | ||
* >vincentyification@gmail.com</a>> | ||
*/ | ||
public class JavaBot { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
try { | ||
new JavaBot().go(); | ||
} catch(IllegalStateException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
ConnectionManager manager = new SimpleConnectionManager(); | ||
|
||
void go() throws IllegalStateException { | ||
manager.establishConnection(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// CLASS CREATED 2014/10/19 AT 5:16:59 P.M. | ||
// SEChat.java by Unihedron | ||
package com.gmail.inverseconduit; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
/** | ||
* Generates locations to the destinated address.<br> | ||
* SEChat @ com.gmail.inverseconduit | ||
* | ||
* @author Unihedron<<a href="mailto:vincentyification@gmail.com" | ||
* >vincentyification@gmail.com</a>> | ||
*/ | ||
enum SEChat { | ||
chatSO("stackoverflow"), | ||
chatSE("stackexchange"), | ||
chatMSE("meta." + chatSE.dir); | ||
|
||
private final String dir; | ||
|
||
SEChat(String dir) { | ||
this.dir = dir; | ||
} | ||
|
||
URI urlToRoom(int id) throws IllegalArgumentException { | ||
if (id <= 0) | ||
throw new IllegalArgumentException("id must be a positive number."); | ||
try { | ||
return new URI("http://chat." + dir + ".com/rooms/" + id); | ||
} catch(URISyntaxException e) { | ||
throw new IllegalArgumentException(e.getClass().getName() + ":" + e.getMessage()); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/gmail/inverseconduit/SimpleConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// CLASS CREATED 2014/10/19 AT 4:48:27 P.M. | ||
// SimpleConnectionManager.java by Unihedron | ||
package com.gmail.inverseconduit; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.client.fluent.Form; | ||
import org.apache.http.client.fluent.Request; | ||
|
||
class SimpleConnectionManager implements ConnectionManager { | ||
|
||
private static final String email = "10395287@opayq.com", password = "Polyhedron0"; | ||
|
||
@Override | ||
public void establishConnection() { | ||
login(); | ||
try { | ||
System.out.println(Request.Post(SEChat.chatSO.urlToRoom(139) + "/java").bodyForm(Form.form().add("input", "~ Hello World").build()).execute().returnContent()); | ||
} catch(IllegalArgumentException | IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean login() { | ||
try { | ||
System.out.println(Request.Post("http://stackoverflow.com/users/login?returnurl=http%3a%2f%2fchat.stackoverflow.com%2frooms%2f139").bodyForm(Form.form().add("email", email).add("password", password).build()).execute().returnContent()); | ||
} catch(IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
} |