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
93 changes: 93 additions & 0 deletions src/main/java/EquationSolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import java.util.ArrayList;

public class EquationSolver {
static String eq = "1/3";
static String num = "";
static ArrayList<String> hold;

public static void main(String[] args) {
hold = new ArrayList<String>();
for (int i = 0; i < eq.length(); i++) {
if (eq.charAt(eq.length() - 1) == '+' || eq.charAt(eq.length() - 1) == '-'
|| eq.charAt(eq.length() - 1) == '/' || eq.charAt(eq.length() - 1) == '*') {
System.out.println("Not A Valid Equation");
System.exit(0);
}

if (Character.isDigit(eq.charAt(i))) {
num += "" + eq.charAt(i);

} else {
// int add = Integer.parseInt(num);
hold.add(num);
num = "";

}

if (eq.charAt(i) == '+') {
hold.add("+");
}
if (eq.charAt(i) == '-') {
hold.add("-");
}
if (eq.charAt(i) == '*') {
hold.add("*");
}
if (eq.charAt(i) == '/') {
hold.add("/");
}
/*
* 5+6*7-8/2 5+42-8/2 5+42-4 47-4 43
*/
}
hold.add(num);
num = "";


boolean done = false;
String[] symbols = { "*", "/", "+", "-" };
int currentIndex = 0;
String currentSym = symbols[currentIndex];
while (!done) {
boolean found = false;

for (int i = 0; i < hold.size(); i++) {
if (hold.get(i).equals(currentSym)) {
double fVal = Double.parseDouble(hold.get(i - 1));
double sVal = Double.parseDouble(hold.get(i + 1));
double solution = 0;
if (hold.get(i).equals("*")) {
solution = fVal * sVal;
}
if (hold.get(i).equals("/")) {
solution = fVal / sVal;
}
if (hold.get(i).equals("+")) {
solution = fVal + sVal;
}
if (hold.get(i).equals("-")) {
solution = fVal - sVal;
}
hold.remove(i - 1);
hold.remove(i - 1);
String ans = "" + solution;
hold.set(i - 1, ans);
found = true;
break;
}
}
if (!found) {
currentIndex++;

if (currentIndex >= symbols.length) {
done = true;
} else {

currentSym = symbols[currentIndex];
}
}
}

}

}
11 changes: 8 additions & 3 deletions src/main/java/org/jointheleague/discord_bot_example/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public Bot(String token, String channelName) {
helpListener = new _HelpListener(channelName);
}


public void connect(boolean printInvite) {

api = new DiscordApiBuilder().setToken(token).login().join();
Expand All @@ -47,9 +48,9 @@ public void connect(boolean printInvite) {
api.addMessageCreateListener(dl);
helpListener.addHelpEmbed(dl.getHelpEmbed());

CurrencyConverter cc = new CurrencyConverter(channelName);
api.addMessageCreateListener(cc);
helpListener.addHelpEmbed(cc.getHelpEmbed());
// CurrencyConverter cc = new CurrencyConverter(channelName);
// api.addMessageCreateListener(cc);
// helpListener.addHelpEmbed(cc.getHelpEmbed());

ToDoList list = new ToDoList(channelName);
api.addMessageCreateListener(list);
Expand Down Expand Up @@ -127,6 +128,9 @@ public void connect(boolean printInvite) {
DiscordZoomAccess dza = new DiscordZoomAccess(channelName);
api.addMessageCreateListener(dza);
helpListener.addHelpEmbed(dza.getHelpEmbed());

EquatonSolver eq = new EquatonSolver(channelName);
api.addMessageCreateListener(eq);

CovidCaseGetter covid = new CovidCaseGetter(channelName);
api.addMessageCreateListener(covid);
Expand Down Expand Up @@ -192,6 +196,7 @@ public void connect(boolean printInvite) {
api.addMessageCreateListener(new RandomCase(channelName));
api.addMessageCreateListener(new GetTime(channelName));
api.addMessageCreateListener(new ScreenCapture(channelName));
api.addMessageCreateListener(new LisztsLists(channelName));
api.addMessageCreateListener(new StarSignSeeker(channelName));
api.addMessageCreateListener(new War(channelName));
//api.addMessageCreateListener(new Depression(channelName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void launch(String[] args) {
// Load all of the bots for every channel
for (int i = 0; i < channels.length; i++) {
new Bot(n.getToken(), channels[i]).connect(i == 0);

}
}
}
197 changes: 197 additions & 0 deletions src/main/java/org/jointheleague/modules/EquatonSolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package org.jointheleague.modules;

import java.util.ArrayList;
import java.util.Random;

import org.javacord.api.event.message.MessageCreateEvent;

import net.aksingh.owmjapis.api.APIException;

public class EquatonSolver extends CustomMessageCreateListener {
private static final String command = "!equation";

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

}

@Override
public void handle(MessageCreateEvent event) throws APIException {
// TODO Auto-generated method stub

if (event.getMessageContent().contains("!equation")) {
String eqws = event.getMessageContent().substring(9);
String eq = "";
for (int i = 0; i < eqws.length(); i++) {
if (eqws.charAt(i) == ' ') {
continue;
} else {
eq += eqws.charAt(i);

}
}
//eq is good here
String num = "";
ArrayList<String> hold;

hold = new ArrayList<String>();
for (int i = 0; i < eq.length(); i++) {

if (Character.isDigit(eq.charAt(i))) {
num="";
num += "" + eq.charAt(i);

} else {
if(num.equals("")) {

}
// int add = Integer.parseInt(num);
else {
hold.add(num);
}


}

if (eq.charAt(i) == '+') {
hold.add("+");
}
if (eq.charAt(i) == '-') {
hold.add("-");
}
if (eq.charAt(i) == '*') {
hold.add("*");
}
if (eq.charAt(i) == '/') {
hold.add("/");
}
if (eq.charAt(i) == '%') {
hold.add("%");

}
if (eq.charAt(i) == '(') {
hold.add("(");
}
if (eq.charAt(i) == ')') {
hold.add(")");
}

}
// ArrayList<String> input = new ArrayList<String>();
//
// for (int i = start; i < end; i++) {
//
// input.add("" + eq.charAt(i));
//
//
// }
//
//
//

// solveEquation(input);
// System.out.println("input " +solveEquation(input));
// hold.add(0, solveEquation(input));

event.getChannel().sendMessage(solveEquation(hold));
}

}

public String solveEquation(ArrayList<String> hold) {

boolean done = false;
String[] symbols = {"*", "/", "%", "-", "+" };
int currentIndex = 0;
String currentSym = symbols[currentIndex];
while (!done) {
boolean found = false;

for (int i = 0; i < hold.size(); i++) {
//System.out.println("hold.geti is " + hold.get(i));
if (hold.get(i).equals(currentSym)) {
double fVal = Double.parseDouble(hold.get(i - 1));
double sVal = Double.parseDouble(hold.get(i + 1));
double solution = 0;

if (hold.get(i).equals("*")) {
solution = fVal * sVal;

}
if (hold.get(i).equals("/")) {
solution = fVal / sVal;

}
if (hold.get(i).equals("+")) {
solution = fVal + sVal;

}
if (hold.get(i).equals("-")) {
solution = fVal - sVal;

}
if (hold.get(i).equals("%")) {
solution = fVal % sVal;

}


hold.remove(i - 1);
hold.remove(i - 1);
String ans = "" + solution;
hold.set(i - 1, ans);
found = true;
break;
}
if(hold.get(i).equals("(")) {

solveParenth(hold, i);
}

}
if (!found) {
currentIndex++;

if (currentIndex >= symbols.length) {
done = true;
} else {

currentSym = symbols[currentIndex];
}
}
}
String ans = hold.get(0);
return (ans);

}
public void solveParenth(ArrayList<String> hold, int place) {
ArrayList<String> in = new ArrayList<String>();
int end = -1;
for(int i = place+=1;i<hold.size();i++) {

if(hold.get(i).equals(")")) {
end=i;

break;

}
else {
in.add(hold.get(i));
}
}
solveEquation(in);
System.out.println("in is "+ in);
System.out.println("hold before removes "+hold);
//in is good here
hold.remove(place);
hold.remove(end-1);
for(int i = place;i<end+1;i++) {
System.out.println(i-1);
System.out.println(hold);
hold.remove(i-1);
}


System.out.println("hold after all of the removes " + hold);
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/jointheleague/modules/LisztsLists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.jointheleague.modules;

import java.util.Random;

import org.javacord.api.event.message.MessageCreateEvent;

import net.aksingh.owmjapis.api.APIException;

public class LisztsLists extends CustomMessageCreateListener {
private static final String command = "!lisztlist";
public LisztsLists(String channelName) {
super(channelName);
// TODO Auto-generated constructor stub
}

@Override
public void handle(MessageCreateEvent event) throws APIException {
// TODO Auto-generated method stub
if(event.getMessageContent().contains("!lisztlist")) {
int r = new Random().nextInt(7);
if(r == 0) {
event.getChannel().sendMessage("Liszt’s father was strict about him practicing with a metronome, which might be one reason Liszt was well-known for his ability to keep absolute tempo.");
}
if(r == 1) {
event.getChannel().sendMessage("In addition to his father knowing the Classical greats, Liszt himself studied with Carl Czerny as a boy. Carl Czerny was one of Beethoven’s best students, and was a renowned piano teacher.");
}
if(r == 2) {
event.getChannel().sendMessage("Liszt was Elvis before Elvis was Elvis. They called it “Lisztomania” – women would faint and go into a frenzy when he performed, so much so that local doctors thought it was an epidemic of mental illness.");
}
if(r == 3) {
event.getChannel().sendMessage("Liszt’s fame allowed him to fill concert halls with his solo performances, and he elevated the piano as a solo instrument in the concert hall as well.");
}
if(r == 4) {
event.getChannel().sendMessage("Because of his motivation, drive and hard work, Liszt built up an unparalleled technical prowess at the piano. ");
}
if(r == 5) {
event.getChannel().sendMessage("Liszt was such an intense piano player – loud enough to fill a recital hall on his own – that he would break piano strings while playing.");
}
if(r == 6) {
event.getChannel().sendMessage("In addition to being virtuosic and loud, Liszt created an entire genre of music – the symphonic poem.");
}
if(r == 7) {
event.getChannel().sendMessage("Liszt was known for being generous to friends and family.");
}


}


}

}
4 changes: 2 additions & 2 deletions src/main/resources/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"channels": ["channelName"],
"token": "discordToken"
"channels": ["louis_d_bot"],
"token": "NzYzOTIzMTk1NTk3ODE1ODI4.X3-w6g.DzJFBWUl6DTVdSJ92D4PkFnm65Q"
}