1- Copy via ssh the jar file to the Raspberry Pi:
1+ # Bite Board-Bot
2+
3+ > [ !TIP]
4+ > This project is a Java reimplementation of the
5+ > [ Bite Board Bot in TypeScript] ( https://github.com/YanWittmann/bite-board-bot ) , since the TypeScript version faced
6+ > installation issues on Raspberry Pi devices.
7+
8+ A Discord bot that allows for creating custom Menu Providers that can then fetch the menu for a specific day from a
9+ specific canteen or other food location.
10+
11+ <img alt =" Example Menu output " height =" 380 " src =" img/discord-bot-example-output-1.png " />
12+
13+ <!-- TOC -->
14+ * [ Bite Board-Bot] ( #bite-board-bot )
15+ * [ Installation] ( #installation )
16+ * [ Setup] ( #setup )
17+ * [ Configuration] ( #configuration )
18+ * [ token / clientId] ( #token--clientid )
19+ * [ dataStoragePath] ( #datastoragepath )
20+ * [ mensaMenuImagePreviewService] ( #mensamenuimagepreviewservice )
21+ * [ googleImageApiKey / googleImageApiApplicationId] ( #googleimageapikey--googleimageapiapplicationid )
22+ * [ language] ( #language )
23+ * [ Inviting the bot to your server] ( #inviting-the-bot-to-your-server )
24+ * [ Usage] ( #usage )
25+ * [ Commands: Fetching the menu] ( #commands-fetching-the-menu )
26+ * [ Commands: Providers] ( #commands-providers )
27+ * [ Commands: Scheduled Fetching] ( #commands-scheduled-fetching )
28+ * [ Creating a Menu Provider] ( #creating-a-menu-provider )
29+ * [ Raspberry Pi setup] ( #raspberry-pi-setup )
30+ <!-- TOC -->
31+
32+ ## Installation
33+
34+ Before being able to run the bot for the first time (` java -jar ... ` ), you need to configure the bot.
35+ See the [ Configuration] ( #configuration ) section for more information.
36+
37+ ``` batch
38+ git clone https://github.com/YanWittmann/bite-board-bot-java
39+ cd bite-board-bot-java
40+ mvn clean package
41+ java -jar target/bite-board-bot.jar
42+ ```
43+
44+ ## Setup
45+
46+ ### Configuration
47+
48+ For this, copy the
49+ [ bite-board-config-template.json] ( src/main/resources/bot/bite-board-bot-template.properties )
50+ file into a new file called
51+ [ bite-board-config.json] ( src/main/resources/bot/bite-board-bot.properties )
52+ and configure the values inside according to the following instructions.
53+
54+ If you need to change the path to the configuration file to somewhere outside the jar file, you can do so by setting a
55+ ` BITE_BOARD_CONFIG_PATH ` environment variable in your process.
56+
57+ Make sure to rerun ` mvn clean package ` after changing the configuration file.
58+
59+ #### token / clientId
60+
61+ The token is the bot token you get from the [ Discord Developer Portal] ( https://discord.com/developers/applications ) .
62+ For this, you will need to create a new application and a bot user for it.
63+ There are plenty of tutorials on how to do this on the internet already.
64+
65+ - The ` discordBotToken ` is the token of the bot, which you can find under the ** Bot** tab of your bot in the portal.
66+
67+ Unused:
68+
69+ - The ` discordClientId ` is the client ID of the bot, which you can find under the ** OAuth2** tab of your bot in the
70+ portal.
71+
72+ #### dataStoragePath
73+
74+ Is a path to a JSON file that will contain data the bot needs to store, such as user settings and periodic tasks.
75+ This file will be created if it does not exist yet.
76+ The default is a file ` bot-data.json ` in the current working directory.
77+
78+ #### mensaMenuImagePreviewService
79+
80+ This can be either ` none ` , ` googleApi ` or ` googleImages ` .
81+ Depending on the value, the bot will use a different service to fetch images for the menu embeds or not fetch any images
82+ at all.
83+
84+ - ` none ` : No images will be fetched.
85+ - ` googleApi ` : The Google Image API will be used to fetch images, see parameters below. Up to 100 images can be fetched
86+ per day for free, after that you will need to pay for the service.
87+ - ` googleImages ` : Google Images will be used to fetch images. This is free and the image quality is better than the API
88+ (in my opinion), although the resolution is (much) lower.
89+
90+ #### googleImageApiKey / googleImageApiApplicationId
91+
92+ The Google Image API key and application ID are used to fetch images for the menu embeds.
93+ You can get them from the [ Google Cloud Console] ( https://console.cloud.google.com/ ) .
94+ Configure ` googleApi ` for ` mensaMenuImagePreviewService ` to use the Google Image API.
95+
96+ > Honestly, this is not worth it. The images from the API are just so much worse that the ones from the Google Images
97+ > search. I recommend just using the Google Images search.
98+
99+ #### language
100+
101+ The language the bot should use for the menu embeds. Currently, ` en ` and ` de ` are supported.
102+ If you need to add your own language, you can do so by adding a new JSON file to the
103+ [ lang] ( src/main/resources/bot/lang )
104+ directory and putting its name in the [ LanguageManager.java] ( src/main/java/menu/service/LanguageManager.java ) file at
105+ the top into the list.
106+
107+ ### Inviting the bot to your server
108+
109+ To invite the bot to your server, you need to create an invitation link.
110+ You can do that on the ** OAuth2** tab of your bot in the
111+ [ Discord Developer Portal] ( https://discord.com/developers/applications ) as well.
112+ Make sure to allow the following permissions (at least):
113+
114+ ![ Invite the bot to your server] ( img/discord-bot-invitation.png )
115+
116+ ## Usage
117+
118+ This bot can fetch menus in two modes: triggered by a user command and scheduled periodic fetching.
119+
120+ ### Commands: Fetching the menu
121+
122+ The bot provides a ` /menu ` command that allows users to retrieve the menu for specific days or meals from supported menu
123+ providers.
124+ Use it, followed by a subcommand specifying the date for which you want to see the menu.
125+ Depending on your language, you may use your appropriate subcommands.
2126
3- ``` shell
4- C:
\U sers
\u ser
> scp
" I:\projects\bite-board-bot-java\target\bite-board-bot.jar" [email protected] :/home/yan/workspace/bite-board-bot/
5- 6- bite-board-bot.jar 100% 66KB 1.7MB/s 00:00
7127```
128+ /menu today | /menu heute
129+ /menu tomorrow | /menu morgen
130+ /menu monday | /menu montag
131+ /menu tuesday | /menu dienstag
132+ /menu wednesday | /menu mittwoch
133+ /menu thursday | /menu donnerstag
134+ /menu friday | /menu freitag
135+ ```
136+
137+ If configured, the bot will fetch images for relevant menu items and display them alongside the menu.
8138
9- Any java version >= 8 will work, for example on my Raspberry Pi:
139+ ### Commands: Providers
140+
141+ You may want to specify your preferred provider for the menu by using the ` /menu provider ` command with a ` provider `
142+ parameter.
143+
144+ To view all available providers, use the ` /menu listproviders ` command.
145+
146+ ### Commands: Scheduled Fetching
147+
148+ In addition to user-triggered commands, the bot also supports scheduled periodic fetching of menus from configured
149+ providers.
150+ This feature allows the bot to automatically post menu information at regular intervals, removing the need to manually
151+ request it each day.
152+
153+ To create a scheduled fetch, your user needs to have the ` periodic ` role.
154+ For security reasons, roles can only be changed by editing the ` bot-data.json ` file directly.
155+ In the ` users ` object, add a new key with your Discord tag (not ` id#number ` format or the ` userId ` ) and set the
156+ ` roles ` array to include ` periodic ` .
157+ You can easily create such an entry by executing the ` /menu provider ` command once on your user.
158+
159+ Then, run the following command in the Discord channel where you want the menu to be posted.
160+ Note that the ` time ` parameter is in UTC, meaning you will have to calculate based on your timezone.
161+ You can also use the ` /menu time ` command to get the current UTC time as reference.
162+ In order to be able to post the menu for the next day(s), you can set an ` add ` time in minutes that will add the given
163+ amount of minutes to the current time before determining the day for which to fetch the menu.
164+
165+ ```
166+ /menu schedule time:18:00:00 provider:Hochschule Mannheim add:1440
167+ ```
168+
169+ Your JSON bot data could look like this afterward:
170+
171+ ``` json
172+ {
173+ "sendDailyMenuInfo" : [{
174+ "addTime" : 1440 ,
175+ "provider" : " Hochschule Mannheim" ,
176+ "time" : " 18:00:00" ,
177+ "channelId" : " some-channel-id"
178+ }],
179+ "users" : [{
180+ "preferredMenuProvider" : " Hochschule Mannheim" ,
181+ "roles" : [" periodic" ],
182+ "userId" : " some-user-id"
183+ }]
184+ }
185+ ```
186+
187+ ## Creating a Menu Provider
188+
189+ To create a new menu provider, you need to create a new class that extends the
190+ [ MenuItemsProvider] ( src/main/java/menu/providers/MenuItemsProvider.java )
191+ class.
192+ See the
193+ [ HochschuleMannheimTagessichtMenuProvider] ( src/main/java/menu/providers/implementations/HochschuleMannheimTagessichtMenuProvider.java )
194+ for an example.
195+
196+ After finishing it, you need to register your provider in the
197+ [ BiteBoardBotEntrypoint] ( src/main/java/menu/bot/BiteBoardBotEntrypoint.java )
198+ file by passing an instance into
199+ the [ BiteBoardBot] ( src/main/java/menu/bot/BiteBoardBot.java ) constructor.
200+
201+ ## Raspberry Pi setup
202+
203+ Any java version >= 8 will work, this for example installed java 17:
10204
11205``` shell
12206sudo apt update
@@ -15,13 +209,19 @@ sudo apt install default-jdk
15209java -version
16210```
17211
18- Start the bot with:
212+ Copy via ssh the jar file to the Raspberry Pi after building it:
213+
214+ ``` shell
215+ C:
\U sers
\u ser
> scp
" I:\projects\bite-board-bot-java\target\bite-board-bot.jar" [email protected] :/home/user/workspace/bite-board-bot/
216+ 217+ bite-board-bot.jar 100% 66KB 1.7MB/s 00:00
218+ ```
219+
220+ Start the bot with to be able to access it later again:
19221
20222```shell
21223screen -S bite-board-bot -d -m java -jar bite-board-bot.jar
22224screen -r bite-board-bot
23225```
24226
25- https://askubuntu.com/a/124903
26-
27- Ctrl+a followed by d. Note the lower case.
227+ [To detach a screen session](https://askubuntu.com/a/124903): Ctrl+a followed by d. Note the lower case.
0 commit comments