{"version":3,"file":"say.mjs","names":[],"sources":["../../src/operations/say.ts"],"sourcesContent":["import type { SingleConnection } from \"~/client/connection\";\nimport { sendPrivmsg } from \"./privmsg\";\nimport { awaitResponse } from \"~/await/await-response\";\nimport { MessageError } from \"~/client/errors\";\nimport { NoticeMessage } from \"~/message/twitch-types/notice\";\nimport { UserstateMessage } from \"~/message/twitch-types/userstate\";\n\nexport function removeCommands(message: string): string {\n  return message.startsWith(\".\") || message.startsWith(\"/\")\n    ? `/ ${message}`\n    : message;\n}\n\nexport class SayError extends MessageError {\n  public failedChannelName: string;\n  public messageText: string;\n  public action: boolean;\n\n  public constructor(\n    failedChannelName: string,\n    failedMessage: string,\n    action: boolean,\n    message: string,\n    cause?: Error,\n  ) {\n    super(message, cause);\n    this.failedChannelName = failedChannelName;\n    this.messageText = failedMessage;\n    this.action = action;\n  }\n}\n\nconst badNoticeIds = new Set([\n  \"msg_banned\", // You are permanently banned from talking in <channel>.\n  \"msg_bad_characters\", // Your message was not sent because it contained too many unprocessable characters.\n  // If you believe this is an error, please rephrase and try again.\n  \"msg_channel_blocked\", // Your message was not sent because your account is not in good standing in this channel.\n  \"msg_channel_suspended\", // This channel has been suspended.\n  \"msg_duplicate\", // Your message was not sent because it is identical to the previous one you sent,\n  // less than 30 seconds ago.\n  \"msg_emoteonly\", // This room is in emote only mode. You can find your currently available emoticons using\n  // the smiley in the chat text area.\n  \"msg_facebook\", // You must Facebook Connect to send messages to this channel. You can Facebook Connect in\n  // your Twitch settings under the connections tab.\n  \"msg_followersonly\", // This room is in <duration> followers-only mode. Follow <channel> to join the community!\n  \"msg_followersonly_followed\", // This room is in <duration1> followers-only mode. You have been following for\n  // <duration2>. Continue following to chat!\n  \"msg_followersonly_zero\", // This room is in followers-only mode. Follow <channel> to join the community!\n  \"msg_r9k\", // This room is in r9k mode and the message you attempted to send is not unique.\n  \"msg_ratelimit\", // Your message was not sent because you are sending messages too quickly.\n  \"msg_rejected\", // \tHey! Your message is being checked by mods and has not been sent.\n  \"msg_rejected_mandatory\", // Your message wasn't posted due to conflicts with the channel's moderation settings.\n  \"msg_room_not_found\", // The room was not found.\n  \"msg_slowmode\", // This room is in slow mode and you are sending messages too quickly. You will be able to\n  // talk again in <number> seconds.\n  \"msg_subsonly\", // This room is in subscribers only mode. To talk, purchase a channel subscription at\n  // https://www.twitch.tv/products/<broadcaster login name>/ticket?ref=subscriber_only_mode_chat.\n  \"msg_suspended\", // Your account has been suspended.\n  \"msg_timedout\", // You are banned from talking in <channel> for <number> more seconds.\n  \"msg_verified_email\", // \tThis room requires a verified email address to chat. Please verify your email at\n  // https://www.twitch.tv/settings/profile.\n]);\n\nexport async function say(\n  conn: SingleConnection,\n  channelName: string,\n  messageText: string,\n  replyToId?: string,\n  action = false,\n): Promise<UserstateMessage> {\n  let command;\n  let errorMessage;\n  let errorType: (message: string, cause?: Error) => Error;\n  if (action) {\n    command = `/me ${messageText}`;\n    errorMessage = `Failed to say [#${channelName}]: /me ${messageText}`;\n    errorType = (message, cause) =>\n      new SayError(channelName, messageText, true, message, cause);\n  } else {\n    command = removeCommands(messageText);\n    errorMessage = `Failed to say [#${channelName}]: ${messageText}`;\n    errorType = (message, cause) =>\n      new SayError(channelName, messageText, false, message, cause);\n  }\n  void sendPrivmsg(conn, channelName, command, replyToId);\n\n  return awaitResponse(conn, {\n    success: (message): message is UserstateMessage =>\n      message instanceof UserstateMessage &&\n      message.channel.login === channelName,\n    failure: (message) =>\n      message instanceof NoticeMessage &&\n      message.channel?.login === channelName &&\n      badNoticeIds.has(message.id!),\n    errorType,\n    errorMessage,\n  });\n}\n\nexport async function me(\n  conn: SingleConnection,\n  channelName: string,\n  message: string,\n): Promise<UserstateMessage> {\n  return say(conn, channelName, message, undefined, true);\n}\n\nexport async function reply(\n  conn: SingleConnection,\n  channelName: string,\n  messageID: string,\n  message: string,\n): Promise<UserstateMessage> {\n  return say(conn, channelName, message, messageID);\n}\n"],"mappings":";;;;;;AAOA,SAAgB,eAAe,SAAyB;AACtD,QAAO,QAAQ,WAAW,IAAI,IAAI,QAAQ,WAAW,IAAI,GACrD,KAAK,YACL;;AAGN,IAAa,WAAb,cAA8B,aAAa;CACzC;CACA;CACA;CAEA,YACE,mBACA,eACA,QACA,SACA,OACA;AACA,QAAM,SAAS,MAAM;AACrB,OAAK,oBAAoB;AACzB,OAAK,cAAc;AACnB,OAAK,SAAS;;;AAIlB,MAAM,eAAe,IAAI,IAAI;CAC3B;CACA;CAEA;CACA;CACA;CAEA;CAEA;CAEA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CAED,CAAC;AAEF,eAAsB,IACpB,MACA,aACA,aACA,WACA,SAAS,OACkB;CAC3B,IAAI;CACJ,IAAI;CACJ,IAAI;AACJ,KAAI,QAAQ;AACV,YAAU,OAAO;AACjB,iBAAe,mBAAmB,YAAY,SAAS;AACvD,eAAa,SAAS,UACpB,IAAI,SAAS,aAAa,aAAa,MAAM,SAAS,MAAM;QACzD;AACL,YAAU,eAAe,YAAY;AACrC,iBAAe,mBAAmB,YAAY,KAAK;AACnD,eAAa,SAAS,UACpB,IAAI,SAAS,aAAa,aAAa,OAAO,SAAS,MAAM;;AAE5D,aAAY,MAAM,aAAa,SAAS,UAAU;AAEvD,QAAO,cAAc,MAAM;EACzB,UAAU,YACR,mBAAmB,oBACnB,QAAQ,QAAQ,UAAU;EAC5B,UAAU,YACR,mBAAmB,iBACnB,QAAQ,SAAS,UAAU,eAC3B,aAAa,IAAI,QAAQ,GAAI;EAC/B;EACA;EACD,CAAC;;AAGJ,eAAsB,GACpB,MACA,aACA,SAC2B;AAC3B,QAAO,IAAI,MAAM,aAAa,SAAS,KAAA,GAAW,KAAK;;AAGzD,eAAsB,MACpB,MACA,aACA,WACA,SAC2B;AAC3B,QAAO,IAAI,MAAM,aAAa,SAAS,UAAU"}