Skip to content

Commit 48eb109

Browse files
authored
Merge pull request #16 from AMeierDev/staging
deploy prod version
2 parents 33d7908 + a8bdaad commit 48eb109

File tree

11 files changed

+195
-61
lines changed

11 files changed

+195
-61
lines changed

.github/workflows/build_java.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Build_Java_Only
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the master branch
8+
push:
9+
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
15+
jobs:
16+
# This workflow contains a single job called "build"
17+
build:
18+
# The type of runner that the job will run on
19+
runs-on: ubuntu-latest
20+
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24+
- uses: actions/checkout@v2
25+
26+
- name: Set up JDK 11
27+
uses: actions/setup-java@v2
28+
with:
29+
java-version: '11'
30+
distribution: 'adopt'
31+
- name: Build with Maven
32+
run: mvn clean package

.github/workflows/build_java_docker.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# This is a basic workflow to help you get started with Actions
22

3-
name: CI
3+
name: Build Java BuildDepolyDocker Start Docker on Server
44

55
# Controls when the workflow will run
66
on:
77
# Triggers the workflow on push or pull request events but only for the master branch
88
push:
9-
pull_request:
109
branches:
1110
- main
1211
- staging

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ USER telegrambot
2020

2121
#CMD ["echo $UID"]
2222

23-
ENTRYPOINT ["sh" , "-c", "java -cp java.telegrambots.jar:./lib/* de.bigamgamen.java.telegrambots.hertlhendl.HertlHendlBot ${BOT_TOKEN}:${BOT_KEY} ${BOT_NAME} ${CREATOR_ID}"]
23+
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}"]

create_volume.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
docker volume create chatbotvol
2-
chown 1001:1001 /var/lib/docker/volumes/chatbotvol/_data
1+
docker volume create --opt type=none --opt o=bind --opt device=~/data/chatbotvol-develop --name chatbotvol-develop
2+
chown 1001:1001 ~/data/chatbotvol-develop

pom.xml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4-
xmlns="http://maven.apache.org/POM/4.0.0"
5-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<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">
63
<modelVersion>4.0.0</modelVersion>
74

85
<groupId>de.bigamgamen</groupId>
96
<artifactId>java.telegrambots</artifactId>
107
<version>0.9-FINAL</version>
11-
8+
129
<name>java.telegrambots</name>
1310

1411
<properties>
@@ -77,15 +74,15 @@
7774
<dependency>
7875
<groupId>org.apache.logging.log4j</groupId>
7976
<artifactId>log4j-api</artifactId>
80-
<version>2.15.0</version>
77+
<version>2.17.2</version>
8178
</dependency>
8279

8380
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
8481
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
8582
<dependency>
86-
<groupId>org.apache.logging.log4j</groupId>
87-
<artifactId>log4j-core</artifactId>
88-
<version>2.17.1</version>
83+
<groupId>org.apache.logging.log4j</groupId>
84+
<artifactId>log4j-core</artifactId>
85+
<version>2.17.2</version>
8986
</dependency>
9087

9188
<dependency>
@@ -96,9 +93,10 @@
9693
</dependency>
9794
</dependencies>
9895

99-
<build><!-- Kopiert alle Libs einzeln in den Lib Ordner wie früher. -->
96+
<build>
97+
<!-- Kopiert alle Libs einzeln in den Lib Ordner wie früher. -->
10098

101-
<finalName>${project.name}</finalName>
99+
<finalName>${project.name}</finalName>
102100

103101
<plugins>
104102
<plugin>
@@ -125,4 +123,4 @@
125123
</build>
126124

127125

128-
</project>
126+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package de.bigamgamen.java.helper;
2+
3+
import java.net.MalformedURLException;
4+
import java.net.URL;
5+
6+
import de.bigamgamen.java.telegrambots.hertlhendl.domain.HertlBotOrder;
7+
8+
/**
9+
* 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
10+
* @author Bigmama
11+
*
12+
*/
13+
public class PaypalLinkGenerator
14+
{
15+
public static String DEFAULT_CURRENCY = "EUR";
16+
public static String CURRENCY_CODE = "&currency_code=";
17+
18+
public static String BUSINESS = "&business="; // (Zahlungsempfänger) = PayPal E-Mail des Zahlungsempfängers
19+
public static String AMOUNT = "&amount="; // (Betrag) = 123.12 (Achtung, mit Punkt als Dezimaltrennzeichen)
20+
public static String ITEM_NAME = "&item_name="; // (Artikelname)
21+
public static String URL_START = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick";
22+
23+
public PaypalLinkGenerator()
24+
{
25+
26+
}
27+
28+
public URL generatePayPalLinkForOrder(final HertlBotOrder order, String adminEmail) throws MalformedURLException
29+
{
30+
final StringBuilder sb = new StringBuilder(URL_START);
31+
sb.append(BUSINESS).append(adminEmail);
32+
sb.append(AMOUNT).append(Pricehelper.getPriceAsDotString(order.getBigIntegerSumme()));
33+
sb.append(ITEM_NAME).append(order.getPayPalDescription());
34+
sb.append(CURRENCY_CODE).append(DEFAULT_CURRENCY);
35+
36+
final URL paylpalLink = new URL(sb.toString());
37+
return paylpalLink;
38+
}
39+
40+
}

src/main/java/de/bigamgamen/java/helper/Pricehelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ private Pricehelper() {
1111
public static String getPriceAsEuroString(BigInteger priceInCent) {
1212
return NumberFormat.getCurrencyInstance().format(priceInCent.doubleValue() / 100);
1313
}
14+
public static String getPriceAsDotString(BigInteger priceInCent) {
15+
return Double.toString(priceInCent.doubleValue() / 100);
16+
}
17+
1418
}

src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/HertlHendlBot.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.math.BigInteger;
27+
import java.net.MalformedURLException;
2728
import java.net.URISyntaxException;
2829
import java.net.URL;
2930
import java.util.ArrayList;
@@ -52,6 +53,7 @@
5253
import com.google.common.annotations.VisibleForTesting;
5354

5455
import de.bigamgamen.java.helper.IOHelper;
56+
import de.bigamgamen.java.helper.PaypalLinkGenerator;
5557
import de.bigamgamen.java.telegrambots.hertlhendl.api.RightController;
5658
import de.bigamgamen.java.telegrambots.hertlhendl.api.RoleController;
5759
import de.bigamgamen.java.telegrambots.hertlhendl.builder.TelegramKeyBoardBuilder;
@@ -84,6 +86,7 @@ public class HertlHendlBot extends AbilityBot
8486
public static final String ABILITY_NAME_ADMIN_CLOSE_ORDERS = "admincloseorders";
8587
public static final String ABILITY_NAME_CLOSE_ORDER = "closeorder";
8688
public static final String ABILITY_NAME_COMMIT_ORDER = "commitorder";
89+
public static final String ABILITY_NAME_PAYPAL_LINK = "paypallink";
8790

8891
private static final String MESSAGE_CLOSE_SUCCESSFULL = "Die Bestellung wurde erfolgreich geschlossen.";
8992
private static final String ALL_MESSAGE_CLOSE_SUCCESSFULL =
@@ -98,6 +101,7 @@ public class HertlHendlBot extends AbilityBot
98101
private final static String BOT_TOKEN = "";
99102
private final static String BOT_USERNAME = "";
100103
private final static String ADMIN_DEFAULT_NAME = "Admin";
104+
101105
private static Integer CREATOR_ID = 0;
102106
private static String HERTL_URL =
103107
"http://ks3266365.kimsufi.com:2341/?url=https://hertel-haehnchen.de/standplatzsuche?search=92637";
@@ -108,6 +112,10 @@ public class HertlHendlBot extends AbilityBot
108112
private final RoleController roleController;
109113
private final Long creatorId;
110114

115+
private String creatorPayPalEmail ="";
116+
private final PaypalLinkGenerator payPalGenerator = new PaypalLinkGenerator();
117+
118+
111119
public static void main(final String[] args)
112120
throws ParserConfigurationException, SAXException, IOException, URISyntaxException, TelegramApiException
113121
{
@@ -116,13 +124,14 @@ public static void main(final String[] args)
116124
final String token = args[0] != null ? args[0] : BOT_TOKEN;
117125
final String username = args[1] != null ? args[1] : BOT_USERNAME;
118126
final Long creatorId = args[2] != null ? Long.valueOf(args[2]) : CREATOR_ID;
119-
final HertlHendlBot bot = new HertlHendlBot(token, username, creatorId);
127+
final String creatorPayPalEmail = args[3] != null ? args[3] : "";
128+
final HertlHendlBot bot = new HertlHendlBot(token, username, creatorId, creatorPayPalEmail);
120129
final TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
121130
api.registerBot(bot);
122131
LOG.info("HertlHendlBot successfull started");
123132
}
124133

125-
public HertlHendlBot(final String botToken, final String botUsername, Long creatorId)
134+
public HertlHendlBot(final String botToken, final String botUsername, Long creatorId, String creatorPayPalEmail)
126135
throws ParserConfigurationException, SAXException, IOException, URISyntaxException
127136
{
128137
super(botToken, botUsername);
@@ -132,6 +141,7 @@ public HertlHendlBot(final String botToken, final String botUsername, Long creat
132141
this.rightController = new HertlRightController(creatorId);
133142
this.roleController = new HertlRoleController(this.rightController);
134143
this.creatorId = creatorId;
144+
this.creatorPayPalEmail = creatorPayPalEmail;
135145
this.initAdminUser();
136146
}
137147

@@ -515,6 +525,41 @@ public Ability showLocationPhoto()
515525
}).build();
516526
}
517527

528+
public Ability showPayPalLink()
529+
{
530+
return Ability.builder().name(ABILITY_NAME_PAYPAL_LINK).info("PaypalLink").locality(
531+
ALL).privacy(PUBLIC).input(1).action(context ->
532+
{
533+
//TOFDO nur mit Recht dazu
534+
535+
final int bestellId = Integer.parseInt(context.firstArg());
536+
final Long chatId = context.chatId();
537+
final HertlBotOrder bestellung = hertlBotDao.loadBestellung(
538+
chatId,
539+
TelegramHelper.getTotalUserName(context.user()),
540+
bestellId);
541+
//TODO logik for closed Order
542+
543+
final SendMessage message = new SendMessage();
544+
message.setChatId(Long.toString(context.chatId()));
545+
try
546+
{
547+
message.setText(this.payPalGenerator.generatePayPalLinkForOrder(bestellung, this.creatorPayPalEmail).toString());
548+
this.silent.execute(message);
549+
}
550+
catch(final MalformedURLException e)
551+
{
552+
e.printStackTrace();
553+
LOG.error("Fehler beim genieren PayPalLink:{}", e);
554+
}
555+
556+
557+
558+
559+
560+
}).build();
561+
}
562+
518563
private void sendPhotoFromUpload(final InputStream is, String fileName, final Long chatId)
519564
{
520565
final SendPhoto sendPhotoRequest = new SendPhoto(); // 1
@@ -534,7 +579,7 @@ private void sendPhotoFromUpload(final InputStream is, String fileName, final Lo
534579
}
535580
catch(final TelegramApiException e)
536581
{
537-
e.printStackTrace();
582+
LOG.error("Fehler beim schicken des Photos:{}", e);
538583
}
539584
}
540585

src/main/java/de/bigamgamen/java/telegrambots/hertlhendl/builder/TelegramKeyBoardBuilder.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,29 @@ public TelegramKeyBoardBuilder(HertlBotRootDao hertlBotDao) {
2929
public List<KeyboardRow> loadAndShowMyOrdersAsKeyBoard(final Long chatId, String userName) {
3030
final List<KeyboardRow> keyboard = new ArrayList<>();
3131

32-
hertlBotDao.loadUser(chatId,userName).getBestellungen()
33-
.forEach(bestellung -> addButtonToKeyBoard(keyboard, this.createOrderLink(bestellung)));
32+
this.hertlBotDao.loadUser(chatId,userName).getBestellungen()
33+
.forEach(bestellung -> this.addButtonToKeyBoard(keyboard, this.createOrderLink(bestellung)));
3434

3535
return keyboard;
3636
}
3737

3838
public List<KeyboardRow> loadAndShowAllArticleForOrder(final Long chatId, final Integer bestellungId) {
3939
final List<KeyboardRow> keyboard = new ArrayList<>();
4040

41-
hertlBotDao.root().artikels().all().forEach(
42-
artikel -> addButtonToKeyBoard(keyboard, createAddPositiontoOrderLink(artikel, bestellungId)));
41+
this.hertlBotDao.root().artikels().all().forEach(
42+
artikel -> this.addButtonToKeyBoard(keyboard, this.createAddPositiontoOrderLink(artikel, bestellungId)));
4343

4444
KeyboardRow row = new KeyboardRow();
45-
row.add(new KeyboardButton(createKeyForAbility(HertlHendlBot.ABILITY_NAME_COMMIT_ORDER+" "+bestellungId)));
45+
row.add(new KeyboardButton(this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_COMMIT_ORDER+" "+bestellungId)));
4646
keyboard.add(row);
4747

4848
row = new KeyboardRow();
49-
row.add(new KeyboardButton(createKeyForAbility(HertlHendlBot.ABILITY_NAME_CLOSE_ORDER+" "+bestellungId)));
49+
row.add(new KeyboardButton(this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_CLOSE_ORDER+" "+bestellungId)));
50+
keyboard.add(row);
51+
52+
//TODO erst wenn die order geliefert wurde.
53+
row = new KeyboardRow();
54+
row.add(new KeyboardButton(this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_PAYPAL_LINK+" "+bestellungId)));
5055
keyboard.add(row);
5156

5257
return keyboard;
@@ -55,7 +60,7 @@ public List<KeyboardRow> loadAndShowAllArticleForOrder(final Long chatId, final
5560
private void addButtonToKeyBoard(List<KeyboardRow> keyboard, String buttonString) {
5661
KeyboardRow rowToUse = null;
5762

58-
for (KeyboardRow row : keyboard) {
63+
for (final KeyboardRow row : keyboard) {
5964
if (row.size() < MAX_BUTTON_PER_ROW) {
6065
rowToUse = row;
6166
}
@@ -72,19 +77,19 @@ private void addButtonToKeyBoard(List<KeyboardRow> keyboard, String buttonString
7277

7378
public String createAndShowNewOrder(final Long chatId, String userName) {
7479

75-
final HertlBotOrder bestellung = hertlBotDao.createNewBestellungForUser(chatId, userName);
80+
final HertlBotOrder bestellung = this.hertlBotDao.createNewBestellungForUser(chatId, userName);
7681

7782
return this.createOrderLink(bestellung);
7883
}
7984

8085
public String createOrderLink(final HertlBotOrder bestellung) {
8186
return this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_ORDER) + " " + Integer.toString(bestellung.getIndex())
82-
+ System.lineSeparator();
87+
+ System.lineSeparator();
8388
}
8489

8590
public String createAddPositiontoOrderLink(final HertlBotArticle artikel, final Integer bestellungId) {
8691
return this.createKeyForAbility(HertlHendlBot.ABILITY_NAME_ADD_POSITION) + " " + artikel.getName() + " "
87-
+ bestellungId + System.lineSeparator();
92+
+ bestellungId + System.lineSeparator();
8893
}
8994

9095
public String createAbilityListForHelp(List<String> abilities) {

0 commit comments

Comments
 (0)