Reintroducing topic handling
This commit is contained in:
parent
eb2538edc0
commit
1357336ba0
@ -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`
|
||||
|
11
index.ts
11
index.ts
@ -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) {
|
||||
|
@ -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 ?? [];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user