Compare commits

...
Sign in to create a new pull request.

29 commits

Author SHA1 Message Date
Phil
e11c5eeabe [fix debug] cache implementation 2022-02-15 17:01:20 +01:00
Phil
f46069eba5 added workflow 2021-09-14 20:37:34 +02:00
Phil
02f5a34c9f dummyfile 2021-09-14 20:37:26 +02:00
Phil
1499f9db0e disabled telegram bot 2021-09-14 20:31:04 +02:00
Phil
2d8bdf1691 updated prefix 2021-09-14 20:30:55 +02:00
Phil
b9695a06f2 new prefix 2021-09-14 20:30:36 +02:00
Phil
31e52cd9a4 globalfunctioned 2021-09-14 20:18:32 +02:00
Phil
9e30c5e0e9 code cleanup 2021-09-14 20:06:55 +02:00
Phil
03a6ebf5b8 updated help 2021-09-14 20:04:39 +02:00
Phil
04845a673e populated with code 2021-09-14 20:04:09 +02:00
Phil
6a7cf70640 inital init 2021-09-14 20:03:55 +02:00
Phil
6897e40fcc added globalfunctions 2021-09-14 20:03:43 +02:00
Phil
bcb8df9253 added db connect to startup functions 2021-09-14 20:03:21 +02:00
Phil
2aff278c70 added table 2021-09-14 20:03:06 +02:00
Phil
eb30bc6351 moved DB init to functions 2021-09-14 20:02:55 +02:00
Phil
59aa392d66 registered ban command 2021-09-14 20:02:36 +02:00
Phil
8be3f41e07 removed unneeded requerements 2021-09-14 20:02:19 +02:00
Phil
02870f8f12 udpated 2021-09-14 20:01:57 +02:00
Phil
b0e9e14658 added telegram support to in progress 2021-09-14 15:08:49 +02:00
Phil
ec1696a83a updated changelog 2021-09-14 14:06:36 +02:00
Phil
6ee0a7b98b updated version 2021-09-14 14:01:51 +02:00
Phil
bf01c8aae3 Merge branch 'master' of https://github.com/FlipperLP/I-SH into dev 2021-09-14 14:01:19 +02:00
Phil
be885808dc added table sync 2021-09-14 13:58:24 +02:00
Phil
02fb86e070 added telegram token to env 2021-08-16 19:30:54 +02:00
Phil
d2e3b3fe0c added telegram bot to startup functions 2021-08-16 19:30:38 +02:00
Phil
d717ad4d8d added telegram bot api 2021-08-16 19:30:25 +02:00
Phil
0db3b18a89 added telegram bot inintal file 2021-08-16 19:30:01 +02:00
Phil
80e74f8243 updated example config 2020-10-25 13:56:40 +01:00
Phil
9d3c105dfb updated names 2020-10-25 13:56:16 +01:00
31 changed files with 969 additions and 143 deletions

View file

@ -1,21 +1,21 @@
DONE: DONE:
- attachment support - user blacklist
- Pinging and channel sharing - "hub list" command
- **new command prefix "ish!"**
IN PROGRESS: IN PROGRESS:
- hub settings - Server join blacklist
- user blacklist - safer setting up (open invite code = no gud)
- global messaging user blacklist
- Server join blacklist
DROPPED: DROPPED:
(- channel creator (for permission management)) - Implement new message style + add discord invite link
TODO: TODO:
- message editing - Server join whitelist
- Implement new message style + add discord invite link
- safer setting up (open invite code = no gud)
- check nsfw channels
- Telegram support - Telegram support
- global comamnd user blacklist - message editing
(-web interface (that frontend might run somewhere else)) - check nsfw channels
- global command user blacklist
- transfer hub to new owner
(-web interface (that frontend might run somewhere else))
(- Signal support)

View file

@ -4,7 +4,7 @@ const fs = require('fs');
function postMessage(client, message, body, error) { function postMessage(client, message, body, error) {
let color = 0; let color = 0;
if (message.channel.type !== 'dm') color = message.member.displayColor; 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); .run(client.user, message.channel, body, 'About: ', color, false);
} }
@ -13,7 +13,7 @@ function postMessage(client, message, body, error) {
// TODO: make errorlogchannel in server // TODO: make errorlogchannel in server
function error(client, channel, err) { function error(client, channel, err) {
console.error('ERROR: ', 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); .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);
} }

View file

@ -6,7 +6,7 @@ const clean = (text) => {
module.exports.run = async (client, message, args, config) => { module.exports.run = async (client, message, args, config) => {
const args_eval = message.content.split(' ').slice(1); const args_eval = message.content.split(' ').slice(1);
if (message.author.id !== '172031697355800577') return message.react('❌'); 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 { try {
const code = args_eval.join(' '); const code = args_eval.join(' ');
let evaled = eval(code); let evaled = eval(code);

View file

@ -4,27 +4,21 @@ function CommandUsage(prefix, cmdName, subcmd) {
\`\`\`${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) => { module.exports.run = async (client, message, args, config) => {
const currentCMD = module.exports.help;
const [subcmd] = args; const [subcmd] = args;
const commandValues = ['register', 'delete', 'list', 'join', 'leave']; const commandValues = currentCMD.usage.split('|');
if (commandValues.includes(subcmd)) { if (commandValues.includes(subcmd)) {
client.functions.get(`CMD_hub_${subcmd}`) client.functions.get(`CMD_hub_${subcmd}`)
.run(client, message, args, config); .run(client, message, args, config);
} else { } else {
const currentCMD = module.exports.help; messageFail(message, CommandUsage(config.prefix, currentCMD.name, currentCMD.usage));
messageFail(client, message, CommandUsage(config.prefix, currentCMD.name, currentCMD.usage));
} }
}; };
module.exports.help = { module.exports.help = {
name: 'hub', name: 'hub',
title: 'Manage hub', title: 'Manage hub',
usage: 'register|delete|join|leave', usage: 'register|delete|join|leave|list|ban',
desc: 'Manage hubs and links between channels.', desc: 'Manage hubs and links between channels.',
}; };

View file

@ -2,7 +2,7 @@ const { MessageEmbed } = require('discord.js');
// Ping kickoff for bot latency // Ping kickoff for bot latency
function kickoff(client, message) { 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); return sendMessage.run(client.user, message.channel, '📤 Ping...', null, null, false);
} }

View file

@ -1,5 +1,6 @@
{ {
"token": "**************************", "discordToken": "**************************",
"telegramToken": "****************************",
"production": { "production": {
"username": "***", "username": "***",
"password": "*****************", "password": "*****************",

View file

@ -1,6 +1,6 @@
{ {
"name": "I-SH", "name": "I-SH",
"prefix": "+", "prefix": "ish!",
"setup": { "setup": {
"moduleFolders": { "moduleFolders": {
"functionsFolder": "functions", "functionsFolder": "functions",
@ -9,7 +9,8 @@
"startupFunctions": [ "startupFunctions": [
"STARTUP_initCommands", "STARTUP_initCommands",
"STARTUP_initFunctions", "STARTUP_initFunctions",
"STARTUP_envPrep" "STARTUP_envPrep",
"STARTUP_DBConnection"
], ],
"setupFunctions": [ "setupFunctions": [
"SETUP_offlineStat", "SETUP_offlineStat",

View file

@ -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;

View 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'],
},
},
});

View file

@ -1,9 +1,21 @@
// DISABLED: not done
module.exports.run = async (client, message, args, config) => { module.exports.run = async (client, message, args, config) => {
message.reply('ban'); // get subcmd from args
// banns a channel from the hub 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 = { module.exports.help = {
name: 'CMD_hub_ban', name: 'CMD_hub_ban',
parent: 'hub',
}; };

View 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',
};

View file

@ -8,17 +8,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
// creates a embed messagetemplate for succeded actions // creates a embed messagetemplate for succeded actions
function messageSuccess(client, message, body) { function messageSuccess(client, message, body) {
client.functions.get('FUNC_MessageEmbedMessage') client.functions.get('FUNC_richEmbedMessage')
.run(client.user, message.channel, body, '', 4296754, false); .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 // count channel entrys
async function countChannels(hubID) { async function countChannels(hubID) {
const result = await BridgedChannel.findAndCountAll({ where: { hubID } }).catch(errHander); 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; const [subcmd, hubName] = args;
// check if hubname is present // check if hubname is present
if (!hubName) { if (!hubName) {
return messageFail(client, message, return messageFail(message,
`Command usage: `Command usage:
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${hubName || 'HUBNAME'}\`\`\``); \`\`\`${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); const channelAmmount = await countChannels(hubID);
// check hub entry // 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 // check owner
// TODO: Add managment exception // 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 // 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('❌');
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 // 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 && deletedChannels) messageSuccess(client, message, 'Your hub has now been deleted!');
if (deletedHub) 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; return;
default: 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()); reactionCollector.on('end', () => confirmMessage.delete());

View file

@ -6,16 +6,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
// creates a embed messagetemplate for succeded actions // creates a embed messagetemplate for succeded actions
function messageSuccess(client, message, body) { function messageSuccess(client, message, body) {
client.functions.get('FUNC_MessageEmbedMessage') client.functions.get('FUNC_richEmbedMessage')
.run(client.user, message.channel, body, '', 4296754, false); .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 // gets hubID from DB
async function getHubID(hubName) { async function getHubID(hubName) {
const result = await HubName.findOne({ attributes: ['hubID'], where: { hubName } }).catch(errHander); 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) => { module.exports.run = async (client, message, args, config) => {
// check DM // 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 // 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 // get subcmd from args
const [subcmd, hubName] = args; const [subcmd, hubName] = args;
// check if hubname is present // check if hubname is present
if (!hubName) { if (!hubName) {
return messageFail(client, message, return messageFail(message,
`Command usage: `Command usage:
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} HUBNAME\`\`\``); \`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} HUBNAME\`\`\``);
} }
// get hubID // get hubID
const hubID = await getHubID(hubName); 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 // get custom channel
const channelID = message.channel.id; const channelID = message.channel.id;
@ -63,7 +57,7 @@ module.exports.run = async (client, message, args, config) => {
if (created) { if (created) {
messageSuccess(client, message, `This channel is now linked with \`${hubName}\``); messageSuccess(client, message, `This channel is now linked with \`${hubName}\``);
} else { } 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\`.`);
} }
}; };

View file

@ -4,16 +4,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
// creates a embed messagetemplate for succeded actions // creates a embed messagetemplate for succeded actions
function messageSuccess(client, message, body) { function messageSuccess(client, message, body) {
client.functions.get('FUNC_MessageEmbedMessage') client.functions.get('FUNC_richEmbedMessage')
.run(client.user, message.channel, body, '', 4296754, false); .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 // deletes channel entry from DB
async function deleteChannel(channelID) { async function deleteChannel(channelID) {
const result = await BridgedChannel.destroy({ where: { channelID } }).catch(errHander); 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) => { module.exports.run = async (client, message, args, config) => {
// check DM // 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 // 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 // get custom channel id
const channelID = message.channel.id; const channelID = message.channel.id;
@ -37,7 +31,7 @@ module.exports.run = async (client, message, args, config) => {
const created = await deleteChannel(channelID); const created = await deleteChannel(channelID);
// check if channel entry is deleted and give feedback // check if channel entry is deleted and give feedback
if (created) messageSuccess(client, message, 'This channel is now not longer linked!'); 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 = { module.exports.help = {

View file

@ -4,16 +4,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
// creates a embed messagetemplate for succeded actions // creates a embed messagetemplate for succeded actions
function messageSuccess(client, message, body) { function messageSuccess(client, message, body) {
client.functions.get('FUNC_MessageEmbedMessage') client.functions.get('FUNC_richEmbedMessage')
.run(client.user, message.channel, body, '', 4296754, false); .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 // gets hub names from DB
async function getHubNames(ownerID) { async function getHubNames(ownerID) {
const result = await HubName.findAll({ attributes: ['hubName'], where: { ownerID } }).catch(errHander); 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) => { module.exports.run = async (client, message, args, config) => {
// check if in DM // 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 // get hubNames
const hubNames = await getHubNames(message.author.id); const hubNames = await getHubNames(message.author.id);
let names = ''; let names = '';

View file

@ -4,16 +4,10 @@ const errHander = (err) => { console.error('ERROR:', err); };
// creates a embed messagetemplate for succeded actions // creates a embed messagetemplate for succeded actions
function messageSuccess(client, message, body) { function messageSuccess(client, message, body) {
client.functions.get('FUNC_MessageEmbedMessage') client.functions.get('FUNC_richEmbedMessage')
.run(client.user, message.channel, body, '', 4296754, false); .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 // creates channel DB entry
async function createHub(hubName, ownerID, maxHubs) { async function createHub(hubName, ownerID, maxHubs) {
const result = await HubName.findAndCountAll({ where: { ownerID } }).catch(errHander); 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) => { module.exports.run = async (client, message, args, config) => {
// check if in DM // 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 // get subcmd from args
const [subcmd, checkHubName] = args; const [subcmd, checkHubName] = args;
// check if hubname is present // check if hubname is present
if (!checkHubName) { if (!checkHubName) {
return messageFail(client, message, return messageFail(message,
`Command usage: `Command usage:
\`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${checkHubName || 'HUBNAME'}\`\`\``); \`\`\`${config.prefix}${module.exports.help.parent} ${subcmd} ${checkHubName || 'HUBNAME'}\`\`\``);
} }
const hubName = args.join('_').slice(subcmd.length + 1); const hubName = args.join('_').slice(subcmd.length + 1);
const fittedHubName = `${message.id}_${hubName}`; 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); const created = await createHub(fittedHubName, message.author.id, config.maxAllowedHubs);
if (created) { if (created) {
messageSuccess(client, message, messageSuccess(client, message,
`You created \`${hubName}\`! `You created \`${hubName}\`!
You can link with it by using \`${config.prefix}${module.exports.help.parent} join ${fittedHubName}\`. 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.**`); **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 = { module.exports.help = {

View file

@ -1,7 +1,7 @@
// DISABLED: not done // DISABLED: not done
module.exports.run = async (client, message, args, config) => { module.exports.run = async (client, message, args, config) => {
// check if in DM // 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'); message.reply('rnme');
// renames the hub // renames the hub
}; };

View 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',
};

View file

@ -6,7 +6,8 @@ const errHander = (err) => { console.error('ERROR:', err); };
// Deletes all messages in every channel, if its deleted in one // Deletes all messages in every channel, if its deleted in one
module.exports.run = async (guild) => { module.exports.run = async (guild) => {
guild.channels.forEach(async (channel) => { console.log(guild);
guild.channels.cache.forEach(async (channel) => {
if (!channel.type !== 'text') return; if (!channel.type !== 'text') return;
const channelID = channel.id; const channelID = channel.id;
const checkedChannel = await BridgedChannel.findOne({ attributes: ['channelID'], where: { channelID } }).catch(errHander); const checkedChannel = await BridgedChannel.findOne({ attributes: ['channelID'], where: { channelID } }).catch(errHander);

View file

@ -17,5 +17,5 @@ module.exports.run = async (user, channel, body, title, color, footer) => {
}; };
module.exports.help = { module.exports.help = {
name: 'FUNC_MessageEmbedMessage', name: 'FUNC_richEmbedMessage',
}; };

View file

@ -0,0 +1,5 @@
global.errHandler = (err) => console.error('ERROR:', err);
module.exports.help = {
name: 'GLBLFUNC_errHandler',
};

View 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',
};

View 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',
};

View 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',
};

View 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',
};

View file

@ -4,12 +4,15 @@ module.exports.run = async (client, fs, config) => {
// setting inDev var // setting inDev var
console.log(`[${module.exports.help.name}] Setting environment variables...`); console.log(`[${module.exports.help.name}] Setting environment variables...`);
if (fs.existsSync(testToken)) { 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('inDev', true);
config.env.set('token', token); config.env.set('discordToken', discordToken);
config.env.set('telegramToken', telegramToken);
} else { } else {
config.env.set('inDev', false); 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!`); console.log(`[${module.exports.help.name}] Environment variables set!`);
}; };

View file

@ -2,8 +2,6 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
// init Discord client // init Discord client
const client = new Discord.Client({ disableMentions: 'everyone' }); const client = new Discord.Client({ disableMentions: 'everyone' });
// init sequelize
const sequelize = require('sequelize');
// init filesystem // init filesystem
const fs = require('fs'); const fs = require('fs');
// init config // init config
@ -20,16 +18,19 @@ config.setup.startupFunctions.forEach((FCN) => {
INIT.run(client, fs, config); INIT.run(client, fs, config);
}); });
// create conenction to DB
require('./database/SETUP_DBConnection');
// Login the bot // Login the bot
client.login(config.env.get('token')); client.login(config.env.get('discordToken'));
// trigger on bot login // trigger on bot login
client.on('ready', () => { client.on('ready', async () => {
// confirm user logged in // confirm user logged in
console.log(`[${config.name}] Logged in as ${client.user.tag} serving ${client.guilds.cache.size} Servers!`); 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 // set bot player status
config.setup.setupFunctions.forEach((FCN) => { config.setup.setupFunctions.forEach((FCN) => {
client.functions.get(FCN).run(client, config); client.functions.get(FCN).run(client, config);

View 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

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,13 @@
{ {
"name": "i-sh", "name": "i-sh",
"version": "1.1.1", "version": "1.2.0",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"discord.js": "^12.3.1", "discord.js": "^12.3.1",
"mysql2": "^2.2.2", "mysql2": "^2.2.2",
"pretty-ms": "^5.1.0", "pretty-ms": "^5.1.0",
"sequelize": "^5.22.3" "sequelize": "^5.22.3",
"telegram-bot-api": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^6.8.0", "eslint": "^6.8.0",

View file

@ -6,7 +6,7 @@
##### How do I get started with you? ##### 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 ##### I need some help
@ -18,4 +18,4 @@
##### Source Code ##### 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/)!