Skip to content

Commit 226b44b

Browse files
committed
initial commit
1 parent 293494a commit 226b44b

File tree

12 files changed

+3325
-0
lines changed

12 files changed

+3325
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["node8"]
3+
}

.gitignore

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# dist
9+
dist/*
10+
#configuration
11+
config/default.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Typescript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 MSFTserver <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Bot for Discord communties to facilitate crypto coin tipping!
2+
(This README will be updated along with bot updates)
3+
Features:
4+
5+
- Tipbot for any coin running the bitcoind client.
6+
- Help message `!tip`.
7+
- Dynamic plugin loading with permission support.
8+
- **out of the box Supported Coins**
9+
- Dogecoin (DOGE)
10+
- Ravencoin (RVN)
11+
12+
## Requirements
13+
14+
- node > 8.0.0
15+
- npm > 0.12.x
16+
- yarn ( install with npm install -g yarn if not installed )
17+
18+
## Installation
19+
20+
Download the respective coins wallet that uses bitcoind (aka bitcoin-qt).
21+
22+
Create a bot and get the bot's Token: https://discordapp.com/developers/applications/me
23+
24+
make sure you have setup your wallet config properly to facilitate this bot
25+
26+
wallet folder found in %appdata% (default Roaming Folder):
27+
28+
```
29+
server=1
30+
rpcbind=127.0.0.1
31+
rpcallowip=127.0.0.1
32+
rpcport=3335
33+
rpcuser=<Same-as-you-set-in-config.json>
34+
rpcpassword=<Same-as-you-set-in-config.json>
35+
rpcclienttimeout=30
36+
rpcthreads=<Number-of-Threads>
37+
rpcworkqueue=1000
38+
```
39+
40+
rename default.json.example in /config to default.json
41+
42+
edit the following according to your wallets config options set in the previous step:
43+
44+
(you can add more coins by following this format and using the exampleTipper.js)
45+
46+
```
47+
"ravend": {
48+
"port": 3335,
49+
"user": "username",
50+
"pass": "Do-Not-Use-This-Password-Youll-Be-Hacked-For-all-Teh-Moneys!"
51+
},
52+
"doged": {
53+
"port": 3336,
54+
"user": "username",
55+
"pass": "Do-Not-Use-This-Password-Youll-Be-Hacked-For-all-Teh-Moneys!"
56+
},
57+
```
58+
59+
then run:
60+
61+
```
62+
npm install
63+
node bot.js
64+
```
65+
66+
### Development
67+
68+
Be sure to run the command below before working on any code, this ensures
69+
prettier goes to work and keeps code to our standard.
70+
71+
```
72+
yarn install --production=false
73+
```
74+
to run prettier before submitting your code simply run the following in the bots root directory.
75+
76+
```
77+
yarn precommit
78+
```

bot/bot.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"use strict";
2+
3+
// Load up libraries
4+
const Discord = require("discord.js");
5+
// Load config!
6+
let config = require("config");
7+
config = config.get("bot");
8+
9+
var aliases;
10+
try {
11+
aliases = require("./alias.json");
12+
} catch (e) {
13+
//No aliases defined
14+
aliases = {
15+
test: {
16+
process: function(bot, msg) {
17+
msg.channel.send("test");
18+
}
19+
}
20+
};
21+
}
22+
var commands = {};
23+
24+
var bot = new Discord.Client();
25+
26+
bot.on("ready", function() {
27+
console.log(
28+
"Logged in! Serving in " + bot.guilds.array().length + " servers"
29+
);
30+
require("./plugins.js").init();
31+
console.log("type " + config.prefix + "help in Discord for a commands list.");
32+
bot.user.setActivity(config.prefix + "Intialized!");
33+
var text = ["tiprvn", "tipdoge"];
34+
var counter = 0;
35+
setInterval(change, 10000);
36+
37+
function change() {
38+
bot.user.setActivity(config.prefix + text[counter]);
39+
counter++;
40+
if (counter >= text.length) {
41+
counter = 0;
42+
}
43+
}
44+
});
45+
46+
bot.on("disconnected", function() {
47+
console.log("Disconnected!");
48+
process.exit(1); //exit node.js with an error
49+
});
50+
51+
function checkMessageForCommand(msg, isEdit) {
52+
//check if message is a command
53+
if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) {
54+
console.log(
55+
"treating " + msg.content + " from " + msg.author + " as command"
56+
);
57+
var cmdTxt = msg.content.split(" ")[0].substring(config.prefix.length);
58+
var suffix = msg.content.substring(
59+
cmdTxt.length + config.prefix.length + 1
60+
); //add one for the ! and one for the space
61+
if (msg.isMentioned(bot.user)) {
62+
try {
63+
cmdTxt = msg.content.split(" ")[1];
64+
suffix = msg.content.substring(
65+
bot.user.mention().length + cmdTxt.length + config.prefix.length + 1
66+
);
67+
} catch (e) {
68+
//no command
69+
msg.channel.send("Yes?");
70+
return;
71+
}
72+
}
73+
let alias = aliases[cmdTxt];
74+
if (alias) {
75+
var cmd = alias;
76+
} else {
77+
var cmd = commands[cmdTxt];
78+
}
79+
if (cmd) {
80+
// Add permission check here later on ;)
81+
try {
82+
cmd.process(bot, msg, suffix, isEdit);
83+
} catch (e) {
84+
var msgTxt = "command " + cmdTxt + " failed :(";
85+
if (config.debug) {
86+
msgTxt += "\n" + e.stack;
87+
}
88+
msg.channel.send(msgTxt);
89+
}
90+
}
91+
} else {
92+
//message isn't a command or is from us
93+
//drop our own messages to prevent feedback loops
94+
if (msg.author == bot.user) {
95+
return;
96+
}
97+
98+
if (msg.author != bot.user && msg.isMentioned(bot.user)) {
99+
msg.channel.send("yes?"); //using a mention here can lead to looping
100+
} else {
101+
}
102+
}
103+
}
104+
105+
bot.on("message", msg => checkMessageForCommand(msg, false));
106+
/*bot.on("messageUpdate", (oldMessage, newMessage) => {
107+
checkMessageForCommand(newMessage, true);
108+
});*/
109+
110+
exports.addCommand = function(commandName, commandObject) {
111+
try {
112+
commands[commandName] = commandObject;
113+
} catch (err) {
114+
console.log(err);
115+
}
116+
};
117+
exports.addCustomFunc = function(customFunc) {
118+
try {
119+
customFunc(bot);
120+
} catch (err) {
121+
console.log(err);
122+
}
123+
};
124+
exports.commandCount = function() {
125+
return Object.keys(commands).length;
126+
};
127+
128+
bot.login(config.token);

0 commit comments

Comments
 (0)