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