-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
399 additions
and
268 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.