Skip to content

Instantly share code, notes, and snippets.

@blanksus
Last active June 27, 2023 08:06
Show Gist options
  • Save blanksus/4fcedfc6f68bab9b0f61a5b2fc8de3e6 to your computer and use it in GitHub Desktop.
Save blanksus/4fcedfc6f68bab9b0f61a5b2fc8de3e6 to your computer and use it in GitHub Desktop.
Bot Help
const sql = require("../util/sql");
const Discord = require("discord.js")
const tools = require("../util/tools");
const challonge = require("challonge");
const Mong = require("../util/mong").Mong;
const {ObjectID} = require("mongodb");
const challongeClient = challonge.createClient({
apiKey:"***"
});
module.exports = {
name: 'makeround',
description: `Creates a channel category full of valid matches that haven't been played yet.`,
args:true,
async execute(message, args) {
console.log("Making round...");
const MongC = new Mong();
await MongC.connect();
//Gets a raw list of the match position "ids"
let unfilteredMatches = await tools.matchesInRound(parseInt(args[0]));
let matches = [];
//Filters the ones that have already been marked as completed
for (const match of unfilteredMatches) {
let matchInfo = await tools.getMatch(match);
if(matchInfo.state != "complete")
matches.push(matchInfo);
}
//Create the round category
var roundCategory = message.guild.createChannel(`CLAN WARS | ROUND ${args[0]}`,{
type:"category"
});
//Assign all new text channels to the round category parent
roundCategory.then(async (categoryChannel)=>{
for (const match of matches) {
//Gets the team names from the challonge API
var team1Name = await tools.getTeamName(match.player1Id);
var team2Name = await tools.getTeamName(match.player2Id);
//Creates a channel with permission overwrites for the 2 teams playing
message.guild.createChannel(`${team1Name}-vs-${team2Name}`,{
type:"text",
parent:categoryChannel
},[
{id:(await MongC.find("teams",{name:team1Name}))[0].roleID,allow:["VIEW_CHANNEL"]},
{id:(await MongC.find("teams",{name:team2Name}))[0].roleID,allow:["VIEW_CHANNEL"]},
{id:message.guild.defaultRole,deny:["VIEW_CHANNEL"]}
])
.then(async (matchChannel)=>{
matchChannel.overwritePermissions(message.guild.defaultRole,{VIEW_CHANNEL:false});
console.log((await MongC.find("teams",{name:team1Name}))[0].roleID);
console.log(`${team1Name} vs ${team2Name}`);
var embed = new Discord.RichEmbed() //Creates the embed
.setTitle(`**OFFICIAL SL MATCH (ID:3)**`)
.addField(`**Teams playing**`, `${team1Name} vs ${team2Name}`)
.addField(`**Slot**`, `You will be playing the match on <day>`)
.addField(`**Type**`,`<type>`)
.addField(`**DropS roster**`, `<Roster 1>`,true)
.addField(`**PuR3 roster**`, `<Roster 2>`)
.addField(`**HOST**`, `<Host staff>`,true)
.addField(`**WRITER**`, `<Writer staff>`,true)
.addField(`**BROADCASTER**`,`<Broadcaster staff>`,true);
matchChannel.send(embed).then(async msg=>{ //Updates the database with information on the match
var infoObj = await MongC.insert("matchInfos",match);
MongC.insert("matches",{
match:infoObj.ops[0]._id,
channelID:matchChannel.id,
playDate:null,
playTime:null,
type:null,
staff:{
host:null,
writer:null,
broadcaster:null
},
team1Roster:[],
team2Roster:[],
embedID:msg.id
});
});
});
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment