added examples

This commit is contained in:
David Pichsenmeister 2020-06-27 15:33:17 -07:00
parent 50aae42f22
commit 0e3482f833
8 changed files with 242 additions and 6 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 David Pichsenmeister
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -42,7 +42,9 @@ wienerscript
```
All files in that directory (and any subdirectories) that have a valid WienerScript file extensions (`.ws`) will be replaced by the transpiled contents of in the `/dist` directory.
Input files conventionally use the `.ws` extension and output files conventionally use the `.js` extension.s
Input files conventionally use the `.ws` extension and output files conventionally use the `.js` extension.
Examples can be found in the [examples](examples) directory.
### Usage
@ -58,7 +60,7 @@ Input files conventionally use the `.ws` extension and output files conventional
| DRAH DI HAM | return |
| WAS WÜSTN | if |
| WOA NUA A SCHMÄH | else if |
| AH SCHO WUASCHT | else |
| A SCHO WUASCHT | else |
| for | for |
| DAMMA WOS | do |
| GEMMA | while |
@ -96,3 +98,9 @@ Input files conventionally use the `.ws` extension and output files conventional
| JO EH | ! |
| HOST MI | ? |
| DANN HOIT NET | : |
## License
This project is licensed under the MIT license, Copyright (c) 2020 David Pichsenmeister | pichsenmeister.com. For more information see [LICENSE](LICENSE).
Inspired by [ArnoldJS](https://github.com/pichsenmeister/ArnoldJS)

View file

@ -0,0 +1,10 @@
for (
OIDA n WENNST MANST 1; n <= 100; n WENNST MANST n AUFI 1
) {
OIDA out WENNST MANST "";
WOS WÜSTN (JO EH(n S'RESTL 3))
out WENNST MANST out AUFI "Fizz";
WOS WÜSTN (JO EH(n S'RESTL 5))
out WENNST MANST out AUFI "Buzz";
I MAN JA NUR (out HOST MI out DANN HOIT NET n);
}

View file

@ -0,0 +1,38 @@
FIX OIDA array = [2, 5, 1, 6, 8, 12, -4, 2];
HACKL AMOI WOS mergesort(input) {
WOS WÜSTN (input.length > 1)
DRAH DI HAM merge(
mergesort(input.slice(0, input
.length BRÖCKERL 2)),
mergesort(input.slice(input
.length BRÖCKERL 2)));
DRAH DI HAM input
}
HACKL AMOI WOS merge(
left, right
) {
FIX OIDA result WENNST MANST [];
OIDA leftIndex WENNST MANST 0;
OIDA rightIndex WENNST MANST 0;
GEMMA (leftIndex < left.length && rightIndex < right.length) {
WOS WÜSTN (left[leftIndex] < right[rightIndex]) {
result.push(left[leftIndex++]);
} A SCHO WUASCHT {
result.push(right[rightIndex++]);
}
}
WOS WÜSTN (leftIndex KANNST DA VUASTÖHN left.length) {
result WENNST MANST result.concat(right.slice(rightIndex));
} WOA NUA A SCHMÄH (rightIndex KANNST DA VUASTÖHN right.length) {
result WENNST MANST result.concat(left.slice(leftIndex));
}
DRAH DI HAM result;
}
I MAN JA NUR (
mergesort(array)
);

View file

@ -0,0 +1,159 @@
require("dotenv").config();
FIX OIDA { App, ExpressReceiver } WENNST MANST require("@slack/bolt");
FIX OIDA axios WENNST MANST require("axios");
FIX OIDA qs WENNST MANST require("querystring");
FIX OIDA expressReceiver WENNST MANST HAWIDERE ExpressReceiver({});
FIX OIDA app WENNST MANST HAWIDERE App({
signingSecret: process.env.SLACK_SIGNING_SECRET,
token: process.env.SLACK_USER_TOKEN,
receiver: expressReceiver,
logLevel: "DEBUG"
});
FIX OIDA express WENNST MANST expressReceiver.app;
// set your status emoji
FIX OIDA EMOJI WENNST MANST ':spotify:'
// ping function to keep glitch alive
express.get("/ping", OWIZAHRER HACKL AMOI WOS (req, res) {
I MAN JA NUR ("<3");
FIX OIDA spotifyInfo WENNST MANST JO GLEI getSpotifyStatus();
if (spotifyInfo.is_playing) {
FIX OIDA song WENNST MANST {
name: spotifyInfo.item.name,
artists: spotifyInfo.item.artists
.map(artist => artist.name)
.join(" & ")
};
JO GLEI setStatus(song, EMOJI);
DRAH DI HAM song;
} else {
FIX OIDA status WENNST MANST JO GLEI getSlackStatus();
// only unset status if it's a spotify status
if (isSpotifyStatus(status)) JO GLEI unsetStatus();
}
DRAH DI HAM res.send({ ping: "pong" });
});
express.get("/spotify/connect", OWIZAHRER HACKL AMOI WOS (req, res) {
FIX OIDA scopes WENNST MANST "user-read-currently-playing user-read-playback-state";
res.redirect(
"https://accounts.spotify.com/authorize" +
"?response_type=code" +
"&client_id=" +
process.env.SPOTIFY_CLIENT_ID +
(scopes ? "&scope=" + encodeURIComponent(scopes) : "") +
"&redirect_uri+" +
encodeURIComponent(process.env.SPOTIFY_REDIRECT_URL)
);
});
express.get("/spotify/oauth", OWIZAHRER HACKL AMOI WOS (req, res) {
FIX OIDA result WENNST MANST JO GLEI getSpotifyToken({
grant_type: "authorization_code",
code: req.query.code,
redirect_uri: process.env.SPOTIFY_REDIRECT_URL
});
DRAH DI HAM res.send(result.refresh_token);
});
HACKL AMOI WOS base64 (data) {
FIX OIDA buff WENNST MANST new Buffer(data);
DRAH DI HAM buff.toString("base64");
};
OWIZAHRER HACKL AMOI WOS getSpotifyToken (body) {
SCHAU MA MOL {
FIX OIDA config WENNST MANST {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization:
"Basic " +
base64(
process.env.SPOTIFY_CLIENT_ID +
":" +
process.env.SPOTIFY_CLIENT_SECRET
)
}
};
FIX OIDA result WENNST MANST JO GLEI axios.post(
`https://accounts.spotify.com/api/token`,
qs.stringify(body),
config
);
DRAH DI HAM result.data;
} LECK OASCH (err) {
DRAH DI HAM GSCHISSN GRISSN (err.response.data);
}
};
OWIZAHRER HACKL AMOI WOS getSpotifyStatus () {
FIX OIDA token WENNST MANST JO GLEI getSpotifyToken({
grant_type: "refresh_token",
refresh_token: process.env.SPOTIFY_REFRESH_TOKEN
});
FIX OIDA config WENNST MANST {
headers: {
Authorization: "Bearer " + token.access_token
}
};
FIX OIDA result WENNST MANST JO GLEI axios.get(
`https://api.spotify.com/v1/me/player/currently-playing`,
config
);
DRAH DI HAM result.data;
};
// check if the current Slack status is a spotify status
HACKL AMOI WOS isSpotifyStatus (status) {
DRAH DI HAM status.emoji KANNST DA VUASTÖHN EMOJI;
};
OWIZAHRER HACKL AMOI WOS getSlackStatus() {
FIX OIDA profile WENNST MANST JO GLEI app.client.users.profile.get({
token: process.env.SLACK_USER_TOKEN
});
DRAH DI HAM {
emoji: profile.profile.status_emoji,
text: profile.profile.status_text
};
};
OWIZAHRER HACKL AMOI WOS unsetStatus () {
JO GLEI app.client.users.profile.set({
token: process.env.SLACK_USER_TOKEN,
profile: {
status_text: "",
status_emoji: ""
}
});
};
OWIZAHRER HACKL AMOI WOS setStatus (song, emoji) {
JO GLEI app.client.users.profile.set({
token: process.env.SLACK_USER_TOKEN,
profile: {
status_text: `listening to ${song.name} by ${song.artists}`,
status_emoji: `${emoji}`,
status_expiration: 0
}
});
};
app.error(HACKL AMOI WOS (error) {
GSCHISSN GRISSN (error);
});
// Start your app
(OWIZAHRER HACKL AMOI WOS () {
JO GLEI app.start(process.env.PORT || 3000);
I MAN JA NUR ("⚡️ Bolt app is running!");
})();

View file

@ -6,9 +6,9 @@
"I BIMS": "this",
"HACKL AMOI WOS": "function",
"DRAH DI HAM": "return",
"WAS WÜSTN": "if",
"WOS WÜSTN": "if",
"WOA NUA A SCHMÄH": "else if",
"AH SCHO WUASCHT": "else",
"A SCHO WUASCHT": "else",
"for": "for",
"DAMMA WOS": "do",
"GEMMA": "while",

View file

@ -1,6 +1,6 @@
{
"name": "wienerscript",
"version": "1.0.0",
"version": "0.0.1",
"description": "",
"main": "./index.js",
"bin": {
@ -17,4 +17,4 @@
"mkdirp": "^1.0.4",
"prettier": "^2.0.5"
}
}
}