Skip to content

Add support for true edits and deletes through webhooks #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ typings/

# next.js build output
.next

.gitignore
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Supports message delete, update, lock command...
- lock all - Lock all channels in the network: `c!lock all`
- unlock - Unlock the current channel: `c!unlock`
- unlock all - Unlock all channels: `c!unlock all`
- commands are usable by poeple with roles in managerRoles only.
- commands are usable by poeple that have one of the roles in the `managerRoles` field in the config.

## Setup

Clone this repository.
Run `npm install` or `yarn`.

Copy and paste `config.template.json` as `config.json`.
Enter your bot token and all correct informations:
Enter your bot token and all correct information:

```js
{
Expand All @@ -41,8 +41,8 @@ Enter your bot token and all correct informations:
},
"messageDelete": true,
"deleteOnUpdate": true,
"guilds": {
"youGuildName": {
"guilds": [
{
"name": "name",
"identifier": "",
"guildID": "111111",
Expand All @@ -53,7 +53,7 @@ Enter your bot token and all correct informations:
"ignoreBots": true,
"managerRoles": []
},
"otherGuildName": {
{
"name": "name",
"identifier": "",
"guildID": "444444",
Expand All @@ -64,7 +64,7 @@ Enter your bot token and all correct informations:
"ignoreBots": true,
"managerRoles": []
}
}
]
}
```

Expand Down
6 changes: 1 addition & 5 deletions config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"role": false,
"channel": false
},
"prefix": "c!",
"messageDelete": true,
"deleteOnUpdate": true,

"guilds": [
{
"name": "name",
Expand All @@ -18,7 +16,6 @@
"whToken": "",
"ignoreAll": false,
"ignoreBots": true,
"managerRoles": []
},
{
"name": "name2",
Expand All @@ -29,7 +26,6 @@
"whToken": "",
"ignoreAll": false,
"ignoreBots": true,
"managerRoles": []
}
]
}
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ const config = require('./config.json');
const { bot } = require('./src/bot');
const { setup } = require('./src/index');

function formatDate() {
const date = new Date();

return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} - ${date.getHours()}:${date.getMinutes()}`;
}

setup(bot, config);

bot.connect();

bot.on('error', (err) => console.log(`${formatDate()} : ${err.stack || err.message}`) );
bot.on('warn', (msg) => console.log(`${formatDate()} : ${msg}`) );
bot.on('error', (err) => console.log(`${err.stack || err.message}`));
bot.on('warn', (msg) => console.log(`${msg}`));
14 changes: 7 additions & 7 deletions package-lock.json

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

56 changes: 28 additions & 28 deletions src/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ class Resolver {
throw new Error('RESOLVER [user]: All the arguments are either not given or false.');
}
// Checking if args is an array, if it is not, converting it to an array.
if (!Array.isArray(args) ) {
if (!Array.isArray(args)) {
args = `${args}`.split(' ');
}

args.all = args.join(' ');
args.lower = args.all.toLowerCase();
const { users } = client;

const mention = REGEXES.userMention.exec(args[0] );
const mention = REGEXES.userMention.exec(args[0]);

const user = ( (mention && mention[1] ) && users.get(mention[1] ) ) // User mention
|| (REGEXES.id.test(args[0] ) && users.get(args[0] ) ) // User ID
|| (args.all.indexOf('#') > -1 && users.find(u => `${u.username}#${u.discriminator}` === args.all) ) // Username + discrim
const user = ((mention && mention[1] ) && users.get(mention[1])) // User mention
|| (REGEXES.id.test(args[0]) && users.get(args[0])) // User ID
|| (args.all.indexOf('#') > -1 && users.find(u => `${u.username}#${u.discriminator}` === args.all)) // Username + discrim
|| users.find(u => u.username === args.all) // Username
|| users.find(u => u.username.toLowerCase() === args.lower) // Username lowercase
|| users.find(u => u.username.includes(args.all) ) // Username includes
|| users.find(u => u.username.toLowerCase().includes(args.lower) ) // Username lowercase includes
|| users.find(u => u.username.includes(args.all)) // Username includes
|| users.find(u => u.username.toLowerCase().includes(args.lower)) // Username lowercase includes
|| null;// No users found

return user; // Return the user object.
Expand All @@ -63,7 +63,7 @@ class Resolver {
throw new Error('RESOLVER [member]: All the arguments are either not given or false.');
}
// Checking if args is an array, if it is not, converting it to an array.
if (!Array.isArray(args) ) {
if (!Array.isArray(args)) {
args = `${args}`.split(' ');
}

Expand All @@ -73,17 +73,17 @@ class Resolver {

const mention = REGEXES.userMention.exec(args[0] );

const member = ( (mention && mention[1] ) && members.get(mention[1] ) ) // User mention
|| (REGEXES.id.test(args[0] ) && members.get(args[0] ) ) // User ID
|| (args.all.indexOf('#') > -1 && members.find(m => `${m.username}#${m.discriminator}` === args.all) ) // Username + discrim
const member = ((mention && mention[1]) && members.get(mention[1])) // User mention
|| (REGEXES.id.test(args[0]) && members.get(args[0])) // User ID
|| (args.all.indexOf('#') > -1 && members.find(m => `${m.username}#${m.discriminator}` === args.all)) // Username + discrim
|| members.find(m => m.username === args.all) // Username
|| members.find(m => m.nick === args.all) // nickname
|| members.find(m => m.username.toLowerCase() === args.lower) // Username lowercase
|| members.find(m => m.nick && m.nick.toLowerCase() === args.lower) // nickname lowercase
// members.find(m => m.username.includes(args.all) ) || // Username includes
// members.find(m => m.nick && m.nick.includes(args.all) ) || // nickname includes
|| members.find(m => m.username.toLowerCase().includes(args.lower) ) // username lowercase includes
|| members.find(m => m.nick && m.nick.toLowerCase().includes(args.lower) ) // nickname lowercase includes
|| members.find(m => m.username.toLowerCase().includes(args.lower)) // username lowercase includes
|| members.find(m => m.nick && m.nick.toLowerCase().includes(args.lower)) // nickname lowercase includes
|| null; // No member found

return member; // Return the member object.
Expand All @@ -103,22 +103,22 @@ class Resolver {
}

// Checking if args is an array, if it is not, converting it to an array.
if (!Array.isArray(args) ) {
if (!Array.isArray(args)) {
args = `${args}`.split(' ');
}

args.all = args.join(' ');
args.lower = args.all.toLowerCase();
const { roles } = guild;

const mention = REGEXES.roleMention.exec(args[0] );
const mention = REGEXES.roleMention.exec(args[0]);

const role = ( (mention && mention[1] ) && roles.get(mention[1] ) ) // mention
|| (REGEXES.id.test(args[0] ) && roles.get(args[0] ) ) // id
const role = ((mention && mention[1]) && roles.get(mention[1])) // mention
|| (REGEXES.id.test(args[0]) && roles.get(args[0])) // id
|| roles.find(m => m.name === args.all) // name
|| roles.find(m => m.name.toLowerCase() === args.lower) // name lower
|| roles.find(m => m.name.includes(args.all) ) // name includes
|| roles.find(m => m.name.toLowerCase().includes(args.lower) ) // name loxer includes
|| roles.find(m => m.name.includes(args.all)) // name includes
|| roles.find(m => m.name.toLowerCase().includes(args.lower)) // name loxer includes
|| null; // no role found

return role;
Expand All @@ -138,22 +138,22 @@ class Resolver {
}

// Checking if args is an array, if it is not, converting it to an array.
if (!Array.isArray(args) ) {
if (!Array.isArray(args)) {
args = `${args}`.split(' ');
}

args.all = args.join(' ');
args.lower = args.all.toLowerCase();
const { channels } = guild;

const mention = REGEXES.channelMention.exec(args[0] );
const mention = REGEXES.channelMention.exec(args[0]);

const channel = ( (mention && mention[1] ) && channels.get(mention[1] ) )
|| (REGEXES.id.test(args[0] ) && channels.get(args[0] ) )
const channel = ((mention && mention[1]) && channels.get(mention[1]))
|| (REGEXES.id.test(args[0]) && channels.get(args[0]))
|| channels.find(c => c.name === args.all) // name
|| channels.find(c => c.name.toLowerCase() === args.lower) // name lower
|| channels.find(c => c.name.includes(args.all) ) // name includes
|| channels.find(c => c.name.toLowerCase().includes(args.lower) ) // name lower includes
|| channels.find(c => c.name.includes(args.all)) // name includes
|| channels.find(c => c.name.toLowerCase().includes(args.lower)) // name lower includes
|| null; // no channel found

return channel;
Expand All @@ -176,11 +176,11 @@ class Resolver {
args.all = args.join(' ');
args.lower = args.all.toLowerCase();

const guild = (REGEXES.id.test(args[0] ) && guilds.find(g => g.id === args[0] ) ) // ID
const guild = (REGEXES.id.test(args[0]) && guilds.find(g => g.id === args[0])) // ID
|| guilds.find(g => g.name === args.all) // Name
|| guilds.find(g => g.name.toLowerCase() === args.lower) // Lowercase name
|| guilds.find(g => g.name.includes(args.all) ) // Includes name
|| guilds.find(g => g.name.toLowerCase().includes(args.lower) ) // Includes lowercase name
|| guilds.find(g => g.name.includes(args.all)) // Includes name
|| guilds.find(g => g.name.toLowerCase().includes(args.lower)) // Includes lowercase name
|| null;

return guild;
Expand Down
8 changes: 7 additions & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ exports.bot = new Client(config.token, {
defaultImageFormat: 'png',
defaultImageSize: 1024,
autoreconnect: true,
messageLimit: 25,
messageLimit: 1000,
getAllUsers: true,
intents: [
"guilds",
"guildMessages",
"guildMembers",
],
} );

7 changes: 0 additions & 7 deletions src/commands/index.js

This file was deleted.

29 changes: 0 additions & 29 deletions src/commands/lock.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/commands/purge.js

This file was deleted.

29 changes: 0 additions & 29 deletions src/commands/unlock.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/enhancedMention.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ function parse(content, guild) {
let resolved = null;
if (res[1] === '@') {
resolved = ENHANCED_MENTION_CONFIG.role
? Resolver.role(guild, res[2] )
? Resolver.role(guild, res[2])
: null;
if (resolved) {
return resolved.mention;
}

resolved = ENHANCED_MENTION_CONFIG.user
? Resolver.member(guild, res[2] )
? Resolver.member(guild, res[2])
: null;
if (resolved) {
return resolved.mention;
}
return content;
}
if (ENHANCED_MENTION_CONFIG.channel && res[1] === '#') {
resolved = Resolver.channel(guild, res[2] );
resolved = Resolver.channel(guild, res[2]);
return resolved
? resolved.mention
: content;
Expand All @@ -130,7 +130,7 @@ exports.deconstructMention = function (content, guild) {
for (const e of contentArr) {
const res = e.match(MENTION_REGEX);
res
? final.push(extractMention(res, guild) )
? final.push(extractMention(res, guild))
: final.push(e);
}
return final;
Expand Down
Loading