Compare commits
29 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e11c5eeabe | ||
|
|
f46069eba5 | ||
|
|
02f5a34c9f | ||
|
|
1499f9db0e | ||
|
|
2d8bdf1691 | ||
|
|
b9695a06f2 | ||
|
|
31e52cd9a4 | ||
|
|
9e30c5e0e9 | ||
|
|
03a6ebf5b8 | ||
|
|
04845a673e | ||
|
|
6a7cf70640 | ||
|
|
6897e40fcc | ||
|
|
bcb8df9253 | ||
|
|
2aff278c70 | ||
|
|
eb30bc6351 | ||
|
|
59aa392d66 | ||
|
|
8be3f41e07 | ||
|
|
02870f8f12 | ||
|
|
b0e9e14658 | ||
|
|
ec1696a83a | ||
|
|
6ee0a7b98b | ||
|
|
bf01c8aae3 | ||
|
|
be885808dc | ||
|
|
02fb86e070 | ||
|
|
d2e3b3fe0c | ||
|
|
d717ad4d8d | ||
|
|
0db3b18a89 | ||
|
|
80e74f8243 | ||
|
|
9d3c105dfb |
31 changed files with 969 additions and 143 deletions
|
|
@ -1,21 +1,21 @@
|
|||
DONE:
|
||||
- attachment support
|
||||
- Pinging and channel sharing
|
||||
DONE:
|
||||
- user blacklist
|
||||
- "hub list" command
|
||||
- **new command prefix "ish!"**
|
||||
|
||||
IN PROGRESS:
|
||||
- hub settings
|
||||
- user blacklist
|
||||
- global messaging user blacklist
|
||||
- Server join blacklist
|
||||
- Server join blacklist
|
||||
- safer setting up (open invite code = no gud)
|
||||
|
||||
DROPPED:
|
||||
(- channel creator (for permission management))
|
||||
- Implement new message style + add discord invite link
|
||||
|
||||
TODO:
|
||||
- message editing
|
||||
- Implement new message style + add discord invite link
|
||||
- safer setting up (open invite code = no gud)
|
||||
- check nsfw channels
|
||||
- Server join whitelist
|
||||
- Telegram support
|
||||
- global comamnd user blacklist
|
||||
(-web interface (that frontend might run somewhere else))
|
||||
- message editing
|
||||
- check nsfw channels
|
||||
- global command user blacklist
|
||||
- transfer hub to new owner
|
||||
(-web interface (that frontend might run somewhere else))
|
||||
(- Signal support)
|
||||
|
|
@ -4,7 +4,7 @@ const fs = require('fs');
|
|||
function postMessage(client, message, body, error) {
|
||||
let color = 0;
|
||||
if (message.channel.type !== 'dm') color = message.member.displayColor;
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, 'About: ', color, false);
|
||||
}
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ function postMessage(client, message, body, error) {
|
|||
// TODO: make errorlogchannel in server
|
||||
function error(client, channel, err) {
|
||||
console.error('ERROR: ', err);
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, channel, 'Oh no! Something went wrong. This error has been carefully recorded and our nerd is working on it to fix it. Please try again later.', '', 16449540, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const clean = (text) => {
|
|||
module.exports.run = async (client, message, args, config) => {
|
||||
const args_eval = message.content.split(' ').slice(1);
|
||||
if (message.author.id !== '172031697355800577') return message.react('❌');
|
||||
if (message.content.indexOf('token') !== -1) return message.channel.send('Nice try...');
|
||||
if (message.content.indexOf('discordToken') !== -1) return message.channel.send('Nice try...');
|
||||
try {
|
||||
const code = args_eval.join(' ');
|
||||
let evaled = eval(code);
|
||||
|
|
|
|||
|
|
@ -4,27 +4,21 @@ function CommandUsage(prefix, cmdName, subcmd) {
|
|||
\`\`\`${prefix}${cmdName} ${subcmd}\`\`\``;
|
||||
}
|
||||
|
||||
// creates a embed messagetemplate for failed actions
|
||||
function messageFail(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
}
|
||||
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
const currentCMD = module.exports.help;
|
||||
const [subcmd] = args;
|
||||
const commandValues = ['register', 'delete', 'list', 'join', 'leave'];
|
||||
const commandValues = currentCMD.usage.split('|');
|
||||
if (commandValues.includes(subcmd)) {
|
||||
client.functions.get(`CMD_hub_${subcmd}`)
|
||||
.run(client, message, args, config);
|
||||
} else {
|
||||
const currentCMD = module.exports.help;
|
||||
messageFail(client, message, CommandUsage(config.prefix, currentCMD.name, currentCMD.usage));
|
||||
messageFail(message, CommandUsage(config.prefix, currentCMD.name, currentCMD.usage));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'hub',
|
||||
title: 'Manage hub',
|
||||
usage: 'register|delete|join|leave',
|
||||
usage: 'register|delete|join|leave|list|ban',
|
||||
desc: 'Manage hubs and links between channels.',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const { MessageEmbed } = require('discord.js');
|
|||
|
||||
// Ping kickoff for bot latency
|
||||
function kickoff(client, message) {
|
||||
const sendMessage = client.functions.get('FUNC_MessageEmbedMessage');
|
||||
const sendMessage = client.functions.get('FUNC_richEmbedMessage');
|
||||
return sendMessage.run(client.user, message.channel, '📤 Ping...', null, null, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"token": "**************************",
|
||||
"discordToken": "**************************",
|
||||
"telegramToken": "****************************",
|
||||
"production": {
|
||||
"username": "***",
|
||||
"password": "*****************",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "I-SH",
|
||||
"prefix": "+",
|
||||
"prefix": "ish!",
|
||||
"setup": {
|
||||
"moduleFolders": {
|
||||
"functionsFolder": "functions",
|
||||
|
|
@ -9,7 +9,8 @@
|
|||
"startupFunctions": [
|
||||
"STARTUP_initCommands",
|
||||
"STARTUP_initFunctions",
|
||||
"STARTUP_envPrep"
|
||||
"STARTUP_envPrep",
|
||||
"STARTUP_DBConnection"
|
||||
],
|
||||
"setupFunctions": [
|
||||
"SETUP_offlineStat",
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
const Sequelize = require('sequelize');
|
||||
|
||||
const testToken = '../config/config.json';
|
||||
|
||||
const config = require('../config/main.json');
|
||||
|
||||
console.log('[DB] Connecting...');
|
||||
let database;
|
||||
let user;
|
||||
let password;
|
||||
let host;
|
||||
if (config.env.get('inDev')) {
|
||||
const DBCredentials = require(testToken).development;
|
||||
database = DBCredentials.database;
|
||||
user = DBCredentials.username;
|
||||
password = DBCredentials.password;
|
||||
host = DBCredentials.host;
|
||||
} else {
|
||||
database = process.env.DBNameISH;
|
||||
user = process.env.DBUsernameISH;
|
||||
password = process.env.DBPasswISH;
|
||||
host = process.env.DBHost;
|
||||
}
|
||||
const sequelize = new Sequelize(
|
||||
database, user, password, { host, dialect: 'mysql', logging: config.env.get('inDev') },
|
||||
);
|
||||
console.log('[DB] Connected!');
|
||||
|
||||
module.exports = sequelize;
|
||||
global.sequelize = sequelize;
|
||||
32
database/models/bannedUser.js
Normal file
32
database/models/bannedUser.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const Sequelize = require('sequelize');
|
||||
|
||||
module.exports = sequelize.define('bannedUser', {
|
||||
ID: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
userID: {
|
||||
type: Sequelize.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
hubID: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'hubNames',
|
||||
key: 'hubID',
|
||||
},
|
||||
},
|
||||
reason: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
uniqueKeys: {
|
||||
banUnique: {
|
||||
fields: ['userID', 'hubID'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -1,9 +1,21 @@
|
|||
// DISABLED: not done
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
message.reply('ban');
|
||||
// banns a channel from the hub
|
||||
// get subcmd from args
|
||||
const [subcmd, type] = args;
|
||||
// check provided values
|
||||
switch (type) {
|
||||
case 'user':
|
||||
client.functions.get(`CMD_${module.exports.help.parent}_${subcmd}_${type}`)
|
||||
.run(client, message, args, config);
|
||||
return;
|
||||
|
||||
default:
|
||||
return messageFail(message,
|
||||
`Command usage:
|
||||
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${type || 'user'} MESSAGEID REASON\`\`\``);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'CMD_hub_ban',
|
||||
parent: 'hub',
|
||||
};
|
||||
|
|
|
|||
28
functions/CMD_hub_ban_user.js
Normal file
28
functions/CMD_hub_ban_user.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
module.exports.run = async (client, message, args, config) => {
|
||||
// get subcmd from args
|
||||
const [subcmd, type, messageID, reason] = args;
|
||||
if (!messageID || !reason) {
|
||||
return messageFail(message,
|
||||
`Command usage:
|
||||
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${type || 'user'} ${messageID || 'MESSAGEID'} ${reason || 'REASON'}\`\`\``);
|
||||
}
|
||||
// get complete reason
|
||||
let cutLength = 0;
|
||||
[subcmd, type, messageID].map((arg) => cutLength = cutLength + arg.length + 1);
|
||||
const slicedReason = await args.join(' ').slice(cutLength);
|
||||
messageSuccess(message, `\`\`\`${slicedReason}\`\`\``);
|
||||
// check permissions
|
||||
// get messageID => parse messageInstanceID
|
||||
// get messageInstanceID => get channelID
|
||||
// get channel from channelID and lookup messageID
|
||||
// get hubID from channelID
|
||||
// get author => parse userID
|
||||
// check if owner: dont ban owner
|
||||
// post bannedUserEntry [hubID + userID]
|
||||
// update owner
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'CMD_hub_ban_user',
|
||||
parent: 'hub',
|
||||
};
|
||||
|
|
@ -8,17 +8,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
|
|||
|
||||
// creates a embed messagetemplate for succeded actions
|
||||
function messageSuccess(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 4296754, false);
|
||||
}
|
||||
|
||||
// creates a embed messagetemplate for failed actions
|
||||
async function messageFail(client, message, body) {
|
||||
const result = client.functions.get('FUNC_MessageEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
// count channel entrys
|
||||
async function countChannels(hubID) {
|
||||
const result = await BridgedChannel.findAndCountAll({ where: { hubID } }).catch(errHander);
|
||||
|
|
@ -37,7 +30,7 @@ module.exports.run = async (client, message, args, config) => {
|
|||
const [subcmd, hubName] = args;
|
||||
// check if hubname is present
|
||||
if (!hubName) {
|
||||
return messageFail(client, message,
|
||||
return messageFail(message,
|
||||
`Command usage:
|
||||
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${hubName || 'HUBNAME'}\`\`\``);
|
||||
}
|
||||
|
|
@ -47,13 +40,13 @@ module.exports.run = async (client, message, args, config) => {
|
|||
const channelAmmount = await countChannels(hubID);
|
||||
|
||||
// check hub entry
|
||||
if (!hubID) return messageFail(client, message, `There is no hub named ${hubName}. Please check your spelling and try again.`);
|
||||
if (!hubID) return messageFail(message, `There is no hub named ${hubName}. Please check your spelling and try again.`);
|
||||
// check owner
|
||||
// TODO: Add managment exception
|
||||
if (ownerID !== message.author.id) return messageFail(client, message, `You are not the owner of the hub ${hubName}.`);
|
||||
if (ownerID !== message.author.id) return messageFail(message, `You are not the owner of the hub ${hubName}.`);
|
||||
|
||||
// sending pre deletion message
|
||||
const confirmMessage = await messageFail(client, message, `You are about to delete the hub **${hubName}** with ${channelAmmount} connected channels which can't be undone! \nAre you sure?`);
|
||||
const confirmMessage = await messageFail(message, `You are about to delete the hub **${hubName}** with ${channelAmmount} connected channels which can't be undone! \nAre you sure?`);
|
||||
await confirmMessage.react('❌');
|
||||
await confirmMessage.react('✅');
|
||||
|
||||
|
|
@ -75,10 +68,10 @@ module.exports.run = async (client, message, args, config) => {
|
|||
// FIXME: if there are no channels connected, the bot throws an error even if it was successful
|
||||
// if (deletedHub && deletedChannels) messageSuccess(client, message, 'Your hub has now been deleted!');
|
||||
if (deletedHub) messageSuccess(client, message, 'Your hub has now been deleted!');
|
||||
else messageFail(client, message, 'Oh no! It seems something went wrong... Please try again another time. If this error persists, feel free to contact us on our support server.');
|
||||
else messageFail(message, 'Oh no! It seems something went wrong... Please try again another time. If this error persists, feel free to contact us on our support server.');
|
||||
return;
|
||||
default:
|
||||
return messageFail(client, message, 'Please only choose one othe the two options! Try again.');
|
||||
return messageFail(message, 'Please only choose one othe the two options! Try again.');
|
||||
}
|
||||
});
|
||||
reactionCollector.on('end', () => confirmMessage.delete());
|
||||
|
|
|
|||
|
|
@ -6,16 +6,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
|
|||
|
||||
// creates a embed messagetemplate for succeded actions
|
||||
function messageSuccess(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 4296754, false);
|
||||
}
|
||||
|
||||
// creates a embed messagetemplate for failed actions
|
||||
function messageFail(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
}
|
||||
|
||||
// gets hubID from DB
|
||||
async function getHubID(hubName) {
|
||||
const result = await HubName.findOne({ attributes: ['hubID'], where: { hubName } }).catch(errHander);
|
||||
|
|
@ -40,21 +34,21 @@ async function checkPermissions(message) {
|
|||
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
// check DM
|
||||
if (message.channel.type === 'dm') return messageFail(client, message, 'You can\'t link a DM channel!');
|
||||
if (message.channel.type === 'dm') return messageFail(message, 'You can\'t link a DM channel!');
|
||||
// check user permissions
|
||||
if (!await checkPermissions(message)) return messageFail(client, message, 'Hold on! You dont have permissions to manage this channel. Try asking an admin or link another chnanel where you have permissions instead.');
|
||||
if (!await checkPermissions(message)) return messageFail(message, 'Hold on! You dont have permissions to manage this channel. Try asking an admin or link another chnanel where you have permissions instead.');
|
||||
|
||||
// get subcmd from args
|
||||
const [subcmd, hubName] = args;
|
||||
// check if hubname is present
|
||||
if (!hubName) {
|
||||
return messageFail(client, message,
|
||||
return messageFail(message,
|
||||
`Command usage:
|
||||
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} HUBNAME\`\`\``);
|
||||
}
|
||||
// get hubID
|
||||
const hubID = await getHubID(hubName);
|
||||
if (!hubID) return messageFail(client, message, `There is no hub named \`${hubName}\`! But you can create one by using \`${config.prefix}${module.exports.help.parent} register\`.`);
|
||||
if (!hubID) return messageFail(message, `There is no hub named \`${hubName}\`! But you can create one by using \`${config.prefix}${module.exports.help.parent} register\`.`);
|
||||
|
||||
// get custom channel
|
||||
const channelID = message.channel.id;
|
||||
|
|
@ -63,7 +57,7 @@ module.exports.run = async (client, message, args, config) => {
|
|||
if (created) {
|
||||
messageSuccess(client, message, `This channel is now linked with \`${hubName}\``);
|
||||
} else {
|
||||
messageFail(client, message, `A channel in this server is already linked with \`${hubName}\`! Try unlinking it first by using \`${config.prefix}${module.exports.help.parent} leave\`.`);
|
||||
messageFail(message, `A channel in this server is already linked with \`${hubName}\`! Try unlinking it first by using \`${config.prefix}${module.exports.help.parent} leave\`.`);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
|
|||
|
||||
// creates a embed messagetemplate for succeded actions
|
||||
function messageSuccess(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 4296754, false);
|
||||
}
|
||||
|
||||
// creates a embed messagetemplate for failed actions
|
||||
function messageFail(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
}
|
||||
|
||||
// deletes channel entry from DB
|
||||
async function deleteChannel(channelID) {
|
||||
const result = await BridgedChannel.destroy({ where: { channelID } }).catch(errHander);
|
||||
|
|
@ -27,9 +21,9 @@ async function checkPermissions(message) {
|
|||
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
// check DM
|
||||
if (message.channel.type === 'dm') return messageFail(client, message, 'You can\'t unlink a DM channel!');
|
||||
if (message.channel.type === 'dm') return messageFail(message, 'You can\'t unlink a DM channel!');
|
||||
// check user permissions
|
||||
if (!await checkPermissions(message)) return messageFail(client, message, 'Hold on! You dont have permissions to manage this channel. Try asking an admin to remove the link.');
|
||||
if (!await checkPermissions(message)) return messageFail(message, 'Hold on! You dont have permissions to manage this channel. Try asking an admin to remove the link.');
|
||||
|
||||
// get custom channel id
|
||||
const channelID = message.channel.id;
|
||||
|
|
@ -37,7 +31,7 @@ module.exports.run = async (client, message, args, config) => {
|
|||
const created = await deleteChannel(channelID);
|
||||
// check if channel entry is deleted and give feedback
|
||||
if (created) messageSuccess(client, message, 'This channel is now not longer linked!');
|
||||
else messageFail(client, message, 'This channel is not linked with any hub! You can\'t unlink it.');
|
||||
else messageFail(message, 'This channel is not linked with any hub! You can\'t unlink it.');
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
|
|
|
|||
|
|
@ -4,16 +4,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
|
|||
|
||||
// creates a embed messagetemplate for succeded actions
|
||||
function messageSuccess(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 4296754, false);
|
||||
}
|
||||
|
||||
// creates a embed messagetemplate for failed actions
|
||||
function messageFail(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
}
|
||||
|
||||
// gets hub names from DB
|
||||
async function getHubNames(ownerID) {
|
||||
const result = await HubName.findAll({ attributes: ['hubName'], where: { ownerID } }).catch(errHander);
|
||||
|
|
@ -23,7 +17,7 @@ async function getHubNames(ownerID) {
|
|||
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
// check if in DM
|
||||
if (message.channel.type !== 'dm') return messageFail(client, message, 'This command can only be used in DM!');
|
||||
if (message.channel.type !== 'dm') return messageFail(message, 'This command can only be used in DM!');
|
||||
// get hubNames
|
||||
const hubNames = await getHubNames(message.author.id);
|
||||
let names = '';
|
||||
|
|
|
|||
|
|
@ -4,16 +4,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
|
|||
|
||||
// creates a embed messagetemplate for succeded actions
|
||||
function messageSuccess(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 4296754, false);
|
||||
}
|
||||
|
||||
// creates a embed messagetemplate for failed actions
|
||||
function messageFail(client, message, body) {
|
||||
client.functions.get('FUNC_MessageEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
}
|
||||
|
||||
// creates channel DB entry
|
||||
async function createHub(hubName, ownerID, maxHubs) {
|
||||
const result = await HubName.findAndCountAll({ where: { ownerID } }).catch(errHander);
|
||||
|
|
@ -24,26 +18,26 @@ async function createHub(hubName, ownerID, maxHubs) {
|
|||
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
// check if in DM
|
||||
if (message.channel.type !== 'dm') return messageFail(client, message, 'This command can only be used in DM!');
|
||||
if (message.channel.type !== 'dm') return messageFail(message, 'This command can only be used in DM!');
|
||||
// get subcmd from args
|
||||
const [subcmd, checkHubName] = args;
|
||||
// check if hubname is present
|
||||
if (!checkHubName) {
|
||||
return messageFail(client, message,
|
||||
return messageFail(message,
|
||||
`Command usage:
|
||||
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${checkHubName || 'HUBNAME'}\`\`\``);
|
||||
}
|
||||
|
||||
const hubName = args.join('_').slice(subcmd.length + 1);
|
||||
const fittedHubName = `${message.id}_${hubName}`;
|
||||
if (fittedHubName.length > 50) return messageFail(client, message, 'Sorry, your hubname ist too long... Try something shorter.');
|
||||
if (fittedHubName.length > 50) return messageFail(message, 'Sorry, your hubname ist too long... Try something shorter.');
|
||||
const created = await createHub(fittedHubName, message.author.id, config.maxAllowedHubs);
|
||||
if (created) {
|
||||
messageSuccess(client, message,
|
||||
`You created \`${hubName}\`!
|
||||
You can link with it by using \`${config.prefix}${module.exports.help.parent} join ${fittedHubName}\`.
|
||||
**Make sure you only give the hub name to servers that you want to invite.**`);
|
||||
} else messageFail(client, message, `Your account already owns a maximum of ${config.maxAllowedHubs} hubs. You can't create more then that!`);
|
||||
} else messageFail(message, `Your account already owns a maximum of ${config.maxAllowedHubs} hubs. You can't create more then that!`);
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// DISABLED: not done
|
||||
module.exports.run = async (client, message, args, config) => {
|
||||
// check if in DM
|
||||
if (message.channel.type !== 'dm') return messageFail(client, message, 'This command can only be used in DM!');
|
||||
if (message.channel.type !== 'dm') return messageFail(message, 'This command can only be used in DM!');
|
||||
message.reply('rnme');
|
||||
// renames the hub
|
||||
};
|
||||
|
|
|
|||
21
functions/CMD_hub_unban.js
Normal file
21
functions/CMD_hub_unban.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
module.exports.run = async (client, message, args, config) => {
|
||||
// get subcmd from args
|
||||
const [subcmd, type] = args;
|
||||
// check provided values
|
||||
switch (type) {
|
||||
case 'user':
|
||||
client.functions.get(`CMD_${module.exports.help.parent}_${subcmd}_${type}`)
|
||||
.run(client, message, args, config);
|
||||
return;
|
||||
|
||||
default:
|
||||
return messageFail(message,
|
||||
`Command usage:
|
||||
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${type || 'user'} MESSAGEID REASON\`\`\``);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'CMD_hub_ban',
|
||||
parent: 'hub',
|
||||
};
|
||||
|
|
@ -6,7 +6,8 @@ const errHander = (err) => { console.error('ERROR:', err); };
|
|||
|
||||
// Deletes all messages in every channel, if its deleted in one
|
||||
module.exports.run = async (guild) => {
|
||||
guild.channels.forEach(async (channel) => {
|
||||
console.log(guild);
|
||||
guild.channels.cache.forEach(async (channel) => {
|
||||
if (!channel.type !== 'text') return;
|
||||
const channelID = channel.id;
|
||||
const checkedChannel = await BridgedChannel.findOne({ attributes: ['channelID'], where: { channelID } }).catch(errHander);
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@ module.exports.run = async (user, channel, body, title, color, footer) => {
|
|||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'FUNC_MessageEmbedMessage',
|
||||
name: 'FUNC_richEmbedMessage',
|
||||
};
|
||||
|
|
|
|||
5
functions/GLBLFUNC_errHandler.js
Normal file
5
functions/GLBLFUNC_errHandler.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
global.errHandler = (err) => console.error('ERROR:', err);
|
||||
|
||||
module.exports.help = {
|
||||
name: 'GLBLFUNC_errHandler',
|
||||
};
|
||||
11
functions/GLBLFUNC_messageFail.js
Normal file
11
functions/GLBLFUNC_messageFail.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
global.messageFail = async (message, body, keep) => {
|
||||
const client = message.client;
|
||||
const sentMessage = await client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 16449540, false);
|
||||
if (!keep) sentMessage.delete({ timeout: 30000 });
|
||||
return sentMessage;
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'GLBLFUNC_messageFail',
|
||||
};
|
||||
10
functions/GLBLFUNC_messageSuccess.js
Normal file
10
functions/GLBLFUNC_messageSuccess.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
global.messageSuccess = async (message, body) => {
|
||||
const client = message.client;
|
||||
const sentMessage = await client.functions.get('FUNC_richEmbedMessage')
|
||||
.run(client.user, message.channel, body, '', 4296754, false);
|
||||
return sentMessage;
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'GLBLFUNC_messageSuccess',
|
||||
};
|
||||
15
functions/SETUP_telegramBot.js
Normal file
15
functions/SETUP_telegramBot.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const TG = require('telegram-bot-api');
|
||||
|
||||
module.exports.run = async (client, config) => {
|
||||
const telegramClient = new TG({
|
||||
token: config.env.get('telegramToken'),
|
||||
});
|
||||
|
||||
telegramClient.getMe()
|
||||
.then(console.log)
|
||||
.catch(console.err);
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'SETUP_telegramBot',
|
||||
};
|
||||
35
functions/STARTUP_DBConnection.js
Normal file
35
functions/STARTUP_DBConnection.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const Sequelize = require('sequelize');
|
||||
|
||||
const testdiscordToken = '../config/config.json';
|
||||
|
||||
const config = require('../config/main.json');
|
||||
|
||||
module.exports.run = () => {
|
||||
console.log('[DB] Connecting...');
|
||||
let database;
|
||||
let user;
|
||||
let password;
|
||||
let host;
|
||||
if (config.env.get('inDev')) {
|
||||
const DBCredentials = require(testdiscordToken).development;
|
||||
database = DBCredentials.database;
|
||||
user = DBCredentials.username;
|
||||
password = DBCredentials.password;
|
||||
host = DBCredentials.host;
|
||||
} else {
|
||||
database = process.env.DBNameISH;
|
||||
user = process.env.DBUsernameISH;
|
||||
password = process.env.DBPasswISH;
|
||||
host = process.env.DBHost;
|
||||
}
|
||||
const sequelize = new Sequelize(
|
||||
database, user, password, { host, dialect: 'mysql', logging: config.env.get('inDev') },
|
||||
);
|
||||
console.log('[DB] Connected!');
|
||||
|
||||
global.sequelize = sequelize;
|
||||
};
|
||||
|
||||
module.exports.help = {
|
||||
name: 'STARTUP_DBConnection',
|
||||
};
|
||||
|
|
@ -4,12 +4,15 @@ module.exports.run = async (client, fs, config) => {
|
|||
// setting inDev var
|
||||
console.log(`[${module.exports.help.name}] Setting environment variables...`);
|
||||
if (fs.existsSync(testToken)) {
|
||||
const token = require(`.${testToken}`).discordToken;
|
||||
const discordToken = require(`.${testToken}`).discordToken;
|
||||
const telegramToken = require(`.${testToken}`).telegramToken;
|
||||
config.env.set('inDev', true);
|
||||
config.env.set('token', token);
|
||||
config.env.set('discordToken', discordToken);
|
||||
config.env.set('telegramToken', telegramToken);
|
||||
} else {
|
||||
config.env.set('inDev', false);
|
||||
config.env.set('token', process.env.discordToken);
|
||||
config.env.set('discordToken', process.env.BotToken);
|
||||
config.env.set('telegramToken', process.env.BottelegramTokenISH);
|
||||
}
|
||||
console.log(`[${module.exports.help.name}] Environment variables set!`);
|
||||
};
|
||||
|
|
|
|||
15
index.js
15
index.js
|
|
@ -2,8 +2,6 @@
|
|||
const Discord = require('discord.js');
|
||||
// init Discord client
|
||||
const client = new Discord.Client({ disableMentions: 'everyone' });
|
||||
// init sequelize
|
||||
const sequelize = require('sequelize');
|
||||
// init filesystem
|
||||
const fs = require('fs');
|
||||
// init config
|
||||
|
|
@ -20,16 +18,19 @@ config.setup.startupFunctions.forEach((FCN) => {
|
|||
INIT.run(client, fs, config);
|
||||
});
|
||||
|
||||
// create conenction to DB
|
||||
require('./database/SETUP_DBConnection');
|
||||
|
||||
// Login the bot
|
||||
client.login(config.env.get('token'));
|
||||
client.login(config.env.get('discordToken'));
|
||||
|
||||
// trigger on bot login
|
||||
client.on('ready', () => {
|
||||
client.on('ready', async () => {
|
||||
// confirm user logged in
|
||||
console.log(`[${config.name}] Logged in as ${client.user.tag} serving ${client.guilds.cache.size} Servers!`);
|
||||
|
||||
// setup tables
|
||||
console.log('[DB] Syncing tables...');
|
||||
await sequelize.sync();
|
||||
await console.log('[DB] Done syncing!');
|
||||
|
||||
// set bot player status
|
||||
config.setup.setupFunctions.forEach((FCN) => {
|
||||
client.functions.get(FCN).run(client, config);
|
||||
|
|
|
|||
35
migrations/20210914131359-bannedusers.js
Normal file
35
migrations/20210914131359-bannedusers.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => queryInterface.createTable('bannedUsers', {
|
||||
ID: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
userID: {
|
||||
type: Sequelize.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
hubID: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'hubNames',
|
||||
key: 'hubID',
|
||||
},
|
||||
},
|
||||
reason: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
createdAt: Sequelize.DATE,
|
||||
updatedAt: Sequelize.DATE,
|
||||
},
|
||||
{
|
||||
uniqueKeys: {
|
||||
banUnique: {
|
||||
fields: ['userID', 'hubID'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
down: (queryInterface, Sequelize) => queryInterface.dropTable('bannedUsers'),
|
||||
};
|
||||
697
package-lock.json
generated
697
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,12 +1,13 @@
|
|||
{
|
||||
"name": "i-sh",
|
||||
"version": "1.1.1",
|
||||
"version": "1.2.0",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.3.1",
|
||||
"mysql2": "^2.2.2",
|
||||
"pretty-ms": "^5.1.0",
|
||||
"sequelize": "^5.22.3"
|
||||
"sequelize": "^5.22.3",
|
||||
"telegram-bot-api": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.8.0",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
##### How do I get started with you?
|
||||
|
||||
> Use `+help` to learn all the commands.
|
||||
> Use `ish!help` to learn all the commands.
|
||||
|
||||
##### I need some help
|
||||
|
||||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
##### Source Code
|
||||
|
||||
> Feel free to look at my [GitHub](https://github.com/FlipperLP/I-SH/)!
|
||||
> Feel free to look at my [GitHub](https://github.com/FlipperLP/I-SH/)!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue