-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
121 lines (100 loc) · 4.68 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const Discord = require('discord.js');
const Account = require('./account.js');
const { decks } = require('cards');
const bot = new Discord.Client();
const token = 'NTkxNDYzNzQ0MzE2NjM3MTkx.XQxJ2Q._8eBMIn4sXjCufWWvGu_Oc80pTg';
const PREFIX = '.';
var accounts = [];
//Hardcoded for debugging
accounts.push(new Account("BiggestShaq", 1000));
const deck = new decks.StandardDeck();
deck.shuffleAll();
var playerHand = [];
var dealerHand = [];
var gamestarted = false
bot.login(token);
bot.on('ready', () => { console.log('Casino Bot is now online'); });
bot.on('message', message=>{
//Ignore all bots
if(message.author.bot)
return;
let args = message.content.substring(PREFIX.length).split(" ");
var a_index = existsAccount(message.author.username.toString());
console.log(a_index);
//Commands
switch(args[0]){
case 'open':
if(a_index < 0){
var newAccount = new Account(message.author.username.toString(), 1000);
accounts.push(newAccount);
console.log(accounts[0].getBearer());
message.channel.send("Very well good sir. I have created for you an account with " + newAccount.getCredit() + " credits.");
}
else{
message.channel.send("You already have an account with us. Please enjoy your time here.");
}
break;
case 'balance':
/*let i = 0;
for(; i < accounts.length; i++)
if(accounts[i].getBearer() === message.author.username.toString())
break;*/
if(a_index >= 0){
message.channel.send("You have " + accounts[a_index].getCredit() + " credits remaining.");
}else{
message.channel.send("I'm afraid you do not have account with us.");
}
break;
case 'set':
if(a_index >= 0){
message.channel.send("I have set your account to " + accounts[a_index].setCredit(2000) + " credits.");
}else{
message.channel.send("I'm afraid you do not have account with us.");
}
break;
case 'bj':
if(args.length != 2){
message.channel.send("To play blackjack use .bj [amount]");
break;
}
if(a_index >= 0)
{
if(accounts[a_index].getCredit() < args[1]){
message.channel.send("I believe you have insufficient credits to play this amount");
gamestarted = true;
}else{
//Placeholder
if(gamestarted == false){
playerHand = deck.draw(2);
dealerHand = deck.draw(2);
}
let embed = new Discord.RichEmbed()
.setTitle("Blackjack Session Information")
.setAuthor(message.author.username.toString(), (message.author.avatarURL == null)?message.author.defaultAvatarURL:message.author.avatarURL)
.setColor(0x00AE86)
//.setThumbnail("https://cdn.discordapp.com/avatars/" + bot.user.id + "/" + bot.user.avatarURL + ".png")
.setThumbnail(bot.user.avatarURL)
.addField("Your hand:", playerHand[0].rank.shortName + " of " + playerHand[0].suit.name + ", and " + playerHand[1].rank.shortName + " of " + playerHand[1].suit.name)
.addField("Dealer's Hand:" , "[Face Down Card] and " + dealerHand[1].rank.shortName + " of " + dealerHand[1].suit.name);
console.log(message.author.avatarURL);
console.log(bot.user.avatarURL);
message.channel.send({embed});
console.log("Dealer hand: " + dealerHand[0].rank.shortName + " of " + dealerHand[0].suit.name + ", and " + dealerHand[1].rank.shortName + " of " + dealerHand[1].suit.name)
//message.channel.send("I'm sorry, but you have lost " + args[1] + " credits");
//accounts[a_index].deductCredits(parseInt(args[1], 10));
}
}else{
message.channel.send("I'm afraid you do not have account with us.");
}
break;
}
});
function existsAccount(user){
if(accounts.length === 0)
return -1;
let i = 0;
for(; i <= accounts.length; i++)
if(accounts[i].getBearer() === user)
break;
return (i < accounts.length)? i: -1;
}