-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js.bck
225 lines (183 loc) · 7.13 KB
/
app.js.bck
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
A ping pong bot, whenever you send "ping", it replies "pong".
A logmerlixnet Bot, whatever you send "ping,twitter,add,WelcomeMessage,say"
*/
// import the discord.js module
const Discord = require('discord.js');
// create an instance of a Discord Client, and call it bot
const bot = new Discord.Client();
//Bot Config! #Prefix & Token
const config = require("./config.json");
// the token of your bot - https://discordapp.com/developers/applications/me
// const token = '(token)';
// the ready event is vital, it means that your bot will only start reacting to information
// from Discord _after_ ready is emitted.
//TODO New console.log Output:
// funktions:
function commandIs(str, msg) {
return msg.content.toLowerCase().startsWith('config.prefix' + str)
}
function pluck(arry) {
return arry.map(function(item) { return item[`name`]; });
}
function hasRole(mem, role) {
if (pluck(mem.roles).includes(role)){
return true;
} else {
return false;
}
}
bot.on('ready', () => {
console.log('I am ready!');
});
//TODO Welcome Message
bot.on("guildMemberAdd", member => {
let guild = member.guild
guild.defaultChannel.sendMessage(`Welcome ${member.user} to this Server.`).catch(console.error);
});
bot.on("guildCreate", guild => {
console.log(`New guild added : ${guild.name}, owned by $(guild.owner.user.username)`);
});
// Change Status / Check Game // Check Game / He Playing a Game?
bot.on("presenceUpdate", (oldMember, newMember) => {
let guild = newMember.guild;
let playRole = guild.roles.find("name", "Playing Minecraft");
if (!playRole) return;
if (newMember.user.presence.game && newMember.user.presence.game.name === "Minecraft") {
newMember.addRole(playRole).catch(console.error);
}else if (!newMember.user.presence.game && newMember.roles.has(playRole.id)) {
newMember.removeRole(playRole).catch(console.error);
}
});
// Set Prefix for command!
// const prefix = "!";
// create an event listener for messages
bot.on('message', message => {
if (message.author.bot) return;
if (!message.content.startsWith(config.prefix)) return;
let command = message.content.split(" ")[0]
command = command.slice(config.prefix.length);
let args = message.content.split(" ").slice(1);
// if i write add then addiotion this
if (command === "add") {
let numArry = args.map(n => parseInt(n));
let total = numArry.reduce((p, c) => p + c)
message.channel.sendMessage(total).catch(console.error);
}
// if the message is say
if (command === "say") {
// sendMessage nach dem Comamnd "say"
message.channel.sendMessage(args.join(" ")).catch(console.error);
}
// if the message is "ping",
if (message.content.startsWith(config.prefix + "ping")) {
// send "pong" to the same channel.
message.channel.sendMessage('pong!').catch(console.error);
} else
if (message.content.startsWith(config.prefix + "foo")) {
let modRole = message.guild.roles.find("name", "Mods");
if (message.member.roles.has(modRole.id)) {
message.channel.sendMessage("bar!").catch(console.error);
} else {
message.reply("You bleb, you don´t have the permissions to use this Command!").catch(console.error);
}
}
//TODO: KICK Function!
/* Kick dont fixxed!
if (commandIs("kick", message)) {
if (hasRole(message.member, "Moderator") || hasRole(message.member, "Leitung")) {
if (args.length === 1) {
message.channel.sendMessage('Du hast kein Argument definiert. Usage: `!kick @User`')
} else {
message.guild.member(message.mentions.users.first()).kick();
}
}
}
*/
/*
if (message.content.startsWith(config.prefix + "kick")) {
let modRole = message.guild.roles.find("name", "Moderator")
if (!message.member.roles.has(modRole.id))
{ return
message.reply("you bleb, you don´t have the permissions to use this Command!").catch(console.error);
}
//let (message.member.roles.has(modRole.id)) {
if (message.mentions.users.size === 0) {
return message.reply("Usage: `@User to kick`").catch(console.error);
}
let kickMember = message.guild.member(message.mentions.users.first());
if (!kickMember) {
return message.reply("That user does not seen valid").catch(console.error);
}
if (!message.guild.member(bot.user).hasPermission("KICK_MEMBERS")) {
return message.reply("I don´t have the permissions (KICK_MEMBERS) to do this.").catch(console.error);
}
kickMember.kick().then(member => {
message.reply(` der Spieler|User: ${member.user} wurde gekicked.`).catch(console.error);
}).catch(console.error);
}
*/
if (message.content.startsWith(config.prefix + "eval")) {
if (message.author.id !== "156473495348314113") return;
try {
var code = args.join(" ");
var evaled = eval(code);
if (typeof evaled !== "string")
evaled = require("util").inspect(evaled);
message.channel.sendCode("xl", clean(evaled));
} catch(err) {
message.channel.sendMessage(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
}
}
//TODO Avatar!
// if the message is "what is my avatar",
if (message.content.startsWith(config.prefix + "avatar")) {
// send the user's avatar URL
message.reply(message.author.avatarURL).catch(console.error);
}
//TODO twitter APi
//if the Prefix + Twiter write
if (message.content.startsWith(config.prefix + "twitter")) {
// then send this in this channel:
message.channel.sendMessage("Unser Twitter Acc: https://twitter.com/SoulForgeEU").catch(console.error);
}
//TODO TeamSpeak3 APi
//if the Prefix + Twiter write
if (message.content.startsWith(config.prefix + "ts")) {
// then send this in this channel:
message.channel.sendMessage('Ich lade euch ganz herzlich ein zu meinem Teamspeak3 Server: http://www.teamspeak.com/invite/ts3.soulforge.eu/').catch(console.error);
}
}); // END MESSAGE HANDLER
// This is the function zu eval command!
function clean(text) {
if (typeof(text) === "string")
return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
else
return text;
}
// log our bot in - BotToken
bot.login(config.token);
//TODO voiceChannel - MusicBot
/* const DiscordDJ = require('DiscordDJ');
var music = new DiscordDJ();
music.on('ready', () => {
console.log('DiscordDJ is ready!');
});
// play streams using ytdl-core
const ytdl = require('ytdl-core');
const streamOptions = { seek: 0, volume: 1 };
const broadcast = client.createVoiceBroadcast();
voiceChannel.join()
.then(connection => {
const stream = ytdl('https://www.youtube.com/watch?v=XAWgeLF9EVQ', {filter : 'audioonly'});
broadcast.playStream(stream);
const dispatcher = connection.playBroadcast(broadcast);
})
.catch(console.error);
//bot.on("voice", voiceChannel)
//bot.on("voice", voice => {
// let voice = member.guild
// guid.defaultChannel.sendMessage(`Welcome $(member.user) to this Server.`);
*/