Compare commits
2 Commits
c759779135
...
965ab54f20
Author | SHA1 | Date | |
---|---|---|---|
|
965ab54f20 | ||
|
9939d027b9 |
@ -1,11 +1,11 @@
|
|||||||
from node:alpine3.10
|
from node:13
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
COPY index.js avatar.jpg
|
COPY index.js defaultReactions.json avatar.png ./
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD [ "node", "index.js" ]
|
CMD [ "node", "./index.js" ]
|
||||||
|
4
build.sh
Normal file
4
build.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
echo "Ce script ne s’exécute pas, il est là à titre d’exemple"
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
docker build . -t jeancloud/educbot:latest -t jeancloud/educbot:1.0.0 -t jeancloud/educbot:1.0
|
@ -30,5 +30,9 @@
|
|||||||
"dab": {
|
"dab": {
|
||||||
"prefix": ":dab:",
|
"prefix": ":dab:",
|
||||||
"description": "Dab"
|
"description": "Dab"
|
||||||
|
},
|
||||||
|
"fuck": {
|
||||||
|
"prefix": "🖕",
|
||||||
|
"description": "Je vous emmerde!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,15 @@
|
|||||||
<link rel="stylesheet" href="main.css" />
|
<link rel="stylesheet" href="main.css" />
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
|
<title>Éduc-Bot, le bot d’éduc-pop</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main id="educbot-status">
|
<main id="educbotstatus">
|
||||||
<p v-if="connection">Connecté !</p>
|
<p v-if="connection">Connecté !</p>
|
||||||
<p v-else="">Non connecté !</p>
|
<p v-else="">Non connecté !</p>
|
||||||
<p>{{message}}</p>
|
<p>{{message}}</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li v-for="(value, key) in reactions">
|
<li v-for="(value, key) in reactions">
|
||||||
<!--<img src="https://discordapp.com/assets/08c0a077780263f3df97613e58e71744.svg" width="30px" />
|
|
||||||
-->
|
|
||||||
{{value.prefix}}
|
{{value.prefix}}
|
||||||
<span v-for="person in value.people">{{person}}</span>
|
<span v-for="person in value.people">{{person}}</span>
|
||||||
</li>
|
</li>
|
||||||
|
18
index.js
18
index.js
@ -17,12 +17,19 @@ const defaultReactions = JSON.parse(fs.readFileSync('defaultReactions.json', 'ut
|
|||||||
|
|
||||||
/* The html page will render data passed in WS */
|
/* The html page will render data passed in WS */
|
||||||
const WebSocket = require('ws')
|
const WebSocket = require('ws')
|
||||||
const wss = new WebSocket.Server({ port: process.env.WS_PORT })
|
const wss = new WebSocket.Server({ port: process.env.WS_PORT || '8080' })
|
||||||
wss.on('connection', ws => {
|
wss.on('connection', ws => {
|
||||||
ws.isAlive = true;
|
ws.isAlive = true;
|
||||||
ws.on('pong', heartbeat);
|
ws.on('pong', heartbeat);
|
||||||
ws.on('message', message => {
|
ws.on('message', message => {
|
||||||
const data = JSON.parse(message)
|
var data;
|
||||||
|
try {
|
||||||
|
data = JSON.parse(message)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!('channel' in data && 'action' in data && 'web_token' in data)) {
|
if (!('channel' in data && 'action' in data && 'web_token' in data)) {
|
||||||
ws.send('{"error":"invalid request"}')
|
ws.send('{"error":"invalid request"}')
|
||||||
return
|
return
|
||||||
@ -199,7 +206,7 @@ client.on('message', msg => {
|
|||||||
msg.reply(text)
|
msg.reply(text)
|
||||||
}
|
}
|
||||||
else if (msg.content === '!educpop-web') {
|
else if (msg.content === '!educpop-web') {
|
||||||
msg.reply('https://educbot.jean-cloud.net?channel_id=' + msg.channel.id + '&web_token=' + channel.web_token)
|
msg.reply('https://educbot.jean-cloud.net?channel_id=' + msg.channel.id + '&web_token=' + channel.web_token + '&ws_port=' + (process.env.EXT_WS_PORT || process.env.WS_PORT || '8080'))
|
||||||
}
|
}
|
||||||
/* save and ignore own messages */
|
/* save and ignore own messages */
|
||||||
else if(msg.author.username === process.env.BOT_USERNAME){
|
else if(msg.author.username === process.env.BOT_USERNAME){
|
||||||
@ -210,14 +217,15 @@ client.on('message', msg => {
|
|||||||
else if(msg.content.startsWith('-')) {
|
else if(msg.content.startsWith('-')) {
|
||||||
const content = msg.content.slice(1)
|
const content = msg.content.slice(1)
|
||||||
if (content.toLowerCase() in reactions) {
|
if (content.toLowerCase() in reactions) {
|
||||||
educpopDelPerson(channel, msg.member.nickname, content.toLowerCase())
|
//TODO est-ce qu’un nickname vide aura la valeur username ?
|
||||||
|
educpopDelPerson(channel, msg.member.nickname || msg.member.username, content.toLowerCase())
|
||||||
msg.delete()
|
msg.delete()
|
||||||
reply(channel)
|
reply(channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (msg.content.toLowerCase() in reactions) {
|
else if (msg.content.toLowerCase() in reactions) {
|
||||||
var reaction = msg.content.toLowerCase()
|
var reaction = msg.content.toLowerCase()
|
||||||
educpopAddPerson(channel, msg.member.nickname, msg.content.toLowerCase())
|
educpopAddPerson(channel, msg.author.nickname || msg.author.username, msg.content.toLowerCase())
|
||||||
msg.delete()
|
msg.delete()
|
||||||
reply(channel)
|
reply(channel)
|
||||||
}
|
}
|
||||||
|
16
main.js
16
main.js
@ -1,11 +1,11 @@
|
|||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
var app = new Vue({
|
var app = new Vue({
|
||||||
el: '#educbot-status',
|
el: '#educbotstatus',
|
||||||
data: {
|
data: {
|
||||||
web_token: '',
|
web_token: '',
|
||||||
channel_id: '',
|
channel_id: '',
|
||||||
ws: null,
|
ws: null,
|
||||||
ws_url: 'ws://localhost:8080',
|
ws_url: 'wss://educbot.jean-cloud.net',
|
||||||
reactions: {},
|
reactions: {},
|
||||||
connection: false,
|
connection: false,
|
||||||
message: '',
|
message: '',
|
||||||
@ -14,17 +14,19 @@ window.onload = function () {
|
|||||||
var url = new URL(location.href)
|
var url = new URL(location.href)
|
||||||
this.web_token = url.searchParams.get('web_token')
|
this.web_token = url.searchParams.get('web_token')
|
||||||
this.channel_id = url.searchParams.get('channel_id')
|
this.channel_id = url.searchParams.get('channel_id')
|
||||||
if (this.web_token == '' || this.channel_id == '') {
|
this.ws_port = url.searchParams.get('ws_port') || '8080'
|
||||||
console.err('missing parameters to vue instance')
|
if (this.web_token == '' || this.channel_id == '' || this.ws_port == '') {
|
||||||
|
this.message = 'Erreur ! L’adresse n’est pas valide :( Redemandez-la à Educ-Bot avec la commande « !educpop-web ».'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.ws = new WebSocket(this.ws_url)
|
window.WebSocket = window.WebSocket || window.MozWebSocket
|
||||||
|
this.ws = new WebSocket(this.ws_url + ':' + this.ws_port)
|
||||||
this.ws.onmessage = (data) => {
|
this.ws.onmessage = (data) => {
|
||||||
var reactions = JSON.parse(data.data)
|
var reactions = JSON.parse(data.data)
|
||||||
if ('error' in reactions) {
|
if ('error' in reactions) {
|
||||||
this.message = 'Erreur ! '
|
this.message = 'Erreur ! '
|
||||||
if (reactions.error === "bad channel") {
|
if (reactions.error === "bad channel") {
|
||||||
this.message += 'Les identifiants sont incorrect ! Redemandez les à Educ-Bot avec la commande "!educpop-web"'
|
this.message += 'Les identifiants sont incorrect ! Redemandez les à Educ-Bot avec la commande « !educpop-web ».'
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -36,9 +38,11 @@ window.onload = function () {
|
|||||||
}
|
}
|
||||||
this.ws.onclose = () => {
|
this.ws.onclose = () => {
|
||||||
this.connection = false
|
this.connection = false
|
||||||
|
this.message = 'Erreur ! La connection avec le bot a été perdue :( Essayez d’actualiser la page.'
|
||||||
}
|
}
|
||||||
this.ws.onerror = () => {
|
this.ws.onerror = () => {
|
||||||
this.connection = false
|
this.connection = false
|
||||||
|
this.message = 'Erreur ! La connection avec le bot a été perdue :( Essayez d’actualiser la page.'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^12.1.1"
|
"discord.js": "^12.1.1",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
|
"lodash.clonedeep": "^4.5.0",
|
||||||
|
"randomstring": "^1.1.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user