Skip to content

Commit

Permalink
Make ok and err lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyaodu committed Oct 3, 2023
1 parent 9edde39 commit 9a8ef5a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 60 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "muffin",
"version": "1.0.0",
"license": "MIT",
"main": "dist/app.js",
"scripts": {
"build": "rm -rf dist && mkdir -p dist && tsc",
"lint": "eslint --cache --report-unused-disable-directives . && prettier --check .",
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MatchingJob extends Job {
}

const joined = lines.join("\n");
return errored ? Result.Err(joined) : Result.Ok(joined);
return errored ? Result.err(joined) : Result.ok(joined);
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ abstract class ScheduledDirectMessageJob extends Job {
}

const joined = lines.join("\n");
return errored ? Result.Err(joined) : Result.Ok(joined);
return errored ? Result.err(joined) : Result.ok(joined);
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ class SummaryMessageJob extends Job {
}

const joined = lines.join("\n");
return errored ? Result.Err(joined) : Result.Ok(joined);
return errored ? Result.err(joined) : Result.ok(joined);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/config-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConfigCache {
static async load(app: App): Promise<Result<ConfigCache, string>> {
const botUserIdResult = await getBotUserId(app);
if (!botUserIdResult.ok) {
return Result.Err(
return Result.err(
`could not determine bot user ID: ${botUserIdResult.error}`,
);
}
Expand All @@ -40,7 +40,7 @@ class ConfigCache {
console.log(`bot user ID: ${botUserId}`);
console.log(`loaded config: ${JSON.stringify(config.toJSON())}`);

return Result.Ok(new ConfigCache(botUserId, config));
return Result.ok(new ConfigCache(botUserId, config));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/services/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function getUsersToMatch(
const botUserId = (await cacheProvider.get(app)).botUserId;
const filtered = getMembersResult.value.filter((user) => user !== botUserId);

return Result.Ok(filtered);
return Result.ok(filtered);
}

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ async function createGroups(
): Promise<Result<undefined, string>> {
const usersResult = await getUsersToMatch(app, round.channel);
if (!usersResult.ok) {
return Result.Err(`could not get users to match: ${usersResult.error}`);
return Result.err(`could not get users to match: ${usersResult.error}`);
}

const groups = makeGroups(usersResult.value);
Expand All @@ -104,7 +104,7 @@ async function createGroups(
await round.save();
});

return Result.Ok(undefined);
return Result.ok(undefined);
}

export { createGroups };
6 changes: 3 additions & 3 deletions src/services/mock-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const mockAddReactions: typeof addReactions = async (
console.log(
`mock reactions to ${channel} ${timestamp}: ${reactions.join(", ")}`,
);
return Result.Ok(undefined);
return Result.ok(undefined);
};

const mockSendMessage: typeof sendMessage = async (
Expand All @@ -72,7 +72,7 @@ const mockSendMessage: typeof sendMessage = async (
text: string,
) => {
console.log(`mock message to ${channel}: ${text}`);
return Result.Ok(fakeTimestampGenerator.get());
return Result.ok(fakeTimestampGenerator.get());
};

const mockSendDirectMessage: typeof sendDirectMessage = async (
Expand All @@ -81,7 +81,7 @@ const mockSendDirectMessage: typeof sendDirectMessage = async (
text: string,
) => {
console.log(`mock direct message to ${userIds.join(",")}: ${text}`);
return Result.Ok([
return Result.ok([
fakeChannelGenerator.get(userIds),
fakeTimestampGenerator.get(),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/services/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function createRound(
};

const round = await RoundModel.create(rawRound);
return Result.Ok(round);
return Result.ok(round);
}

export { createRound };
44 changes: 22 additions & 22 deletions src/services/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ async function getBotUserId(app: App): Promise<Result<string, string>> {
const response = await catchWrapper(app.client.auth.test());

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

if (typeof response.user_id !== "string") {
const message = "user_id is missing from auth.test response";
console.error(message, response);
return Result.Err(message);
return Result.err(message);
}

return Result.Ok(response.user_id);
return Result.ok(response.user_id);
}

/**
Expand All @@ -75,7 +75,7 @@ async function getConversationMembers(
const response = await catchWrapper(promise);

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

if (response.members) {
Expand All @@ -85,7 +85,7 @@ async function getConversationMembers(
cursor = response.response_metadata?.next_cursor;
} while (cursor);

return Result.Ok(members);
return Result.ok(members);
}

type User = Exclude<
Expand All @@ -105,16 +105,16 @@ async function getUserInfo(
const response = await catchWrapper(app.client.users.info({ user }));

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

if (response.user === undefined) {
const message = "user is missing from users.info response";
console.error(message, response);
return Result.Err(message);
return Result.err(message);
}

return Result.Ok(response.user);
return Result.ok(response.user);
}

/**
Expand All @@ -137,10 +137,10 @@ async function addReaction(
);

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

return Result.Ok(undefined);
return Result.ok(undefined);
}

// If any of these errors are encountered when adding a reaction, don't
Expand Down Expand Up @@ -179,7 +179,7 @@ async function addReactions(
}
}

return lines.length === 0 ? Result.Ok(undefined) : Result.Err(lines);
return lines.length === 0 ? Result.ok(undefined) : Result.err(lines);
}

/**
Expand All @@ -199,16 +199,16 @@ async function sendMessage(
);

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

if (response.ts === undefined) {
const message = "ts is missing from chat.postMessage response";
console.error(message, response);
return Result.Err(message);
return Result.err(message);
}

return Result.Ok(response.ts);
return Result.ok(response.ts);
}

/**
Expand All @@ -231,10 +231,10 @@ async function editMessage(
);

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

return Result.Ok(undefined);
return Result.ok(undefined);
}

/**
Expand All @@ -254,16 +254,16 @@ async function openDirectMessage(
);

if (!response.ok) {
return Result.Err(response.error ?? "unknown error");
return Result.err(response.error ?? "unknown error");
}

if (response.channel?.id === undefined) {
const message = "channel.id is missing from conversations.open response";
console.error(message, response);
return Result.Err(message);
return Result.err(message);
}

return Result.Ok(response.channel.id);
return Result.ok(response.channel.id);
}

/**
Expand All @@ -279,16 +279,16 @@ async function sendDirectMessage(
): Promise<Result<[string, string], string>> {
const channelResult = await openDirectMessage(app, userIds);
if (!channelResult.ok) {
return Result.Err(`failed to open direct message: ${channelResult.error}`);
return Result.err(`failed to open direct message: ${channelResult.error}`);
}
const channel = channelResult.value;

const sendMessageResult = await sendMessage(app, channel, text);
if (!sendMessageResult.ok) {
return Result.Err(`failed to send message: ${sendMessageResult.error}`);
return Result.err(`failed to send message: ${sendMessageResult.error}`);
}

return Result.Ok([channel, sendMessageResult.value]);
return Result.ok([channel, sendMessageResult.value]);
}

export {
Expand Down
Loading

0 comments on commit 9a8ef5a

Please sign in to comment.