Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally ping user within bot command's message #240

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/features/commands.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import fetch from "node-fetch";
import { Client, Message, TextChannel } from "discord.js";
import { Client, Message, TextChannel, MessageMentions } from "discord.js";
import cooldown from "./cooldown";
import { ChannelHandlers } from "../types";
import { isStaff } from "../helpers/discord";

import * as report from "../commands/report";

const prepareOptionalPingForward = ({ users, roles, repliedUser }: MessageMentions) => {
const formatReceiverID = (receiverID: string) => `<@${receiverID}>`;
const pingedReceiversIDs = [...users.keys(), ...roles.keys()];
const pingedReceivers = pingedReceiversIDs.map(formatReceiverID);

if (repliedUser?.id) {
pingedReceivers.unshift(formatReceiverID(repliedUser.id));
}

if (!pingedReceivers.length) {
return {};
}

return {
content: `Hey ${pingedReceivers.join(', ')}! :wave: Please check the hint below. :point_down: \n\u200B`
};
}

export const setupInteractions = (bot: Client) => {
bot.on("interactionCreate", (interaction) => {
if (interaction.isMessageContextMenu()) {
Expand Down Expand Up @@ -264,6 +282,7 @@ https://beta.reactjs.org/learn/sharing-state-between-components`,
category: "Reactiflux",
handleMessage: (msg) => {
msg.channel.send({
...prepareOptionalPingForward(msg.mentions),
embeds: [
{
title: "Asking to ask",
Expand Down Expand Up @@ -296,6 +315,7 @@ How To Ask Questions The Smart Way https://git.io/JKscV
category: "Reactiflux",
handleMessage: (msg) => {
msg.channel.send({
...prepareOptionalPingForward(msg.mentions),
embeds: [
{
title: "Attaching Code",
Expand All @@ -322,6 +342,7 @@ Link a Snack to share React Native examples: https://snack.expo.io
category: "Reactiflux",
handleMessage: (msg) => {
msg.channel.send({
...prepareOptionalPingForward(msg.mentions),
embeds: [
{
title: "Don’t ping or DM other devs you aren’t actively talking to",
Expand Down