34}
35
36// Zulip API helpers
37async function getStreamId(streamName) {
38 const response = await fetch(`${ZULIP_URL}/api/v1/get_stream_id?stream=${encodeURIComponent(streamName)}`, {
39 headers: {
40 "Authorization": `Basic ${btoa(`${ZULIP_BOT_EMAIL}:${ZULIP_BOT_KEY}`)}`,
46
47async function getStreamTopics(streamId) {
48 const response = await fetch(`${ZULIP_URL}/api/v1/users/me/${streamId}/topics`, {
49 headers: {
50 "Authorization": `Basic ${btoa(`${ZULIP_BOT_EMAIL}:${ZULIP_BOT_KEY}`)}`,
56
57async function sendMessage(stream, topic, content) {
58 const response = await fetch(`${ZULIP_URL}/api/v1/messages`, {
59 method: "POST",
60 headers: {
1import { spotifyAPI } from "https://esm.town/v/stevekrouse/spotifyAPI";
2import { spotifyGetPlaylistTracks } from "https://esm.town/v/neverstew/spotifyGetPlaylistTracks";
3
10 const tracks = tracksRes.items.map(i => i.track);
11
12 return spotifyAPI({
13 token,
14 endpoint: `playlists/${id}/tracks`,
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export let spotifyAPI = ({ token, endpoint, ...params }) =>
4 fetchJSON(
5 `https://api.spotify.com/v1/${endpoint}${
6 "method" in params && ["POST", "PUT", "DELETE"].includes(params["method"])
7 ? ""
1import { spotifyAPI } from "https://esm.town/v/stevekrouse/spotifyAPI";
2
3export let spotifyGetPlaylist = async (id, { token, ...params }) =>
4 spotifyAPI({
5 token,
6 endpoint: `playlists/${id}?${new URLSearchParams(params).toString()}`,
1import { spotifyAPI } from "https://esm.town/v/stevekrouse/spotifyAPI";
2
3export let spotifyCreatePlaylist = async ({ token, ...params }) =>
4 spotifyAPI({
5 token,
6 endpoint: `users/funkmastermatt/playlists`,
52 try {
53 // Get access token
54 const response = await fetch("https://accounts.spotify.com/api/token", {
55 method: "POST",
56 headers: {
69 return accessToken;
70 }
71 console.error("Bad response from Spotify API", await response.text());
72 throw Error("Unable to request Spotify Access Token");
73 } catch (e) {
1# getSpotifyAccess Token
2
3Request an access token for use with the Spotify Web API.
4
5Requires environment variables from your Spotify Developers account.
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
10
11# Todos
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1148 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1149 <title>CerebrasCoder</title>
1150 <link rel="preconnect" href="https://fonts.googleapis.com" />
1151 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1152 <link
1153 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1154 rel="stylesheet"
1155 />
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
10
11# Todos