Reintroducing topic handling

This commit is contained in:
Alex Thomassen 2023-01-11 20:40:11 +00:00
parent eb2538edc0
commit 1357336ba0
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
3 changed files with 18 additions and 3 deletions

View File

@ -5,6 +5,7 @@ Spaghetti code music bot to replace the garbage that's SinusBot.
## Requirements
- Node.js v19
- Node.js v18 LTS should work as well, but it was developed on v19.
- npm
- TypeScript
- `npm install -g typescript`
@ -17,3 +18,5 @@ Spaghetti code music bot to replace the garbage that's SinusBot.
2. Copy `config.sample.js` to `config.js` and fill in the values
3. Run `npm install`
4. Run `npm run start`
- Alternatively, deploy it as a `pm2 service` using `npm run deploy`
- For updating the pm2 service after changes, run `npm run update`

View File

@ -414,7 +414,16 @@ async function search(message: Message, words: string[])
return;
}
const result = results[0];
console.log('YouTube results from search', search, results);
let result = results[0];
if (!options['no-topic']) {
const topicResult = results.find(video => video.snippet.channelTitle.includes('- Topic'));
if (topicResult) {
result = topicResult;
console.log('"Topic" found, using that instead of the first result', result);
}
}
// Remove the "searching" reaction
if (searching) {

View File

@ -39,12 +39,15 @@ export default class YouTube {
*/
async searchVideos(query: string, maxResults: number | undefined = 50): Promise<youtube.Schema$SearchResult[]>
{
const response = await this.client.search.list({
const searchQuery = {
part: ['snippet'],
maxResults: maxResults,
q: query,
safeSearch: 'none',
type: ['video'],
});
};
const response = await this.client.search.list(searchQuery);
return response.data.items ?? [];
}