Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to add mods to CCModDB #11

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c5d448d
Update dependencies
krypciak Feb 20, 2024
9873d66
Add 'mod-add' command
krypciak Feb 20, 2024
85b4683
Move CCModDB repo info to secrets.json
krypciak Feb 21, 2024
1df0795
Fix .ccmod's not working
krypciak Feb 21, 2024
c052f29
Fix 'mod-add' not accepting some .zip urls
krypciak Feb 24, 2024
01ffc06
Change 'mod-add' to 'publish-mod'
krypciak Mar 11, 2024
3267bbe
Adapt .prettierrc.json options to better match the already existing c…
krypciak Apr 25, 2024
7c3ed27
Format structures.ts & mod-database.ts
krypciak Apr 25, 2024
5df0206
Use typings directly from CCModDB
krypciak Apr 25, 2024
7be88f6
Convert the .cc mods & .cc tools implementation to the new ccmod.json…
krypciak Apr 25, 2024
2f3b387
Silence typescript errors
krypciak Apr 25, 2024
0f47be9
Display more mod and tool metadata
krypciak Apr 25, 2024
6d71fb9
Also remove icons from mod names
krypciak Apr 26, 2024
b8a0290
Add CCModDB testing branch publish-mod support
krypciak May 4, 2024
2b54b91
Move to the new multi-branch mod database setupp
krypciak Jul 24, 2024
4cdce49
Allow the publish-mod command only in the specified channel
krypciak Aug 6, 2024
df82483
Force update the ccmoddb when an already existing mod archive url is …
krypciak Aug 6, 2024
73ec380
Supress publish-mod embeds
krypciak Aug 6, 2024
6ae27f9
Fix error related to deprecation of the mod package.json
krypciak Aug 6, 2024
bb4478d
Add the source argument to publish-mod
krypciak Aug 8, 2024
742450f
Make the publishChannelId secrets field an array
krypciak Aug 22, 2024
cfcb50b
Update mod endpoints to CCDirectLink
krypciak Sep 18, 2024
750c9b1
Update package.json CCModDB repo
krypciak Sep 18, 2024
ad1bfb1
Fix npm run lint not working
krypciak Oct 23, 2024
c0b65bc
Fix eslint not passing
krypciak Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add the source argument to publish-mod
krypciak committed Aug 8, 2024
commit bb4478d27b06bd26522a0f8477a6c3ee42435c0a
38 changes: 24 additions & 14 deletions src/commands/ccmoddb-pr/pr.ts
Original file line number Diff line number Diff line change
@@ -42,18 +42,19 @@ async function checkUrlFileType(url: string): Promise<string | undefined> {
} catch (error) {}
}

function addOrUpdateUrl(inputs: InputLocations, url: string): {changedAnything: boolean; index: number} {
const obj = {url};
function addOrUpdateUrl(inputs: InputLocations, url: string, source: string): {status: 'pushed' | 'changed' | 'sameUrl'; index: number} {
const obj = {url, source};
const repoUrl = url.split('/').slice(0, 5).join('/');
for (let i = 0; i < inputs.length; i++) {
const input = inputs[i];
if (input.url.startsWith(repoUrl)) {
const changedAnything = inputs[i].url != obj.url;
const status = inputs[i].url == obj.url ? 'sameUrl' : 'changed';
obj.source = source || obj.source
inputs[i] = obj;
return {changedAnything, index: i};
return {status, index: i};
}
}
return {index: inputs.push(obj), changedAnything: true};
return {index: inputs.push(obj), status: 'pushed'};
}

const stableBranch = 'stable';
@@ -62,8 +63,7 @@ const botBranchPrefix = 'ccbot/';
const inputLocationsPath = 'input-locations.json';
const inputLocationsOldPath = 'input-locations.old.json';

async function createPr(url: string, author: string, isTestingBranch: boolean) {
const branch = isTestingBranch ? testingBranch : stableBranch;
async function createPr(url: string, author: string, branch: string, source: string) {
if (!url.startsWith('https://github.com/') || !(url.endsWith('.zip') || url.endsWith('.ccmod'))) {
return 'Invalid url :(';
}
@@ -83,15 +83,15 @@ async function createPr(url: string, author: string, isTestingBranch: boolean) {
const inputLocationsStr = await OctokitUtil.fetchFile(branch, inputLocationsPath);
const inputLocationsJson: InputLocations = JSON.parse(inputLocationsStr);

const {changedAnything, index} = addOrUpdateUrl(inputLocationsJson, url);
const {status, index} = addOrUpdateUrl(inputLocationsJson, url, source);

let toCommit: {path: string; json: InputLocations};
if (changedAnything) {
if (status == 'pushed' || status == 'changed') {
toCommit = {path: inputLocationsPath, json: inputLocationsJson};
} else {
/* if nothing was changed in input-locations.json (aka the supplied url was already in input-locations.json)
* then change the entry in input-locations.old.json just slightly so that the database actually updates */

/* input-locations.old.json has the same contents as input-locations.json at this moment */
const inputLocationsOldJson: InputLocations = JSON.parse(inputLocationsStr);
inputLocationsOldJson[index].url = url.substring(0, url.length - 1);
@@ -131,22 +131,32 @@ export default class ModsPrCommand extends CCBotCommand {
type: 'string',
default: 'stable',
},
{
key: 'source',
prompt: 'The relative path to the directory containing the `ccmod.json` file.',
type: 'string',
default: '',
},
],
};
super(client, opt);

this.publishChannelId = publishChannelId;
}

public async run(message: commando.CommandoMessage, args: {url: string; branch: string}): Promise<discord.Message | discord.Message[]> {
public async run(message: commando.CommandoMessage, args: {url: string; branch: string; source: string}): Promise<discord.Message | discord.Message[]> {
if (this.publishChannelId && message.channel.id !== this.publishChannelId) {
return await message.say(`This command is only allowed in <#${this.publishChannelId}>`);
}
if (!OctokitUtil.isInited()) return await message.say('Not configured to be used here!');

const text = await createPr(args.url, message.author.tag, args.branch == 'testing');
if (args.branch != stableBranch && args.branch != testingBranch) {
return message.say('Invalid branch!', {});
}

const text = await createPr(args.url, message.author.tag, args.branch, args.source);
const msg = await message.say(text, {});
msg.suppressEmbeds(true)
return msg
msg.suppressEmbeds(true);
return msg;
}
}