diff --git a/src/DirectMessages/DMHandler.ts b/src/DirectMessages/DMHandler.ts index 49e3cbc..d2866fe 100644 --- a/src/DirectMessages/DMHandler.ts +++ b/src/DirectMessages/DMHandler.ts @@ -1,6 +1,6 @@ import { sendDirectMessage } from 'services/twitter-api'; import { findUser } from 'services/database'; -import TEXTS from './texts'; +import { getRandomUserNotFoundMessage } from './texts'; import { handleConfig, handleProject, handleDefaultDM, handleDelete, handleDeleteAll, handleInit, handleMain, handleHelp, handleThread } from './handlers'; import { handleSettings } from './settings/handleSettings'; @@ -12,7 +12,7 @@ function withUser() { const userId = message.sender_id; const user = await findUser(userId); - if (!user) return sendDirectMessage(userId, TEXTS.USER_NOT_FOUND); + if (!user) return sendDirectMessage(userId, getRandomUserNotFoundMessage()); return mainFunc(message, user); }; diff --git a/src/DirectMessages/handlers.ts b/src/DirectMessages/handlers.ts index 73b7813..91c696e 100644 --- a/src/DirectMessages/handlers.ts +++ b/src/DirectMessages/handlers.ts @@ -1,5 +1,5 @@ import type { Project } from '@doist/todoist-api-typescript'; -import TEXTS, { generateConfigText, generateInitText, generateInvalidDMText } from './texts'; +import TEXTS, { generateConfigText, generateInitText, generateInvalidDMText, getRandomAddedToAccountText } from './texts'; import { getTodoistProjects, getTodoistUserData, revokeAccessToken, addTodoistTask } from 'services/todoist-api'; import { getProjectNumFromMessage, getDefaultTaskContent, getUserCustomTaskContent } from 'services/texts'; import { decryptString } from 'services/crypto'; @@ -123,7 +123,7 @@ const handleDefaultDM: DMHandlerFunction = async (message, user) => { if (user.noResponse) return; - sendDirectMessage(userId, TEXTS.ADDED_TO_ACCOUNT); + sendDirectMessage(userId, getRandomAddedToAccountText()); }; const handleInvalidDM = async (message) => { @@ -171,8 +171,10 @@ const handleMain: DMHandlerFunction = async (message: TWDirectMessage, user) => Bugsnag.notify(e); return sendDirectMessage(userId, TEXTS.BAD_TOKEN + '\nErr: TDS_ERROR'); } + + if (user.noResponse) return; - sendDirectMessage(userId, TEXTS.ADDED_TO_ACCOUNT); + sendDirectMessage(userId, getRandomAddedToAccountText()); }; const handleThread: DMHandlerFunction = async (message: TWDirectMessage, user) => { @@ -214,7 +216,9 @@ const handleThread: DMHandlerFunction = async (message: TWDirectMessage, user) = return sendDirectMessage(userId, TEXTS.BAD_TOKEN + '\nErr: TDS_ERROR'); } - sendDirectMessage(userId, TEXTS.ADDED_TO_ACCOUNT); + if (user.noResponse) return; + + sendDirectMessage(userId, getRandomAddedToAccountText()); }; diff --git a/src/DirectMessages/texts.ts b/src/DirectMessages/texts.ts index 993dda7..bfab052 100644 --- a/src/DirectMessages/texts.ts +++ b/src/DirectMessages/texts.ts @@ -1,37 +1,74 @@ -enum TWHookServerTexts { - USER_NOT_FOUND = 'šŸ”“ User Not Found.\nPlease use\n/init\nto initialize your account', - INVALID_PROJECT_NUM = 'šŸ”“ Invalid project number\n', - BAD_TOKEN = 'šŸ”“ Something is wrong with your account configuration.\nPlease run\n/init\ncommand', - TWEETS_SAVED_TO = 'šŸ”“ Now the tweets will be saved to:\n', - ADDED_TO_ACCOUNT = 'šŸ”“ Added to your account', - CANT_DELETE = 'šŸ”“ Can\'t delete your account. Try again. If the problem persists, contact @dubisdev_', - DELETED_ACCOUNT = 'šŸ”“ All your account data has been deleted', - ALERT_DELETE = 'šŸ”“ Are you sure you want to delete your account? This action CAN NOT be undone. \nType\n/deleteall\nto continue', - HELP = 'šŸ”“ Available Commands:\n\n/init - Set up your account\n/config - Get your account data\n/delete - Delete your account\n/project - Set up your default project\n/help - Shows this message\n\nāš ļø Don\'t forget the slash (/) before the command' -} -export const generateInitText = (userId: string) => ` -šŸ”“ Hi there!\n\ +export const getRandomAddedToAccountText = () => { + const texts = [ + 'šŸ”“ Added to your account', + 'šŸ”“ Tweet added to your account', + 'šŸ”“ I\'ve added that to your account', + 'šŸ”“ The tweet\'s been added to your account', + 'šŸš€ Tweet added to your account', + 'šŸš€ Added to your account', + 'šŸš€ I\'ve added that to your account', + 'šŸš€ The tweet\'s been added to your account'] as const; + return texts[Math.floor(Math.random() * texts.length)]; +}; + +export const getRandomUserNotFoundMessage = () => { + const texts = [ + 'šŸ”“ User not found. Please send \'/init\' to start using this bot', + 'āŒ User not found. Please send \'/init\' to start using this bot', + 'šŸ”“ I couldn\'t find you in my database. Please send \'/init\' to start using this bot', + 'āŒ I couldn\'t find you in my database. Please send \'/init\' to start using this bot', + 'ā“ User Not Found. Who are you? Please send \'/init\' to start using this bot', + 'ā“ I couldn\'t find you in my database. Who are you? Please send \'/init\' to start using this bot', + 'šŸ”“ User Not Found. Who are you? Please send \'/init\' to start using this bot' + ] as const; + return texts[Math.floor(Math.random() * texts.length)]; +}; + +const TWHookServerTexts = { + USER_NOT_FOUND: 'šŸ”“ User Not Found.\nPlease use\n/init\nto initialize your account', + INVALID_PROJECT_NUM: 'šŸ”“ Invalid project number\n', + BAD_TOKEN: 'šŸ”“ Something is wrong with your account configuration.\nPlease run\n/init\ncommand', + TWEETS_SAVED_TO: 'šŸ”“ Now tweets will be saved to:\n', + CANT_DELETE: 'šŸ”“ Can\'t delete your account. Maybe your account has already been deleted?', + DELETED_ACCOUNT: 'šŸ”“ All your account data has been deleted', + ALERT_DELETE: 'šŸ”“ Are you sure you want to delete your account? This action CAN NOT be undone. \nType\n/deleteall\nto continue', + HELP: 'šŸ”“ Available Commands:\n\n/init - Set up your account\n/config - Get your account data\n/delete - Delete your account\n/project - Set up your default project\n/help - Shows this message\n\nāš ļø Don\'t forget the slash (/) before the command' +} as const; + +export const generateInitText = (userId: string) => { + const HEADER_EMOJIS = ['šŸ”“', 'šŸ‘‹', 'šŸš€', 'šŸ“’'] as const; + const headerEmoji = HEADER_EMOJIS[Math.floor(Math.random() * HEADER_EMOJIS.length)]; + return ` +${headerEmoji} Hi there!\n\ I'm AddTodoist bot and I'm here to help you save tweets and threads to your Todoist account.\n\ \nFirst of all, you must cofigure me for making me able to access your account.\n\n\ Follow this steps:\n\ 1. Go to https://todoist.com/oauth/authorize?client_id=${process.env.TODOIST_CLIENT_ID}&scope=data:read_write&state=${userId}\n\ 2. Grant app permissions.\n\ 3. When you are done I will come back to set up your projects cofiguration.`; +}; export const generateConfigText = ({ username, email, projectName, projectId, -}) => ` -šŸ”“ This is your current configuration:\n\ +}) => { + const HEADER_EMOJIS = ['šŸ”“', 'āš™ļø', 'ā¬‡ļø', 'šŸ”Ž'] as const; + const headerEmoji = HEADER_EMOJIS[Math.floor(Math.random() * HEADER_EMOJIS.length)]; + return ` +${headerEmoji} This is your current configuration:\n\ - Username: ${username}\n\ - Email: ${email}\n\ - Project: ${projectName} (id: ${projectId})`; +}; -export const generateInvalidDMText = (username: string) => ` -šŸ”“ Welcome ${username}!\n\n\ +export const generateInvalidDMText = (username: string) => { + const HEADER_EMOJIS = ['šŸ”“', 'šŸš«', 'āŒ', 'ā“'] as const; + const headerEmoji = HEADER_EMOJIS[Math.floor(Math.random() * HEADER_EMOJIS.length)]; + return ` +${headerEmoji} Hi ${username}!\n\n\ It seems like you have sent me an invalid message.\n\n\ Please, send me a valid command or type\n\ '/init'\n\ @@ -39,5 +76,6 @@ to start your account configuration.\n\n\ For more information type\n\ '/help'\n\n\ āš ļø Don't forget the slash (/) before the commands`; +}; export default TWHookServerTexts;