💄 some improvements

This commit is contained in:
Adrian Amaglio 2020-04-02 18:01:29 +02:00
parent ec79a69eab
commit a72a1dbaeb
3 changed files with 19 additions and 2 deletions

View File

@ -10,6 +10,7 @@
<main id="educbot-status">
<p v-if="connection">Connecté !</p>
<p v-else="">Non connecté !</p>
<p>{{message}}</p>
<ul>
<li v-for="(value, key) in reactions">
<!--<img src="https://discordapp.com/assets/08c0a077780263f3df97613e58e71744.svg" width="30px" />

View File

@ -2,6 +2,9 @@
require('dotenv').config();
const fs = require('fs');
/* Catch evry unhandled promise rejection */
process.on('unhandledRejection', error => console.error('Uncaught Promise Rejection', error));
/* Deep clone of objects */
const clonedeep = require('lodash.clonedeep')
@ -147,9 +150,14 @@ const client = new Discord.Client();
client.on('ready', () => {
console.log('Connected to Discord as ' + client.user.tag);
client.user.setAvatar('avatar.png')
client.user.setUsername('Educ-Bot')
});
/* Discord message center */
client.on('message', msg => {
//TODO
//const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`);
//if (!prefixRegex.test(message.content)) return;
if (msg.content === '!educpop-enable') {
if (msg.channel.id in channels) {
msg.reply('Jécoute déjà ce canal texte.')

12
main.js
View File

@ -8,6 +8,7 @@ window.onload = function () {
ws_url: 'ws://localhost:8080',
reactions: {},
connection: false,
message: '',
},
created: function () {
var url = new URL(location.href)
@ -19,8 +20,15 @@ window.onload = function () {
}
this.ws = new WebSocket(this.ws_url)
this.ws.onmessage = (data) => {
this.reactions = JSON.parse(data.data)
console.log(this.reactions)
var reactions = JSON.parse(data.data)
if ('error' in reactions) {
this.message = 'Erreur ! '
if (reactions.error === "bad channel") {
this.message += 'Les identifiants sont incorrect ! Redemandez les à Educ-Bot avec la commande "!educpop-web"'
}
return
}
this.reactions = reactions
}
this.ws.onopen = () => {
this.sendWs('init')