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

Re-write DM Autoresponse into typescript #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/modules/chess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Eris from "eris";
import ConfigDB from "../lib/ConfigDB";
import Permissions from "../lib/Permissions";
import { ModuleOptions } from "../types/lib";
import { translateTypeCreator } from "../types/translate";

let table = "chess";

Expand Down Expand Up @@ -180,7 +181,7 @@ class chess {
private games: { [keyof: string]: any };
private client: Eris.Client;
private pvpcraft: any;
private i10010n: any;
private i10010n: translateTypeCreator;
private r: any;
private perms: Permissions;
private messageSender: any;
Expand Down
31 changes: 22 additions & 9 deletions src/modules/dmAutoResponder.js → src/modules/dmAutoResponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
*/
"use strict";

class dmAutoResponder {
import { Module, ModuleConstructor } from "../types/moduleDefinition";
import { ModuleOptions } from "../types/lib";
import { translateTypeCreator } from "../types/translate";
import PvPCraft from "../PvPCraft";
import Eris, { TextChannel } from "eris";

const dmAutoResponder: ModuleConstructor = class dmAutoResponder implements Module {
private i10010n: translateTypeCreator;
private pvpcraft: PvPCraft;
private client: Eris.Client;

/**
* Instantiates the module
* @constructor
Expand All @@ -21,10 +31,9 @@ class dmAutoResponder {
* @param {PvPClient} e.pvpClient PvPCraft client library instance
* @param {Function} e.i10010n internationalization function
*/
constructor(e) {
constructor(e: ModuleOptions) {
this.client = e.client;
this.pvpcraft = e.pvpcraft;
this.raven = e.raven;
this.i10010n = e.i10010n;
}

Expand All @@ -33,16 +42,20 @@ class dmAutoResponder {
* @param {Message} msg
* @returns {boolean | Promise}
*/
checkMisc(msg) {
if (msg.channel.guild) return false;
checkMisc(msg: Eris.Message<TextChannel> | Eris.Message) {
if ("guild" in msg.channel) return false;
if (msg.author.bot) return false;
const translate = this.i10010n(this.pvpcraft.getChannelLanguage(msg.channel.id));
const lowercaseContents = msg.content.toLowerCase();
if (lowercaseContents.includes("invite") || lowercaseContents.includes("discord.gg")) return msg.channel.createMessage(translate `https://invite.pvpcraft.ca`);
if (lowercaseContents.includes("help") || lowercaseContents.includes("docs")) return msg.channel.createMessage(translate `https://bot.pvpcraft.ca/docs`);
if (lowercaseContents.startsWith("/") || lowercaseContents.startsWith("!!") || lowercaseContents.startsWith("//")) return msg.channel.createMessage(translate `This command cannot be used in dms`);
if (lowercaseContents.includes("invite") || lowercaseContents.includes("discord.gg")) return msg.channel.createMessage(translate`https://invite.pvpcraft.ca`);
if (lowercaseContents.includes("help") || lowercaseContents.includes("docs")) return msg.channel.createMessage(translate`https://bot.pvpcraft.ca/docs`);
if (lowercaseContents.startsWith("/") || lowercaseContents.startsWith("!!") || lowercaseContents.startsWith("//")) return msg.channel.createMessage(translate`This command cannot be used in dms`);
return false;
}

getCommands() {
return []
}
}

module.exports = dmAutoResponder;
module.exports = dmAutoResponder;
3 changes: 2 additions & 1 deletion src/modules/hat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import Permissions from "../lib/Permissions";
import * as Sentry from "@sentry/node";
import { combineTwoImages, getImageFromFile, getImageFromUrl } from "../lib/hats";
import { GuildCommand } from "../lib/Command/Command";
import { translateTypeCreator } from "../types/translate";

const hat: ModuleConstructor = class hat implements Module {
private client: Eris.Client;
private perms: Permissions;
private i10010n: any;
private i10010n: translateTypeCreator;

/**
* Instantiates the module
Expand Down
3 changes: 2 additions & 1 deletion src/modules/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { ModuleOptions } from "../types/lib";
import Eris from "eris";
import { Module, ModuleCommand, ModuleConstructor } from "../types/moduleDefinition";
import Command from "../lib/Command/Command";
import { translateTypeCreator } from "../types/translate";

const help: ModuleConstructor = class help implements Module {
private i10010n: any;
private i10010n: translateTypeCreator;

/**
* Instantiates the module
Expand Down
3 changes: 2 additions & 1 deletion src/modules/minecraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Eris, { GuildChannel, TextChannel } from "eris";
import ConfigDB from "../lib/ConfigDB";
import WebSocket from "ws";
import Command, { GuildCommand } from "../lib/Command/Command";
import { translateTypeCreator } from "../types/translate";

type MCAuth = {
chat?: string;
Expand All @@ -36,7 +37,7 @@ export const minecraft: ModuleConstructor = class minecraft implements Module {
private client: Eris.Client;
private perms: Permissions;
private messageSender: any;
private i10010n: any;
private i10010n: translateTypeCreator;
private minecraftConnections: WebSocket[];

/**
Expand Down
3 changes: 2 additions & 1 deletion src/modules/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ModuleOptions } from "../types/lib";
import Permissions from "../lib/Permissions";
import Eris from "eris";
import Command from "../lib/Command/Command";
import { translateTypeCreator } from "../types/translate";

let google = require("google");

Expand All @@ -20,7 +21,7 @@ let cheerio = require("cheerio");
const search: ModuleConstructor = class search implements Module {
private client: Eris.Client;
private perms: Permissions;
private i10010n: any;
private i10010n: translateTypeCreator;

/**
* Instantiates the module
Expand Down
3 changes: 2 additions & 1 deletion src/modules/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Config from "../lib/Config";
import Permissions from "../lib/Permissions";
import Eris from "eris";
import Command, { GuildCommand } from "../lib/Command/Command";
import { translateTypeCreator } from "../types/translate";
const now = require('performance-now');

const os = require('os');
Expand All @@ -21,7 +22,7 @@ const utilities: ModuleConstructor = class utilities implements Module {
private perms: Permissions;
private client: Eris.Client;
private config: Config;
private i10010n: any;
private i10010n: translateTypeCreator;

/**
* Instantiates the module
Expand Down
3 changes: 2 additions & 1 deletion src/modules/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import ConfigDB from "../lib/ConfigDB";
import Permissions from "../lib/Permissions";
import * as Sentry from "@sentry/node";
import { GuildCommand } from "../lib/Command/Command";
import { translateTypeCreator } from "../types/translate";

const welcome: ModuleConstructor = class welcome implements Module {
private client: Eris.Client;
private config: ConfigDB;
private perms: Permissions;
private i10010n: any;
private i10010n: translateTypeCreator;

/**
* Instantiates the module
Expand Down