diff --git a/.github/workflows/build_java.yml b/.github/workflows/build_java.yml
new file mode 100644
index 0000000..edb67d1
--- /dev/null
+++ b/.github/workflows/build_java.yml
@@ -0,0 +1,32 @@
+# This is a basic workflow to help you get started with Actions
+
+name: Build_Java_Only
+
+# Controls when the workflow will run
+on:
+ # Triggers the workflow on push or pull request events but only for the master branch
+ push:
+
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+ # This workflow contains a single job called "build"
+ build:
+ # The type of runner that the job will run on
+ runs-on: ubuntu-latest
+
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v2
+
+ - name: Set up JDK 11
+ uses: actions/setup-java@v2
+ with:
+ java-version: '11'
+ distribution: 'adopt'
+ - name: Build with Maven
+ run: mvn clean package
\ No newline at end of file
diff --git a/.github/workflows/build_java_docker.yml b/.github/workflows/build_java_docker.yml
index 680dfa9..55e07e2 100644
--- a/.github/workflows/build_java_docker.yml
+++ b/.github/workflows/build_java_docker.yml
@@ -1,12 +1,11 @@
# This is a basic workflow to help you get started with Actions
-name: CI
+name: Build Java BuildDepolyDocker Start Docker on Server
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
- pull_request:
branches:
- main
- staging
diff --git a/Dockerfile b/Dockerfile
index 73871a2..eebacab 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -20,4 +20,4 @@ USER telegrambot
#CMD ["echo $UID"]
-ENTRYPOINT ["sh" , "-c", "java -cp java.telegrambots.jar:./lib/* de.bigamgamen.java.telegrambots.hertlhendl.HertlHendlBot ${BOT_TOKEN}:${BOT_KEY} ${BOT_NAME} ${CREATOR_ID}"]
+ENTRYPOINT ["sh" , "-c", "java -cp java.telegrambots.jar:./lib/* de.bigamgamen.java.telegrambots.hertlhendl.HertlHendlBot ${BOT_TOKEN}:${BOT_KEY} ${BOT_NAME} ${CREATOR_ID} ${CREATOR_PAYPAL_EMAIL}"]
diff --git a/create_volume.sh b/create_volume.sh
index a76d241..653c94b 100644
--- a/create_volume.sh
+++ b/create_volume.sh
@@ -1,2 +1,2 @@
-docker volume create chatbotvol
-chown 1001:1001 /var/lib/docker/volumes/chatbotvol/_data
\ No newline at end of file
+docker volume create --opt type=none --opt o=bind --opt device=~/data/chatbotvol-develop --name chatbotvol-develop
+chown 1001:1001 ~/data/chatbotvol-develop
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 149ee3c..f78d115 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,14 +1,11 @@
-
+
4.0.0
de.bigamgamen
java.telegrambots
0.9-FINAL
-
+
java.telegrambots
@@ -77,15 +74,15 @@
org.apache.logging.log4j
log4j-api
- 2.15.0
+ 2.17.2
- org.apache.logging.log4j
- log4j-core
- 2.17.1
+ org.apache.logging.log4j
+ log4j-core
+ 2.17.2
@@ -96,9 +93,10 @@
-
+
+
- ${project.name}
+ ${project.name}
@@ -125,4 +123,4 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/de/bigamgamen/java/helper/PaypalLinkGenerator.java b/src/main/java/de/bigamgamen/java/helper/PaypalLinkGenerator.java
new file mode 100644
index 0000000..99257f8
--- /dev/null
+++ b/src/main/java/de/bigamgamen/java/helper/PaypalLinkGenerator.java
@@ -0,0 +1,40 @@
+package de.bigamgamen.java.helper;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import de.bigamgamen.java.telegrambots.hertlhendl.domain.HertlBotOrder;
+
+/**
+ * generates a link like https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=greatsave@web.de¤cy_code=EUR&amount=1&item_name=Knowledgebase%20Spende
+ * @author Bigmama
+ *
+ */
+public class PaypalLinkGenerator
+{
+ public static String DEFAULT_CURRENCY = "EUR";
+ public static String CURRENCY_CODE = "¤cy_code=";
+
+ public static String BUSINESS = "&business="; // (Zahlungsempfänger) = PayPal E-Mail des Zahlungsempfängers
+ public static String AMOUNT = "&amount="; // (Betrag) = 123.12 (Achtung, mit Punkt als Dezimaltrennzeichen)
+ public static String ITEM_NAME = "&item_name="; // (Artikelname)
+ public static String URL_START = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick";
+
+ public PaypalLinkGenerator()
+ {
+
+ }
+
+ public URL generatePayPalLinkForOrder(final HertlBotOrder order, String adminEmail) throws MalformedURLException
+ {
+ final StringBuilder sb = new StringBuilder(URL_START);
+ sb.append(BUSINESS).append(adminEmail);
+ sb.append(AMOUNT).append(Pricehelper.getPriceAsDotString(order.getBigIntegerSumme()));
+ sb.append(ITEM_NAME).append(order.getPayPalDescription());
+ sb.append(CURRENCY_CODE).append(DEFAULT_CURRENCY);
+
+ final URL paylpalLink = new URL(sb.toString());
+ return paylpalLink;
+ }
+
+}
diff --git a/src/main/java/de/bigamgamen/java/helper/Pricehelper.java b/src/main/java/de/bigamgamen/java/helper/Pricehelper.java
index ddc0eec..15e653c 100644
--- a/src/main/java/de/bigamgamen/java/helper/Pricehelper.java
+++ b/src/main/java/de/bigamgamen/java/helper/Pricehelper.java
@@ -11,4 +11,8 @@ private Pricehelper() {
public static String getPriceAsEuroString(BigInteger priceInCent) {
return NumberFormat.getCurrencyInstance().format(priceInCent.doubleValue() / 100);
}
+ public static String getPriceAsDotString(BigInteger priceInCent) {
+ return Double.toString(priceInCent.doubleValue() / 100);
+ }
+
}
diff --git a/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/HertlHendlBot.java b/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/HertlHendlBot.java
index 114c75b..61b0d4d 100644
--- a/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/HertlHendlBot.java
+++ b/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/HertlHendlBot.java
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
@@ -52,6 +53,7 @@
import com.google.common.annotations.VisibleForTesting;
import de.bigamgamen.java.helper.IOHelper;
+import de.bigamgamen.java.helper.PaypalLinkGenerator;
import de.bigamgamen.java.telegrambots.hertlhendl.api.RightController;
import de.bigamgamen.java.telegrambots.hertlhendl.api.RoleController;
import de.bigamgamen.java.telegrambots.hertlhendl.builder.TelegramKeyBoardBuilder;
@@ -84,6 +86,7 @@ public class HertlHendlBot extends AbilityBot
public static final String ABILITY_NAME_ADMIN_CLOSE_ORDERS = "admincloseorders";
public static final String ABILITY_NAME_CLOSE_ORDER = "closeorder";
public static final String ABILITY_NAME_COMMIT_ORDER = "commitorder";
+ public static final String ABILITY_NAME_PAYPAL_LINK = "paypallink";
private static final String MESSAGE_CLOSE_SUCCESSFULL = "Die Bestellung wurde erfolgreich geschlossen.";
private static final String ALL_MESSAGE_CLOSE_SUCCESSFULL =
@@ -98,6 +101,7 @@ public class HertlHendlBot extends AbilityBot
private final static String BOT_TOKEN = "";
private final static String BOT_USERNAME = "";
private final static String ADMIN_DEFAULT_NAME = "Admin";
+
private static Integer CREATOR_ID = 0;
private static String HERTL_URL =
"http://ks3266365.kimsufi.com:2341/?url=https://hertel-haehnchen.de/standplatzsuche?search=92637";
@@ -108,6 +112,10 @@ public class HertlHendlBot extends AbilityBot
private final RoleController roleController;
private final Long creatorId;
+ private String creatorPayPalEmail ="";
+ private final PaypalLinkGenerator payPalGenerator = new PaypalLinkGenerator();
+
+
public static void main(final String[] args)
throws ParserConfigurationException, SAXException, IOException, URISyntaxException, TelegramApiException
{
@@ -116,13 +124,14 @@ public static void main(final String[] args)
final String token = args[0] != null ? args[0] : BOT_TOKEN;
final String username = args[1] != null ? args[1] : BOT_USERNAME;
final Long creatorId = args[2] != null ? Long.valueOf(args[2]) : CREATOR_ID;
- final HertlHendlBot bot = new HertlHendlBot(token, username, creatorId);
+ final String creatorPayPalEmail = args[3] != null ? args[3] : "";
+ final HertlHendlBot bot = new HertlHendlBot(token, username, creatorId, creatorPayPalEmail);
final TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
api.registerBot(bot);
LOG.info("HertlHendlBot successfull started");
}
- public HertlHendlBot(final String botToken, final String botUsername, Long creatorId)
+ public HertlHendlBot(final String botToken, final String botUsername, Long creatorId, String creatorPayPalEmail)
throws ParserConfigurationException, SAXException, IOException, URISyntaxException
{
super(botToken, botUsername);
@@ -132,6 +141,7 @@ public HertlHendlBot(final String botToken, final String botUsername, Long creat
this.rightController = new HertlRightController(creatorId);
this.roleController = new HertlRoleController(this.rightController);
this.creatorId = creatorId;
+ this.creatorPayPalEmail = creatorPayPalEmail;
this.initAdminUser();
}
@@ -515,6 +525,41 @@ public Ability showLocationPhoto()
}).build();
}
+ public Ability showPayPalLink()
+ {
+ return Ability.builder().name(ABILITY_NAME_PAYPAL_LINK).info("PaypalLink").locality(
+ ALL).privacy(PUBLIC).input(1).action(context ->
+ {
+ //TOFDO nur mit Recht dazu
+
+ final int bestellId = Integer.parseInt(context.firstArg());
+ final Long chatId = context.chatId();
+ final HertlBotOrder bestellung = hertlBotDao.loadBestellung(
+ chatId,
+ TelegramHelper.getTotalUserName(context.user()),
+ bestellId);
+ //TODO logik for closed Order
+
+ final SendMessage message = new SendMessage();
+ message.setChatId(Long.toString(context.chatId()));
+ try
+ {
+ message.setText(this.payPalGenerator.generatePayPalLinkForOrder(bestellung, this.creatorPayPalEmail).toString());
+ this.silent.execute(message);
+ }
+ catch(final MalformedURLException e)
+ {
+ e.printStackTrace();
+ LOG.error("Fehler beim genieren PayPalLink:{}", e);
+ }
+
+
+
+
+
+ }).build();
+ }
+
private void sendPhotoFromUpload(final InputStream is, String fileName, final Long chatId)
{
final SendPhoto sendPhotoRequest = new SendPhoto(); // 1
@@ -534,7 +579,7 @@ private void sendPhotoFromUpload(final InputStream is, String fileName, final Lo
}
catch(final TelegramApiException e)
{
- e.printStackTrace();
+ LOG.error("Fehler beim schicken des Photos:{}", e);
}
}
diff --git a/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/builder/TelegramKeyBoardBuilder.java b/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/builder/TelegramKeyBoardBuilder.java
index fc525f1..e2380e0 100644
--- a/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/builder/TelegramKeyBoardBuilder.java
+++ b/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/builder/TelegramKeyBoardBuilder.java
@@ -29,8 +29,8 @@ public TelegramKeyBoardBuilder(HertlBotRootDao hertlBotDao) {
public List loadAndShowMyOrdersAsKeyBoard(final Long chatId, String userName) {
final List keyboard = new ArrayList<>();
- hertlBotDao.loadUser(chatId,userName).getBestellungen()
- .forEach(bestellung -> addButtonToKeyBoard(keyboard, this.createOrderLink(bestellung)));
+ this.hertlBotDao.loadUser(chatId,userName).getBestellungen()
+ .forEach(bestellung -> this.addButtonToKeyBoard(keyboard, this.createOrderLink(bestellung)));
return keyboard;
}
@@ -38,15 +38,20 @@ public List loadAndShowMyOrdersAsKeyBoard(final Long chatId, String
public List loadAndShowAllArticleForOrder(final Long chatId, final Integer bestellungId) {
final List keyboard = new ArrayList<>();
- hertlBotDao.root().artikels().all().forEach(
- artikel -> addButtonToKeyBoard(keyboard, createAddPositiontoOrderLink(artikel, bestellungId)));
+ this.hertlBotDao.root().artikels().all().forEach(
+ artikel -> this.addButtonToKeyBoard(keyboard, this.createAddPositiontoOrderLink(artikel, bestellungId)));
KeyboardRow row = new KeyboardRow();
- row.add(new KeyboardButton(createKeyForAbility(HertlHendlBot.ABILITY_NAME_COMMIT_ORDER+" "+bestellungId)));
+ row.add(new KeyboardButton(this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_COMMIT_ORDER+" "+bestellungId)));
keyboard.add(row);
row = new KeyboardRow();
- row.add(new KeyboardButton(createKeyForAbility(HertlHendlBot.ABILITY_NAME_CLOSE_ORDER+" "+bestellungId)));
+ row.add(new KeyboardButton(this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_CLOSE_ORDER+" "+bestellungId)));
+ keyboard.add(row);
+
+ //TODO erst wenn die order geliefert wurde.
+ row = new KeyboardRow();
+ row.add(new KeyboardButton(this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_PAYPAL_LINK+" "+bestellungId)));
keyboard.add(row);
return keyboard;
@@ -55,7 +60,7 @@ public List loadAndShowAllArticleForOrder(final Long chatId, final
private void addButtonToKeyBoard(List keyboard, String buttonString) {
KeyboardRow rowToUse = null;
- for (KeyboardRow row : keyboard) {
+ for (final KeyboardRow row : keyboard) {
if (row.size() < MAX_BUTTON_PER_ROW) {
rowToUse = row;
}
@@ -72,19 +77,19 @@ private void addButtonToKeyBoard(List keyboard, String buttonString
public String createAndShowNewOrder(final Long chatId, String userName) {
- final HertlBotOrder bestellung = hertlBotDao.createNewBestellungForUser(chatId, userName);
+ final HertlBotOrder bestellung = this.hertlBotDao.createNewBestellungForUser(chatId, userName);
return this.createOrderLink(bestellung);
}
public String createOrderLink(final HertlBotOrder bestellung) {
return this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_ORDER) + " " + Integer.toString(bestellung.getIndex())
- + System.lineSeparator();
+ + System.lineSeparator();
}
public String createAddPositiontoOrderLink(final HertlBotArticle artikel, final Integer bestellungId) {
return this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_ADD_POSITION) + " " + artikel.getName() + " "
- + bestellungId + System.lineSeparator();
+ + bestellungId + System.lineSeparator();
}
public String createAbilityListForHelp(List abilities) {
diff --git a/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/domain/HertlBotOrder.java b/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/domain/HertlBotOrder.java
index fa5eaf4..d60a587 100644
--- a/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/domain/HertlBotOrder.java
+++ b/src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/domain/HertlBotOrder.java
@@ -10,7 +10,7 @@
import one.microstream.persistence.types.Persister;
public class HertlBotOrder {
-
+
private static final String ORDER_UNCOMMITED = "UNBESTÄTIGT";
private static final String ORDER_COMMITED = "BESTÄTIGT";
private static final String ORDER_CLOSED = "GESCHLOSSEN";
@@ -23,52 +23,57 @@ public class HertlBotOrder {
private List positionen = new ArrayList<>();
private Boolean commited = false;
private Boolean closed = false;
-
+
public HertlBotOrder() {
-
+
}
-
+
public HertlBotOrder(final HertlBotUser user, final List positionen) {
this.bestellDatum = LocalDate.now();
this.user = user;
this.positionen = positionen;
}
-
+
public synchronized void addPosition(HertlBotPosition position, final Persister persister)
{
- positionen.add(position);
+ this.positionen.add(position);
persister.store(position);
- persister.store(positionen);
+ persister.store(this.positionen);
}
-
+
public String getBestellDatumFormated() {
return this.bestellDatum.format(DateTimeFormatter.ofPattern(DD_MM_YYYY));
}
-
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder(ORDER_TITLE + " " + this.index);
sb.append(" Für: " + this.getUser().getUserName())
- .append(" Vom: " + this.getBestellDatumFormated() + ". "
- + (isCommited() ? ORDER_COMMITED : ORDER_UNCOMMITED)
- + "\n und "
- + (isClosed() ? ORDER_CLOSED: ORDER_OPEN)
- + System.lineSeparator());
+ .append(" Vom: " + this.getBestellDatumFormated() + ". "
+ + (this.isCommited() ? ORDER_COMMITED : ORDER_UNCOMMITED)
+ + "\n und "
+ + (this.isClosed() ? ORDER_CLOSED: ORDER_OPEN)
+ + System.lineSeparator());
this.positionen.forEach(pos -> sb.append(pos.toString()+System.lineSeparator()));
sb.append("Summe: "+ this.getSumme());
return sb.toString();
}
-
- private String getSumme() {
- BigInteger summe = new BigInteger("0");
- for(HertlBotPosition pos : positionen)
+
+
+ public BigInteger getBigIntegerSumme() {
+ BigInteger summe = new BigInteger("0");
+ for(final HertlBotPosition pos : this.positionen)
{
summe = summe.add(pos.getPositionPrice());
}
- return Pricehelper.getPriceAsEuroString(summe);
+ return summe;
}
+ private String getSumme() {
+ return Pricehelper.getPriceAsEuroString(this.getBigIntegerSumme());
+ }
+
public HertlBotUser getUser() {
return this.user;
}
@@ -81,43 +86,49 @@ public List getPositionen() {
public void setPositionen(final List positionen) {
this.positionen = positionen;
}
-
+
public LocalDate getBestellDatum() {
return this.bestellDatum;
}
-
+
public void setBestellDatum(final LocalDate bestellDatum) {
this.bestellDatum = bestellDatum;
}
-
+
public int getIndex() {
return this.index;
}
-
+
public void setIndex(final int index) {
this.index = index;
}
-
+
public Boolean isClosed()
{
- return closed;
+ return this.closed;
}
-
+
public void setClosed(Boolean closed)
{
this.closed = closed;
}
-
+
public Boolean isCommited()
{
return this.commited;
}
-
+
public void setCommited(Boolean commited)
{
this.commited = commited;
}
-
-
+ public String getPayPalDescription()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
}
diff --git a/start_docker_example.sh b/start_docker_example.sh
index c830d86..a858cd9 100644
--- a/start_docker_example.sh
+++ b/start_docker_example.sh
@@ -3,4 +3,4 @@ docker run -d --restart unless-stopped --name chatbot -v chatbotvol:/opt/telegra
#Develop
docker run -it -v chatbotvol:/opt/telegrambot/data --env-file ./env.list amgamen/chatbot
-docker run -it -v chatbotvol:/opt/telegrambot/data -e "BOT_TOKEN=" -e "BOT_KEY=" -e "BOT_NAME=" -e "CREATOR_ID=" amgamen/chatbot
+docker run -v chatbotvol:/opt/telegrambot/data --restart unless-stopped --name bot-develop -d -e "BOT_TOKEN=2103518689" -e "BOT_KEY=" -e "BOT_NAME=" -e "CREATOR_ID=" -e "CREATOR_PAYPAL_EMAIL=" amgamen/chatbot:develop