From 7051a0b8411197dd5e506d41c70c2cc91ba88a8c Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 1 Sep 2023 12:04:43 -0600 Subject: [PATCH] Add country code to SMS messages --- index.js | 9 +++++---- package-lock.json | 11 ++++++++++- package.json | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 70ec2c1..3679280 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ // a simple express server that takes any URL and console logs it const config = require('./config.json'); +const phone = require("phone").phone; const express = require('express'); const axios = require('axios'); const Discord = require('discord.js'); @@ -70,13 +71,13 @@ app.post('/sms', async (req, res) => { hook.send({ content: out['text'], files: out['images'], - username: "MMS", + username: `MMS [${phone(`+${data.From}`).countryIso3}]`, avatarURL: encodeURI(`https://tiley.herokuapp.com/avatar/${cnam.replaceAll(" ", "")}/${cnam.replaceAll(" ", "")}.png?s=500`) }) modhook.send({ content: out['text'], files: out['images'], - username: `MMS from ${cnam} (${data.From})`, + username: `MMS from ${cnam} (${data.From}) [${phone(`+${data.From}`).countryIso3}]`, avatarURL: encodeURI(`https://tiley.herokuapp.com/avatar/${cnam.replaceAll(" ", "")}/${cnam.replaceAll(" ", "")}.png?s=500`) }) } else { // It's an SMS @@ -84,12 +85,12 @@ app.post('/sms', async (req, res) => { data.Message = decodeURIComponent(data.Message); hook.send({ content: data.Message, - username: "SMS", + username: `SMS [${phone(`+${data.From}`).countryIso3}]`, avatarURL: encodeURI(`https://tiley.herokuapp.com/avatar/${cnam.replaceAll(" ", "")}/${cnam.replaceAll(" ", "")}.png?s=500`) }) modhook.send({ content: data.Message, - username: `SMS from ${cnam} (${data.From})`, + username: `SMS from ${cnam} (${data.From}) [${phone(`+${data.From}`).countryIso3}]`, avatarURL: encodeURI(`https://tiley.herokuapp.com/avatar/${cnam.replaceAll(" ", "")}/${cnam.replaceAll(" ", "")}.png?s=500`) }) } diff --git a/package-lock.json b/package-lock.json index e88e709..8f4cbc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "discord.js": "^14.13.0", "express": "^4.18.2", "ffmpeg": "^0.0.4", - "ffmpeg-static": "^5.2.0" + "ffmpeg-static": "^5.2.0", + "phone": "^3.1.40" } }, "node_modules/@derhuerst/http-basic": { @@ -833,6 +834,14 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" }, + "node_modules/phone": { + "version": "3.1.40", + "resolved": "https://registry.npmjs.org/phone/-/phone-3.1.40.tgz", + "integrity": "sha512-RyQgv8Xl8a43LFBLrYnlS2rTOFFg5Se6DNTG2OXHZlWqC7cHcD/KA1irHjJToeQOoCVZg63pYIlXqG4cuOj/vg==", + "engines": { + "node": ">=12" + } + }, "node_modules/progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", diff --git a/package.json b/package.json index 7f2e4f2..a7c4095 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "discord.js": "^14.13.0", "express": "^4.18.2", "ffmpeg": "^0.0.4", - "ffmpeg-static": "^5.2.0" + "ffmpeg-static": "^5.2.0", + "phone": "^3.1.40" } }