Skip to content

Commit

Permalink
pass config as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoins committed Apr 13, 2018
1 parent c2687dc commit d7f1582
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CommandoClient } from 'discord.js-commando';
import { Config } from '@natsuki/util';
export declare class Module {
static client: CommandoClient;
static config: Config;
static client: CommandoClient;
/**
* Initializes module
* @param client
Expand All @@ -13,5 +13,5 @@ export declare class Module {
* Register events
* @param client
*/
private registerListeners(client);
private registerListeners(client, config);
}
6 changes: 3 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/lib/Events.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { Message } from 'discord.js';
export declare const onMessage: (message: Message) => Promise<void>;
import { Config } from '@natsuki/util';
export declare const onMessage: (message: Message, config: Config) => Promise<void>;
6 changes: 3 additions & 3 deletions dist/lib/Events.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/Events.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Config } from '@natsuki/util'
import { onMessage } from './lib/Events'

export class Module {
public static client: CommandoClient
public static config: Config
static config: Config
static client: CommandoClient

/**
* Initializes module
Expand All @@ -15,14 +15,14 @@ export class Module {
public async init (client: CommandoClient, config: Config) {
Module.client = client
Module.config = config
await this.registerListeners(client)
await this.registerListeners(client, config)
}

/**
* Register events
* @param client
*/
private async registerListeners (client: CommandoClient): Promise<void> {
client.on('message', await onMessage)
private async registerListeners (client: CommandoClient, config: Config): Promise<void> {
client.on('message', async (message) => await onMessage(message, config))
}
}
10 changes: 5 additions & 5 deletions src/lib/Events.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Message, TextChannel } from 'discord.js'
import axios from 'axios'
import { Module } from '../'
import { Logger, MessageUtility } from '@natsuki/util'
import { Logger, MessageUtility, Config } from '@natsuki/util'
import { User as NatsukiUser } from '@natsuki/db'
import { giveXp } from './'

const { api } = Module.config
const baseRoute = `${api.address}/users`

export const onMessage = async (message: Message) => {
export const onMessage = async (message: Message, config: Config) => {
if (message.author.bot || !message.content || !message.content.trim()
|| typeof message.channel !== typeof TextChannel) {
return
}

const { api } = Module.config
const baseRoute = `${api.address}/users`

// Prevent the user from earning xp for bot commands.
// Handles *most* bots.
const firstTwoMatch = message.content.trim().substring(0, 2).match(/[a-z]/ig)
Expand Down

0 comments on commit d7f1582

Please sign in to comment.