Skip to content

Commit

Permalink
Merge pull request #170 from CatalysmsServerManager/niekcandaele/issu…
Browse files Browse the repository at this point in the history
…e166
  • Loading branch information
niekcandaele committed Jul 14, 2020
2 parents 38ec018 + ea1ea08 commit fb6168d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 3 deletions.
2 changes: 0 additions & 2 deletions api/hooks/discordBot/commands/sdtd/serverInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ServerInfo extends Commando.Command {

let serverInfo = await sails.helpers.loadSdtdserverInfo(sdtdServer.id);


if (!serverInfo || !serverInfo.serverInfo || !serverInfo.stats) {
return msg.channel.send(`Could not load server data. Make sure the server is online.`);
}
Expand Down Expand Up @@ -108,7 +107,6 @@ ${serverInfo.serverInfo.EACEnabled} EAC
:small_orange_diamond: Max zombies: ${serverInfo.serverInfo.MaxSpawnedZombies}
:small_orange_diamond: Blood moon enemy count: ${serverInfo.serverInfo.BloodMoonEnemyCount}
:small_orange_diamond: Land claim size: ${serverInfo.serverInfo.LandClaimSize} - Dead zone: ${serverInfo.serverInfo.LandClaimDeadZone} - Expiry date: ${serverInfo.serverInfo.LandClaimExpiryTime}
:small_orange_diamond: Game difficulty: ${serverInfo.serverInfo.GameDifficulty}
:small_orange_diamond: Drop on death: ${serverInfo.serverInfo.DropOnDeath}
:small_orange_diamond: Player killing mode: ${serverInfo.serverInfo.PlayerKillingMode}
:small_orange_diamond: Air drop frequency: ${serverInfo.serverInfo.AirDropFrequency / 24} days
Expand Down
2 changes: 1 addition & 1 deletion test/lifecycle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ before(function (done) {
csrf: false
},

port: 0,
port: 1338,

datastores: {
default: {
Expand Down
124 changes: 124 additions & 0 deletions test/unit/hooks/discordCommands/serverInfo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
const expect = require('chai').expect;
const Command = require('../../../../api/hooks/discordBot/commands/sdtd/serverInfo');
const Channel = require('discord.js').TextChannel;
const customEmbed = require('../../../../api/hooks/discordBot/util/createEmbed').CustomEmbed;

describe('Discord - serverInfo', function () {
let sendStub;
beforeEach(() => {
const serverInfoResponse = {
...sails.testServer,
stats: {
gametime: { days: 1, hours: 7, minutes: 0 },
players: 0,
hostiles: 0,
animals: 0

},
serverInfo: {

GameType: '7DTD',
GameName: 'My Game',
GameHost: 'CSMM Dev',
ServerDescription: 'A 7 Days to Die server',
ServerWebsiteURL: '',
LevelName: 'Navezgane',
GameMode: 'Survival',
Version: 'Alpha.19.0.154',
IP: '192.168.1.1',
CountryCode: 'DE',
SteamID: '90137051741492337',
CompatibilityVersion: 'Alpha 19',
Platform: 'LinuxPlayer',
ServerLoginConfirmationText: '',
Port: 26900,
CurrentPlayers: 0,
MaxPlayers: 8,
GameDifficulty: 2,
DayNightLength: 60,
BloodMoonFrequency: 7,
BloodMoonRange: 0,
BloodMoonWarning: 8,
ZombiesRun: -1,
ZombieMove: 0,

ZombieMoveNight: 3,
ZombieFeralMove: 3,
ZombieBMMove: 3,
XPMultiplier: 100,
DayCount: 3,
Ping: -1,
DropOnDeath: 1,
DropOnQuit: 0,
BloodMoonEnemyCount: 8,
EnemyDifficulty: 0,
PlayerKillingMode: 3,
CurrentServerTime: 7000,
DayLightLength: 18,
BlockDurabilityModifier: -1,
BlockDamagePlayer: 100,
BlockDamageAI: 100,
BlockDamageAIBM: 100,
AirDropFrequency: 72,
LootAbundance: 100,
LootRespawnDays: 30,
MaxSpawnedZombies: 64,
LandClaimCount: 1,
LandClaimSize: 41,
LandClaimDeadZone: 30,
LandClaimExpiryTime: 7,
LandClaimDecayMode: 0,
LandClaimOnlineDurabilityModifier: 4,
LandClaimOfflineDurabilityModifier: 4,
LandClaimOfflineDelay: 0,
PartySharedKillRange: 100,
MaxSpawnedAnimals: 50,
ServerVisibility: 2,
BedrollExpiryTime: 45,
IsDedicated: true,
IsPasswordProtected: true,
ShowFriendPlayerOnMap: true,
BuildCreate: false,
EACEnabled: true,
Architecture64: true,
StockSettings: true,
StockFiles: true,
ModdedConfig: false,

RequiresMod: false,
AirDropMarker: false,
EnemySpawnMode: true,
IsPublic: true
}
};
sandbox.stub(SdtdConfig, 'find').callsFake(() => ['some random shit']);
sandbox.stub(SdtdServer, 'findOne').callsFake(() => sails.testServer);
sendStub = sandbox.stub(Channel.prototype, 'send').callsFake(async () => null);
sandbox.stub(sails.helpers, 'loadSdtdserverInfo').callsFake(async () => serverInfoResponse);
Command.prototype.client = { customEmbed: customEmbed };
});

it('Sends a Discord message', async function () {

await Command.prototype.run(
{
guild: { id: 'doesntmatter' },
channel: new Channel({}, {})
},
{ server: 1 });

expect(Channel.prototype.send).to.have.been.calledOnce;
const sendCall = sendStub.getCall(0).firstArg;
const settings = sendCall.fields.find(_ => _.name === 'Settings');
const settingsContentArr = settings.value.split('\n').filter(_ => _.length);
expect(settingsContentArr.length).to.be.equal(settingsContentArr.filter(onlyUnique).length);
});
});

function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}




0 comments on commit fb6168d

Please sign in to comment.