Skip to content

Commit

Permalink
ScheduleBot for Dota v1.1.0
Browse files Browse the repository at this point in the history
Merged branch dota-dev into dota
  • Loading branch information
MeLlamoPablo committed Jan 6, 2017
2 parents b6084b2 + 69caf3c commit 0051ff2
Show file tree
Hide file tree
Showing 23 changed files with 624 additions and 260 deletions.
38 changes: 37 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = {
// The bot's command prefix. The bot will recognize as command any message that begins with it.
// i.e: "-schedulebot foo" will trigger the command "foo",
// whereas "ScheduleBot foo" will do nothing at all.
//
// If you replace YOUR_BOT_USER_ID with your bot's user ID, the prefix will be a mention to
// your bot. You can get that ID in https://discordapp.com/developers/applications/me/
// (click on your application, and find it under "App Details" > "Client ID"
prefix: "<@YOUR_BOT_USER_ID>",

// This is a readable version of the prefix. Generally, this is the same as prefix, but if
Expand Down Expand Up @@ -41,6 +45,14 @@ module.exports = {
// List of accepted timezones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
default_timezone: "Europe/Madrid",

// The time format that will be used for the create command. The bot will read a date string
// and will attempt to interpret it as the following format. If the passed time doesn't
// match the format, the command will result in an error.
//
// A list of valid format tokens can be found at:
// http://momentjs.com/docs/#year-month-and-day-tokens
time_format: "DD/MM/YYYY HH:mm",

// If this option is enabled, the bot will delete the message that triggered it, and its own
// response, after the specified amount of time has passed.
// Enable this if you don't want your channel to be flooded with bot messages.
Expand All @@ -57,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 All @@ -77,7 +106,14 @@ module.exports = {
// --server flag to the add-inhouse command.
// Go to that command's file (Or type -schedulebot add-ihouse --help)
// to see possible values.
defaultServer: "Luxembourg"
defaultServer: "Luxembourg",

// If enabled is true, the bot will ticket any lobbies using the provided league id.
// Make sure that the steam bot is an admin of that league.
ticketing: {
enabled: false,
league_id: 12345
}
}
};

Expand Down
43 changes: 43 additions & 0 deletions lib/commands/admin/kick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";

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

module.exports = new Clapp.Command({
name: "kick",
desc: "Kicks a player from an event.",
fn: (argv, context) => {
return new Promise((fulfill, reject) => {
db.events.get(argv.args.id).then(event => {
if (event !== null) {
db.confirms.getByUser(event, context.msg.author).then(attends => {
if (attends) {
db.confirms.add(event, context.msg.author, false)
.then(() => context.summaryHandler.updateSummary(event))
.then(() => {
fulfill(context.msg.author + " 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.");
}).catch(reject);
} else {
fulfill("Error: the specifier user isn't attending the specified " +
"event.");
}
}).catch(reject);
} else {
fulfill("Error: the specified event `" + argv.args.id + "` doesn't exist.");
}
}).catch(reject);
});
},
args: [
require("./shared/user"),
{
name: "id",
desc: "The ID of the event",
type: "number",
required: true
}
]
});
15 changes: 14 additions & 1 deletion lib/commands/admin/remove-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ module.exports = new Clapp.Command({
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();
}
});

Promise.all([deleteSummaryPromise, deleteEventPromise]).then(() => {
Promise.all(
[deleteSummaryPromise, deleteEventPromise, closeLobbyPromise]
).then(() => {
fulfill("The event `" + eventName+ "` was successfully deleted.");
}).catch(err => {
console.error(err);
Expand Down
93 changes: 55 additions & 38 deletions lib/commands/general/add-inhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,45 @@ module.exports = new Clapp.Command({
return new Promise((fulfill, reject) => {
db.events.get(argv.args.id).then(event => {
if (event !== null) {
let inhouseProps = {};
if (event.limit >= 10) {
let inhouseProps = {};

inhouseProps.gameMode = argv.flags.gamemode.toLowerCase().replace(" ", "");
inhouseProps.server = argv.flags.server.toLowerCase().replace(" ", "");
inhouseProps.autoBalance = !argv.flags["no-balance"];
inhouseProps.gameMode = argv.flags.gamemode.toLowerCase().replace(" ", "");
inhouseProps.server = argv.flags.server.toLowerCase().replace(" ", "");
inhouseProps.autoBalance = !argv.flags.nobalance;

db.events.addInhouse(event, inhouseProps).then(() => {
// Kick every user that hasn't linked their Steam from the event
db.confirms.getByEvent(event).then(confirms => {
let people = confirms.map(e => { return e.user });
db.events.addInhouse(event, inhouseProps).then(() => {
// Kick every user that hasn't linked their Steam from the event
db.confirms.getByEvent(event).then(confirms => {
let people = confirms.map(e => {
return e.user
});

for (let i = 0; i < people.length; i++) {
db.users.getByDiscord(people[i]).then(user => {
if (user === null || user.steam_id === null) {
db.confirms.deleteByUserAndEvent(
people[i], event.id
).then(() => {
context.summaryHandler.updateSummary(event)
.catch(reject);
}).catch(reject);
}
}).catch(reject);
}
}).catch(reject);
context.summaryHandler.updateSummary(event).catch(reject);
for (let i = 0; i < people.length; i++) {
db.users.getByDiscord(people[i]).then(user => {
if (user === null || user.steam_id === null) {
db.confirms.deleteByUserAndEvent(
people[i], event.id
).then(() => {
context.summaryHandler.updateSummary(event)
.catch(reject);
}).catch(reject);
}
}).catch(reject);
}
}).catch(reject);
context.summaryHandler.updateSummary(event).catch(reject);

fulfill("The inhouse has been added to the event `#"
+ argv.args.id + "`\n" +
"If there were any people who confirmed their attendance, but didn't" +
" have their Steam account linked, they have been removed.");
}).catch(reject);
fulfill("The inhouse has been added to the event `#"
+ argv.args.id + "`\n" +
"If there were any people who confirmed their attendance, but " +
"didn't have their Steam account linked, they have been removed.");
}).catch(reject);
} else {
fulfill("The event's player limit must be 10 or greater in order to add" +
" an inhouse."); // TODO once edit command gets implemented, modify
// this to tell the user to edit the event.
}
} else {
fulfill("The event `#" + argv.args.id + "` doesn't exist.");
}
Expand All @@ -59,20 +67,25 @@ module.exports = new Clapp.Command({
new Clapp.Flag({
name: "gamemode",
desc: "The inhouse game mode. Possible values are:\n" +
"- Captains Mode\n" +
"- All Pick",
"Captains Mode, All Pick, Ranked All Pick, Captains Draft, Random Draft, Single" +
" Draft, All Random",
type: "string",
default: "Captains Mode",
alias: "g",
validations: [
{
errorMessage: "Supported values are:\"Captains Mode\" and \"All Pick\"",
errorMessage: "Type --help for a list of supported values",
validate: val => {
let value = val.toLowerCase().replace(" ", "");

switch (value) {
case "captainsmode":
case "allpick":
case "captainsdraft":
case "randomdraft":
case "singledraft":
case "allrandom":
case "rankedallpick":
return true;
default:
return false;
Expand All @@ -84,13 +97,8 @@ module.exports = new Clapp.Command({
new Clapp.Flag({
name: "server",
desc: "The inhouse server. Possible values are:\n" +
"- US West\n" +
"- US East\n" +
"- Luxembourg\n" +
"- Australia\n" +
"- Stockholm\n\n" +
"" +
"If you wish to have another server added, please talk to this bot's author.",
"US West, US East, Luxembourg, Australia, Stockholm, Singapore, Dubai, Austria," +
" Brazil, South Africa, Chile, Peru, India, Japan.",
type: "string",
default: cfg.dota.defaultServer,
alias: "s",
Expand All @@ -106,6 +114,15 @@ module.exports = new Clapp.Command({
case "luxembourg":
case "australia":
case "stockholm":
case "singapore":
case "dubai":
case "austria":
case "brazil":
case "southafrica":
case "chile":
case "peru":
case "india":
case "japan":
return true;
default:
return false;
Expand All @@ -115,7 +132,7 @@ module.exports = new Clapp.Command({
]
}),
new Clapp.Flag({
name: "no-balance",
name: "nobalance",
desc: "Disable automatic team balance.",
type: "boolean",
default: false,
Expand Down
31 changes: 23 additions & 8 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 @@ -37,16 +38,30 @@ module.exports = new Clapp.Command({
return el.attends;
}) : [];

if (attendanceConfirms.length < event.limit) {
// Don't let people confirm yes if the event is full, but do let
// people confirm no even if the event is full.
if (
attendanceConfirms.length < event.limit
&& argv.args.attendance === "yes"
) {
db.confirms.add(
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
Loading

0 comments on commit 0051ff2

Please sign in to comment.