Skip to content

Commit

Permalink
Support VEXU and VAIC teams in team
Browse files Browse the repository at this point in the history
  • Loading branch information
brenapp committed Dec 23, 2022
1 parent 9276f8f commit d8d01cd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
25 changes: 25 additions & 0 deletions bot/commands/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Creates discord events for every event in the region
**/

import Command, { Permissions } from "~lib/command";
import * as robotevents from "robotevents";

const EventsCommand = Command({
names: ["create_events"],
documentation: {
description: "Creates discord events for every event in the region",
options: (builder) =>
builder.addStringOption((option) =>
option
.setName("region")
.setDescription("The region to create events for")
.setRequired(true)
),
},
check: Permissions.admin,

async exec(interaction) {
const region = interaction.options.getString("region", true);
},
});
21 changes: 19 additions & 2 deletions bot/commands/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EmbedBuilder } from "@discordjs/builders";
import { CommandInteraction } from "discord.js";
import { APIEmbedField } from "discord-api-types/v9";
import { Match } from "robotevents/out/endpoints/matches";
import { ProgramAbbr } from "robotevents/out/endpoints/programs";

function getOutcomes(id: number, matches: Match[]) {
let wins = 0;
Expand Down Expand Up @@ -166,12 +167,28 @@ const TeamCommand = Command({

async exec(interaction) {
const number = interaction.options.getString("number", true);
const team = await robotevents.teams.get(number, "VRC");
let program = [
interaction.options.getString("program", false) as ProgramAbbr | null,
];

if (!team) {
if (!program[0]) {
program = ["VRC", "VEXU", "VAIC"];
}

let programIds = program.map(
(program) => robotevents.programs.get(program as ProgramAbbr)!
);
const teams = await robotevents.teams.search({
number: [number],
program: programIds,
});

if (teams.length < 1) {
return interaction.reply(`Team \`${number}\` cannot be found.`);
}

const team = teams[0];

const embed = await getEmbed(team, interaction);

try {
Expand Down
5 changes: 5 additions & 0 deletions bot/lib/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export const Permissions = {
!(await fn(interaction));
},

admin: async (interaction: CommandInteraction<CacheType>) => {
const member = await interaction.guild?.members.fetch(interaction.user.id);
return member?.permissions.has("ADMINISTRATOR") ?? false;
},

all:
(...permissions: PermissionFunction[]) =>
async (interaction: CommandInteraction<CacheType>) => {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "liquid",
"version": "0.0.0",
"description": "A discord bot template, with default support for slash commands",
"name": "vexbot",
"version": "2.0.0",
"description": "Custom discord for SC Robotics",
"main": "out/bot/main.js",
"scripts": {
"build": "tsc",
Expand Down

0 comments on commit d8d01cd

Please # to comment.