Skip to content

Commit

Permalink
Merge pull request #2 from AstroGD/update-202104-1
Browse files Browse the repository at this point in the history
April 2021 Update
  • Loading branch information
AstroGD authored Apr 11, 2021
2 parents 4410919 + 4ddb382 commit a212416
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 118 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Discord Bot Mainframe + Discord Accept Rules Module
# Discord Accept Rules

This is version 2.0.0 of my Discord Bot Mainframe with my Discord Accept Rules Module installed
Discord Accept Rules is a simple Discord Bot that let's members get a role by clicking on a reaction.
While this can be used in many different ways, the most common is to get access to a server after verifying and agreeing to the servers rules.

This is a simple bot with just one use case - No overloaded functionality and not resource-heavy

## Installation

Expand Down
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# V2.2.0
#### Released: 11.04.2021

## New
:memo: Add changelog.md

## Changes
:recycle: Refactor software version checks to simplify update notifications
:memo: Update Readme for the separation of no longer supported mainframe

## Dependency updates
:arrow_up: discord.js to 12.5.3
:arrow_up: follow-redirects to 1.13.3
23 changes: 8 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/**
* Discord Bot Mainframe
* @version 2.0.0
* @author AstroGD - https://www.astrogd.eu
* @since 2018-07-15
*/

const scriptName = 'main.js',
version = '2.0.0';
const scriptName = 'main.js';

//Required Modules and Files
const Discord = require("discord.js");
const config = require(`${__dirname}/config/config.json`);
const fs = require("fs-extra");
const readline = require("readline");
const package = require(`${__dirname}/package.json`);

//Instances
const client = new Discord.Client();
Expand All @@ -23,7 +22,7 @@ const rl = readline.createInterface({
rl.setPrompt("> ");

//Required Scripts
const tools = require(`${__dirname}/tools/tools.js`)(Discord, client, fs, __dirname, version);
const tools = require(`${__dirname}/tools/tools.js`)(Discord, client, fs, __dirname);

//Module Definition
const discord_accept_rules_bot = require(`${__dirname}/modules/discord-accept-rules-bot.js`)(client, fs, tools, __dirname);
Expand Down Expand Up @@ -78,11 +77,9 @@ async function init() {
if (!VERSIONINFO) {
tools.log(scriptName, "Version couldn't be fetched. Make sure you have a connection to the internet and access to software.astrogd.eu", 1);
} else {
if (tools.isVersionLower(VERSIONINFO.version, version)) tools.log(scriptName, `Theres a new version available for Discord Mainframe (${version} --> ${VERSIONINFO.version})`, 2);
if (tools.isVersionLower(VERSIONINFO.version, package.version)) tools.log(scriptName, `Theres a new version available for Discord accept rules bot by AstroGD (${package.version} --> ${VERSIONINFO.version})`, 2);
}

tools.checkToolsVersion();

tools.log(scriptName, "Logging in...");
try {
await client.login(config.token);
Expand All @@ -101,14 +98,11 @@ async function checkVersion() {
}

let newVerAvailable = false;
if (tools.isVersionLower(VERSIONINFO.version, version)) {
tools.log(scriptName, `Theres a new version available for Discord Mainframe (${version} --> ${VERSIONINFO.version})`, 2);
if (tools.isVersionLower(VERSIONINFO.version, package.version)) {
tools.log(scriptName, `Theres a new version available for Discord accept rules bot by AstroGD (${package.version} --> ${VERSIONINFO.version})`, 2);
newVerAvailable = true;
}

if (tools.checkToolsVersion()) newVerAvailable = true;
if (discord_accept_rules_bot.checkVersion()) newVerAvailable = true;

return newVerAvailable;
}

Expand Down Expand Up @@ -149,8 +143,7 @@ rl.on("line", async (input) => {
console.log(`===== Discord Bot Mainframe Commands\n\nshutdown: Deactivates all correctly installed Modules and shuts the bot down\ncheckversion: Checks if there is a new version available\nhelp: Displays all commands available from Modules or Mainframe\nreloaddb: Reloads Database. Use only if changes were made manually\nreloadconfig: Reloads Config. Use only if changes were made manually\n\n=====`);
break;
case "checkversion":
if (await checkVersion()) console.log("One or more Modules need an update!");
else console.log("Everythings up to date!");
if (!await checkVersion()) console.log("Everythings up to date!");
break;
default:
if (!success) {
Expand All @@ -165,5 +158,5 @@ rl.on("line", async (input) => {
});

rl.pause();
console.log(`Starting ${scriptName} V${version}...`);
console.log(`Starting ${scriptName} V${package.version}...`);
init();
31 changes: 6 additions & 25 deletions modules/discord-accept-rules-bot.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
/**
* Discord Accept Rules Bot
* @version 2.1.2
* @author AstroGD - https://www.astrogd.eu
* @since 2018-07-15
*/

var scriptName = "modules.discord-accept-rules-bot.js",
version = "2.1.2",
mainframeMinVersion = "2.0.0";

const path = require("path");
const scriptName = "modules.discord-accept-rules-bot.js";
const package = require(path.join(__dirname, "../package.json"));

module.exports = function (client, fs, tools, dir) {

var config;

async function init(deactivated) {
tools.log(scriptName, `Initializing ${scriptName} V${version}`);
tools.log(scriptName, `Initializing ${scriptName} V${package.version}`);

this.intialized = true;

if (tools.checkMainframeVersion(mainframeMinVersion)) {
this.initialized = true;
} else {
tools.log(scriptName, `This Module requires a Mainframe Version of ${mainframeMaxVersion} or higher. Please update your Mainframe. This Module is not being activated.`, 2);
return;
}
if (!deactivated) {
this.activated = true;
}

if (tools.isVersionLower(VERSIONINFO.packages.acceptRulesBot, version)) tools.log(scriptName, `Theres a new version available for Discord Accept Rules Module (${version} --> ${VERSIONINFO.packages.acceptRulesBot})`, 2);

this.db = JSON.parse(fs.readFileSync(`${dir}/db/discord-accept-rules-bot.db`, "utf-8"));
this.config = checkConfigVersion(require(`${dir}/config/discord-accept-rules-bot.json`));
config = this.config;
Expand Down Expand Up @@ -277,15 +268,6 @@ module.exports = function (client, fs, tools, dir) {
}
}

function checkVersion() {
if (tools.isVersionLower(VERSIONINFO.packages.acceptRulesBot, version)) {
tools.log(scriptName, `Theres a new version available for Discord Accept Rules Module (${version} --> ${VERSIONINFO.packages.acceptRulesBot})`, 2);
return true;
}

return false;
}

function checkConfigVersion(config) {
if (config.hasOwnProperty("version") && config.version >= 2) return config;
config.version = 2;
Expand Down Expand Up @@ -328,7 +310,6 @@ module.exports = function (client, fs, tools, dir) {
init,
activate,
deactivate,
command,
checkVersion
command
}
}
42 changes: 21 additions & 21 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-accept-rules-bot",
"version": "2.1.4",
"version": "2.2.0",
"description": "Let your Members accept the rules first and then give them a role",
"main": "main.js",
"scripts": {
Expand All @@ -18,8 +18,8 @@
},
"homepage": "https://github.com/AstroGD/discord-accept-rules-bot#readme",
"dependencies": {
"discord.js": "^12.5.1",
"follow-redirects": "^1.13.2",
"discord.js": "^12.5.3",
"follow-redirects": "^1.13.3",
"fs-extra": "^9.1.0"
}
}
67 changes: 15 additions & 52 deletions tools/tools.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* Tools js
* @version 2.0.3
* @author AstroGD - https://www.astrogd.eu
* @since 2018-07-15
*/
var scriptName = "tools.js",
version = "2.0.3",
mainframeMinVersion = "2.0.0";
var scriptName = "tools.js";
const path = require("path");

module.exports = function (Discord, client, fs, dir, mainframeversion) {
module.exports = function (Discord, client, fs, dir) {
const package = require(path.join(__dirname, "../package.json"));

async function init() {
let currdate = new Date();
Expand All @@ -17,24 +16,10 @@ module.exports = function (Discord, client, fs, dir, mainframeversion) {
await fs.ensureDirSync(`${dir}/log/`);
this.stream = await fs.createWriteStream(`${dir}/log/${this.startupdate}.log`);

let mainframeversion_check = mainframeversion.split(".");
let mainframeversion_min = mainframeMinVersion.split(".");
let mainframeversion_allowed = false;
this.initialized = true;

if (mainframeversion_check[0] > mainframeversion_min[0]) mainframeversion_allowed = true;
if (mainframeversion_check[0] == mainframeversion_min[0] && mainframeversion_check[1] > mainframeversion_min[1]) mainframeversion_allowed = true;
if (mainframeversion_check[0] == mainframeversion_min[0] && mainframeversion_check[1] == mainframeversion_min[1] && mainframeversion_check[2] > mainframeversion_min[2]) mainframeversion_allowed = true;
if (mainframeversion_check[0] == mainframeversion_min[0] && mainframeversion_check[1] == mainframeversion_min[1] && mainframeversion_check[2] == mainframeversion_min[2]) mainframeversion_allowed = true;

if (!mainframeversion_allowed) {
this.stream.write(`[${scriptName}] WARN This Module requires a Mainframe Version of ${mainframeversion_min.join(".")} or higher. Please update your Mainframe. This Module is not being activated.`);
throw new Error(`[${scriptName}] This Module requires a Mainframe Version of ${mainframeversion_min.join(".")} or higher. Please update your Mainframe. This Module is not being activated.`);
} else {
this.initialized = true;
}

this.stream.write(`[${this.startupdate}] INFO [${scriptName}] ${scriptName} V${version} initialized\n`);
console.log(`[${this.startupdate}] INFO [${scriptName}] ${scriptName} V${version} initialized`);
this.stream.write(`[${this.startupdate}] INFO [${scriptName}] ${scriptName} V${package.version} initialized\n`);
console.log(`[${this.startupdate}] INFO [${scriptName}] ${scriptName} V${package.version} initialized`);
}

function log(x, msg, state) {
Expand Down Expand Up @@ -94,23 +79,6 @@ module.exports = function (Discord, client, fs, dir, mainframeversion) {
}
}

function checkMainframeVersion(minVersion) {
let mainframeversion_check = mainframeversion.split(".");
let mainframeversion_min = minVersion.split(".");
let mainframeversion_allowed = false;

if (mainframeversion_check[0] > mainframeversion_min[0]) mainframeversion_allowed = true;
if (mainframeversion_check[0] == mainframeversion_min[0] && mainframeversion_check[1] > mainframeversion_min[1]) mainframeversion_allowed = true;
if (mainframeversion_check[0] == mainframeversion_min[0] && mainframeversion_check[1] == mainframeversion_min[1] && mainframeversion_check[2] > mainframeversion_min[2]) mainframeversion_allowed = true;
if (mainframeversion_check[0] == mainframeversion_min[0] && mainframeversion_check[1] == mainframeversion_min[1] && mainframeversion_check[2] == mainframeversion_min[2]) mainframeversion_allowed = true;

if (!mainframeversion_allowed) {
return false;
} else {
return true;
}
}

function isVersionLower(base, check) {
base = base.split(".");
check = check.split(".");
Expand Down Expand Up @@ -158,7 +126,7 @@ module.exports = function (Discord, client, fs, dir, mainframeversion) {
var options = {
'method': 'GET',
'hostname': 'software.astrogd.eu',
'path': '/mainframe/version.json',
'path': '/accept-rules/version.json',
'headers': {},
'maxRedirects': 20
};
Expand Down Expand Up @@ -198,29 +166,24 @@ module.exports = function (Discord, client, fs, dir, mainframeversion) {
return null;

}
versionInfo = JSON.parse(versionInfo.toString());

return versionInfo;
}

function checkToolsVersion() {
if (isVersionLower(VERSIONINFO.packages.tools, version)) {
this.log(scriptName, `Theres a new version available for Mainframe Tools (${version} --> ${VERSIONINFO.packages.tools})`, 2);
return true;
try {
versionInfo = JSON.parse(versionInfo.toString());
} catch (error) {
this.log(scriptName, `Something went wrong while checking for a newer version. Please check the repository manually to see if there is a new version available.`, 1);
return null;
}

return false;
return versionInfo;
}

return {
init,
log,
logFile,
command,
checkMainframeVersion,
makeEmbed,
checkVersion,
isVersionLower,
checkToolsVersion
isVersionLower
}
}

0 comments on commit a212416

Please sign in to comment.