updated gitignore as to not expose the bot token :P
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
package org.sugarcanemc.wikifaqbot.webapi;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
public class WebAPI implements Runnable {
|
||||
|
||||
static final File WEB_ROOT = new File("/WebAPI");
|
||||
static final String DEFAULT_File = "index.html";
|
||||
static final String FILE_NOT_FOUND = "404.html";
|
||||
static final String METHOD_NOT_SUPPORTED = "mns.html"; // (file not supported)
|
||||
|
||||
// port
|
||||
static final int PORT = 80;
|
||||
// port
|
||||
|
||||
static final boolean verbose = true;
|
||||
|
||||
private Socket connect;
|
||||
|
||||
public void webapi(Socket c) {
|
||||
connect = c;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
ServerSocket serverConnect = new ServerSocket(PORT);
|
||||
System.out.println("[WebAPI] WebAPI Started on " + "IP" + PORT);
|
||||
//TODO Make sys.out read IP
|
||||
while(true) {
|
||||
WebAPI server = new WebAPI();
|
||||
if (verbose) {
|
||||
System.out.println("[WebAPI] Connection Open.");
|
||||
}
|
||||
|
||||
Thread thread = new Thread(server);
|
||||
thread.start();
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("[WebAPI] Server Connection error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedReader in = null; PrintWriter out = null; BufferedOutputStream dataOut = null;
|
||||
String fileRequested = null;
|
||||
|
||||
try{
|
||||
in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
|
||||
out = new PrintWriter(connect.getOutputStream());
|
||||
dataOut = new BufferedOutputStream(connect.getOutputStream());
|
||||
String input = in.readLine();
|
||||
StringTokenizer parse = new StringTokenizer(input);
|
||||
String method = parse.nextToken().toUpperCase();
|
||||
fileRequested = parse.nextToken().toLowerCase();
|
||||
if(!method.equals("GET") && !method.equals("HEAD")) {
|
||||
if (verbose) {
|
||||
System.out.println("501 Not Implemeted: " + method + "method.");
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
} catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.sugarcanemc.wikifaqbot;
|
||||
package tech.nevets.lunarbot;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import org.sugarcanemc.wikifaqbot.commands.CoinCmd;
|
||||
import org.sugarcanemc.wikifaqbot.commands.DiceCmd;
|
||||
import org.sugarcanemc.wikifaqbot.commands.InfoCmd;
|
||||
import org.sugarcanemc.wikifaqbot.commands.PingCmd;
|
||||
import org.sugarcanemc.wikifaqbot.config.Config;
|
||||
import org.sugarcanemc.wikifaqbot.config.ConfigHandler;
|
||||
import org.sugarcanemc.wikifaqbot.config.ConfigUtils;
|
||||
import tech.nevets.lunarbot.commands.games.CoinCmd;
|
||||
import tech.nevets.lunarbot.commands.games.DiceCmd;
|
||||
import tech.nevets.lunarbot.commands.wiki.InfoCmd;
|
||||
import tech.nevets.lunarbot.commands.games.PingCmd;
|
||||
import tech.nevets.lunarbot.config.Config;
|
||||
import tech.nevets.lunarbot.config.ConfigHandler;
|
||||
import tech.nevets.lunarbot.config.ConfigUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.sugarcanemc.wikifaqbot.commands;
|
||||
package tech.nevets.lunarbot.commands.games;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.sugarcanemc.wikifaqbot.config.ConfigHandler;
|
||||
import tech.nevets.lunarbot.config.ConfigHandler;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class CoinCmd extends ListenerAdapter {
|
||||
@Override
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.sugarcanemc.wikifaqbot.commands;
|
||||
package tech.nevets.lunarbot.commands.games;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.sugarcanemc.wikifaqbot.config.ConfigHandler;
|
||||
import tech.nevets.lunarbot.config.ConfigHandler;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Random;
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.sugarcanemc.wikifaqbot.commands;
|
||||
package tech.nevets.lunarbot.commands.games;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.sugarcanemc.wikifaqbot.config.ConfigHandler;
|
||||
import tech.nevets.lunarbot.config.ConfigHandler;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.sugarcanemc.wikifaqbot.commands;
|
||||
package tech.nevets.lunarbot.commands.wiki;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.sugarcanemc.wikifaqbot.config.ConfigHandler;
|
||||
import tech.nevets.lunarbot.config.ConfigHandler;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class InfoCmd extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent e) {
|
||||
if (e.getAuthor().isBot()) return;
|
||||
Message message = e.getMessage();
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.sugarcanemc.wikifaqbot.config;
|
||||
package tech.nevets.lunarbot.config;
|
||||
|
||||
public class Config {
|
||||
private String prefix;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.sugarcanemc.wikifaqbot.config;
|
||||
package tech.nevets.lunarbot.config;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.sugarcanemc.wikifaqbot.config;
|
||||
package tech.nevets.lunarbot.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -25,7 +25,7 @@ public class ConfigUtils {
|
||||
|
||||
try {
|
||||
FileWriter writer = new FileWriter("config.yml");
|
||||
writer.write("prefix: \"!\"\nbotToken: \"BOTTOKEN\"\nmode: \"default\"");
|
||||
writer.write("prefix: \"!\"\nbotToken: \"BOTTOKEN\"");
|
||||
writer.close();
|
||||
System.out.println("Successfully wrote to config.yml");
|
||||
} catch (IOException e) {
|
||||
165
src/main/java/tech/nevets/lunarbot/webapi/WebAPI.java
Normal file
165
src/main/java/tech/nevets/lunarbot/webapi/WebAPI.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package tech.nevets.lunarbot.webapi;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
public class WebAPI {
|
||||
public static void main(String args[]) {
|
||||
WebServer ws = new WebServer();
|
||||
ws.start();
|
||||
}
|
||||
}
|
||||
|
||||
class WebServer {
|
||||
|
||||
|
||||
protected void start() {
|
||||
ServerSocket s;
|
||||
|
||||
System.out.println("Webserver starting up on port 80");
|
||||
System.out.println("(press ctrl-c to exit)");
|
||||
try {
|
||||
// create the main server socket
|
||||
s = new ServerSocket(80);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error: " + e);
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Waiting for connection");
|
||||
for (;;) {
|
||||
try {
|
||||
|
||||
Socket remote = s.accept();
|
||||
|
||||
System.out.println("Connection, sending data.");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||
remote.getInputStream()));
|
||||
PrintWriter out = new PrintWriter(remote.getOutputStream());
|
||||
|
||||
String str = ".";
|
||||
while (!str.equals(""))
|
||||
str = in.readLine();
|
||||
|
||||
out.println("HTTP/1.0 200 OK");
|
||||
out.println("Content-Type: text/html");
|
||||
out.println("Server: Bot");
|
||||
out.println("");
|
||||
out.println("<H1>WebAPI is running</H2>");
|
||||
out.flush();
|
||||
remote.close();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** static final File WEB_ROOT = new File("/WebAPI");
|
||||
static final String DEFAULT_File = "index.html";
|
||||
static final String FILE_NOT_FOUND = "404.html";
|
||||
static final String METHOD_NOT_SUPPORTED = "mns.html"; // (file not supported)
|
||||
|
||||
// port
|
||||
static final int PORT = 80;
|
||||
// port
|
||||
|
||||
static final boolean verbose = true;
|
||||
|
||||
private Socket connect;
|
||||
|
||||
public void webapi(Socket c) {
|
||||
connect = c;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
ServerSocket serverConnect = new ServerSocket(PORT);
|
||||
System.out.println("[WebAPI] WebAPI Started on " + "IP" + PORT);
|
||||
while(true) {
|
||||
WebAPI server = new WebAPI();
|
||||
if (verbose) {
|
||||
System.out.println("[WebAPI] Connection Open.");
|
||||
}
|
||||
|
||||
Thread thread = new Thread(server);
|
||||
thread.start();
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("[WebAPI] Server Connection error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedReader in = null; PrintWriter out = null; BufferedOutputStream dataOut = null;
|
||||
String fileRequested = null;
|
||||
|
||||
try{
|
||||
in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
|
||||
out = new PrintWriter(connect.getOutputStream());
|
||||
dataOut = new BufferedOutputStream(connect.getOutputStream());
|
||||
String input = in.readLine();
|
||||
StringTokenizer parse = new StringTokenizer(input);
|
||||
String method = parse.nextToken().toUpperCase();
|
||||
fileRequested = parse.nextToken().toLowerCase();
|
||||
if(!method.equals("GET") && !method.equals("HEAD")) {
|
||||
if (verbose) {
|
||||
System.out.println("501 Not Implemeted: " + method + "method.");
|
||||
}
|
||||
File file = new File(WEB_ROOT, METHOD_NOT_SUPPORTED);
|
||||
int fileLength = file.length();
|
||||
String conetentMimeType = "ext/html";
|
||||
byte[] fileData = readFileData(file, fileLength)
|
||||
private byte[] readFileData(File file, int fileLength) {
|
||||
FileInputStream fileIn = null;
|
||||
byte[] fileData = new byte[fileLength];
|
||||
fileIn = new FileInputStream(file);
|
||||
fileIn.read(fileData);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
} catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
**/
|
||||
Reference in New Issue
Block a user