-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from wsknorth/dev
0.1.2
- Loading branch information
Showing
16 changed files
with
435 additions
and
1,033 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ENV=development | ||
DEBUG=Midna:* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docs/Readme.md |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<h1 align="center"> | ||
<img width="200px" src="/docs/images/midna.png_large"/> | ||
<br/>midna | ||
</h1> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/standard/standard"><img src="https://img.shields.io/badge/Code_style-Standard-green.svg?style=for-the-badge" alt="Standard"></a> | ||
<a href="#"><img src="https://img.shields.io/badge/Version-0.1.2-blue.svg?style=for-the-badge" alt="Version"></a> | ||
<a href="https://t.me/midnabot"><img src="https://img.shields.io/badge/Telegram-midnabot-blue.svg?style=for-the-badge" alt="Telegram"></a> | ||
</p> | ||
|
||
<br/> | ||
|
||
## Sandbox - [gf3/sandbox](https://github.com/gf3/sandbox) | ||
|
||
Execute JavaScript code | ||
``` | ||
/sandbox ```console.log('Hello world')``` | ||
``` | ||
|
||
## Roll - [troygoode/node-roll](https://github.com/troygoode/node-roll) | ||
|
||
Roll dices | ||
``` | ||
/roll 2d10 | ||
``` | ||
|
||
## Development | ||
|
||
Clone the repository | ||
```bash | ||
$ git clone https://github.com/wsknorth/midna.git && cd midna | ||
``` | ||
|
||
Install dependencies | ||
```bash | ||
$ npm install | ||
``` | ||
|
||
Edit the configuration file | ||
```bash | ||
$ cp lib/configs/configs.sample.json lib/configs/configs.json | ||
$ vi lib/configs/configs.json | ||
``` | ||
|
||
Run | ||
```bash | ||
$ npm start | ||
``` | ||
|
||
## Production | ||
|
||
Copy `midna.service` in `/etc/systemd/system` | ||
```bash | ||
$ sudo cp midna.service /etc/systemd/system/midna.service | ||
``` | ||
|
||
Create midna user | ||
```bash | ||
$ sudo useradd -r -s /bin/bash -G midna midna | ||
``` | ||
|
||
Enable | ||
```bash | ||
$ sudo systemctl enable midna | ||
``` | ||
|
||
Start | ||
```bash | ||
$ sudo systemctl start midna | ||
``` | ||
|
||
Stop | ||
```bash | ||
$ sudo systemctl stop midna | ||
``` | ||
|
||
## Versioning | ||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/wsknorth/midna/tags). | ||
|
||
## Author | ||
Sabato Luca "[wsknorth](https://github.com/wsknorth)" Guadagno | ||
|
||
## License | ||
This project is licensed under the MIT License - see the [License](License.md) file for details |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const debug = require('debug')('Midna:about') | ||
|
||
const { name, version, author, homepage } = require('../../package.json') | ||
|
||
const about = () => (ctx) => { | ||
const username = ctx.update.message.from.username | ||
const text = ctx.update.message.text | ||
debug(`${username}: ${text}`) | ||
|
||
return ctx.replyWithMarkdown(`*${name} ${version}*\n${author}\n${homepage}`) | ||
} | ||
|
||
module.exports = { about } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
{ | ||
"development": { | ||
"username": "your bot username", | ||
"token": "your bot token" | ||
"username": "your bot username for development", | ||
"token": "your bot token for development" | ||
}, | ||
|
||
"production": { | ||
"username": "your bot username for production", | ||
"token": "your bot token for production", | ||
"webhook": "your webhook for production", | ||
"path": "your path for the webhook", | ||
"port": 3000, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('dotenv').load() | ||
|
||
const { telegraf } = require('./telegraf') | ||
|
||
telegraf.startPolling() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const Koa = require('koa') | ||
const body = require('koa-body') | ||
|
||
const { configs } = require('../configs') | ||
const { telegraf } = require('../telegraf') | ||
|
||
const application = new Koa() | ||
|
||
telegraf.telegram.setWebhook(configs.webhook) | ||
application.use(body()) | ||
application.use((ctx, next) => { | ||
return (ctx.method === 'POST' || ctx.url === configs.path) | ||
? telegraf.handleUpdate(ctx.request.body, ctx.response) | ||
: next() | ||
}) | ||
|
||
module.exports = { koa: application } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require('dotenv').load() | ||
|
||
const { koa } = require('./koa') | ||
const { configs } = require('./configs') | ||
|
||
koa.listen(configs.port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const Telegraf = require('telegraf') | ||
|
||
const { configs } = require('../configs') | ||
const { sandbox } = require('../sandbox') | ||
const { about } = require('../about') | ||
const { roll } = require('../roll') | ||
|
||
const bot = new Telegraf(configs.token, { username: configs.username }) | ||
|
||
bot.command('sandbox', sandbox()) | ||
bot.command('about', about()) | ||
bot.command('roll', roll()) | ||
|
||
module.exports = { telegraf: bot } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Service] | ||
ExecStart=/usr/bin/node /var/www/midna/lib/production.js | ||
Restart=always | ||
StandardOutput=syslog | ||
StandardError=syslog | ||
SyslogIdentifier=midna | ||
User=midna | ||
Group=midna | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Oops, something went wrong.