Skip to content

Commit

Permalink
Merge pull request #492 from Project-Coda/ask-to-join
Browse files Browse the repository at this point in the history
Ask to join
  • Loading branch information
ikifar2012 authored Oct 6, 2024
2 parents 74efb92 + 1d57866 commit 5768596
Show file tree
Hide file tree
Showing 11 changed files with 620 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or with the host.
// "forwardPorts": [3000, 5432],
"forwardPorts": [3306],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
Expand Down
48 changes: 0 additions & 48 deletions .eslintrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/eslint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/setup-node@v4.0.4
- name: Install eslint
run: npm install -g eslint@8.57.0
- name: Install dev dependencies
run: npm install --only=dev
- name: Run eslint
run: eslint --ext .js .
run: npx eslint .
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
87 changes: 87 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const globals = require('globals');
const js = require('@eslint/js');

const {
FlatCompat,
} = require('@eslint/eslintrc');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

module.exports = [...compat.extends('eslint:recommended'), {
languageOptions: {
globals: {
...globals.node,
},

ecmaVersion: 2021,
sourceType: 'commonjs',
},

rules: {
'arrow-spacing': ['warn', {
before: true,
after: true,
}],

'brace-style': ['error', 'stroustrup', {
allowSingleLine: true,
}],

'comma-dangle': ['error', 'always-multiline'],
'comma-spacing': 'error',
'comma-style': 'error',
curly: ['error', 'multi-line', 'consistent'],
'dot-location': ['error', 'property'],
'handle-callback-err': 'off',
indent: ['error', 'tab'],
'keyword-spacing': 'error',

'max-nested-callbacks': ['error', {
max: 4,
}],

'max-statements-per-line': ['error', {
max: 2,
}],

'no-console': 'off',
'no-empty-function': 'error',
'no-floating-decimal': 'error',
'no-inline-comments': 'error',
'no-lonely-if': 'error',
'no-multi-spaces': 'error',

'no-multiple-empty-lines': ['error', {
max: 2,
maxEOF: 1,
maxBOF: 0,
}],

'no-shadow': ['error', {
allow: ['err', 'resolve', 'reject', 'msg'],
}],

'no-trailing-spaces': ['error'],
'no-undef': 'off',
'object-curly-spacing': ['error', 'always'],
'prefer-const': 'error',
quotes: ['error', 'single'],
semi: ['error', 'always'],

'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],

'space-in-parens': 'error',
'space-infix-ops': 'error',
'space-unary-ops': 'error',
'spaced-comment': 'error',
yoda: 'error',
},
}];
45 changes: 33 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const autorole = require('./utilities/autorole.js');
const vctools = require('./utilities/vc-tools.js');
const { checkMention } = require('./utilities/message-filter.js');
const nodecron = require('node-cron');
const vclogs = require('./utilities/vc-logs.js');
global.client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildModeration],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
Expand All @@ -38,23 +39,25 @@ global.client.once('ready', async () => {
});

(async () => {
db = await mariadb.getConnection();
const db = await mariadb.getConnection();
// drop table if it exists
// only for testing
// await db.query('DROP TABLE IF EXISTS roles');
// await db.query('DROP TABLE IF EXISTS custom_vc');
// create roles table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS roles (id VARCHAR(255) PRIMARY KEY, emoji VARCHAR(255), raw_emoji VARCHAR(255), message_id VARCHAR(255), channel_id VARCHAR(255)) COLLATE utf8mb4_general_ci CHARSET utf8mb4;');
// create notify table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS notify (user_id VARCHAR(255) PRIMARY KEY, name VARCHAR(255))');
// create settings table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS settings (setting VARCHAR(255) PRIMARY KEY, value BOOLEAN)');
// create custom vc table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS custom_vc (user_id VARCHAR(255) PRIMARY KEY, channel_id VARCHAR(255))');
await db.query('CREATE TABLE IF NOT EXISTS custom_vc (user_id VARCHAR(255), channel_id VARCHAR(255) PRIMARY KEY, ask_to_join_vc VARCHAR(255))');
await db.query('CREATE TABLE IF NOT EXISTS custom_vc_queue (user_id VARCHAR(255) PRIMARY KEY, channel_id VARCHAR(255), ask_to_join_vc VARCHAR(255), message_id VARCHAR(255), FOREIGN KEY (channel_id) REFERENCES custom_vc(channel_id) ON DELETE CASCADE)');
// create auto role table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS auto_role (role_id VARCHAR(255) PRIMARY KEY)');
// create coda strikes table if it doesn't exist
// await db.query('DROP TABLE IF EXISTS coda_strikes');
await db.query('CREATE TABLE IF NOT EXISTS coda_strikes (user_id VARCHAR(255) PRIMARY KEY, strikes INT, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)');
await db.query('CREATE TABLE IF NOT EXISTS vc_logs (user_id VARCHAR(255) PRIMARY KEY, previous_channel VARCHAR(255), new_channel VARCHAR(255), timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)');
db.end();
}
)();
Expand Down Expand Up @@ -174,7 +177,7 @@ global.client.on('messageReactionAdd', async (reaction, user) => {
console.log(emoji);
// query db for role
try {
db = await mariadb.getConnection();
const db = await mariadb.getConnection();
const role = await db.query('SELECT * FROM roles WHERE emoji = ? AND message_id = ?', [emoji, message.id]);
db.end();
const roleId = String(role[0].id);
Expand Down Expand Up @@ -252,15 +255,33 @@ global.client.on('messageReactionRemove', async (reaction, user) => {
);

global.client.on('voiceStateUpdate', async (oldState, newState) => {
newUserChannel = await newState.channelId;
oldUserChannel = await oldState.channelId;
const createcustomvc = env.utilities.customvc.channel;
await CustomVC.Cleanup(oldState);
if (newUserChannel === createcustomvc) {
CustomVC.Create(newState);
try {
await CustomVC.Cleanup(oldState);
// ensure channel still exists
newUserChannel = await newState.channelId;
oldUserChannel = await oldState.channelId;
userid = await newState.member.id;
await vclogs.updateChannel(userid, oldUserChannel, newUserChannel);
await CustomVC.cleanupAskToJoinMessage(oldUserChannel, newUserChannel, userid);
if (!newUserChannel) return;
// get parent category of newState channel
const createcustomvc = env.utilities.customvc.channel;
const asktojoin_category = env.utilities.customvc.asktojoin;
const parent = await vctools.getParentChannel(newUserChannel);
if (newUserChannel === createcustomvc) {
await CustomVC.Create(newState);
}
if (parent === asktojoin_category) {
await CustomVC.askToJoinSendMessage(userid, newUserChannel);
}
await CustomVC.setUserCustomVCPermissions(newState, oldState);
await vctools.setBitrate();
}
await vctools.setBitrate();
await CustomVC.setUserCustomVCPermissions(newState, oldState);
catch (error) {
console.error(error);
embedcreator.sendError(error);
}

});

// listen for button interactions
Expand Down
39 changes: 33 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
},
"homepage": "https://github.com/Project-Coda/Coda-Utilities#readme",
"devDependencies": {
"@eslint/js": "^9.12.0",
"eslint": "^9.12.0",
"globals": "^15.10.0",
"nodemon": "^3.1.7"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 5768596

Please sign in to comment.