Skip to content

Commit

Permalink
feat: Insult people that send non text messages at leet time. (#258)
Browse files Browse the repository at this point in the history
- Update contributor.
- Add/Update watchLeet related tests.
- Only enable debug command in production environment.
  • Loading branch information
dotKuro authored Aug 19, 2020
1 parent 37cda4e commit 3c9e38f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"name": "Alexander Kampf",
"email": "akampftcg@gmail.com"
"email": "mail@akampf.dev"
},
{
"name": "Noah Hummel",
Expand Down
46 changes: 46 additions & 0 deletions src/commands/__tests__/watchLeet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe("watchLeetCommand", () => {
const store = createStore(rootReducer);
const chatId = "someChatId";
const mockCtx = {
updateType: "message",
chat: { id: chatId },
update: { message: { text: "1337" } },
reply: jest.fn(),
Expand All @@ -50,6 +51,7 @@ describe("watchLeetCommand", () => {
const chatId = "someChatId";
const fromId = "someUserId";
const mockCtx = {
updateType: "message",
chat: { id: chatId },
from: { id: fromId },
update: { message: { text: "1337" } },
Expand All @@ -72,6 +74,7 @@ describe("watchLeetCommand", () => {
const chatId = "someChatId";
const fromId = "someUserId";
const mockCtx = {
updateType: "message",
chat: { id: chatId },
from: { id: fromId },
update: { message: { text: "some stupid shit" } },
Expand All @@ -89,11 +92,35 @@ describe("watchLeetCommand", () => {
timekeeper.reset();
});

it("replies to non-text messages during leet", () => {
const store = createStore(rootReducer);
const chatId = "someChatId";
const fromId = "someUserId";
const mockCtx = {
updateType: "message",
chat: { id: chatId },
from: { id: fromId },
update: { message: {} },
reply: jest.fn(),
};

timekeeper.freeze(duringLeet.toDate());

translationMiddleware({ i18n, store })(mockCtx, () => {});
store.dispatch(actions.enableChat(chatId));
watchLeetCommand({ store, config })(mockCtx);

expect(mockCtx.reply).toHaveBeenCalled();

timekeeper.reset();
});

it("replies to multiple 1337 messages from the same person during leet", () => {
const store = createStore(rootReducer);
const chatId = "someChatId";
const fromId = "someUserId";
const mockCtx = {
updateType: "message",
chat: { id: chatId },
from: { id: fromId },
update: { message: { text: "some stupid shit" } },
Expand All @@ -112,4 +139,23 @@ describe("watchLeetCommand", () => {

timekeeper.reset();
});

it("ignores non message update types", () => {
const store = createStore(rootReducer);
const chatId = "someChatId";
const mockCtx = {
updateType: "something else",
reply: jest.fn(),
};

timekeeper.freeze(duringLeet.toDate());

translationMiddleware({ i18n, store })(mockCtx, () => {});
store.dispatch(actions.enableChat(chatId));
watchLeetCommand({ store, config })(mockCtx);

expect(mockCtx.reply).not.toHaveBeenCalled();

timekeeper.reset();
});
});
6 changes: 5 additions & 1 deletion src/commands/watchLeet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ const telegramUtility = require("../util/telegram");
const watchLeet = ({ store, config: { leetHour, leetMinute, timezone } }) => (
ctx
) => {
if (ctx.updateType !== "message") {
return;
}

const chatId = telegramUtility.chatIdInContext(ctx);

if (!getters.isChatEnabled(chatId)(store.getState())) {
return;
}

const message = telegramUtility.messageInContext(ctx);
const message = telegramUtility.messageInContext(ctx) || "";

if (isCurrentlyLeet(leetHour, leetMinute, timezone)) {
if (getters.isLeetInChatAborted(chatId)(store.getState())) {
Expand Down
6 changes: 4 additions & 2 deletions src/leetbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ module.exports = (token, config, telegramOptions) => {
bot.command("disable", commands.disable({ store }));
bot.command("info", commands.info({ store, config }));
bot.command("setLanguage", commands.setLanguage({ store }));
bot.command("debug", commands.debug({ store }));
if (process.env.NODE_ENV !== "production") {
bot.command("debug", commands.debug({ store }));
}
bot.command("score", commands.score({ store }));
bot.hears(/.*/, commands.watchLeet({ store, config }));
bot.use(commands.watchLeet({ store, config }));

// Start the bot.
bot.startPolling();
Expand Down

0 comments on commit 3c9e38f

Please sign in to comment.