Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherPillow committed Aug 6, 2023
0 parents commit 9f6df6a
Show file tree
Hide file tree
Showing 5 changed files with 780 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
81 changes: 81 additions & 0 deletions GoldenAlias.golden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const fs = require('fs');

module.exports = class {
constructor(logger, config, api) {
this.logger = logger;
this.config = config;
this.api = api;

this.chat = api.chatlog;

this.logger.success('GoldenAlias loaded!');

this.config = api.config;

if (!this.config.get('aliases'))
this.config.set('aliases', []);

this.api.commands.register('/galias', (args, client) => {
if (args.length < 1)
return this.chat.warn('Usage: /galias <list/add/remove>');


switch (args[0]) {
case 'list':
this.chat.info('Listing aliases:');
this.config.get('aliases').forEach(alias => {
this.chat.small(`${alias.name} -> ${alias.value}`);
})
break;
case 'add':
if (args.length < 3)
return this.chat.warn('Usage: /galias add <alias> <value>');

const [name, ...value] = args.slice(1);
const alias = { name, value: value.join(' ') };

this.config.get('aliases').push(alias);

this.chat.info(`Added alias ${name} -> ${value.join(' ')}`);

this.api.commands.register(`${name.startsWith('/') ? '' : '/'}${name}`, (args, client) => {
this.registerAlias(`${alias.name.startsWith('/') ? '' : '/'}${alias.name}`, alias.value);
})

this.config.save();
break;
case 'remove':
if (args.length < 2)
return this.chat.warn('Usage: /galias remove <alias>');

const rmname = args[1];

const index = this.config.get('aliases').findIndex(alias => alias.name === rmname);

this.config.get('aliases').splice(index, 1);
this.chat.info(`Removed alias ${rmname}`);

this.config.save();
break;

default:
this.chat.warn('Usage: /galias <list/add>');
break;
}
});

this.config.get('aliases').forEach(alias => {
this.registerAlias(`${alias.name.startsWith('/') ? '' : '/'}${alias.name}`, alias.value);
})

}

registerAlias(name, value) {
this.api.commands.register(name, (args, client) => {
this.api.proxy.remoteClient.write(
'chat',
{ message: value + (args.length > 0 ? ' ' + args.join(' ') : '') }
);
})
}
}
6 changes: 6 additions & 0 deletions GoldenAlias.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Name": "GoldenAlias",
"ID": "com.anotherpillow.goldenalias",
"Version": "1.0",
"Main": "GoldenAlias.golden.js::default"
}
Loading

0 comments on commit 9f6df6a

Please sign in to comment.