Skip to content

Commit

Permalink
Merge branches 'telegram-esm' and 'imagemagick'
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Dec 28, 2023
3 parents 9d46a6f + a77ec5c + d6cfe4d commit 4bff6fb
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 69 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ jobs:
rustup component add clippy
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo fmt -- --check
- name: Compile icon/resources.res
if: ${{ matrix.platform == 'windows-latest' }}
run: |
$InstallationPath = vswhere -products * -latest -prerelease -property installationPath
pushd "$($InstallationPath)\VC\Auxiliary\Build"
cmd /c "vcvarsall.bat x64 & set" |
foreach {
if ($_ -match "=") {
$v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
.\icon\create-resources.ps1
- name: Build, get version
run: |
Expand Down
17 changes: 17 additions & 0 deletions icon/create-resources.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$ErrorActionPreference = "Stop"

# https://learn.microsoft.com/en-us/windows/win32/menurc/using-rc-the-rc-command-line-

cd "$PSScriptRoot"

& magick convert icon.svg `
`( "-clone" 0 "-resize" 16x16 `) `
`( "-clone" 0 "-resize" 32x32 `) `
`( "-clone" 0 "-resize" 48x48 `) `
`( "-clone" 0 "-resize" 64x64 `) `
`( "-clone" 0 "-resize" 96x96 `) `
`( "-clone" 0 "-resize" 128x128 `) `
`( "-clone" 0 "-resize" 256x256 `) `
"-delete" 0 "-alpha" remove "-colors" 256 fend-icon.ico

& rc /v resources.rc
Binary file removed icon/fend-icon-128.png
Binary file not shown.
Binary file removed icon/fend-icon-150.png
Binary file not shown.
Binary file removed icon/fend-icon-16.png
Binary file not shown.
Binary file removed icon/fend-icon-256.ico
Binary file not shown.
Binary file removed icon/fend-icon-256.png
Binary file not shown.
Binary file removed icon/fend-icon-32.png
Binary file not shown.
Binary file removed icon/fend-icon-44.png
Binary file not shown.
Binary file removed icon/fend-icon-48.png
Binary file not shown.
Binary file removed icon/fend-icon-500.png
Binary file not shown.
Binary file removed icon/fend-icon-64.png
Binary file not shown.
Binary file removed icon/fend-icon-96.png
Binary file not shown.
Binary file removed icon/fend-icon.ico
Binary file not shown.
Binary file removed icon/resources.res
Binary file not shown.
81 changes: 33 additions & 48 deletions telegram-bot/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const fend = require('fend-wasm-nodejs');
const https = require("https");
import fend from 'fend-wasm-nodejs';

const TELEGRAM_BOT_API_TOKEN = process.env.TELEGRAM_BOT_API_TOKEN;

Expand All @@ -12,7 +11,7 @@ LAMBDA_URL="..."
curl "https://api.telegram.org/bot${TELEGRAM_BOT_API_TOKEN}/setWebhook" --form-string "url=${LAMBDA_URL}"
*/

const processInput = (input, chatType) => {
async function processInput(input, chatType) {
if (input == '/start' || input == '/help') {
return "fend is an arbitrary-precision unit-aware calculator.\n\nYou can send it maths questions like '1+1', 'sin(pi)' or 'sqrt(5)'. In group chats, you'll need to enclose your input in [[double square brackets]] like this: [[1+1]].";
}
Expand All @@ -36,7 +35,7 @@ const processInput = (input, chatType) => {
}
};

const processMessage = async (message) => {
async function processMessage(message) {
let text = message.text;
let result = processInput(text, message.chat.type);
if (result != null && result != '') {
Expand All @@ -53,7 +52,7 @@ const processMessage = async (message) => {
}
};

const processUpdate = async (update) => {
async function processUpdate(update) {
console.log('Update: ' + JSON.stringify(update));
if (update.message && update.message.text) {
await processMessage(update.message);
Expand All @@ -73,7 +72,7 @@ const processUpdate = async (update) => {
}
};

const pollUpdates = async () => {
async function pollUpdates() {
try {
var highestOffet = 441392434;
while (true) {
Expand All @@ -92,49 +91,35 @@ const pollUpdates = async () => {
}
};

const postJSON = (url, jsonBody, method='POST', headers={}) => {
return new Promise(function(resolve, reject) {
let postData = Buffer.from(JSON.stringify(jsonBody), 'utf8');
let req = https.request(url, {
method,
headers: {
'Content-Type': 'application/json ; charset=UTF-8',
'Content-Length': postData.length,
...headers
}
}, res => {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
let responseObject = JSON.parse(body);
if (responseObject.ok) {
resolve(responseObject.result);
} else {
console.log('Error: ' + JSON.stringify(responseObject));
reject(responseObject); // has fields 'description' and 'error_code'
}
});
});
req.write(postData);
req.end();
});
};
async function postJSON(url, body) {
let response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json ; charset=UTF-8',
},
body: JSON.stringify(body),
});
let responseObject = await response.json();
if (responseObject.ok) {
return responseObject.result;
} else {
const msg = 'Error: ' + JSON.stringify(responseObject);
console.log(msg);
throw new Error(msg);
}
}

if (process.env.AWS_REGION) {
// we're running in AWS Lambda
exports.handler = async (event) => {
let update = JSON.parse(event.body);
try {
await processUpdate(update);
} catch (error) {
console.log(error);
}
return { statusCode: 200, body: 'ok' };
};
} else {
export async function handler(event) {
let update = JSON.parse(event.body);
try {
await processUpdate(update);
} catch (error) {
console.log(error);
}
return { statusCode: 200, body: 'ok' };
}

if (!process.env.AWS_REGION) {
// running locally
pollUpdates();
}
1 change: 1 addition & 0 deletions telegram-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0",
"description": "Arbitrary-precision unit-aware calculator",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
14 changes: 7 additions & 7 deletions web/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ cd "$(dirname "$0")"

(cd ../wasm && wasm-pack build --target no-modules --out-dir ../web/pkg)

cp ../icon/fend-icon-128.png .
convert -resize "128x128" ../icon/icon.svg fend-icon-128.png

mkdir -p documentation

(cd ../documentation && pandoc --standalone \
--output=../web/documentation/index.html \
--metadata-file=pandoc-metadata.yml \
--lua-filter=include-code-files.lua \
--lua-filter=include-files.lua \
--lua-filter=add-header-ids.lua \
index.md)
--output=../web/documentation/index.html \
--metadata-file=pandoc-metadata.yml \
--lua-filter=include-code-files.lua \
--lua-filter=include-files.lua \
--lua-filter=add-header-ids.lua \
index.md)
28 changes: 14 additions & 14 deletions windows-msix/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ $Env:WINDOWS_CERT_PASSWORD = "MyPassword"
# $PSScriptRoot is the directory of this script

if (Test-Path $PSScriptRoot\build) {
Remove-Item -Recurse -Force $PSScriptRoot\build
Remove-Item -Recurse -Force $PSScriptRoot\build
}

if (Test-Path $PSScriptRoot\fend.msix) {
Remove-Item -Force $PSScriptRoot\fend.msix
Remove-Item -Force $PSScriptRoot\fend.msix
}

if (Test-Path $PSScriptRoot\fend-windows-x64.msix) {
Remove-Item -Force $PSScriptRoot\fend-windows-x64.msix
Remove-Item -Force $PSScriptRoot\fend-windows-x64.msix
}

mkdir $PSScriptRoot\build
Copy-Item $PSScriptRoot\..\target\release\fend.exe $PSScriptRoot\build
(Get-Content $PSScriptRoot\AppxManifest.xml).replace('$FEND_VERSION', $Env:FEND_VERSION) | Set-Content $PSScriptRoot\build\AppxManifest.xml
Copy-Item $PSScriptRoot\..\icon\fend-icon-44.png $PSScriptRoot\build
Copy-Item $PSScriptRoot\..\icon\fend-icon-150.png $PSScriptRoot\build
& magick convert -resize 44x44 $PSScriptRoot\..\icon\icon.svg $PSScriptRoot\build\fend-icon-44.png
& magick convert -resize 150x150 $PSScriptRoot\..\icon\icon.svg $PSScriptRoot\build\fend-icon-150.png

& "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\makeappx.exe" `
pack `
/d $PSScriptRoot\build `
/p $PSScriptRoot\fend.msix `
/verbose
pack `
/d $PSScriptRoot\build `
/p $PSScriptRoot\fend.msix `
/verbose

& "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe" `
sign `
/fd SHA256 /a `
/f $PSScriptRoot\fend-signing-cert.pfx `
/p $Env:WINDOWS_CERT_PASSWORD `
$PSScriptRoot\fend.msix
sign `
/fd SHA256 /a `
/f $PSScriptRoot\fend-signing-cert.pfx `
/p $Env:WINDOWS_CERT_PASSWORD `
$PSScriptRoot\fend.msix

Move-Item $PSScriptRoot\fend.msix $PSScriptRoot\fend-windows-x64.msix

0 comments on commit 4bff6fb

Please sign in to comment.