added Source

This commit is contained in:
thiesyy 2019-10-21 23:20:06 +02:00
parent a62775b855
commit 6940fa89fd
No known key found for this signature in database
GPG Key ID: 3560E52BC0B3CA40
2 changed files with 306 additions and 0 deletions

26
pom.xml Normal file
View File

@ -0,0 +1,26 @@
<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>FridaysForFutureBot</groupId>
<artifactId>FridaysForFutureBot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>TelegramAPI</groupId>
<artifactId>TelegramAPI</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,280 @@
package de.Thiesyy.FridayForFutureBot.Core;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import de.mrbesen.telegram.TelegramAPI;
import de.mrbesen.telegram.event.events.UserSendMessageEvent;
import de.mrbesen.telegram.objects.TMessage;
import de.mrbesen.telegram.objects.TUser;
public class FridayForFutureBot {
private long mainchatid = -1;
private boolean heistrunning = false;
private int heistid = 0;
public static FridayForFutureBot instance;
private HashMap<Long, Integer> coins = new HashMap<Long, Integer>();
private HashMap<Long, String> codename = new HashMap<Long, String>();
private int MAXHEISTSIZE = 5;
private int Minsize = 1;
private static Long HeistOwner = 0L;
private boolean Heistprerun = false;
private boolean HeistInAction = false;
private ArrayList<String> codenames = new ArrayList<String>();
private File configfile = new File("Config.cfg");
public TelegramAPI tgapi;
private String apikey = "0";
public static void main(String[] args) {
instance = new FridayForFutureBot();
}
public FridayForFutureBot() {
initcodenames();
readApiKey();
tgapi = new TelegramAPI(apikey, "FriForFutBot");
tgapi.setLongpolling(true);
tgapi.setHelpText("Im ready.");
tgapi.getEventManager().registerEvent(UserSendMessageEvent.class, this::handleMessages);
tgapi.setUpdateInterval(60);
tgapi.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}
private void initcodenames() {
codenames.add("Shakira");
codenames.add("Albina");
codenames.add("Camilla");
codenames.add("Avitus");
codenames.add("Lysander");
codenames.add("Isidore");
codenames.add("Bruno");
codenames.add("Jarl");
codenames.add("Bozo");
codenames.add("Boss");
}
public int getCoins(long id) {
if (!coins.containsKey(id))
setCoins(id, 1000);
int Coins = coins.get(id);
if (Coins < 5) {
coins.remove(id);
setCoins(id, 1000);
tgapi.sendAsync(mainchatid, "i Refilled your Coins.");
}
return Coins;
}
public void setCoins(long id, int amount) {
if (coins.containsKey(id))
coins.remove(id);
coins.put(id, amount);
}
public void handleMessages(Object obj) {
UserSendMessageEvent e = (UserSendMessageEvent) obj;
TUser user = e.getUser();
TMessage msgo = e.getMessage();
String msg = msgo.getText().toLowerCase();
long cid = msgo.getChatID();
if (msg.contains("klimaschutz")) {
tgapi.sendAsync(cid, "Klimaschutz ist sehr wichtig Genossinnen und Genossen!");
} else if (msg.startsWith(".roulette")) {
int a = new Random().nextInt(6);
if (a == 0)
tgapi.sendAsync(cid, "Der Revolver hat geschossen. Du bist tot.");
else
tgapi.sendAsync(cid, "*click*, Du hast überlebt.");
} else if (msg.startsWith(".help")) {
tgapi.sendAsync(cid, ".help - help\n.roulette - play roulette\nKlimaschutz\n.chatid\n.coins\n.heist");
} else if (msg.startsWith(".chatid")) {
tgapi.sendAsync(cid, user.getID() + " ist deine ChatID.");
} else if (msg.startsWith(".coins")) {
mainchatid = cid;
System.out.println(user.getName());
tgapi.sendAsync(cid, "Du hast: " + getCoins(user.getID()) + " Coins.");
} else if (msg.startsWith(".heist")) {
mainchatid = cid;
if (!heistrunning) {
if (!Heistprerun && !HeistInAction) {
HeistOwner = user.getID();
joinHeist(HeistOwner);
heistid++;
tgapi.sendAsync(cid,
"Du hast einen Überfall gestartet. Andere können mit '.heist' dem Überfall beitreten. Sende noch einmal '.heist' um den Überfall zu starten! Dein Deckname: "
+ getCodename(HeistOwner));
heistrunning = true;
Heistprerun = true;
new Thread(new Runnable() {
@Override
public void run() {
int gid = heistid;
Long owner = HeistOwner;
try {
Thread.sleep(1000*60*5);
} catch (InterruptedException e) {
}
if(owner.equals(HeistOwner) && gid == heistid) {
tgapi.sendAsync(cid, "Es sind nicht genug leute dem Überfall beigetreten.");
HeistOwner = 0L;
HeistInAction = false;
Heistprerun = false;
heistrunning = false;
codename.clear();
}
}
}).start();
}
} else {
if (Heistprerun) {
if(user.getID() == HeistOwner) {
if(codename.size() > Minsize) {
Heistprerun = false;
HeistInAction = true;
tgapi.sendAsync(cid, "Der Überfall startet nun.");
runHeist();
}
else {
tgapi.sendAsync(cid, "Es sind zuwenig Leute dabei.");
}
}else {
if(!isinHeist(user.getID())) {
if(codename.size() > MAXHEISTSIZE) {
tgapi.sendAsync(cid, "Der Überfall ist bereits voll.");
}else {
joinHeist(user.getID());
tgapi.sendAsync(cid,
"Du hast dich dem Überfall angeschlossen. Dein Deckname: " + getCodename(user.getID()));
}
}else {
tgapi.sendAsync(cid, "du bist schon dabei!");
}
}
} else
tgapi.sendAsync(cid, "Der Überfall läuft bereits!");
}
}
System.out.println(msg);
}
private boolean isinHeist(Long id) {
return codename.containsKey(id);
}
private void joinHeist(Long id) {
String cnme = unusedCodename();
System.out.println(cnme);
codename.put(id, cnme);
}
private void runHeist() {
new Thread(new Runnable() {
@Override
public void run() {
boolean gudboi = false;
Long problemmaker = 0L;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
String names = "";
Set<Entry<Long, String>> es = codename.entrySet();
for (Entry<Long, String> etry : es) {names+=etry.getValue()+",";}
tgapi.sendAsync(mainchatid, names+ " haben die Bank betreten!");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
tgapi.sendAsync(mainchatid, "Sie zücken ihre Waffen und bedrohen die Angestellten.");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
if(new Random().nextBoolean()) {
tgapi.sendAsync(mainchatid, "Oh nein! Ein Wachmann ist in der Bank und er hat eine Waffe!");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
problemmaker = getRandomHeister();
gudboi = true;
tgapi.sendAsync(mainchatid, getCodename(problemmaker) + " wurde angeschossen und ist auf der Stelle tot. Er verliert 500 Coins!");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
tgapi.sendAsync(mainchatid, "Der Rest bekommt das volle Geld des überfalls. der Teil des gestorbenen wurde von der Polizei genommen.");
}else {
tgapi.sendAsync(mainchatid, "Der Überfall läuft super! Sie holen sich ihr Geld, und hauen ab!");
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
tgapi.sendAsync(mainchatid, "Der Überfall ist beendet.");
for (Entry<Long, String> etry : es) {setCoins(etry.getKey(), getCoins(etry.getKey())+200);}
if(gudboi)
setCoins(problemmaker, getCoins(problemmaker)-700);
HeistOwner = 0L;
HeistInAction = false;
Heistprerun = false;
heistrunning = false;
codename.clear();
}
}).start();;
}
private Long getRandomHeister() {
ArrayList<Long> list = new ArrayList<Long>();
Set<Entry<Long, String>> es = codename.entrySet();
for (Entry<Long, String> etry : es) {list.add(etry.getKey());}
return list.get(new Random().nextInt(list.size()));
}
private String unusedCodename() {
for (String cdnme : codenames) {
Set<Entry<Long, String>> es = codename.entrySet();
boolean ok = true;
for (Entry<Long, String> etry : es) {
if (cdnme.equalsIgnoreCase(etry.getValue()))
ok = false;
}
if (ok)
return cdnme;
}
return "Error";
}
private String getCodename(Long id) {
return codename.get(id);
}
public void readApiKey() {
if (!configfile.exists())
try {
configfile.createNewFile();
} catch (IOException e) {
}
try {
Scanner s = new Scanner(configfile);
if (s.hasNextLine())
apikey = s.nextLine();
} catch (FileNotFoundException e) {
}
}
}