Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xsduan committed Nov 22, 2018
2 parents 1a66760 + f7f0fd4 commit 7ab9924
Show file tree
Hide file tree
Showing 18 changed files with 399 additions and 268 deletions.
130 changes: 0 additions & 130 deletions bot.ts

This file was deleted.

71 changes: 0 additions & 71 deletions commands.ts

This file was deleted.

18 changes: 18 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import c from "config";

import Conniebot from "./src";
import commands from "./src/commands";

const token = "token";
const database = "database";

if (!c.has(token)) {
throw new TypeError("Couldn't find a token to connect with.");
}

if (!c.has(database)) {
throw new TypeError("No database filename listed.");
}

const conniebot = new Conniebot(c.get(token), c.get(database));
conniebot.registerCommands(commands);
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "conniebot",
"version": "3.1.0",
"version": "3.1.1",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
"scripts": {
"lint": "tslint -p . -c tslint.json -e './**/*.json'",
"fix": "tslint --fix -p . -c tslint.json -e './**/*.json'",
"start": "nodemon --exitcrash --ignore *.sqlite -x ts-node bot.ts",
"start": "nodemon --exitcrash --ignore *.sqlite -x ts-node index.ts",
"forever": "forever start --uid conniebot --killSignal=SIGTERM -a -c \"npm start\" ./",
"test": "npm run lint"
},
Expand Down
70 changes: 70 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import c from "config";

import { ICommands } from ".";
import help from "./help";

/**
* Extension methods for different reply commands.
*
* All functions are bound to the instance of the currently running Conniebot.
*/
const commands: ICommands = {
/**
* Funnels a message object to the actual {@link help} function.
*/
async help(message) {
help(message.channel, message.client.user);
},

/**
* Set channel for an arbitrary event. (see {@link INotifRow})
*
* @param event The event name (only the first 50 characters are used)
*/
async notif(message, event) {
if (message.author.id !== c.get("owner")) {
return message.reply("Sorry, but you don't have permissions to do that.");
}

if (!event) {
return message.reply("Sorry, you need to specify an event.");
}

const channel = message.channel;
let returnMessage: string;

try {
await this.db.setChannel(event, channel.id);
returnMessage = `Got it! Will send notifications for ${event} to ${message.channel}.`;
} catch (err) {
console.log(err);
returnMessage = "Something went wrong while trying to set notifications.";
}

return channel.send(returnMessage);
},

/**
* Tries to respond in a timely fashion.
*
* @param roundtrip Should the heartbeat be sent to the message ("roundtrip")
*/
async ping(message, roundtrip?) {
// received message
const created = message.createdTimestamp;
const elapsedMsg = `${Date.now() - created} ms`;

// wait for send
const pingReturn = await message.channel.send(`I'm alive! (${elapsedMsg})`);
const pingMsg = Array.isArray(pingReturn) ? pingReturn[0] : pingReturn;
const roundtripMsg = `${Date.now() - created} ms`;

if (roundtrip === "roundtrip") {
pingMsg.edit(`${pingMsg}, roundtrip ${roundtripMsg}`);
}

return `${elapsedMsg}, ${roundtripMsg}`;
},
};

export default commands;
Loading

0 comments on commit 7ab9924

Please sign in to comment.