[mirotalksfu] - add Discord bot, update dep

هذا الالتزام موجود في:
Miroslav Pejic
2024-10-24 22:37:09 +02:00
الأصل f58b0f3a2d
التزام fad947d25e
7 ملفات معدلة مع 112 إضافات و6 حذوفات

عرض الملف

@@ -79,6 +79,7 @@
- Right-click options on video elements for additional controls.
- Supports [REST API](app/api/README.md) (Application Programming Interface).
- Integration with [Slack](https://api.slack.com/apps/) for enhanced communication.
- Integration with [Discord](https://discord.com) for enhanced communication.
- Utilizes [Sentry](https://sentry.io/) for error reporting.
- And much more...

73
app/src/Discord.js Normal file
عرض الملف

@@ -0,0 +1,73 @@
'use strict';
const { Client, GatewayIntentBits } = require('discord.js');
const Logger = require('./Logger');
const log = new Logger('Discord');
// Discord Bot Class Implementation
class Discord {
constructor(token, commands) {
this.token = token;
this.commands = commands;
this.discordClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent, // Make sure this is enabled in your Discord Developer Portal
],
});
this.setupEventHandlers();
this.discordClient.login(this.token).catch((error) => {
log.error('Failed to login to Discord:', error);
});
}
setupEventHandlers() {
this.discordClient.once('ready', () => {
log.info(`Discord Bot Logged in as ${this.discordClient.user.tag}!`, '😎');
});
this.discordClient.on('error', (error) => {
log.error(`Discord Client Error: ${error.message}`, { stack: error.stack });
});
this.discordClient.on('messageCreate', async (message) => {
if (message.author.bot) return;
for (const command of this.commands) {
if (message.content.startsWith(command.name)) {
switch (command.name) {
case '/sfu':
const roomId = this.generateMeetingRoom(command.baseUrl);
await this.sendMessage(message.channel, `${command.message} ${roomId}`);
break;
//....
default:
await this.sendMessage(message.channel, command.message);
break;
}
break; // Exit the loop after finding the command
}
}
});
}
generateMeetingRoom(baseUrl) {
const roomId = Math.random().toString(36).substring(2, 10);
return `${baseUrl}${roomId}`;
}
async sendMessage(channel, content) {
try {
await channel.send(content);
} catch (error) {
log.error(`Failed to send message: ${error.message}`);
}
}
}
module.exports = Discord;

عرض الملف

@@ -55,7 +55,7 @@ dev dependencies: {
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.99
* @version 1.6.00
*
*/
@@ -86,6 +86,7 @@ const yaml = require('js-yaml');
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = yaml.load(fs.readFileSync(path.join(__dirname, '/../api/swagger.yaml'), 'utf8'));
const Sentry = require('@sentry/node');
const Discord = require('./Discord.js');
const restrictAccessByIP = require('./middleware/IpWhitelist.js');
const packageJson = require('../../package.json');
@@ -180,6 +181,14 @@ if (sentryEnabled) {
*/
}
// Discord Bot
const { enabled, commands, token } = config.discord || {};
if (enabled && commands.length > 0 && token) {
const discordBot = new Discord(token, commands);
log.info('Discord bot is enabled and starting');
}
// Stats
const defaultStats = {
enabled: true,

عرض الملف

@@ -284,6 +284,28 @@ module.exports = {
enabled: false,
signingSecret: '',
},
discord: {
/*
Discord
1. Go to the Discord Developer Portal: https://discord.com/developers/.
2. Create a new application and name it whatever you like.
3. Under the Bot section, click Add Bot and confirm.
4. Copy your bot token (this will be used later).
5. Under OAuth2 -> URL Generator, select bot scope, and under Bot Permissions, select the permissions you need (e.g., Send Messages and Read Messages).
6. Copy the generated invite URL, open it in a browser, and invite the bot to your Discord server.
7. Add the Bot in the Server channel permissions
8. Type /sfu (commands.name) in the channel, the response will return a URL for the meeting
*/
enabled: false,
token: '',
commands: [
{
name: '/sfu',
message: 'Here is your SFU meeting room:',
baseUrl: 'https://sfu.mirotalk.com/join/',
},
],
},
IPLookup: {
/*
GeoJS

عرض الملف

@@ -1,6 +1,6 @@
{
"name": "mirotalksfu",
"version": "1.5.99",
"version": "1.6.00",
"description": "WebRTC SFU browser-based video calls",
"main": "Server.js",
"scripts": {
@@ -64,6 +64,7 @@
"compression": "1.7.4",
"cors": "2.8.5",
"crypto-js": "4.2.0",
"discord.js": "^14.16.3",
"dompurify": "^3.1.7",
"express": "4.21.1",
"express-openid-connect": "^2.17.1",

عرض الملف

@@ -11,7 +11,7 @@ if (location.href.substr(0, 5) !== 'https') location.href = 'https' + location.h
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.99
* @version 1.6.00
*
*/
@@ -4500,7 +4500,7 @@ function showAbout() {
imageUrl: image.about,
customClass: { image: 'img-about' },
position: 'center',
title: 'WebRTC SFU v1.5.99',
title: 'WebRTC SFU v1.6.00',
html: `
<br />
<div id="about">

عرض الملف

@@ -9,7 +9,7 @@
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.99
* @version 1.6.00
*
*/