Skip to content

Commit

Permalink
Merge pull request #153 from slmnio/voicestream
Browse files Browse the repository at this point in the history
Voicestream
  • Loading branch information
slmnio authored Nov 19, 2022
2 parents 630463d + 35f5664 commit 5ccbf27
Show file tree
Hide file tree
Showing 20 changed files with 1,189 additions and 18 deletions.
3 changes: 3 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"nodemon": "^2.0.7"
},
"dependencies": {
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.13.0",
"@twurple/api": "^5.2.5",
"@twurple/auth": "^5.2.5",
"airtable": "^0.10.1",
Expand All @@ -28,6 +30,7 @@
"discord.js": "^13.3.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"libsodium-wrappers": "^0.7.10",
"node-fetch": "^2.6.1",
"ora": "^5.4.0",
"sharp": "^0.30.1",
Expand Down
2 changes: 1 addition & 1 deletion server/src/airtable-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function setRebuilding(isRebuilding) {
// Starting with syncing Matches

// const tables = ["Matches", "Teams", "Themes", "Events", "Players", "Player Relationships"];
const tables = ["Broadcasts", "Clients", "Channels", "Players", "Events", "Event Series", "Teams", "Ad Reads", "Ad Read Groups", "News", "Matches", "Themes", "Socials", "Accolades", "Player Relationships", "Brackets", "Live Guests", "Headlines", "Maps", "Map Data", "Heroes", "Log Files", "Tracks", "Track Groups", "Track Group Roles"];
const tables = ["Broadcasts", "Clients", "Channels", "Discord Bots", "Players", "Events", "Event Series", "Teams", "Ad Reads", "Ad Read Groups", "News", "Matches", "Themes", "Socials", "Accolades", "Player Relationships", "Brackets", "Live Guests", "Headlines", "Maps", "Map Data", "Heroes", "Log Files", "Tracks", "Track Groups", "Track Group Roles"];
const staticTables = ["Redirects"];

function deAirtable(obj) {
Expand Down
20 changes: 17 additions & 3 deletions server/src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ async function dataUpdate(id, data, options) {
if (JSON.stringify(store.get(id)) !== JSON.stringify(data)) {
// console.log(`Data update on [${id}]`);
recents.sent++;
if (!(options && options.custom)) updateFunction(id, { oldData: store.get(id), newData: data });
if (data) data = await removeAntiLeak(id, data);
// if (options?.eager) console.log("Sending");
await broadcast(id, "data_update", id, data);
if (!(options && options.custom)) updateFunction(id, { oldData: store.get(id), newData: data });
}
}

Expand Down Expand Up @@ -198,7 +198,13 @@ async function set(id, data, options) {

if (data?.__tableName === "Channels") {
auth.set(`channel_${id}`, data);
return; // not setting it on global requestble store
return; // not setting it on global requestable store
}

if (data?.__tableName === "Discord Bots") {
auth.set(`bot_${cleanID(id)}`, data);

return; // not setting it on global requestable store
}

if (data?.__tableName === "Events") {
Expand Down Expand Up @@ -266,6 +272,7 @@ async function set(id, data, options) {

await dataUpdate(id, data, options);
store.set(id, data);

}
function cleanID(id) {
if (!id) return null;
Expand Down Expand Up @@ -318,12 +325,18 @@ async function getPlayer(discordID) {
async function getChannel(airtableID) {
return auth.get(`channel_${cleanID(airtableID)}`);
}
async function getBot(airtableID) {
return auth.get(`bot_${cleanID(airtableID)}`);
}
async function getChannelByID(channelID) {
return (await getChannels()).find(channel => channel.channel_id === channelID);
}
async function getChannels() {
return await Promise.all(((await get("Channels"))?.ids || []).map(id => getChannel(id)));
}
async function getBots() {
return await Promise.all(((await get("Discord Bots"))?.ids || []).map(id => getBot(id)));
}

async function getTwitchAccessToken(channel) {
// get stored access token, check if it's valid
Expand All @@ -349,6 +362,7 @@ module.exports = {
getPlayer,
getChannel,
getChannelByID,
getTwitchAccessToken
getTwitchAccessToken,
getBots
}
};
1 change: 1 addition & 0 deletions server/src/custom-datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function tableUpdated(tableName, Cache) {
if (tableName === "Matches") matchUpdate(Cache);
if (tableName === "Broadcasts") broadcastUpdate(Cache);
if (tableName === "Players") playerList(Cache);
// TODO: maybe add discord bots here?
}
module.exports = tableUpdated;

Expand Down
Loading

0 comments on commit 5ccbf27

Please sign in to comment.