-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into hiring-looking-channel
- Loading branch information
Showing
8 changed files
with
411 additions
and
268 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @lambocreeper @jason2605 @ajsaraujo @theboxmage | ||
* @lambocreeper @jason2605 @theboxmage @saramaebee |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Events, Message } from "discord.js"; | ||
import EventHandler from "../../abstracts/EventHandler"; | ||
import getConfigValue from "../../utils/getConfigValue"; | ||
|
||
class ShowcaseDiscussionThreadHandler extends EventHandler { | ||
constructor() { | ||
super(Events.MessageCreate); | ||
} | ||
|
||
async handle(message: Message): Promise<void> { | ||
if (message.channelId !== getConfigValue("SHOWCASE_CHANNEL_ID")) return; | ||
|
||
const username = message.member?.nickname ?? message.member?.user.username; | ||
|
||
try { | ||
await message.startThread({ | ||
name: `Discuss ${username}'s Showcase Post` | ||
}); | ||
} catch (error) { | ||
console.error("Failed to create thread for showcase post", { | ||
error | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export default ShowcaseDiscussionThreadHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/event/handlers/ShowcaseDiscussionThreadHandlerTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expect } from "chai"; | ||
import { createSandbox, SinonSandbox } from "sinon"; | ||
import { CustomMocks } from "@lambocreeper/mock-discord.js"; | ||
import { Events } from "discord.js"; | ||
import ShowcaseDiscussionThreadHandler from "../../../src/event/handlers/ShowcaseDiscussionThreadHandler"; | ||
import EventHandler from "../../../src/abstracts/EventHandler"; | ||
import getConfigValue from "../../../src/utils/getConfigValue"; | ||
|
||
describe("ShowcaseDiscussionThreadHandler", () => { | ||
describe("constructor()", () => { | ||
it("creates a handler for messageCreate", () => { | ||
const handler = new ShowcaseDiscussionThreadHandler(); | ||
|
||
expect(handler.getEvent()).to.equal(Events.MessageCreate); | ||
}); | ||
}); | ||
|
||
describe("handle()", () => { | ||
let sandbox: SinonSandbox; | ||
let handler: EventHandler; | ||
|
||
beforeEach(() => { | ||
sandbox = createSandbox(); | ||
handler = new ShowcaseDiscussionThreadHandler(); | ||
}); | ||
|
||
it("does nothing if the message is not sent in the showcase channel", async () => { | ||
const message = CustomMocks.getMessage({ channel_id: "not-the-showcase-channel" }); | ||
const startThreadStub = sandbox.stub(message, "startThread"); | ||
|
||
await handler.handle(message); | ||
|
||
expect(startThreadStub.called).to.be.false; | ||
}); | ||
|
||
it("creates a thread if the message is sent in the showcase channel", async () => { | ||
const message = CustomMocks.getMessage({ channel_id: getConfigValue("SHOWCASE_CHANNEL_ID") }); | ||
const startThreadStub = sandbox.stub(message, "startThread"); | ||
|
||
await handler.handle(message); | ||
|
||
expect(startThreadStub.called).to.be.true; | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters