Skip to content

Commit

Permalink
Merge pull request #319 from dysolix/master
Browse files Browse the repository at this point in the history
Some library related fixes and changes
  • Loading branch information
Querijn committed Apr 27, 2024
2 parents 0f160a7 + 02c364f commit 84ef217
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
10 changes: 9 additions & 1 deletion settings/shared_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@
],
"objective-c": [
"objc"
],
"python": [
"py"
]
},
"channelTopics": {
"lol": [
"lol",
"v4"
],
"lcu": [
Expand All @@ -147,6 +149,12 @@
],
"lor": [
"lor"
],
"val": [
"val"
],
"rso": [
"rso"
]
},
"checkInterval": 10800000
Expand Down
18 changes: 7 additions & 11 deletions src/RiotAPILibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ export default class RiotAPILibraries {
}

public onLibs(message: Discord.Message, isAdmin: boolean, command: string, args: string[]) {

let topics: string[] = ["v4"];
let topics: string[] = ["v4"]; // Default tag applies to all channels that don't have specific tags and when no tags are specified in the command
if ("name" in message.channel) {
for (const [topic, tags] of Object.entries(this.settings.riotApiLibraries.channelTopics)) {
if (message.channel.name.toLowerCase().includes(topic)) {
Expand All @@ -89,9 +88,7 @@ export default class RiotAPILibraries {
}

if (args.length > 1) {
for (let i = 1; i < args.length; i++) {
topics.push(args[i].toLowerCase());
}
topics = args.slice(1).map(x => x.toLowerCase()); // Set the tags to the ones specified in the command
}

const param = args[0].toLowerCase();
Expand All @@ -108,10 +105,8 @@ export default class RiotAPILibraries {
const libraryResponse = await fetch(json.download_url);
const libraryInfo: APILibraryStruct = await libraryResponse.json();

const hasAtLeastOneTag = !!libraryInfo.tags?.some((tag) =>
tags.includes(tag)
);
if (!hasAtLeastOneTag) {
const hasAllTags = tags.every(tag => libraryInfo.tags?.includes(tag));
if (!hasAllTags) {
return { stars: 0, valid: false, library: null, links: [] };
}

Expand All @@ -120,7 +115,8 @@ export default class RiotAPILibraries {
// Make a list of the links
const githubLink = `github.com/${libraryInfo.owner}/${libraryInfo.repo}`;
let links = libraryInfo.links ? libraryInfo.links.map(link => `[${link.name}](${link.url})`) : []; // Can be empty array or null, sigh
if (links.length === 0 || links.some(l => l.indexOf(githubLink) !== 0)) {

if (links.length === 0 || links.every(l => l.indexOf(githubLink) === -1)) {
// Make sure there is at least the github link
links = [`[Github](https://${githubLink})`].concat(links);
}
Expand Down Expand Up @@ -177,7 +173,7 @@ export default class RiotAPILibraries {
}

private async getLibrariesForLanguage(language: string, tags: string[] = ["v4"]): Promise<LibraryDescription[]> {
const response = await fetch(this.settings.riotApiLibraries.baseURL + language);
const response = await fetch(this.settings.riotApiLibraries.baseURL + language, this.fetchSettings);
switch (response.status) {
case 200: {
// continue
Expand Down

0 comments on commit 84ef217

Please sign in to comment.