init
This commit is contained in:
commit
a0429d2883
5
config.json
Normal file
5
config.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"discord": {
|
||||||
|
"token": "vide il faut insérer votre token ici"
|
||||||
|
}
|
||||||
|
}
|
1512
package-lock.json
generated
Normal file
1512
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
package.json
Normal file
15
package.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"main": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "ts-node src/index.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"discord.js": "^12.5.3",
|
||||||
|
"gestion-listener": "file:../gestion-listener"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tsconfig/node10": "^1.0.7",
|
||||||
|
"@types/node": "^14.14.37",
|
||||||
|
"typescript": "^4.2.4"
|
||||||
|
}
|
||||||
|
}
|
BIN
save/722815725474938890
Normal file
BIN
save/722815725474938890
Normal file
Binary file not shown.
BIN
save/824967889626988584
Normal file
BIN
save/824967889626988584
Normal file
Binary file not shown.
15
save/prop.json
Normal file
15
save/prop.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"address":"https://feeds.leparisien.fr/leparisien/rss",
|
||||||
|
"timeloop": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"https://www.ledauphine.com/rss",
|
||||||
|
"timeloop": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address":"https://tomuss.univ-lyon1.fr/S/2021/Printemps/rss/dcd1262cd88a3c2",
|
||||||
|
"timeloop": 30
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
BIN
save/tmp.db
Normal file
BIN
save/tmp.db
Normal file
Binary file not shown.
99
src/index.ts
Normal file
99
src/index.ts
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
import { ManageListener } from "gestion-listener"
|
||||||
|
import { Client, DMChannel, Message, NewsChannel, TextChannel } from "discord.js"
|
||||||
|
|
||||||
|
import {show} from "./show"
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
import { openSync } from "fs"
|
||||||
|
|
||||||
|
const config: {'discord': {'token': string}} = require('../config.json')
|
||||||
|
|
||||||
|
// setup Discord
|
||||||
|
const monClient = new Client();
|
||||||
|
let channel_on: Array<TextChannel | NewsChannel | DMChannel> = [];
|
||||||
|
|
||||||
|
// setup gestion listener
|
||||||
|
let mesMl: {ml: ManageListener, channel: TextChannel | NewsChannel | DMChannel}[] = [];
|
||||||
|
// const ml = new ManageListener(path.join(__dirname, '../save/tmp.db'));
|
||||||
|
|
||||||
|
const fun_rss = async (message: Message, args: string[], ml: ManageListener) : Promise<void> => {
|
||||||
|
switch(args[0]) {
|
||||||
|
case 'start':
|
||||||
|
channel_on.push(message.channel);
|
||||||
|
await ml.startAll();
|
||||||
|
console.log(`Demarrage du service sur ${message.channel.toString()}`);
|
||||||
|
message.channel.send('Le feed va bientôt apparaitre 😉');
|
||||||
|
break;
|
||||||
|
case 'stop':
|
||||||
|
channel_on.splice(channel_on.indexOf(message.channel));
|
||||||
|
await ml.stopAll();
|
||||||
|
console.log(`Arret du service sur #${message.channel.toString()}`);
|
||||||
|
message.channel.send('Le feed a bien été retiré 🤐');
|
||||||
|
break;
|
||||||
|
case 'add':
|
||||||
|
if(args[1]) {
|
||||||
|
ml.registerListener({
|
||||||
|
address: args[1]
|
||||||
|
});
|
||||||
|
message.channel.send(`Ajout du service correspondant au lien : ${args[1]} 👌`);
|
||||||
|
}
|
||||||
|
else message.channel.send(`L'argument doit etre un lien vers un flux rss valide`)
|
||||||
|
break;
|
||||||
|
case 'help':
|
||||||
|
default:
|
||||||
|
// console.log(show.show_rss_help());
|
||||||
|
message.channel.send(show.show_rss_help());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const init_ml = async (message: Message) : Promise<ManageListener> => {
|
||||||
|
const new_path = path.join(__dirname, `../save/${message.channel.id}`);
|
||||||
|
openSync(new_path, 'w');
|
||||||
|
const new_ml = new ManageListener(new_path);
|
||||||
|
mesMl.push({
|
||||||
|
ml: new_ml,
|
||||||
|
channel: message.channel
|
||||||
|
});
|
||||||
|
|
||||||
|
new_ml.on("newEntries", async (obj) => {
|
||||||
|
if (obj) {
|
||||||
|
obj.map((item: any) => `${item.link}\n\t${item.title} :: Le ${(new Date()).toLocaleTimeString()}\n`)
|
||||||
|
.forEach((item: string) => {
|
||||||
|
// console.log(`${item}\n`);
|
||||||
|
message.channel.send(`${item}\n`);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
await new_ml.save();
|
||||||
|
});
|
||||||
|
|
||||||
|
await new_ml.load();
|
||||||
|
|
||||||
|
return new_ml;
|
||||||
|
}
|
||||||
|
|
||||||
|
monClient.on('message', async (message) => {
|
||||||
|
const splited_message = message.content.split(' ');
|
||||||
|
if(splited_message[0] === "C2") {
|
||||||
|
const index_ml = mesMl.map(i => i.channel).indexOf(message.channel);
|
||||||
|
let ml: ManageListener;
|
||||||
|
if(!mesMl.map(i => i.channel).includes(message.channel))
|
||||||
|
ml = await init_ml(message);
|
||||||
|
else
|
||||||
|
ml = mesMl[index_ml].ml;
|
||||||
|
switch(splited_message[1]) {
|
||||||
|
case 'rss':
|
||||||
|
await fun_rss(message, splited_message.slice(2), ml);
|
||||||
|
break;
|
||||||
|
case 'help':
|
||||||
|
default:
|
||||||
|
// console.log(show.show_help());
|
||||||
|
message.channel.send(show.show_help())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
monClient.login(config.discord.token);
|
||||||
|
|
||||||
|
console.log("Let's goooo");
|
26
src/show.ts
Normal file
26
src/show.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
const BOT_KEYWORD = 'C2';
|
||||||
|
|
||||||
|
export namespace show {
|
||||||
|
export function show_help(): string {
|
||||||
|
return `Voici la version 0.0.1 du script d'execution de skeptiCOM. Il prend en charge la version actuel du projet, c'est à dire un bot discord intéragissant avec des flux RSS et renvoyant periodiquement les nouvelles mises à jours de ce dernier.
|
||||||
|
|
||||||
|
Pour utiliser le bot il faut appeller le mot clé "${BOT_KEYWORD}" suivie de l'action a réaliser
|
||||||
|
|
||||||
|
Les actions réalisables sont les suivantes:
|
||||||
|
\`\`\`
|
||||||
|
- rss - permet de gerer les flux rss
|
||||||
|
- help - permet d'afficher ce message
|
||||||
|
\`\`\``
|
||||||
|
}
|
||||||
|
export function show_rss_help(): string {
|
||||||
|
return `Voici la version 0.0.1 du script d'execution de skeptiCOM. Il prend en charge la version actuel du projet, c'est à dire un bot discord intéragissant avec des flux RSS et renvoyant periodiquement les nouvelles mises à jours de ce dernier.
|
||||||
|
|
||||||
|
Les actions combinable avec le service rss sont :
|
||||||
|
\`\`\`
|
||||||
|
- start - permet de démarrer la lecture de flux dans le channel courant
|
||||||
|
- stop - permet d'arreter le flux dans ce channel
|
||||||
|
- add <url vers un flux rss valide> - permet d'ajouter un flux à la liste des flux suivies
|
||||||
|
- help - permet d'afficher ce message
|
||||||
|
\`\`\``
|
||||||
|
}
|
||||||
|
}
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"extends": "@tsconfig/node10/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "build"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user