Compare commits

..

3 Commits

  1. 2
      bot.js
  2. 23
      src/handle/runtime/events/messageCreate.js
  3. 4
      src/handle/runtime/events/ready.js
  4. 20
      src/handle/startup/run/getflags.js
  5. 2
      src/handle/startup/run/setstatus.js
  6. 25
      src/util/ts/src/tag.ts
  7. 63
      src/util/ts/src/tagfilter.ts
  8. 9
      src/util/ts/tag.d.ts
  9. 21
      src/util/ts/tag.js
  10. 10
      src/util/ts/tagfilter.d.ts
  11. 77
      src/util/ts/tagfilter.js
  12. 11
      src/util/ts/tsconfig.json

@ -25,6 +25,8 @@ const startBot = async () => {
client.log(client.utils.gr(client.config.randResp.clistart), {color: "#78d9f8", source: "NATS"}, true, true); //natsuki's wakeup log client.log(client.utils.gr(client.config.randResp.clistart), {color: "#78d9f8", source: "NATS"}, true, true); //natsuki's wakeup log
require('./src/handle/startup/run/getflags')(client);
await require('./src/db/connect')(client); //connect to database await require('./src/db/connect')(client); //connect to database
await require('./src/handle/startup/run/collect')(client); //load in commands and events await require('./src/handle/startup/run/collect')(client); //load in commands and events
await require('./src/handle/startup/run/login')(client); //log in to discord await require('./src/handle/startup/run/login')(client); //log in to discord

@ -0,0 +1,23 @@
module.exports = async (client, message) => {
if (!message.content || !message.content.length) {return;} //privileged intent fallback
if ([`<@${client.user.id}>`, `<@!${client.user.id}>`].includes(message.content.trim())) {} //TODO insert ping hello
let cmd = {};
cmd.msg = message.content.toLowerCase().trim(); //i believe in shitty naming conventions :D
let prefixUsed = cmd.msg.startsWith(client.basePrefix) ? client.basePrefix //stamdard default/dev client prefix
: cmd.msg.startsWith(`<@${client.user.id}>`) ? `<@${client.user.id}>` //mention prefix
: cmd.msg.startsWith(`<@!${client.user.id}>`) ? `<@!${client.user.id}>` //nicknamed mention prefix
: null //no prefix used
cmd.prefix = prefixUsed;
if (!cmd.prefix) {return;} // ----------> PREFIXED GATEWAY <----------
cmd.msg = cmd.msg.slice(prefixUsed.length);
let args = cmd.msg.split(/\s+/gm); //"args" is split by ALL WHITESPACE AND IS LOWERCASED
cmd.name = args.shift(); //the command without the prefix
cmd.msg = args.join(" ");
cmd.args = message.content.trim().slice(prefixUsed.length).trim().split(/ +/gm).slice(1); //args but preserves text state and newlines
};

@ -1,7 +1,5 @@
const Discord = require('discord.js');
module.exports = async client => { module.exports = async client => {
client.prefix = "n?"; client.basePrefix = client.config.options.dev ? client.config.options.prefix || "n!" : "n?";
require('../../startup/run/hello')(client); // startup info require('../../startup/run/hello')(client); // startup info
require('../../startup/run/setstatus')(client); require('../../startup/run/setstatus')(client);

@ -0,0 +1,20 @@
const chalk = require('chalk');
const {Tag, TagFilter} = require('../../../util/ts/tagfilter');
module.exports = client => {
const options = new TagFilter([
new Tag(['dev', 'd', 'developer', 'test'], 'dev', 'toggle'),
new Tag(['prefix', 'devprefix'], 'prefix', 'append')
]).test(process.argv.slice(2).join(" "));
client.config.options = {};
if (Object.keys(options).length) { //log and set options
client.log(`${chalk.gray.bold("Arguments detected.")}`, {source: 'args'}, 0, 1);
Object.keys(options).forEach(arg => {
client.config.options[arg] = options[arg];
client.log(`${chalk.gray.bold(arg)}${chalk.gray(':')} ${chalk.blue(options[arg])}`, {source: 'args'});
});
console.log('');
}
};

@ -1,5 +1,5 @@
module.exports = client => { module.exports = client => {
const prefix = client.prefix; const prefix = client.basePrefix;
const statuses = { const statuses = {
"PLAYING": [ "PLAYING": [
`with my darling`, 'RAIN: Shadow Lords', "with my waifu", "with the neko formula", `with my darling`, 'RAIN: Shadow Lords', "with my waifu", "with the neko formula",

@ -0,0 +1,25 @@
export class Tag {
triggers: string[] = [];
tagName: string;
filterType: TagFilterType;
constructor(triggers: string[], tagName: string, filterType: TagFilterType) {
let trigger: string; for (trigger of triggers) {
this.triggers.push(
trigger.trim().startsWith("-") ? trigger.trim() : `-${trigger.trim()}`
);
}
this.tagName = tagName;
this.filterType = filterType;
};
public addTrigger(trigger: string): Tag {
this.triggers.push(
trigger.trim().startsWith("-") ? trigger.trim() : `-${trigger.trim()}`
);
return this;
};
}
type TagFilterType = "append" | "toggle" | "listAppend";

@ -0,0 +1,63 @@
import {Tag} from "./tag";
export {Tag};
export class TagFilter {
tags: Tag[];
triggers: Map<String, String>;
filterTypes: Map<String, TagFilterType>;
constructor(tags: Tag[]) {
this.tags = tags;
this.triggers = new Map<String, String>();
this.filterTypes = new Map<String, TagFilterType>();
let tag: Tag;
for (tag of this.tags) {
let trigger: string; for (trigger of tag.triggers) {
this.triggers.set(trigger, tag.tagName);
}
if (!this.filterTypes.has(tag.tagName)) {this.filterTypes.set(tag.tagName, tag.filterType);}
}
}
public test(text: string): object {
var filtered: object = {};
var reading: string = null;
var filterType: TagFilterType;
var ticks = {};
let words = text.trim().split(/\s+/g);
let word: string; for (word of words) {
if (word.startsWith('-') && word.length > 1 && this.triggers.has(word.trim())) {
filterType = this.filterTypes.get(this.triggers.get(word.trim()));
reading = !['append', 'listAppend'].includes(filterType) ? null : word.trim();
if (!reading) {filtered[`${this.triggers.get(word.trim())}`] = true;}
else {filtered[`${this.triggers.get(reading)}`] = filterType == 'append' ? '' : Array.isArray(filtered[`${this.triggers.get(reading)}`]) ? filtered[`${this.triggers.get(reading)}`] : [];}
if (filterType == "listAppend") {
if (ticks[`${this.triggers.get(word.trim())}`] && ticks[`${this.triggers.get(word.trim())}`].length) {filtered[`${this.triggers.get(word.trim())}`].push(ticks[`${this.triggers.get(word.trim())}`]);}
ticks[`${this.triggers.get(word.trim())}`] = '';
}
}
else if (reading) {
if (filterType == "listAppend") {ticks[`${this.triggers.get(reading)}`] += ` ${word}`;}
else {filtered[`${this.triggers.get(reading)}`] = `${filtered[`${this.triggers.get(reading)}`]} ${word}`;}
}
}
let tick: string; for (tick of Object.keys(ticks)) {
if (ticks[tick].length) {filtered[tick].push(ticks[tick]);}
}
let key: string; for (key of Object.keys(filtered)) {
if (typeof filtered[key] == 'string') {filtered[key] = filtered[key].trim();}
else if (Array.isArray(filtered[key])) {
let subkey: string; for (subkey of filtered[key]) {
filtered[key][filtered[key].indexOf(subkey)] = subkey.trim();
}
}
}
return filtered;
};
}
type TagFilterType = "append" | "toggle" | "listAppend";

@ -0,0 +1,9 @@
export declare class Tag {
triggers: string[];
tagName: string;
filterType: TagFilterType;
constructor(triggers: string[], tagName: string, filterType: TagFilterType);
addTrigger(trigger: string): Tag;
}
declare type TagFilterType = "append" | "toggle" | "listAppend";
export {};

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tag = void 0;
class Tag {
constructor(triggers, tagName, filterType) {
this.triggers = [];
let trigger;
for (trigger of triggers) {
this.triggers.push(trigger.trim().startsWith("-") ? trigger.trim() : `-${trigger.trim()}`);
}
this.tagName = tagName;
this.filterType = filterType;
}
;
addTrigger(trigger) {
this.triggers.push(trigger.trim().startsWith("-") ? trigger.trim() : `-${trigger.trim()}`);
return this;
}
;
}
exports.Tag = Tag;

@ -0,0 +1,10 @@
import { Tag } from "./tag";
export { Tag };
export declare class TagFilter {
tags: Tag[];
triggers: Map<String, String>;
filterTypes: Map<String, TagFilterType>;
constructor(tags: Tag[]);
test(text: string): object;
}
declare type TagFilterType = "append" | "toggle" | "listAppend";

@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagFilter = exports.Tag = void 0;
const tag_1 = require("./tag");
Object.defineProperty(exports, "Tag", { enumerable: true, get: function () { return tag_1.Tag; } });
class TagFilter {
constructor(tags) {
this.tags = tags;
this.triggers = new Map();
this.filterTypes = new Map();
let tag;
for (tag of this.tags) {
let trigger;
for (trigger of tag.triggers) {
this.triggers.set(trigger, tag.tagName);
}
if (!this.filterTypes.has(tag.tagName)) {
this.filterTypes.set(tag.tagName, tag.filterType);
}
}
}
test(text) {
var filtered = {};
var reading = null;
var filterType;
var ticks = {};
let words = text.trim().split(/\s+/g);
let word;
for (word of words) {
if (word.startsWith('-') && word.length > 1 && this.triggers.has(word.trim())) {
filterType = this.filterTypes.get(this.triggers.get(word.trim()));
reading = !['append', 'listAppend'].includes(filterType) ? null : word.trim();
if (!reading) {
filtered[`${this.triggers.get(word.trim())}`] = true;
}
else {
filtered[`${this.triggers.get(reading)}`] = filterType == 'append' ? '' : Array.isArray(filtered[`${this.triggers.get(reading)}`]) ? filtered[`${this.triggers.get(reading)}`] : [];
}
if (filterType == "listAppend") {
if (ticks[`${this.triggers.get(word.trim())}`] && ticks[`${this.triggers.get(word.trim())}`].length) {
filtered[`${this.triggers.get(word.trim())}`].push(ticks[`${this.triggers.get(word.trim())}`]);
}
ticks[`${this.triggers.get(word.trim())}`] = '';
}
}
else if (reading) {
if (filterType == "listAppend") {
ticks[`${this.triggers.get(reading)}`] += ` ${word}`;
}
else {
filtered[`${this.triggers.get(reading)}`] = `${filtered[`${this.triggers.get(reading)}`]} ${word}`;
}
}
}
let tick;
for (tick of Object.keys(ticks)) {
if (ticks[tick].length) {
filtered[tick].push(ticks[tick]);
}
}
let key;
for (key of Object.keys(filtered)) {
if (typeof filtered[key] == 'string') {
filtered[key] = filtered[key].trim();
}
else if (Array.isArray(filtered[key])) {
let subkey;
for (subkey of filtered[key]) {
filtered[key][filtered[key].indexOf(subkey)] = subkey.trim();
}
}
}
return filtered;
}
;
}
exports.TagFilter = TagFilter;

@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es2017", "es6", "dom"],
"target": "es2017",
"declaration": true,
"outDir": "./"
},
"include": ["src/**/*"],
"exclude": []
}
Loading…
Cancel
Save