neural networks

pull/29/head
Matthew 2020-09-27 02:11:26 -04:00
parent 7dc3afbc27
commit 22ce6dfa7c
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
8 changed files with 61 additions and 3 deletions

View File

@ -28,6 +28,7 @@
},
"dependencies": {
"axios": "^0.19.2",
"brain.js": "^2.0.0-beta.2",
"eris": "^0.13.3",
"eris-pagination": "bsian03/eris-pagination",
"express": "^4.17.1",

View File

@ -3,7 +3,7 @@ import pluris from 'pluris';
import mongoose from 'mongoose';
import { promises as fs } from 'fs';
import { Collection, Command, LocalStorage, Util, ServerManagement, Event } from '.';
import { File, FileInterface, Member, MemberInterface, Moderation, ModerationInterface, Note, NoteInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface, Score, ScoreInterface, Staff, StaffInterface, Stat, StatInterface } from '../models';
import { File, FileInterface, Member, MemberInterface, Moderation, ModerationInterface, NNTrainingData, NNTrainingDataInterface, Note, NoteInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface, Score, ScoreInterface, Staff, StaffInterface, Stat, StatInterface } from '../models';
import { Config } from '../../types'; // eslint-disable-line
pluris(eris);
@ -21,14 +21,14 @@ export default class Client extends eris.Client {
public serverManagement: ServerManagement;
public db: { File: mongoose.Model<FileInterface>, Member: mongoose.Model<MemberInterface>, Moderation: mongoose.Model<ModerationInterface>, Note: mongoose.Model<NoteInterface>, PagerNumber: mongoose.Model<PagerNumberInterface>, Rank: mongoose.Model<RankInterface>, Redirect: mongoose.Model<RedirectInterface>, Score: mongoose.Model<ScoreInterface>, Staff: mongoose.Model<StaffInterface>, Stat: mongoose.Model<StatInterface>, local: { muted: LocalStorage } };
public db: { File: mongoose.Model<FileInterface>, Member: mongoose.Model<MemberInterface>, Moderation: mongoose.Model<ModerationInterface>, NNTrainingData: mongoose.Model<NNTrainingDataInterface>, Note: mongoose.Model<NoteInterface>, PagerNumber: mongoose.Model<PagerNumberInterface>, Rank: mongoose.Model<RankInterface>, Redirect: mongoose.Model<RedirectInterface>, Score: mongoose.Model<ScoreInterface>, Staff: mongoose.Model<StaffInterface>, Stat: mongoose.Model<StatInterface>, local: { muted: LocalStorage } };
constructor(token: string, options?: eris.ClientOptions) {
super(token, options);
this.commands = new Collection<Command>();
this.events = new Collection<Event>();
this.intervals = new Collection<NodeJS.Timeout>();
this.db = { File, Member, Moderation, Note, PagerNumber, Rank, Redirect, Score, Staff, Stat, local: { muted: new LocalStorage('muted') } };
this.db = { File, Member, Moderation, NNTrainingData, Note, PagerNumber, Rank, Redirect, Score, Staff, Stat, local: { muted: new LocalStorage('muted') } };
}
public async loadDatabase() {

View File

@ -147,4 +147,8 @@ export default class Util {
public randomNumber(min: number, max: number): number {
return Math.round(Math.random() * (max - min) + min);
}
public encode(arg: string) {
return arg.split('').map((x) => x.charCodeAt(0) / 400);
}
}

View File

@ -27,6 +27,7 @@ export { default as roleinfo } from './roleinfo';
export { default as score } from './score';
export { default as stats } from './stats';
export { default as storemessages } from './storemessages';
export { default as train } from './train';
export { default as unban } from './unban';
export { default as unmute } from './unmute';
export { default as whois } from './whois';

View File

@ -79,6 +79,7 @@ export default class Score extends Command {
}
if (!user) return this.error(message.channel, 'Member not found.');
const score = await this.client.db.Score.findOne({ userID: user.id });
if (!score) return this.error(message.channel, 'Community Report has not been generated yet.');
let totalScore = '0';
let activityScore = '0';
let moderationScore = '0';

37
src/commands/train.ts Normal file
View File

@ -0,0 +1,37 @@
import { Message, TextChannel } from 'eris';
import { Client, Command } from '../class';
export default class Train extends Command {
constructor(client: Client) {
super(client);
this.name = 'train';
this.description = 'Trains a neural network.';
this.usage = `${this.client.config.prefix}train <channel> <message id> <0: good | 1: bad>`;
this.permissions = 1;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (args?.length < 3) return this.client.commands.get('help').run(message, [this.name]);
if (args[2] !== '0' && args[2] !== '1') return this.error(message.channel, 'Result must be either 0 or 1.');
const channel = <TextChannel> this.client.util.resolveGuildChannel(args[0], this.mainGuild);
if (!channel) return this.error(message.channel, 'Channel could not be found.');
if (channel.type !== 0) return this.error(message.channel, 'Invalid channel type.');
let msg: Message;
try {
msg = await channel.getMessage(args[1]);
} catch {
return this.error(message.channel, 'Could not find message.');
}
if (!msg) return this.error(message.channel, 'Message could not be found.');
await this.client.db.NNTrainingData.updateOne({ name: 'tc' }, { $addToSet: { data: { input: this.client.util.encode(msg.content), output: { res: Number(args[2]) } } } });
await message.delete();
return this.success(message.channel, 'Neural Network trained successfully.');
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}

View File

@ -0,0 +1,13 @@
import { Document, Schema, model } from 'mongoose';
export interface NNTrainingDataInterface extends Document {
name: string,
data: [{ input: any, output: object }];
}
const NNTrainingData: Schema = new Schema({
name: String,
data: Array,
});
export default model<NNTrainingDataInterface>('NNTrainingData', NNTrainingData);

View File

@ -1,6 +1,7 @@
export { default as File, FileInterface } from './File';
export { default as Member, MemberInterface } from './Member';
export { default as Moderation, ModerationInterface } from './Moderation';
export { default as NNTrainingData, NNTrainingDataInterface } from './NNTrainingData';
export { default as Note, NoteInterface } from './Note';
export { default as PagerNumber, PagerNumberInterface, PagerNumberRaw } from './PagerNumber';
export { default as Rank, RankInterface } from './Rank';