Inventory collapse thing (not sure if I fixed anything), stylistic condition choices
This commit is contained in:
parent
99ccca2412
commit
cdaba3c951
|
@ -6,7 +6,7 @@ export const id = new Command(
|
||||||
"get your id bozo",
|
"get your id bozo",
|
||||||
"id",
|
"id",
|
||||||
(msg, agent) => {
|
(msg, agent) => {
|
||||||
if (agent.platform == "mpp") {
|
if (agent.platform === "mpp") {
|
||||||
return `ID: \`${
|
return `ID: \`${
|
||||||
(msg.originalMessage as any).p._id
|
(msg.originalMessage as any).p._id
|
||||||
}\` Cosmic ID: \`${msg.p._id}\``;
|
}\` Cosmic ID: \`${msg.p._id}\``;
|
||||||
|
|
|
@ -18,19 +18,19 @@ export async function readInventory(userId: Inventory["userId"]) {
|
||||||
|
|
||||||
export function collapseInventory(inventoryData: Item[]) {
|
export function collapseInventory(inventoryData: Item[]) {
|
||||||
for (let i = 0; i < inventoryData.length; i++) {
|
for (let i = 0; i < inventoryData.length; i++) {
|
||||||
if (i > 0) {
|
if (i <= 0) continue;
|
||||||
if (inventoryData[i].id == inventoryData[i - 1].id) {
|
|
||||||
if (
|
if (inventoryData[i].id === inventoryData[i - 1].id) {
|
||||||
typeof (inventoryData[i - 1] as StackableItem).count ==
|
if (
|
||||||
"number" &&
|
typeof (inventoryData[i - 1] as StackableItem).count ===
|
||||||
typeof (inventoryData[i] as StackableItem).count == "number"
|
"number" &&
|
||||||
) {
|
typeof (inventoryData[i] as StackableItem).count === "number"
|
||||||
(inventoryData[i - 1] as StackableItem).count += (
|
) {
|
||||||
inventoryData[i] as StackableItem
|
(inventoryData[i - 1] as StackableItem).count += (
|
||||||
).count;
|
inventoryData[i] as StackableItem
|
||||||
inventoryData.splice(i, 1);
|
).count;
|
||||||
i--;
|
inventoryData.splice(i, 1);
|
||||||
}
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ export function handlePermission(node1: string, node2: string) {
|
||||||
|
|
||||||
// Check nodes in order
|
// Check nodes in order
|
||||||
for (let i = 0; i < hierarchy1.length; i++) {
|
for (let i = 0; i < hierarchy1.length; i++) {
|
||||||
if (hierarchy1[i] == hierarchy2[i]) {
|
if (hierarchy1[i] === hierarchy2[i]) {
|
||||||
// Last node?
|
// Last node?
|
||||||
if (i == hierarchy1.length - 1 || i == hierarchy2.length - 1) {
|
if (i === hierarchy1.length - 1 || i === hierarchy2.length - 1) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
@ -33,8 +33,8 @@ export function handlePermission(node1: string, node2: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wildcard?
|
// Wildcard?
|
||||||
if (hierarchy1[i] == "*") return true;
|
if (hierarchy1[i] === "*") return true;
|
||||||
if (hierarchy2[i] == "*") return true;
|
if (hierarchy2[i] === "*") return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ export interface ChatMessage<T = unknown> {
|
||||||
|
|
||||||
function onChildMessage(msg: ChatMessage) {
|
function onChildMessage(msg: ChatMessage) {
|
||||||
const consoleAgent = ServiceLoader.agents.find(
|
const consoleAgent = ServiceLoader.agents.find(
|
||||||
ag => ag.platform == "console"
|
ag => ag.platform === "console"
|
||||||
) as ConsoleAgent | undefined;
|
) as ConsoleAgent | undefined;
|
||||||
|
|
||||||
if (!consoleAgent) return;
|
if (!consoleAgent) return;
|
||||||
|
@ -34,7 +34,7 @@ function onChildMessage(msg: ChatMessage) {
|
||||||
|
|
||||||
function onConsoleMessage(text: string) {
|
function onConsoleMessage(text: string) {
|
||||||
const consoleAgent = ServiceLoader.agents.find(
|
const consoleAgent = ServiceLoader.agents.find(
|
||||||
ag => ag.platform == "console"
|
ag => ag.platform === "console"
|
||||||
) as ConsoleAgent | undefined;
|
) as ConsoleAgent | undefined;
|
||||||
|
|
||||||
if (!consoleAgent) return;
|
if (!consoleAgent) return;
|
||||||
|
@ -77,7 +77,7 @@ export class MicroHandler {
|
||||||
|
|
||||||
for (let i in ServiceLoader.agents) {
|
for (let i in ServiceLoader.agents) {
|
||||||
const agent2 = ServiceLoader.agents[i];
|
const agent2 = ServiceLoader.agents[i];
|
||||||
if (agent2.platform == "mpp") {
|
if (agent2.platform === "mpp") {
|
||||||
agent.emit(
|
agent.emit(
|
||||||
"log",
|
"log",
|
||||||
`${i} - ${agent2.platform} - ${
|
`${i} - ${agent2.platform} - ${
|
||||||
|
@ -101,7 +101,7 @@ export class MicroHandler {
|
||||||
let walkie = agent as ConsoleAgent;
|
let walkie = agent as ConsoleAgent;
|
||||||
let talky = ServiceLoader.agents[index];
|
let talky = ServiceLoader.agents[index];
|
||||||
|
|
||||||
if (index == ServiceLoader.agents.indexOf(walkie))
|
if (index === ServiceLoader.agents.indexOf(walkie))
|
||||||
return "Why would you want to chat with yourself?";
|
return "Why would you want to chat with yourself?";
|
||||||
|
|
||||||
// Remove old listeners
|
// Remove old listeners
|
||||||
|
|
|
@ -74,7 +74,7 @@ export class DiscordAgent extends ServiceAgent<Discord.Client> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
if (typeof str == "string") {
|
if (typeof str === "string") {
|
||||||
const channel = await this.client.channels.fetch(
|
const channel = await this.client.channels.fetch(
|
||||||
msg.channelId
|
msg.channelId
|
||||||
);
|
);
|
||||||
|
|
|
@ -80,7 +80,7 @@ export class MPPAgent extends ServiceAgent<Client> {
|
||||||
|
|
||||||
// Send message in chat
|
// Send message in chat
|
||||||
if (str) {
|
if (str) {
|
||||||
if (typeof str == "string") {
|
if (typeof str === "string") {
|
||||||
if (str.includes("\n")) {
|
if (str.includes("\n")) {
|
||||||
let sp = str.split("\n");
|
let sp = str.split("\n");
|
||||||
|
|
||||||
|
|
|
@ -80,9 +80,9 @@ export class CosmicColor {
|
||||||
let g = (~~this.g || 0).toString(16);
|
let g = (~~this.g || 0).toString(16);
|
||||||
let b = (~~this.b || 0).toString(16);
|
let b = (~~this.b || 0).toString(16);
|
||||||
|
|
||||||
if (r.length == 1) r = "0" + r;
|
if (r.length === 1) r = "0" + r;
|
||||||
if (g.length == 1) g = "0" + g;
|
if (g.length === 1) g = "0" + g;
|
||||||
if (b.length == 1) b = "0" + b;
|
if (b.length === 1) b = "0" + b;
|
||||||
|
|
||||||
return "#" + r + g + b;
|
return "#" + r + g + b;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { parse as parsePath } from "path/posix";
|
||||||
* @returns Parsed YAML config
|
* @returns Parsed YAML config
|
||||||
*/
|
*/
|
||||||
export function loadConfig<T>(configPath: string, defaultConfig: T): T {
|
export function loadConfig<T>(configPath: string, defaultConfig: T): T {
|
||||||
|
console.time(`Loading config ${configPath}`);
|
||||||
// Config exists?
|
// Config exists?
|
||||||
if (existsSync(configPath)) {
|
if (existsSync(configPath)) {
|
||||||
// Load config
|
// Load config
|
||||||
|
@ -30,12 +31,12 @@ export function loadConfig<T>(configPath: string, defaultConfig: T): T {
|
||||||
obj2: Record<string, unknown>
|
obj2: Record<string, unknown>
|
||||||
) {
|
) {
|
||||||
for (const key of Object.keys(obj2)) {
|
for (const key of Object.keys(obj2)) {
|
||||||
if (typeof obj[key] == "undefined") {
|
if (typeof obj[key] === "undefined") {
|
||||||
obj[key] = obj2[key];
|
obj[key] = obj2[key];
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof obj[key] == "object" && !Array.isArray(obj[key])) {
|
if (typeof obj[key] === "object" && !Array.isArray(obj[key])) {
|
||||||
mix(
|
mix(
|
||||||
obj[key] as Record<string, unknown>,
|
obj[key] as Record<string, unknown>,
|
||||||
obj2[key] as Record<string, unknown>
|
obj2[key] as Record<string, unknown>
|
||||||
|
@ -54,6 +55,7 @@ export function loadConfig<T>(configPath: string, defaultConfig: T): T {
|
||||||
} else {
|
} else {
|
||||||
// Write default config to disk and use that
|
// Write default config to disk and use that
|
||||||
writeConfig(configPath, defaultConfig);
|
writeConfig(configPath, defaultConfig);
|
||||||
|
|
||||||
return defaultConfig as T;
|
return defaultConfig as T;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue