Skip to content

Commit

Permalink
Merge branch 'test-branch' of https://github.com/ZyC0R3/Rita into tes…
Browse files Browse the repository at this point in the history
…t-branch
  • Loading branch information
JShep89 committed Sep 8, 2019
2 parents 70d8958 + 3783a08 commit 5ea9a7f
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 364 deletions.
99 changes: 99 additions & 0 deletions .pi/translate_bot
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: translate_bot
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 5
# Default-Stop: 0 1 2 3 4 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO

dir="/home/pi/Rita"
cmd="npm run-script start"
user="pi"

name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"

get_pid() {
cat "$pid_file"
}

is_running() {
[ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>&1
}

case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in 1 2 3 4 5 6 7 8 9 10
# for i in `seq 10`
do
if ! is_running; then
break
fi

echo -n "."
sleep 1
done
echo

if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit 0
8 changes: 8 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}
100 changes: 88 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
## RITA (beta)
Translation bot built using `discord.js` and `Google Translate API`.

![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/ZyC0R3/Rita/1.1.6?label=Stable%20Version&style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/ZyC0R3/Rita.svg?style=plastic)
![GitHub](https://img.shields.io/github/license/ZyC0R3/Rita.svg?style=plastic)
![GitHub issues](https://img.shields.io/github/issues-raw/ZyC0R3/Rita.svg?style=plastic)
[![invite](https://img.shields.io/badge/Discord_Support-JOIN-7289DA.svg?style=plastic&)](https://discordapp.com/invite/mgNR64R)
![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/ZyC0R3/Rita/1.1.6?label=Stable%20Version)
[![codebeat badge](https://codebeat.co/badges/a26b41c5-771e-4452-8a60-1947b0ed302c)](https://codebeat.co/projects/github-com-zyc0r3-rita-1-1-6)
![GitHub last commit](https://img.shields.io/github/last-commit/ZyC0R3/Rita.svg)
![GitHub](https://img.shields.io/github/license/ZyC0R3/Rita.svg)
![GitHub issues](https://img.shields.io/github/issues-raw/ZyC0R3/Rita.svg)
[![invite](https://img.shields.io/badge/Discord_Support-JOIN-7289DA.svg?)](https://discordapp.com/invite/mgNR64R)


#### Current Test Branch
![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/ZyC0R3/Rita/test-branch?label=Test%20Version&style=plastic)
![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/ZyC0R3/Rita/test-branch?label=Test%20Version)

## Coming Soon!

01. Error Message Support Section.
02. Auto Reverse transaltion for the auto function.
03. `!t tasks #TargetChannel` Implementation
03. `!t tasks #TargetChannel` Implementation.
04. Setup on a Raspberry Pi Section.
05. gulp-watch updated dependancies.
06. Patch for Chinese language support.
07. Various Security vulnerabilites fixed.
08. Various commands re-activated.
09. Introduction of a Streamlined Command Handler. (This will be done as a New Project)

## New in 1.1.6
* Updated ReadMe with Local Installation Support Section.
Expand All @@ -34,11 +41,12 @@ Translation bot built using `discord.js` and `Google Translate API`.
05. [C-3PO to RITA Bot Migration (EXPERIMENTAL)](#migration)
06. [Heroku Database Support](#database)
07. [Local Installation Support](#local)
08. [Troubleshooting](#troubleshooting)
09. [Error Messages](#errors)
10. [Commands](#commands)
11. [Credits & License](#credits-&-license)
12. [Design Team](#design-team)
08. [Setup on a Raspberry Pi](#pi)
09. [Troubleshooting](#troubleshooting)
10. [Error Messages](#errors)
11. [Commands](#commands)
12. [Credits & License](#credits-&-license)
13. [Design Team](#design-team)

## <a name="features"></a>Features
* Translate custom messages
Expand Down Expand Up @@ -160,6 +168,74 @@ Run `npm install -g gulp` in your console to install gulp. Build the bot code
#### 5. Invite your bot to your server and configure it!
Return to step 4 in [Setting up a New Bot](#new-bot).

## <a name="pi"></a>Setup on a Raspberry Pi
We recommend to initially run your bot in a local environment on your laptop before you run the translator on a Raspberry Pi. The local setup allows you to get familiar with the setup and the settings.

The following description allows a headless configuration. Only a network connection is required. This description is explicitely for running the bot on a Raspberry Pi 4, but the setup should be similar for earlier version.

Recommendation: run it locally first before putting the code on pi. Easier to ensure that .env variabels are setup correctly.

#### 1. Write Raspbian on your SD card
Download the minimal image of Raspbian (https://www.raspberrypi.org/downloads/raspbian/). This setup is based on Raspbian Buster Lite, July 2019.

Use balenaEtcher(https://www.balena.io/etcher/) to write the image on your SD card.

For more Information: See https://www.raspberrypi.org/documentation/installation/installing-images/README.md

#### 2. Enable SSH
Enable SSH by placing a file named “ssh” (without any extension) onto the boot partition of the SD card.

#### 3. Start and Login
* Pop your prepared SD card, power and a network cable into the Pi.
* Find your Pi's IP Adrdress. Check your Router's DHCP allocation table or use a mobile app like Fing (https://play.google.com/store/apps/details?id=com.overlook.android.fing) to find the IP of Pi.
* Install WinSCP and Putty on your Laptop.
* Start Putty and login into your Pi. Username: pi, PW: raspberry. Change your password with 'passwd'.

#### 4. Initial Setup
* Type `raspi-config` and change your locales
* Update the package lists from repositories: `sudo apt-get update`
* Update your repositories: `sudo apt-get dist-upgrade`

#### 5. Install node and npm
The fastes way to install the current node and npm versions (https://nodejs.org/en/download/) was to follow the description from nodesource (https://github.com/nodesource/distributions/blob/master/README.md):
* Get the source: `curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -`
* Install: `sudo apt-get install -y nodejs`
* Check version: `node -v` and `npm -v`

#### 6. Get the code
It is recommend to install git and pull from your fork or main:
* Install git: `sudo apt-get install git`
* Create the folder for the source: `mkdir Rita`
* Clone the repository: `git clone https://github.com/ZyC0R3/Rita.git`
* Checkout the branch you need: `git checkout --track origin/1.1.7`

Alternative: move the source code with WinSCP from your local environment to the Pi.

#### 7. Install the database
Install sqlite3 with `sudo apt-get install sqlite3`.

Create an empty database file (`sqlite3 database.db`)and call `.tables`)

#### 8. Copy your .env
Use WinSCP to copy your .env file from your local environment to the Pi.

#### 9. Run the code
* Install gulp is installed: `sudo npm install -g gulp` (not sure if still necessary)
* Make sure you are in the Rita folder
* Get and install all packages of RITA: `npm install`
* Build the code: `npm run-script build`
* Start the bot: `npm run-script start`

#### 10. Autostart
There are different ways to make the bot initialize at startup. The following description is based on `init.d` and `update-rc.d`:
* Create a `init.d` script: Edit the script template in `.pi/translate_bot` if necessary and copy it to the folder `/etc/init.d/` with `sudo mv .pi/translate_bot /etc/init.d/.`
* Make the file executable: `sudo chmod +x /etc/init.d/translate_bot`
* Update the system script links: `sudo update-rc.d translate_bot defaults`
* Now, you can interact with the bot service with commands `sudo service translate_bot start`, `sudo service translate_bot status` and `sudo service translate_bot stop`
* The logging will be in `/var/log/translate_bot.err` and `/var/log/translate_bot.log`
* Reboot and hope everything is running smooth: `sudo reboot`
* Enjoy (or return to step 4 in [Setting up a New Bot](#new-bot) if you haven't done yet)

## <a name="troubleshooting"></a>Troubleshooting
* You can set up debugging Webhooks using the following steps
1. Create a new channel on your server to receive the Webhooks, let's say `#Webhooks`.
Expand Down
5 changes: 5 additions & 0 deletions issue_label_bot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
label-alias:
bug: 'Bug'
feature_request: 'Enhancement'
question: 'Question'

Loading

0 comments on commit 5ea9a7f

Please sign in to comment.