Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ src/main/java/org.jointheleague.Launcher.java
.travis.yml
run.sh
appspec.yml
/.gradle/
1 change: 1 addition & 0 deletions DiscordBot_v2
Submodule DiscordBot_v2 added at cf1e85
2 changes: 2 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/test/
/main/
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
}

group = 'org.jointheleague'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jointheleague/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void main(String[] args) {
String channelName = System.getenv("CHANNEL_NAME");
String discordToken = System.getenv("DISCORD_TOKEN");
boolean printDiscordInvite = true;

System.out.println("Running :)");
//Instantiate DiscordBot and connect
DiscordBot discordBot = new DiscordBot(discordToken, channelName);
discordBot.connect(printDiscordInvite);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/jointheleague/discord_bot/DiscordBot.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.jointheleague.discord_bot;

import org.javacord.api.DiscordApi;

import org.javacord.api.DiscordApiBuilder;
import org.jointheleague.features.abstract_classes.Feature;
import org.jointheleague.features.examples.second_features.HighLowGame;
import org.jointheleague.features.examples.third_features.CatFactsApi;
import org.jointheleague.features.examples.third_features.ImgurApi;
import org.jointheleague.features.examples.third_features.MazeGame;
import org.jointheleague.features.examples.third_features.NewsApi;
import org.jointheleague.features.examples.third_features.RockPaperSciApi;
import org.jointheleague.features.examples.first_features.CurrentTime;
import org.jointheleague.features.examples.first_features.RandomNumber;
import org.jointheleague.features.help_embed.HelpListener;
Expand All @@ -24,12 +28,13 @@ public DiscordBot(String token, String channelName) {
this.token = token;
this.channelName = channelName;
helpListener = new HelpListener(channelName);
System.out.println(channelName);
}

public void connect(boolean printInvite) {

api = new DiscordApiBuilder().setToken(token).login().join();

api = new DiscordApiBuilder().setAllIntents().setToken(token).login().join();
//Print the URL to invite the bot
if (printInvite) {
System.out.println("To authorize your bot, send your teacher this link: " + api.createBotInvite()
Expand All @@ -48,6 +53,9 @@ public void connect(boolean printInvite) {
addFeature(new HighLowGame(channelName));
addFeature(new NewsApi(channelName));
addFeature(new CatFactsApi(channelName));
addFeature(new ImgurApi(channelName));
addFeature(new RockPaperSciApi(channelName));
addFeature(new MazeGame(channelName));
}

private void addFeature(Feature feature){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.jointheleague.features.examples.third_features;

import java.awt.Event;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.concurrent.CompletableFuture;
import org.javacord.api.entity.message.Message;
import org.javacord.api.event.message.MessageCreateEvent;
import org.jointheleague.features.abstract_classes.Feature;
import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed;
import org.springframework.web.reactive.function.client.WebClient;


public class ImgurApi extends Feature {

public final String IMAGE_COMMAND = "!image";
private WebClient webClient;
private static final String baseUrl = "https://imgur.com";
static String imageName = "";
String clientID = "4d7979a11b2ca0c";
String clientSecret = "249c3c725c980eae4dcaeb1ef7e2617fabee7e94";

public ImgurApi(String channelName) {
super(channelName);

//Create a help embed to describe feature when !help command is sent
helpEmbed = new HelpEmbed(
IMAGE_COMMAND,
"Use this method to search for any image or video you'd like!"
);
this.webClient = WebClient
.builder()
.baseUrl(baseUrl)
.build();
}

@Override
public void handle(MessageCreateEvent event) {
String messageContent = event.getMessageContent();
if (messageContent.contains(IMAGE_COMMAND)) {
//respond to message here!
//System.out.println("Hi!");
imageName = event.getMessageContent().replaceAll("!image ", "");

String output = "https://imgur.com/search?q="+imageName;

event.getChannel().sendMessage(output);


}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package org.jointheleague.features.examples.third_features;

import java.awt.Event;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import org.javacord.api.entity.message.Message;
import org.javacord.api.event.message.MessageCreateEvent;
import org.jointheleague.features.abstract_classes.Feature;
import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed;
import org.springframework.web.reactive.function.client.WebClient;

import io.netty.channel.Channel;


public class MazeGame extends Feature {

public final String IMAGE_COMMAND = "!MazeGame";
private WebClient webClient;
int row = 4;
int col = 0;
private static final String baseUrl = "";
String[][] Array = {{"⬜","⬛","⬛","⬛","⬛","🟩"},
{"⬛","⬛","⬛","⬛","⬛","⬛"},
{"⬛","⬛","⬜","⬛","⬜","⬜"},
{"⬛","⬛","⬛","⬛","⬛","⬜"},
{"🟨","⬜","⬜","⬜","⬛","⬛"}};
String pos = Array[row][col];

public MazeGame(String channelName) {
super(channelName);

//Create a help embed to describe feature when !help command is sent
helpEmbed = new HelpEmbed(
IMAGE_COMMAND,
"Use this method to a maze game!"
);
this.webClient = WebClient
.builder()
.baseUrl(baseUrl)
.build();
}

@Override
public void handle(MessageCreateEvent event) {

String messageContent = event.getMessageContent();
if (messageContent.contains(IMAGE_COMMAND)) {
//respond to message here!
String maze = "";
for (int i = 0; i < Array.length; i++) {

// Loop through all elements of current row
for (int j = 0; j < Array[i].length; j++) {
maze += Array[i][j] + " ";

}
maze = maze + "\n";

}
event.getChannel().sendMessage(maze);
}
String message = event.getMessageContent();
if (message.contains(IMAGE_COMMAND)) {

//respond to message here!
String direction = event.getMessageContent().replaceAll("!MazeGame ", "");
if(direction.equalsIgnoreCase("left")) {
//1 Check if can move (barrier or goes out of bounds)
//2 If can't, print can't
String oldpos = Array[row][col];
//3 If can, replace that square with black, and the new one with yello
if(col-1 >= 0) {
col = col-1;
}
else {
event.getChannel().sendMessage("You can't move here! Out of bounds");
}
String newpositon = Array[row][col];

if(newpositon == "⬛") {
Array[row][col]= "🟨";
Array[row][col+1] = "⬛";

event.getChannel().sendMessage(printMaze(Array));
}
else if(newpositon == "🟩") {
event.getChannel().sendMessage("You won!");
}


}
if(direction.equalsIgnoreCase("right")) {
String oldpos = Array[row][col];
System.out.println("Array val:" + Array[row][0].length());
//3 If can, replace that square with black, and the new one with yello
if(col+1 < 6) {
col = col+1;
}
else {
event.getChannel().sendMessage("You can't move here! Out of bounds");
}
String newpositon = Array[row][col];

if(newpositon == "⬛") {

Array[row][col] = "🟨";
Array[row][col-1] = "⬛";

event.getChannel().sendMessage(printMaze(Array));
}
else if(newpositon == "🟩") {
event.getChannel().sendMessage("You won!");
}
System.out.println("Col: " + col);

}
if(direction.equalsIgnoreCase("up")) {
String oldpos = Array[row][col];
System.out.println(row);
//3 If can, replace that square with black, and the new one with yello
if(row-1 >= 0) {
row = row-1;

}
else {
event.getChannel().sendMessage("You can't move here! Out of bounds.");


}
String newpositon = Array[row][col];

if(newpositon == "⬛") {
Array[row][col] = "🟨";
Array[row+1][col] = "⬛";


}
else if(newpositon == "🟩") {
event.getChannel().sendMessage("You won!");
}

event.getChannel().sendMessage(printMaze(Array));
System.out.println(row);

}
if(direction.equalsIgnoreCase("down")) {
String oldpos = Array[row][col];
//3 If can, replace that square with black, and the new one with yello
if(row-1 < Array[0][col].length()) {
row = row+1;
}
else {
event.getChannel().sendMessage("You can't move here! Out of bounds");
}
String newpositon = Array[row][col];

if(newpositon == "⬛") {

Array[row][col] = "🟨";
Array[row-1][col] = "⬛";

event.getChannel().sendMessage(printMaze(Array));
}

else if(newpositon == "🟩") {
event.getChannel().sendMessage("You won!");
}


}

}



}
public String printMaze(String[][] Array) {
String maze = "";
for (int i = 0; i < Array.length; i++) {

// Loop through all elements of current row
for (int j = 0; j < Array[i].length; j++) {

maze += Array[i][j]+"";
}
maze+= "\n";
}
return maze;
}
}
Loading