Skip to content

Commit

Permalink
Created project!
Browse files Browse the repository at this point in the history
  • Loading branch information
Unihedro committed Oct 19, 2014
0 parents commit 108a4da
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Eclipse stuff
.project
.classpath
.settings/*

# IDE Junk
/bin
*.class
46 changes: 46 additions & 0 deletions pom.xml
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 src/main/java/com/gmail/inverseconduit/ConnectionManager.java
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();

}
31 changes: 31 additions & 0 deletions src/main/java/com/gmail/inverseconduit/JavaBot.java
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();
}

}
35 changes: 35 additions & 0 deletions src/main/java/com/gmail/inverseconduit/SEChat.java
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());
}
}
}
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;
}

}

0 comments on commit 108a4da

Please sign in to comment.