Compare commits

...

6 Commits

Author SHA1 Message Date
54709a898b updated api 2022-03-06 11:20:36 -06:00
d6d75abd87 removed extra comment 2022-02-24 10:41:15 -06:00
0ff3a57747 updated readme 2022-02-15 16:05:16 -06:00
9fb3bf6941 renamed index to main lol 2022-02-15 16:01:08 -06:00
2956e24684 comments 2022-02-15 15:50:36 -06:00
c2447b180e fixed type definition errors 2022-02-15 15:24:45 -06:00
17 changed files with 143 additions and 53 deletions

View File

@@ -2,10 +2,6 @@
# 1800queue # 1800queue
## Invite info
needs: create commands/send messages
## Prerequirements ## Prerequirements
Download and install [Node.js](https://nodejs.org/en/) Download and install [Node.js](https://nodejs.org/en/)
@@ -48,6 +44,8 @@ Download and install [Node.js](https://nodejs.org/en/)
## Starting ## Starting
**Important**: the bot's invite needs permission to `Create Commands` and `Send Messages`
1. Open the `scripts` folder 1. Open the `scripts` folder
2. Open the folder that corresponds with your operating system 2. Open the folder that corresponds with your operating system
3. Run the `start` file 3. Run the `start` file

3
dist/lang.js vendored
View File

@@ -99,7 +99,7 @@ function get(id, args = {}) {
if (typeof found === 'string') if (typeof found === 'string')
return (0, lang_1.template)(found, args); return (0, lang_1.template)(found, args);
if (found.embed === true) if (found.embed === true)
return (0, lang_1.embedObjStr)(found, id); return (0, lang_1.embedObjStr)(found, args, id);
finding = found; finding = found;
} }
else else
@@ -144,4 +144,3 @@ function getEmbed(id, args = {}, otherOptions = {}) {
return embedData; return embedData;
} }
exports.getEmbed = getEmbed; exports.getEmbed = getEmbed;
debugger;

View File

12
dist/util/discord.js vendored
View File

@@ -5,9 +5,7 @@ const discord_js_1 = require("discord.js");
const main_1 = require("./main"); const main_1 = require("./main");
/** /**
* get the GuildMember of an interaction * get the GuildMember of an interaction
* @param interaction
* @throws errorMessage class if it cannot be read * @throws errorMessage class if it cannot be read
* @returns member
*/ */
function getMember(interaction) { function getMember(interaction) {
const member = interaction.member; const member = interaction.member;
@@ -18,9 +16,7 @@ function getMember(interaction) {
exports.getMember = getMember; exports.getMember = getMember;
/** /**
* get the TextChannel of an interaction * get the TextChannel of an interaction
* @param interaction
* @throws errorMessage class if it cannot be read * @throws errorMessage class if it cannot be read
* @returns member
*/ */
function getChannel(interaction) { function getChannel(interaction) {
const channel = interaction.channel; const channel = interaction.channel;
@@ -29,11 +25,19 @@ function getChannel(interaction) {
return channel; return channel;
} }
exports.getChannel = getChannel; exports.getChannel = getChannel;
/**
* get the TextChannel of an interaction
* @throws errorMessage class if the Member cannot be read
*/
function memberIsMod(interaction) { function memberIsMod(interaction) {
const member = getMember(interaction); const member = getMember(interaction);
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES'); return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
} }
exports.memberIsMod = memberIsMod; exports.memberIsMod = memberIsMod;
/**
* get the TextChannel of an interaction
* @throws errorMessage class if the Member cannot be read or if Member is not a mod
*/
function memberIsModThrow(interaction) { function memberIsModThrow(interaction) {
if (!memberIsMod(interaction)) if (!memberIsMod(interaction))
throw (0, main_1.emsg)('discord.notMod'); throw (0, main_1.emsg)('discord.notMod');

37
dist/util/lang.js vendored
View File

@@ -2,6 +2,12 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.embedObjEmbed = exports.embedObjStr = exports.resolveColor = exports.bigString = exports.template = void 0; exports.embedObjEmbed = exports.embedObjStr = exports.resolveColor = exports.bigString = exports.template = void 0;
const discord_js_1 = require("discord.js"); const discord_js_1 = require("discord.js");
/**
*
* @param str
* @param args
* @returns
*/
function template(str, args) { function template(str, args) {
return str.replace(/{\w+}/g, str => { return str.replace(/{\w+}/g, str => {
const key = str.substring(1, str.length - 1); const key = str.substring(1, str.length - 1);
@@ -11,12 +17,18 @@ function template(str, args) {
}); });
} }
exports.template = template; exports.template = template;
function bigString(str) { /**
if (typeof str === 'object') * converts bigString to string
return str.join('\n'); */
return str; function bigString(bigStr) {
if (Array.isArray(bigStr))
return bigStr.join('\n');
return bigStr;
} }
exports.bigString = bigString; exports.bigString = bigString;
/**
* converts Hex Color string to an RGB array
*/
function resolveColor(color) { function resolveColor(color) {
color = color.replace(/[^0-9a-f]/gi, ''); color = color.replace(/[^0-9a-f]/gi, '');
const colorNum = [0, 0, 0]; const colorNum = [0, 0, 0];
@@ -30,14 +42,21 @@ function resolveColor(color) {
return colorNum; return colorNum;
} }
exports.resolveColor = resolveColor; exports.resolveColor = resolveColor;
function embedObjStr(embedData, fallback = '') { /**
if (embedData.content !== undefined) * converts embedObj to a string if applicable
return bigString(embedData.content); * @param fallback the string to use if no valid strings can be found
if (embedData.description !== undefined) */
return bigString(embedData.description); function embedObjStr(embedObj, args = {}, fallback = '') {
if (embedObj.content !== undefined)
return template(bigString(embedObj.content), args);
if (embedObj.description !== undefined)
return template(bigString(embedObj.description), args);
return fallback; return fallback;
} }
exports.embedObjStr = embedObjStr; exports.embedObjStr = embedObjStr;
/**
* converts embedObj to Discord.MessageEmbed
*/
function embedObjEmbed(embedObj, args = {}) { function embedObjEmbed(embedObj, args = {}) {
const embed = new discord_js_1.MessageEmbed(), { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj; const embed = new discord_js_1.MessageEmbed(), { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;
if (author !== undefined) { if (author !== undefined) {

3
dist/util/main.js vendored
View File

@@ -43,6 +43,9 @@ function shuffle(array) {
return array; return array;
} }
exports.shuffle = shuffle; exports.shuffle = shuffle;
/**
* use the emsg() function instead
*/
class errorMessage { class errorMessage {
constructor(msg, ephemeral = true) { constructor(msg, ephemeral = true) {
this.msg = msg; this.msg = msg;

View File

@@ -2,7 +2,7 @@
"name": "1800queue", "name": "1800queue",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/main.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"start": "node .", "start": "node .",

View File

@@ -1,11 +1,9 @@
/*eslint prefer-const: "error"*/ /*eslint prefer-const: "error"*/
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { CommandInteraction } from 'discord.js'; import { CommandInteraction } from 'discord.js';
import { IncomingMessage } from 'http'; import http, { IncomingMessage } from 'http';
import http from 'https';
import { emsg } from './util/main'; import { emsg } from './util/main';
import * as Lang from './lang'; import * as Lang from './lang';
import { uniteApiData } from './types/api';
const uniteApiRegex = { const uniteApiRegex = {
//$1 = name, $2 = id //$1 = name, $2 = id
@@ -28,8 +26,8 @@ function getHTML(name: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const init = { const opts = {
host: 'uniteapi.dev', host: '147.182.215.216',
path: `/p/${encodeURIComponent(name)}`, path: `/p/${encodeURIComponent(name)}`,
method: 'GET', method: 'GET',
}; };
@@ -51,7 +49,7 @@ function getHTML(name: string): Promise<string> {
}); });
}; };
const req = http.request(init, callback); const req = http.request(opts, callback);
req.end(); req.end();
}); });

View File

@@ -120,7 +120,7 @@ export function get(id: string, args: basicObjectStr = {}): string {
return template(found, args); return template(found, args);
if (found.embed === true) if (found.embed === true)
return embedObjStr(found as embedObj, id); return embedObjStr(found as embedObj, args, id);
finding = found as LangObj; finding = found as LangObj;

View File

@@ -1,12 +1,6 @@
/* TODO
join message should contain your current position in the queue, editing it to keep it current
*/
import { Client, CommandInteraction, TextChannel } from 'discord.js'; import { Client, CommandInteraction, TextChannel } from 'discord.js';
import * as fs from 'fs'; import * as fs from 'fs';
import * as Lang from './lang'; import * as Lang from './lang';
import { queueInfo, queueInfoBase } from './types/queue';
import { getChannel, getMember, memberIsModThrow } from './util/discord'; import { getChannel, getMember, memberIsModThrow } from './util/discord';
import { emsg } from './util/main'; import { emsg } from './util/main';

5
src/types/api.d.ts vendored
View File

@@ -1,4 +1,7 @@
export interface uniteApiData { /**
* data taken from UniteAPI
*/
interface uniteApiData {
name: string, name: string,
id: string, id: string,
avatar: string, avatar: string,

49
src/types/lang.d.ts vendored
View File

@@ -1,28 +1,66 @@
/**
* any indexable object
*/
//this is a generic type, and needs 'any' //this is a generic type, and needs 'any'
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
type basicObject = {[keys: string]: any}; type basicObject = {[keys: string]: any};
/**
* any indexable object with string values
*/
type basicObjectStr = {[keys: string]: string}; type basicObjectStr = {[keys: string]: string};
/**
* an abstract version of strings
*/
type bigString = string | string[]; type bigString = string | string[];
/**
* an object that contains embeds and can be passed directly to methods like `Discord.TextChannel.send()`
*/
interface embedData { interface embedData {
content?: string, content?: string,
embeds: MessageEmbed[] embeds: MessageEmbed[]
} }
/**
* a representation of an author in the LANG object
*
* `LANG > Language > Embed > Field`
*/
interface embedField { interface embedField {
name: string, name: string,
value: bigString, value: bigString,
inline?: boolean inline?: boolean
} }
/**
* a representation of an author in the LANG object
*
* `LANG > Language > Embed > Author`
*/
interface authorData { interface authorData {
name: string, name: string,
url?: string, url?: string,
icon?: string icon?: string
} }
/**
* a representation of a footer in the LANG object
*
* `LANG > Language > Embed > Footer`
*/
interface footerData { interface footerData {
text: string, text: string,
icon?: string icon?: string
} }
/**
* a representation of an embed in the LANG object
*
* `LANG > Language > Embed`
*/
interface embedObj { interface embedObj {
embed: true, embed: true,
@@ -51,5 +89,16 @@ interface embedObj {
timestamp?: boolean | string | number timestamp?: boolean | string | number
} }
/**
* a specific language in the LANG object
*
* `LANG > Language`
*/
type LangObj = { [keys:string]: LangObj | embedObj | string } type LangObj = { [keys:string]: LangObj | embedObj | string }
/**
* the entire LANG object
*
* `LANG`
*/
type LangObjWhole = { [langid:string]: LangObj } type LangObjWhole = { [langid:string]: LangObj }

View File

@@ -1,8 +1,6 @@
import { GuildMember } from 'discord.js'; interface queueInfoBase {
export interface queueInfoBase {
teamsize: number teamsize: number
} }
export interface queueInfo extends queueInfoBase { interface queueInfo extends queueInfoBase {
players: GuildMember[] players: GuildMember[]
} }

View File

@@ -3,9 +3,7 @@ import { emsg } from './main';
/** /**
* get the GuildMember of an interaction * get the GuildMember of an interaction
* @param interaction
* @throws errorMessage class if it cannot be read * @throws errorMessage class if it cannot be read
* @returns member
*/ */
export function getMember(interaction: CommandInteraction): GuildMember { export function getMember(interaction: CommandInteraction): GuildMember {
const member = interaction.member; const member = interaction.member;
@@ -18,9 +16,7 @@ export function getMember(interaction: CommandInteraction): GuildMember {
/** /**
* get the TextChannel of an interaction * get the TextChannel of an interaction
* @param interaction
* @throws errorMessage class if it cannot be read * @throws errorMessage class if it cannot be read
* @returns member
*/ */
export function getChannel(interaction: CommandInteraction): TextChannel { export function getChannel(interaction: CommandInteraction): TextChannel {
const channel = interaction.channel; const channel = interaction.channel;
@@ -31,12 +27,19 @@ export function getChannel(interaction: CommandInteraction): TextChannel {
return channel; return channel;
} }
/**
* get the TextChannel of an interaction
* @throws errorMessage class if the Member cannot be read
*/
export function memberIsMod(interaction: CommandInteraction): boolean { export function memberIsMod(interaction: CommandInteraction): boolean {
const member = getMember(interaction); const member = getMember(interaction);
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES'); return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
} }
/**
* get the TextChannel of an interaction
* @throws errorMessage class if the Member cannot be read or if Member is not a mod
*/
export function memberIsModThrow(interaction: CommandInteraction) { export function memberIsModThrow(interaction: CommandInteraction) {
if (!memberIsMod(interaction)) if (!memberIsMod(interaction))
throw emsg('discord.notMod'); throw emsg('discord.notMod');

View File

@@ -1,5 +1,11 @@
import { MessageEmbed } from 'discord.js'; import { MessageEmbed } from 'discord.js';
/**
*
* @param str
* @param args
* @returns
*/
export function template(str: string, args: basicObject): string { export function template(str: string, args: basicObject): string {
return str.replace(/{\w+}/g, str => { return str.replace(/{\w+}/g, str => {
@@ -15,12 +21,19 @@ export function template(str: string, args: basicObject): string {
} }
export function bigString(str: bigString): string { /**
if (typeof str === 'object') * converts bigString to string
return str.join('\n'); */
return str; export function bigString(bigStr: bigString): string {
if (Array.isArray(bigStr))
return bigStr.join('\n');
return bigStr;
} }
/**
* converts Hex Color string to an RGB array
*/
export function resolveColor(color: string): [number, number, number] { export function resolveColor(color: string): [number, number, number] {
color = color.replace(/[^0-9a-f]/gi, ''); color = color.replace(/[^0-9a-f]/gi, '');
@@ -41,17 +54,24 @@ export function resolveColor(color: string): [number, number, number] {
return colorNum; return colorNum;
} }
export function embedObjStr(embedData: embedObj, fallback = ''): string { /**
* converts embedObj to a string if applicable
* @param fallback the string to use if no valid strings can be found
*/
export function embedObjStr(embedObj: embedObj, args: basicObjectStr = {}, fallback = ''): string {
if (embedData.content !== undefined) if (embedObj.content !== undefined)
return bigString(embedData.content); return template(bigString(embedObj.content), args);
if (embedData.description !== undefined) if (embedObj.description !== undefined)
return bigString(embedData.description); return template(bigString(embedObj.description), args);
return fallback; return fallback;
} }
/**
* converts embedObj to Discord.MessageEmbed
*/
export function embedObjEmbed(embedObj: embedObj, args: basicObjectStr = {}): MessageEmbed { export function embedObjEmbed(embedObj: embedObj, args: basicObjectStr = {}): MessageEmbed {
const embed = new MessageEmbed(), const embed = new MessageEmbed(),
{ author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj; { author, color, description, fields, footer, image, thumbnail, timestamp, title, url } = embedObj;

View File

@@ -26,7 +26,9 @@ export function shuffle(array: any[]) {
} }
/**
* use the emsg() function instead
*/
export class errorMessage { export class errorMessage {
public msg: string; public msg: string;
public ephemeral: boolean; public ephemeral: boolean;