Skip to content
Merged
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
32 changes: 32 additions & 0 deletions .github/workflows/build_java.yml
Original file line numberDiff line numberDiff line change
@@ -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
3 changes: 1 addition & 2 deletions .github/workflows/build_java_docker.yml
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -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}"]
4 changes: 2 additions & 2 deletions create_volume.sh
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
docker volume create chatbotvol
chown 1001:1001 /var/lib/docker/volumes/chatbotvol/_data
docker volume create --opt type=none --opt o=bind --opt device=~/data/chatbotvol-develop --name chatbotvol-develop
chown 1001:1001 ~/data/chatbotvol-develop
22 changes: 10 additions & 12 deletions pom.xml
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>de.bigamgamen</groupId>
<artifactId>java.telegrambots</artifactId>
<version>0.9-FINAL</version>

<name>java.telegrambots</name>

<properties>
Expand DownExpand Up@@ -77,15 +74,15 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.15.0</version>
<version>2.17.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>

<dependency>
Expand All@@ -96,9 +93,10 @@
</dependency>
</dependencies>

<build><!-- Kopiert alle Libs einzeln in den Lib Ordner wie früher. -->
<build>
<!-- Kopiert alle Libs einzeln in den Lib Ordner wie früher. -->

<finalName>${project.name}</finalName>
<finalName>${project.name}</finalName>

<plugins>
<plugin>
Expand All@@ -125,4 +123,4 @@
</build>


</project>
</project>
40 changes: 40 additions & 0 deletions src/main/java/de/bigamgamen/java/helper/PaypalLinkGenerator.java
Original file line numberDiff line numberDiff line change
@@ -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&currency_code=EUR&amount=1&item_name=Knowledgebase%20Spende
* @author Bigmama
*
*/
public class PaypalLinkGenerator
{
public static String DEFAULT_CURRENCY = "EUR";
public static String CURRENCY_CODE = "&currency_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;
}

}
4 changes: 4 additions & 0 deletions src/main/java/de/bigamgamen/java/helper/Pricehelper.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -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);
}

}
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
Expand DownExpand Up@@ -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;
Expand DownExpand Up@@ -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 =
Expand All@@ -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";
Expand All@@ -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
{
Expand All@@ -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);
Expand All@@ -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();
}

Expand DownExpand Up@@ -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
Expand All@@ -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);
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,24 +29,29 @@ public TelegramKeyBoardBuilder(HertlBotRootDao hertlBotDao) {
public List<KeyboardRow> loadAndShowMyOrdersAsKeyBoard(final Long chatId, String userName) {
final List<KeyboardRow> 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;
}

public List<KeyboardRow> loadAndShowAllArticleForOrder(final Long chatId, final Integer bestellungId) {
final List<KeyboardRow> 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;
Expand All@@ -55,7 +60,7 @@ public List<KeyboardRow> loadAndShowAllArticleForOrder(final Long chatId, final
private void addButtonToKeyBoard(List<KeyboardRow> keyboard, String buttonString) {
KeyboardRow rowToUse = null;

for (KeyboardRow row : keyboard) {
for (final KeyboardRow row : keyboard) {
if (row.size() < MAX_BUTTON_PER_ROW) {
rowToUse = row;
}
Expand All@@ -72,19 +77,19 @@ private void addButtonToKeyBoard(List<KeyboardRow> 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<String> abilities) {
Expand Down
Loading