Skip to content

Commit

Permalink
multiple additions & fixes
Browse files Browse the repository at this point in the history
v1.1.4
- discord.js version check added (optinal)
- error logging fixed (again)
- readme disclaimer adjusted
- issue template addded
  • Loading branch information
Jisagi committed Dec 24, 2018
1 parent 97b19dc commit 06649f2
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 29 deletions.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**Please describe the problem you are having in detail:**

Please describe the problem in as much detail as possible. Please include any thrown error codes as well.

**Additional information:**

- Node.js version:
- Operating system:
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ node_modules/
package-lock.json

# Miscellaneous
guildData.json
guildData*.json
logs/
.vscode/
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
## Information
Did you ever want to create a copy of a guild? Now you can! There is no need to manually create roles, channels and permissions, which can take very long depending on the original guilds size. The script does everything for you. It backs up a guild into a single file and lets you create a new guild from it. You can share your file with others, too.

The following guide is also available in [french](https://github.com/Jisagi/Discord-guild-copy/blob/master/README.fr.md) thanks to TheLightSpirit.

### What will be copied
- Categories
- Text & Voice channels
Expand All @@ -29,9 +27,7 @@ The following guide is also available in [french](https://github.com/Jisagi/Disc
- A preferably empty guild which can be overwritten

## Disclaimer
**_Use this script at your own risk!_**

According to the recent [statement](https://support.discordapp.com/hc/en-us/articles/115002192352-Automated-user-accounts-self-bots000000) of the discord team, any kind of user accounts including so called SelfBots are forbidden. The script must be run with a bot user token.
**The script must be run with a bot user token.** According to discords [statement](https://support.discordapp.com/hc/en-us/articles/115002192352-Automated-user-accounts-self-bots000000), any kind of user account botting including so called SelfBots are forbidden. The script will therefore block the execution with a user account token.

## Installation & Usage
1. Download the repository from github
Expand All @@ -49,11 +45,12 @@ To get the id of a guild open your client settings -> Appearance and then enable
| originalGuildId | The id of the guild you want to clone. Can be left blank if a guildData.json already exists. |
| newGuildId | The id of the new guild you want to clone to. |
| newGuildAdminRoleId | The id of a role with administrator permissions. The bot needs to have this role on the new guild! You can manually create a new role called 'guildcopy' and the script will automatically use it. If you do so, just leave this field empty. |
| copyEmojis | default: false - set to true to copy emojis (see also [Common Behaviour](https://github.com/Jisagi/Discord-guild-copy#common-behaviour)) |
| copyEmojis | default: false - Set to true to copy emojis (see also [Common Behaviour](https://github.com/Jisagi/Discord-guild-copy#common-behaviour)) |
| copyBans | default: false - set to true to copy banned users The bot needs to have the BAN_MEMBERS permission on the original guild if you enable this! |
| language | default: en - set this to any supported language from the `translations` folder |
| language | default: en - Set this to any supported language from the `translations` folder |
| output | default: all - Possible values: `all` for everything, `error` for errors only, `none` for no output at all |
| debug | default: false - set to true for a more detailed general and error output e.g. when creating an issue |
| djsVersionCheck | default: true - Checks the local discord.js version by its commit hash. If you periodically run this script, you might want to disable this |
| debug | default: false - Set to true for a more detailed general and error output e.g. when creating an issue |
| token | Your account token. The bot does not need any permissions on the original guild (only exception: copyBans=true). |

## Common Behaviour
Expand Down Expand Up @@ -84,5 +81,5 @@ This software is licensed under the terms of the GPLv3. For more details see [LI

## Credits
- [EmberVulpix](https://github.com/EmberVulpix) for the command line arguments
- [TheLightSpirit](https://github.com/TheLightSpirit) for the french README translation
- [TheLightSpirit](https://github.com/TheLightSpirit) for the french README translation (not always up-to-date)
- Everybody who helps adding new features and finding bugs!
20 changes: 13 additions & 7 deletions copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ client.on('ready', async () => {
let guildData = { step: 1 };

try {
// npm v5 check (included since node v8)
if (!fs.existsSync('package-lock.json')) throw new Error(Translator.disp('errorNPM1'));

// Check discord.js version
let djsVersion = require('./node_modules/discord.js/package.json').version;
if (djsVersion !== '12.0.0-dev') throw new Error(Translator.disp('errorNPM'));
if (settings.djsVersionCheck) {
let djs = require('./package-lock.json').dependencies['discord.js'].version;
let localVersion = djs.split('#')[1];
let latestVersion = await VersionControl.checkLibraryVersion(Translator);
if (localVersion !== latestVersion.sha) throw new Error(Translator.disp('errorNPM2'));
Logger.logMessage(Translator.disp('messageDjsVersionCheckSuccess'));
}

// Check script version
let { version } = require('./package.json');
Expand All @@ -52,7 +60,7 @@ client.on('ready', async () => {
});
if (result.error) Logger.logMessage(Translator.disp('errorVersionCheckOther', [result.error]))
else if (version !== result.version) throw new Error(Translator.disp('errorVersionCheckOutdated', [version, result.version]));
if (!result.error) Logger.logMessage(Translator.disp('messageVersionCheckSuccess'));
if (!result.error) Logger.logMessage(Translator.disp('messageScriptVersionCheckSuccess'));

// Settings Validation only on restore or clone
let data = { changed: false };
Expand Down Expand Up @@ -101,9 +109,7 @@ client.on('ready', async () => {

client.on('rateLimit', rateLimitObj => {
if (settings.debug) {
Logger.logError(`Rate limit reached!\nTimeout: ${rateLimitObj.timeout}\nLimit: ${rateLimitObj.limit}\n` +
`TimeDiff: ${rateLimitObj.timeDifference}\nMethod: ${rateLimitObj.method}\nPath: ${rateLimitObj.path}\n` +
`Route: ${rateLimitObj.route}`);
Logger.logError(`Rate limit reached! Method: ${rateLimitObj.method}, Path: ${rateLimitObj.path}`);
}
});

Expand All @@ -118,7 +124,7 @@ function printUsage() {
}

function main() {
const args = process.argv.slice(2)
const args = process.argv.slice(2);
if (args.length < 1 || !['backup', 'restore', 'clone'].includes(args[0])) {
printUsage();
} else if (args.length >= 2 && ['backup', 'restore'].includes(args[0])) {
Expand Down
2 changes: 1 addition & 1 deletion objects/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Logger {

static logError(error) {
try {
if (output === 'all' || output === 'error') console.error(debug ? error.stack : error.message || error);
if (output === 'all' || output === 'error') console.error(debug ? error.stack || error : error.message || error);
if (!fs.existsSync(logFolder)) fs.mkdirSync(logFolder);
fs.appendFileSync(`${logFolder}/errors.log`, `[${getDateString()}] ${error.stack || error.message || error}\n`);
} catch (err) {
Expand Down
34 changes: 31 additions & 3 deletions objects/versioncontrol.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
const request = require('request');

class VersionControl {
/**
* Discord.js version check.
* @param {Object} Translator Translator object
*/
static checkLibraryVersion(Translator) {
return new Promise(async (resolve, reject) => {
let link = 'https://api.github.com/repos/hydrabolt/discord.js/commits/master';
let result = await this.requestVersion(Translator, link).catch(err => reject(err));
resolve(result);
});
}

/**
* Online version check.
* @param {Object} translator Translator object
* @param {Object} Translator Translator object
*/
static checkVersion(Translator) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
let link = 'http://guildcopy.jisagi.net/version';
request(link, (err, res, body) => {
let result = await this.requestVersion(Translator, link).catch(err => reject(err));
resolve(result);
});
}

/**
* Utility method
* @param {Object} Translator Translator object
* @param {string} link request link
*/
static requestVersion(Translator, link) {
return new Promise((resolve, reject) => {
let opt = {
url: link,
//headers: { 'User-Agent': 'request' },
};
request(opt, (err, res, body) => {
if (err) return reject(err);
if (res.statusCode !== 200) return reject(Translator.disp('errorVersionCheckStatuscode', [res.statusCode]));
try {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "guildcopy",
"version": "1.1.3",
"version": "1.1.4",
"description": "A tool to copy a discord guild",
"main": "copy.js",
"scripts": {
Expand All @@ -10,6 +10,6 @@
"license": "GPL-3.0",
"dependencies": {
"discord.js": "git://github.com/hydrabolt/discord.js.git#master",
"request": "^2.87.0"
"request": "^2.88.0"
}
}
1 change: 1 addition & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"copyBans": false,
"language": "en",
"output": "all",
"djsVersionCheck": true,
"debug": false,
"token": ""
}
7 changes: 4 additions & 3 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"text": {
"messsageLogin": "Erfolgreich eingeloggt als [@@1@@]. Starte Skript",
"messageLanguageAuthor": "Sprache [@@1@@] ausgewählt. Übersetzt von [@@2@@]",
"messageVersionCheckSuccess": "Aktuellste Sriptversion installiert",
"messageScriptVersionCheckSuccess": "Aktuellste Skriptversion installiert",
"messageDjsVersionCheckSuccess": "Aktuellste discord.js Version installiert",
"messageSerialized": "[@@1@@]. Serialisierte Daten wurden gefunden und werden genutzt",
"messageSerializerGeneralData": "[@@1@@]. Serialisiere allgemeine Daten",
"messageSerializerRoleData": "[@@1@@]. Serialisiere Rollen",
Expand Down Expand Up @@ -42,10 +43,10 @@
"messageCreatorBanData": "[@@1@@]. Banne Nutzer",
"messageCreatorBanDataDebug": "[@@1@@].[@@2@@] Nutzer [@@3@@] gebannt",
"messageGuildCopyFinished": "Servererstellung beendet!\nDie `[@@1@@]` Rolle kann nun gelöscht werden",

"errorOutputParameter": "Ausgabeparameter nicht valide",
"errorUserToken": "Das genutzte Token ist kein Bot Token",
"errorNPM": "Discord.js wurde nicht mittels 'npm install' installiert. Genauere Information gibt es in der README.de",
"errorNPM1": "Bitte update deine Nodejs version auf mindestens Version 8.0.0",
"errorNPM2": "Du hast nicht die aktuellste Version von discord.js. Lösche den 'node_modules' Ordner und die 'package-lock.json' and installiere danach mittels 'npm install' alles neu",
"errorUnspecified": "fehlgeschlagen",
"errorVersionCheckStatuscode": "Versionsüberprüfung fehlgeschlagen mit Statuscode: [@@1@@]",
"errorVersionCheckParsing": "Versionsüberprüfung fehlgeschlagen: Anfrage konnte nicht analysiert werden",
Expand Down
7 changes: 4 additions & 3 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"text": {
"messsageLogin": "Successfully logged in as [@@1@@]. Starting script",
"messageLanguageAuthor": "Language [@@1@@] selected. Translated by [@@2@@]",
"messageVersionCheckSuccess": "Latest script version installed",
"messageScriptVersionCheckSuccess": "Latest script version installed",
"messageDjsVersionCheckSuccess": "Latest discord.js version installed",
"messageSerialized": "[@@1@@]. Serialized data was found and will be used",
"messageSerializerGeneralData": "[@@1@@]. Serializing general data",
"messageSerializerRoleData": "[@@1@@]. Serializing role data",
Expand Down Expand Up @@ -42,10 +43,10 @@
"messageCreatorBanData": "[@@1@@]. Banning user(s)",
"messageCreatorBanDataDebug": "[@@1@@].[@@2@@] Banned user [@@3@@]",
"messageGuildCopyFinished": "Guild copy finished!\nThe last thing to do is to delete the `[@@1@@]` role",

"errorOutputParameter": "Output parameter not valid",
"errorUserToken": "Specified user token is not a bot user token",
"errorNPM": "Please don't install discord.js with 'npm install discord.js'! Installation instructions are in the README",
"errorNPM1": "Please update your Nodejs version to 8.0.0 or higher",
"errorNPM2": "You don't have the latest version of discord.js installed. Please delete the 'node_modules' folder and the 'package-lock.json' and run 'npm install' again",
"errorUnspecified": "failed",
"errorVersionCheckStatuscode": "Version check failed with statuscode: [@@1@@]",
"errorVersionCheckParsing": "Version check failed: Failed to parse request",
Expand Down

0 comments on commit 06649f2

Please sign in to comment.