forked from Gawdl3y/discord-rpbot
-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 0f94428
Showing
10 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
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,22 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
"indent": ["error", "tab", { "SwitchCase": 1 }], | ||
"keyword-spacing": ["error", { | ||
"overrides": { | ||
"if": { "after": false }, | ||
"for": { "after": false }, | ||
"while": { "after": false }, | ||
"catch": { "after": false }, | ||
"switch": { "after": false } | ||
} | ||
}], | ||
"no-else-return": "off", | ||
"no-console": "off" | ||
} | ||
} |
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,4 @@ | ||
/node_modules | ||
npm-debug.log | ||
/lib | ||
settings.yaml |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Schuyler Cebulskie | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,3 @@ | ||
# Discord RPBot | ||
This is a simple bot that currently only contains one useful command: !roll. | ||
More information will hopefully come at some point. |
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,34 @@ | ||
{ | ||
"name": "discord-rpbot", | ||
"version": "0.1.0", | ||
"description": "A Discord bot that contains commands useful for text roleplaying", | ||
"license": "MIT", | ||
"author": "Schuyler Cebulskie <[email protected]> (https://gawdl3y.com/)", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Gawdl3y/discord-rpbot.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Gawdl3y/discord-rpbot/issues" | ||
}, | ||
"keywords": [ | ||
"discord", | ||
"bot", | ||
"roleplaying", | ||
"dice" | ||
], | ||
"scripts": { | ||
"build": "babel src -d lib" | ||
}, | ||
"dependencies": { | ||
"discord.js": "^8.0.0", | ||
"js-yaml": "^3.6.1", | ||
"dice-expression-evaluator": "^0.1.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.0.0", | ||
"babel-eslint": "^6.0.4", | ||
"babel-cli": "^6.0.0", | ||
"babel-preset-es2015": "^6.9.0" | ||
} | ||
} |
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,2 @@ | ||
email: [email protected] | ||
password: SomeCrazyPassword123 |
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,31 @@ | ||
'use babel'; | ||
'use strict'; | ||
|
||
import DiceExpression from 'dice-expression-evaluator'; | ||
|
||
export default class DiceRollCommand { | ||
constructor() { | ||
this.matches = [ | ||
/^!roll\s+([0-9d+ -]+)(>\s*([0-9]+))?\s*$/i, | ||
/\(\s*roll:\s*([0-9d+ -]+)(>\s*([0-9]+))?\s*\)/i | ||
]; | ||
} | ||
|
||
run(message, matchResult) { | ||
try { | ||
const dice = new DiceExpression(matchResult[1]); | ||
const result = dice.roll(); | ||
console.log(result); | ||
if(matchResult.length >= 4 && matchResult[3]) { | ||
const target = parseInt(matchResult[3]); | ||
message.client.sendMessage(message, message.author + (target <= result.roll ? ' has succeeded. ' : ' has failed. ') + ' (Rolled ' + result.roll + ', target ' + target + ')'); | ||
} else { | ||
message.client.sendMessage(message, message.author + ' rolled ' + result.roll + '.'); | ||
} | ||
} catch(e) { | ||
console.log(e); | ||
message.client.sendMessage(message, message.author + ' specified an invalid dice expression.'); | ||
return; | ||
} | ||
} | ||
} |
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,14 @@ | ||
'use babel'; | ||
'use strict'; | ||
|
||
export default class TestCommand { | ||
constructor() { | ||
this.matches = [ | ||
/^!test(\s.*)?$/i | ||
]; | ||
} | ||
|
||
run(message) { | ||
message.client.sendMessage(message, 'Oh boy, the test command is working!'); | ||
} | ||
} |
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,50 @@ | ||
'use babel'; | ||
'use strict'; | ||
|
||
import Discord from 'discord.js'; | ||
import YAML from 'js-yaml'; | ||
import fs from 'fs'; | ||
|
||
// Commands | ||
import TestCommand from './commands/test'; | ||
import DiceRollCommand from './commands/dice-roll'; | ||
const commands = [ | ||
new TestCommand(), | ||
new DiceRollCommand() | ||
]; | ||
|
||
// Parse config | ||
const config = YAML.safeLoad(fs.readFileSync('settings.yaml')); | ||
|
||
// Create client | ||
const bot = new Discord.Client(); | ||
bot.on('ready', () => { | ||
console.log('Bot is ready; logged in as ' + bot.user.username + '#' + bot.user.discriminator + ' (ID ' + bot.user.id + ')'); | ||
}); | ||
bot.on('error', e => { | ||
console.log('ERROR: ' + e); | ||
}); | ||
bot.on('warn', e => { | ||
console.log('WARNING: ' + e); | ||
}); | ||
bot.on('disconnected', () => { | ||
console.log('Disconnected!'); | ||
process.exit(1); | ||
}) | ||
|
||
// Set up commands | ||
bot.on('message', message => { | ||
commandLoop: for(const command of commands) { | ||
for(const match of command.matches) { | ||
const matchResult = match.exec(message.content); | ||
if(matchResult) { | ||
console.log('Running ' + command.constructor.name + ': message="' + message + '" matchResult="' + matchResult + '"'); | ||
command.run(message, matchResult); | ||
break commandLoop; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
// Log in | ||
bot.login(config.email, config.password); |