Skip to content

Commit

Permalink
Two additions
Browse files Browse the repository at this point in the history
- Added quick-inhouse command
- Players now get autoinvited if they confirm after a lobby is created.
  • Loading branch information
MeLlamoPablo committed Jan 5, 2017
1 parent 61358f1 commit 0885aa6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
17 changes: 17 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ module.exports = {
// This also requires the "manage messages" permission
disallow_talking: true,

// quick-inhouse command
// This command creates an instant lobby and adds an inhouse with the default values.
// It is the equivalent of running "@ScheduleBot create (event_name) now" and
// "@ScheduleBot add-inhouse (id)".
quick_inhouse: {
// If false, the command won't be included in the bot, and won't even show on the help.
enabled: true,

// The command name. If you changed this to "qh", the command would be executed as
// @ScheduleBot qh
command_name: "quick-inhouse",

// The created event's name, which is then used as a lobby name. (So you could customize
// this with your guild's name, for instance)
event_name: "Inhouse"
},

db: {
"user": "",
"password": "",
Expand Down
24 changes: 17 additions & 7 deletions lib/commands/general/confirm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use strict";

const Clapp = require('../../modules/clapp-discord/index');
const db = require('../../modules/dbhandler/index');
const Clapp = require('../../modules/clapp-discord/index');
const db = require('../../modules/dbhandler/index');
const ELobbyStatus = require('../../structures/enums/ELobbyStatus');

module.exports = new Clapp.Command({
name: "confirm",
Expand Down Expand Up @@ -47,11 +48,20 @@ module.exports = new Clapp.Command({
event,
context.msg.author,
argv.args.attendance === "yes"
).then(() => {
fulfill("Your attendance status was updated.");
context.summaryHandler.updateSummary(event)
.catch(console.error);
}).catch(reject);
)
.then(() => {
fulfill("Your attendance status was updated.");
context.summaryHandler.updateSummary(event)
.catch(console.error);
})
.then(() => event.getLobbyStatus())
.then(status => {
if (status === ELobbyStatus.CREATED) {
context.dotaHandler.invite(context.msg.author.id)
.catch(reject);
}
})
.catch(reject);
} else {
fulfill("Sorry, the event is full.");
}
Expand Down
32 changes: 32 additions & 0 deletions lib/commands/general/quick-inhouse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

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

module.exports = new Clapp.Command({
name: cfg.quick_inhouse.command_name,
desc: "Quickly creates an inhouse with the default values. This is the equivalent of running " +
`\`${cfg.readable_prefix} create ${cfg.quick_inhouse.event_name} now\` and then ` +
`\`${cfg.readable_prefix} add-inhouse (id)\`.` ,
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
let inhouseProps = {
gameMode: "captainsmode",
server: cfg.dota.defaultServer.toLowerCase().replace(" ", ""),
autoBalance: true
};

db.events.addInstant(cfg.quick_inhouse.event_name, 10)
.then(id => db.events.get(id))
.then(event => new Promise((fulfill2, reject2) => {
db.events.addInhouse(event, inhouseProps)
.then(() => context.summaryHandler.updateSummary(event))
.then(msgId => event.updateMsgId(msgId))
.then(() => fulfill2(event.id)).catch(reject2);
})).then(id => {
fulfill(`Your inhouse has been created with id \`#${id}\`.`);
}).catch(reject);
});
}
});
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ const fs = require('fs')
;

let masterChannel, summaryHandler, botAdmins, blacklist = [], verificator, dotaHandler,
bannedCommands = [],
steamClient = new Steam.SteamClient(),
steamUser = new Steam.SteamUser(steamClient),
steamFriends = new Steam.SteamFriends(steamClient),
dotaClient = new Dota2.Dota2Client(steamClient, false, false);

if (!cfg.quick_inhouse.enabled) {
bannedCommands.push("quick-inhouse.js");
}

let generalApp = new Clapp.App({
name: cfg.name,
desc: pkg.description + "\nhttps://mellamopablo.github.io/schedulebot/",
Expand Down Expand Up @@ -159,7 +164,7 @@ startupPromises.push(
fs.readdir("./lib/commands/general", {encoding: "utf-8"}, (err, files) => {
if (!err) {
files.forEach(file => {
if (file.match(/(?:.+).js/)) {
if (file.match(/(?:.+).js/) && bannedCommands.indexOf(file) === -1) {
generalApp.addCommand(require("./commands/general/" + file));
}
});
Expand Down

0 comments on commit 0885aa6

Please sign in to comment.