Skip to content

Commit

Permalink
Merge branch 'dota-feature-multiple-steam-bots'
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit ff26b5d
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Sat Jan 14 17:15:09 2017 +0100

    Works apparently.

commit bed8095
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Fri Jan 13 11:34:17 2017 +0100

    small progress

commit 07a80e5
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Thu Jan 12 20:47:31 2017 +0100

    Fixed some things + status command (untested)

commit 5594b93
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Thu Jan 12 14:06:28 2017 +0100

    Seems to work now

commit e864b89
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Thu Jan 12 13:26:51 2017 +0100

    Getting an error on lobby creation

commit 100c4df
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Wed Jan 11 20:41:56 2017 +0100

    Still a wip...

commit 64bb4e1
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Wed Jan 11 13:30:49 2017 +0100

    Forgot to upload the next version sql changes

commit 977b5cb
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Wed Jan 11 13:29:45 2017 +0100

    Still a wip

    I'm making soooooo much changes without testing, but I can't right now. Debugging is gonna be fun.

commit 403bf75
Merge: 227c59a 4b005fd
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Wed Jan 11 12:01:08 2017 +0100

    Merge branch 'dota-dev' into dota-feature-multiple-steam-bots

commit 227c59a
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Sat Jan 7 14:22:57 2017 +0100

    Still a work in progress

    Rewriting the dotahandler module.

commit 5d1aa84
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Fri Jan 6 21:38:12 2017 +0100

    Doesn't work so far

commit a95b25e
Author: Pablo Rodríguez <pabloviolin8@gmail.com>
Date:   Fri Jan 6 13:28:27 2017 +0100

    Changed scripts to work with multiple bots
  • Loading branch information
MeLlamoPablo committed Jan 14, 2017
1 parent 4b005fd commit 021bae7
Show file tree
Hide file tree
Showing 22 changed files with 1,288 additions and 571 deletions.
24 changes: 19 additions & 5 deletions lib/commands/admin/force-lobby-start.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
"use strict";

const Clapp = require('../../modules/clapp-discord/index');
const Clapp = require("../../modules/clapp-discord")
, ECloseLobbyError = require("../../structures/enums/ECloseLobbyError")
, db = require("../../modules/dbhandler").events
;

module.exports = new Clapp.Command({
name: "force-lobby-start",
desc: "Forces the current lobby to start, even if there aren't enough players.",
desc: "Forces the lobby for the specified event to start, even if there aren't enough players.",
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
context.dotaHandler.forceStart().catch(reject);
fulfill("Forced current lobby start");
db.events.get(argv.args.event).then(event => {
if (event !== null) {
db.events.getLobbyBotId(event)
.then(botID => context.dotaHandler.forceLobbyStart(botID))
.then(() => fulfill(`Forced lobby start for the event ${event.id}.`))
.catch(reject);
} else {
fulfill("Error: the specified event `" + argv.args.event + "` doesn't exist.");
}
}).catch(reject);
});
}
},
args: [
require("./shared/event")
]
});
42 changes: 27 additions & 15 deletions lib/commands/admin/get-lobby.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
"use strict";

const Clapp = require('../../modules/clapp-discord/index');
const Clapp = require("../../modules/clapp-discord")
, db = require("../../modules/dbhandler").events
;

module.exports = new Clapp.Command({
name: "get-lobby",
desc: "Gets the current lobby name and password sent to you on a DM",
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let lobby = context.dotaHandler.currentLobbyName;
let pass = context.dotaHandler.currentLobbyPassword;
db.events.get(argv.args.event).then(event => {
if (event === null) {
fulfill("Error: the specified event `" + argv.args.event + "` doesn't exist.");
} else {
db.getLobbyBotId(event).then(botID => {
let details = context.dotaHandler.getLobbyDetails(botID);

if (lobby !== null) {
context.msg.author.sendMessage(
"Hello! Here's the information you requested:\n\n" +
if (details === null) {
fulfill("The Dota bot is not in a lobby.");
} else {
context.msg.author.sendMessage(
"Hello! Here's the information you requested:\n\n" +

"- **Current lobby name**: `" + lobby + "`\n" +
"- **Current lobby password**: `" + pass + "`"
).then(() => {
fulfill("The information you requested was sent to you in a DM.");
}).catch(reject);
} else {
fulfill("The Dota bot is not in a lobby.");
}
"- **Lobby name**: `" + details.name + "`\n" +
"- **Lobby password**: `" + details.password + "`"
).then(() => {
fulfill("The information you requested was sent to you in a DM.");
}).catch(reject);
}
}).catch(reject);
}
}).catch(reject);
});
}
},
args: [
require("./shared/event")
]
});
5 changes: 3 additions & 2 deletions lib/commands/admin/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ module.exports = new Clapp.Command({
.then(() => {
fulfill(user + " has been successfully kicked from " +
"the event `" + argv.args.id + "`.\n" +
"Please note that they are able to rejoin it at any time. To " +
"prevent them from doing so, use the `blacklist-add` command.");
"Please note that they are able to rejoin it at any" +
"time. To prevent them from doing so, use the" +
" `blacklist-add` command.");
}).catch(reject);
} else {
fulfill("Error: the specified user isn't attending the specified " +
Expand Down
40 changes: 19 additions & 21 deletions lib/commands/admin/remove-event.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";
"use strict"; // TODO TEST

const Clapp = require('../../modules/clapp-discord/index');
const cfg = require('../../../config');
const db = require('../../modules/dbhandler/index').events;

module.exports = new Clapp.Command({
Expand All @@ -13,27 +12,26 @@ module.exports = new Clapp.Command({
if (event !== null) {
let eventName = event.name;
let deleteSummaryPromise = context.summaryHandler.deleteSummary(event);
let deleteEventPromise = event.deleteEvent();
let closeLobbyPromise = new Promise((fulfill, reject) => {
// If the event has an active lobby, close it
if (
context.dotaHandler.currentLobbyEvent &&
context.dotaHandler.currentLobbyEvent.id === event.id
) {
context.dotaHandler.closeLobby(true).then(fulfill).catch(reject);
} else {
fulfill();
}
let closeLobbyPromise = new Promise((fulfill2, reject2) => {
db.getLobbyBotId(event)
.then(botID => {
// If the bot exists and is in a lobby, close it. Otherwise fulfill.
if (botID && context.dotaHandler.isBotInLobby(botID)) {
context.dotaHandler.closeLobby(botID, true)
.then(fulfill2)
.catch(reject2);
} else {
fulfill2();
}
})
.catch(reject2);
});

Promise.all(
[deleteSummaryPromise, deleteEventPromise, closeLobbyPromise]
).then(() => {
fulfill("The event `" + eventName+ "` was successfully deleted.");
}).catch(err => {
console.error(err);
fulfill("Sorry, an internal error occurred. Please talk to my author.");
});
Promise.all([deleteSummaryPromise, closeLobbyPromise])
.then(() => event.deleteEvent())
.then(() => {
fulfill("The event `" + eventName + "` was successfully deleted.");
}).catch(reject);
} else {
fulfill("Error: the specified event `" + argv.args.id + "` doesn't exist.");
}
Expand Down
8 changes: 8 additions & 0 deletions lib/commands/admin/shared/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Clapp = require("../../../modules/clapp-discord/index");

module.exports = new Clapp.Argument({
name: "event",
desc: "The ID of the event",
type: "number",
required: true
});
41 changes: 41 additions & 0 deletions lib/commands/admin/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";

const Clapp = require("../../modules/clapp-discord");

module.exports = new Clapp.Command({
name: "status",
desc: "Gets information about the Discord bot and Steam bots sent to you on a DM",
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let bots = context.dotaHandler.bots;

let msg = "Hello! Here's the bot status information:\n\n";

let genValueString = (key, value, newline = true) => {
return `- **${key}**: \`${value}\`${newline ? "\n" : ""}`;
};

msg += genValueString(
"Uptime",
Math.floor((context.summaryHandler.bot.uptime / 1000) / 60) + " minutes"
);

for (let i = 0; i < bots.length; i++) {
let dotaClient = bots[i].dota.client;

msg += genValueString(
`Bot #${dotaClient.botId}`,
context.dotaHandler.isBotInLobby(dotaClient.botId)
? `In lobby: ${dotaClient.currentLobby.name} ` +
`(Event #${dotaClient.currentLobby.event.id})`
: `Not in lobby`,
i !== bots.length
);
}

context.msg.author.sendMessage(msg)
.then(() => fulfill("The information you requested was sent to you in a DM."))
.catch(reject);
});
}
});
49 changes: 30 additions & 19 deletions lib/commands/general/resend-invite.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
"use strict";

const Clapp = require('../../modules/clapp-discord/index')
, cfg = require('../../../config')
, db = require('../../modules/dbhandler');
, db = require('../../modules/dbhandler').events
;

module.exports = new Clapp.Command({
name: "resend-invite",
desc: "Resends an invite to the current lobby. You need to have confirmed attendance for" +
" this to work.",
desc: "Resends an invite to the specified event's lobby. You need to have confirmed" +
" attendance for this to work.",
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
context.dotaHandler.currentLobbyEvent.getConfirms().then(people => {
let confirmed = false;
db.get(argv.args.id).then(event => {
if (event !== null) {
event.getConfirms().then(people => {
let confirmed = false;

for (let i = 0; i < people.confirmed.length; i++) {
let discordID = people.confirmed[i];
for (let i = 0; i < people.confirmed.length; i++) {
let discordID = people.confirmed[i];

if (context.msg.author.id === discordID) {
confirmed = true;
}
}
if (context.msg.author.id === discordID) {
confirmed = true;
}
}

if (confirmed) {
context.dotaHandler.invite(context.msg.author.id).then(() => {
fulfill("The invite has been resent. Accept it inside Dota 2.");
if (confirmed) {
db.events.getLobbyBotId().then(botID => context.dotaHandler.invite(
botID, context.msg.author.id
)).then(() => {
fulfill("The invite has been resent. Accept it inside Dota 2.");
}).catch(reject);
} else {
fulfill("Error: you haven't confirmed attendance to the event `#" +
context.dotaHandler.currentLobbyEvent.id + "`.\n" +
"You need to do so before requesting to be invited to the lobby");
}
}).catch(reject);
} else {
fulfill("Error: you haven't confirmed attendance to the event `#" +
context.dotaHandler.currentLobbyEvent.id + "`.\n" +
"You need to do so before requesting to be invited to the lobby");
fulfill("Event #`" + argv.args.id + "` does not exist");
}
}).catch(reject);
});
}
},
args: [
require("./shared/id")
]
});
Loading

0 comments on commit 021bae7

Please sign in to comment.