Skip to content

Commit

Permalink
Merge pull request #1 from CraigChat/master
Browse files Browse the repository at this point in the history
Merge latest
  • Loading branch information
SMarioMan authored Oct 30, 2024
2 parents aa757d7 + 30f1cb4 commit d99f65e
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 37 deletions.
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Contributing

Thanks for considering contributing!

A few rules of thumb:
- This repository uses Yarn.
- Code contributions should match the existing code style.
- `yarn lint` to check the formatting
- `yarn lint:fix` to fix some of the issues
- Discuss additions/changes with us [on Discord](https://discord.gg/craig) before working on them.
- Make sure to run your own instance and ensure minor/major/dependency changes work correctly.
3 changes: 2 additions & 1 deletion apps/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dbots": "^11.0.0",
"dexare": "^3.0.1",
"dotenv": "^16.0.3",
"eris": "github:CraigChat/dysnomia#craig-master",
"eris": "github:CraigChat/dysnomia#2e2e69481c2bc7097070068d502b95ff31d26c8a",
"eventemitter3": "^4.0.7",
"fastq": "^1.13.0",
"i18next": "^21.10.0",
Expand All @@ -47,6 +47,7 @@
"nanoid": "^3.3.4",
"node-fetch": "2.6.7",
"slash-create": "^5.10.0",
"sodium-native": "^4.1.1",
"winston": "^3.11.0",
"ws": "^8.10.0"
},
Expand Down
9 changes: 6 additions & 3 deletions apps/bot/src/modules/autorecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default class AutorecordModule extends DexareModule<DexareClient<CraigBot

const error = await recording
.start(parsedRewards, userData?.webapp ?? false)
.then(() => false)
.then(() => (recording.state === RecordingState.ERROR ? recording.stateDescription || 'Unknown error' : false))
.catch((e) => e);

if (error !== false) {
Expand All @@ -233,8 +233,11 @@ export default class AutorecordModule extends DexareModule<DexareClient<CraigBot
);
reportAutorecordingError(member, guildId, channelId, error, recording);

recording.state = RecordingState.ERROR;
await recording.stop(true).catch(() => {});
if (recording.state !== RecordingState.ERROR) {
recording.state = RecordingState.ERROR;
await recording.stop(true).catch(() => {});
}

if (recording.messageID && recording.messageChannelID)
await this.client.bot
.editMessage(recording.messageChannelID, recording.messageID, {
Expand Down
27 changes: 18 additions & 9 deletions apps/bot/src/modules/recorder/recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class Recording {

messageChannelID: string | null = null;
messageID: string | null = null;
startTime: [number, number] = [0, 0];
startTime: [number, number] | null = null;
startedAt: Date | null = null;
createdAt = new Date();
logs: string[] = [];
Expand Down Expand Up @@ -344,7 +344,7 @@ export default class Recording {
})
.catch((e) => this.recorder.logger.error(`Error writing end date to recording ${this.id}`, e));

const timestamp = process.hrtime(this.startTime);
const timestamp = process.hrtime(this.startTime!);
const time = timestamp[0] * 1000 + timestamp[1] / 1000000;
if (this.startedAt)
await onRecordingEnd(this.user.id, this.channel.guild.id, this.startedAt, time, this.autorecorded, !!this.webapp, false).catch(() => {});
Expand Down Expand Up @@ -465,6 +465,7 @@ export default class Recording {
if (!alreadyConnected) {
this.connection?.removeAllListeners('connect');
this.connection?.removeAllListeners('disconnect');
this.connection?.removeAllListeners('resumed');
this.connection?.removeAllListeners('error');
this.connection?.removeAllListeners('warn');
this.connection?.removeAllListeners('debug');
Expand All @@ -478,11 +479,12 @@ export default class Recording {
connection.on('ready', this.onConnectionReady.bind(this));
connection.on('connect', this.onConnectionConnect.bind(this));
connection.on('disconnect', this.onConnectionDisconnect.bind(this));
connection.on('error', (err) => {
connection.on('resumed', this.onConnectionResumed.bind(this));
connection.on('error', (err: any) => {
this.writeToLog(`Error: ${err}`, 'connection');
this.recorder.logger.error(`Error in connection for recording ${this.id}`, err);
});
connection.on('warn', (m) => {
connection.on('warn', (m: string) => {
this.writeToLog(`Warning: ${m}`, 'connection');
this.recorder.logger.debug(`Warning in connection for recording ${this.id}`, m);
});
Expand Down Expand Up @@ -571,11 +573,17 @@ export default class Recording {

async onConnectionReady() {
if (!this.active) return;
this.writeToLog(`Voice connection ready (state=${this.connection?.ws?.readyState})`, 'connection');
this.recorder.logger.debug(`Recording ${this.id} ready`);
this.writeToLog(`Voice connection ready (state=${this.connection?.ws?.readyState}, mode=${this.connection?.mode})`, 'connection');
this.recorder.logger.debug(`Recording ${this.id} ready (mode=${this.connection?.mode})`);
this.pushToActivity('Automatically reconnected.');
}

async onConnectionResumed() {
if (!this.active) return;
this.writeToLog(`Voice connection resumed (seq=${this.connection?.wsSequence})`, 'connection');
this.recorder.logger.debug(`Recording ${this.id} resumed`);
}

async onConnectionDisconnect(err?: Error) {
if (!this.active) return;
this.writeToLog(`Got disconnected, ${err}`);
Expand Down Expand Up @@ -667,11 +675,10 @@ export default class Recording {

async onData(data: Buffer, userID: string, timestamp: number) {
if (!this.active) return;
data = Buffer.from(data);
if (!userID) return;

let recordingUser = this.users[userID];
const chunkTime = process.hrtime(this.startTime);
const chunkTime = process.hrtime(this.startTime!);
const time = chunkTime[0] * 48000 + ~~(chunkTime[1] / 20833.333);
if (!this.userPackets[userID]) this.userPackets[userID] = [];
if (!recordingUser) {
Expand Down Expand Up @@ -755,7 +762,7 @@ export default class Recording {
this.writer?.writeNoteHeader();
this.notePacketNo++;
}
const chunkTime = process.hrtime(this.startTime);
const chunkTime = process.hrtime(this.startTime!);
const chunkGranule = chunkTime[0] * 48000 + ~~(chunkTime[1] / 20833.333);
this.writer?.writeNote(chunkGranule, this.notePacketNo++, Buffer.from('NOTE' + note));
}
Expand Down Expand Up @@ -820,6 +827,7 @@ export default class Recording {
}

const startedTimestamp = this.startedAt ? Math.floor(this.startedAt.valueOf() / 1000) : null;
const voiceRegion = this.connection?.endpoint?.hostname;
return {
content: '',
embeds: [
Expand All @@ -838,6 +846,7 @@ export default class Recording {
**Recording ID:** \`${this.id}\`
**Channel:** ${this.channel.mention}
${startedTimestamp ? `**Started:** <t:${startedTimestamp}:T> (<t:${startedTimestamp}:R>)` : ''}
${voiceRegion ? `**Voice Region:** ${voiceRegion.replace(/\.discord\.media$/, '')}` : ''}
`}
`,
fields: this.logs.length
Expand Down
4 changes: 2 additions & 2 deletions apps/bot/src/modules/recorder/webapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class WebappClient {
let granulePos = message.readUIntLE(EnnuicastrParts.data.granulePos, 6);

// Calculate our "correct" time to make sure it's not unacceptably far off
const arrivalHrTime = process.hrtime(this.recording.startTime);
const arrivalHrTime = process.hrtime(this.recording.startTime!);
const arrivalTime = arrivalHrTime[0] * 48000 + ~~(arrivalHrTime[1] / 20833.333);

if (granulePos < arrivalTime - 30 * 48000 || granulePos > arrivalTime + 30 * 48000) granulePos = arrivalTime;
Expand Down Expand Up @@ -403,7 +403,7 @@ export class WebappClient {
const ret = Buffer.alloc(EnnuicastrParts.pong.length);
ret.writeUInt32LE(EnnuicastrId.PONG, 0);
data.copy(ret, EnnuicastrParts.pong.clientTime, EnnuicastrParts.ping.clientTime);
const tm = process.hrtime(this.recording.startTime);
const tm = process.hrtime(this.recording.startTime!);
ret.writeDoubleLE(tm[0] * 1000 + tm[1] / 1000000, EnnuicastrParts.pong.serverTime);
this.ws.send(this.wrapMessage(ret, clientId));
break;
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/textCommands/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class JoinCommand extends TextCommand {
style: ButtonStyle.LINK,
label: 'What are slash commands?',
url: 'https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ',
emoji: { name: '❔', id: null }
emoji: { name: '❔' }
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/textCommands/leave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class LeaveCommand extends TextCommand {
style: ButtonStyle.LINK,
label: 'What are slash commands?',
url: 'https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ',
emoji: { name: '❔', id: null }
emoji: { name: '❔' }
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function makeDownloadMessage(recording: Recording, parsedRewards: ParsedR
}
: null
].filter((c) => !!c)
} as Eris.MessageContent;
} as Eris.MessageContent<'hasNonce'>;
}

export async function blessServer(userID: string, guildID: string): Promise<MessageOptions> {
Expand Down
7 changes: 5 additions & 2 deletions apps/dashboard/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Head from 'next/head';
import { useEffect, useState } from 'react';

import Button from '../components/button';
import DropboxButton from '../components/dropboxButton';
import Dropdown, { DropdownItem } from '../components/dropdown';
import GoogleButton from '../components/googleButton';
import Link from '../components/link';
Expand All @@ -21,7 +22,6 @@ import Toggle from '../components/toggle';
import prisma from '../lib/prisma';
import { getAvatarUrl, parseUser } from '../utils';
import { DiscordUser } from '../utils/types';
import DropboxButton from '../components/dropboxButton';

interface Props {
user: DiscordUser;
Expand Down Expand Up @@ -130,7 +130,10 @@ export default function Index(props: Props) {
);
const [driveService, setDriveService] = useState(props.drive.service ?? 'google');

const driveCanEnable = (driveService === 'google' && props.googleDrive) || (driveService === 'onedrive' && props.microsoft);
const driveCanEnable =
(driveService === 'google' && props.googleDrive) ||
(driveService === 'onedrive' && props.microsoft) ||
(driveService === 'dropbox' && props.dropbox);

const benefitDate = new Date(Date.now() + 1000 * 60 * 60);
benefitDate.setMinutes(0);
Expand Down
2 changes: 1 addition & 1 deletion apps/download/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
fontFamily: {
display: ['Lexend', '"Red Hat Text"', ...sans],
body: ['"Red Hat Text"', ...sans],
mono: ['"Ubunto Mono"', ...mono]
mono: ['"Ubuntu Mono"', ...mono]
}
},
variants: {},
Expand Down
9 changes: 6 additions & 3 deletions cook/extnotes.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ int main(int argc, char **argv)

// Get the data
if (packetSize > bufSz) {
buf = realloc(buf, packetSize);
if (!buf)
unsigned char *temp = realloc(buf, packetSize); // Use a temporary pointer
if (!temp) { // Check if memory allocation failed
free(buf); // Free the existing buffer to avoid a memory leak
break;
}
buf = temp; // Only assign buf if realloc was successful
bufSz = packetSize;
}
if (readAll(0, buf, packetSize) != packetSize)
Expand Down Expand Up @@ -185,7 +188,7 @@ int main(int argc, char **argv)
m = time / 60.0;
time -= m * 60;
printf("\t%d:%02d:%02d: ", h, m, (int) time);
printNote(buf, packetSize);
printNote(buf, packetSize);
printf("\r\n");
}
}
Expand Down
Loading

0 comments on commit d99f65e

Please sign in to comment.