forked from SourCreamCulture/dogebeatz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
276 lines (232 loc) · 9.1 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
const config = require("/config.json");
const Moonstone = require("moonstone-wrapper");
const ytdl = require("ytdl-core-discord");
const bot = Moonstone(config.apitoken);
const yts = require("yt-search");
const fetch = require("node-fetch");
const axios = require('axios');
const Constants = Moonstone.Constants;
const prefix = config.prefix;
const ownerid = 'a307faa0-c573-4fd8-8229-6194fab201e0';
const trusted = ['a307faa0-c573-4fd8-8229-6194fab201e0']
bot.on("ready", async (user) => {
console.log("Ready! Logged in as " + user.username);
const topRooms = await bot.getTopRooms();
console.log("There are " + topRooms.length + " available rooms.");
bot.editSelf({avatarUrl: 'https://avatars.githubusercontent.com/u/83242673?s=400&u=78e0a77d196784ca33e981364fda0129b884ec85&v=4'})
const foundRooms = topRooms.filter(
(room) => room.creatorId == ownerid // Filter for rooms created by a specific user
);
//await bot.joinRoom('7bf0dede-b6e7-4fe9-b5a6-6e19f72ce8a3'); //use if you dont know your user id and want to join a specific room
// If the filter found a room, join it, otherwise create one.
const room =
foundRooms.length > 0
? foundRooms[0]
: await bot.createRoom({
name: "Music to Chill to",
description:
"Powered by Code and Made by @SourCream",
privacy: "public",
});
await bot.joinRoom(room); // Join room
});
// Send a message when first joining a room.
bot.on("joinedRoom", async (room) => {
await room.sendChatMessage("Hi, I'm dogebeatz :D");
await room.sendChatMessage(`Type ${prefix}help to see all my commands.`);
});
// Send message to users who join the room
bot.on("userJoinRoom", async (user, room) => {
await user.sendWhisper(
`Hi, welcome to the room! Type ${prefix}help to see all my commands.`
);
// If the user is the bot owner, set them as moderator
if (user.id == ownerid) await user.setAuthLevel(Constants.AuthLevel.MOD);
});
const isPlayingMusic = (room) => {
return (
room.audioConnection &&
room.audioConnection.player &&
room.audioConnection.player.dispatcher
);
};
const commandList = bot.buildChatMessage((b) =>
b
.text("Here's a list of commands:")
.text(`|| ${prefix}play <url | query> - Play a song from youtube.`)
.text(`|| ${prefix}pause - Pause the player.`)
.text(`|| ${prefix}resume - Resume the player.`)
.text(`|| ${prefix}volume <volume> - Set the player volume (0-200)`)
.text(`|| ${prefix}myid - Get your user id`)
.text(`|| ${prefix}lofi - Start playing lofi music`)
.text(`|| ${prefix}chat <message> - Chat with the bot!`)
.text(`|| ${prefix}stats - Get some stats of dogehouse!`)
);
// Listen for chat messages
bot.on("newChatMsg", async (msg) => {
// Command parser
if (msg.user.id === bot.user.id) return
const command = msg.content.includes(" ")
? msg.content.split(" ")[0]
: msg.content;
const args = msg.content.includes(" ")
? msg.content.split(" ").slice(1)
: [];
if (msg.content.startsWith(`${prefix}banner`)){
if (msg.user.id != ownerid) return
//let message = args.join(" ");
//if (!message) return msg.user.sendWhisper('You did not supply a new pfp!');
await bot.editSelf({bannerUrl: 'https://pbs.twimg.com/profile_banners/840626569743912960/1601562221/1500x500'})
return
};
if (msg.content.startsWith(`${prefix}d`)){
if (msg.user.id != ownerid) return
let message = args.join(" ");
if (!message) return msg.user.sendWhisper('You did not supply a new bio!');
await bot.editSelf({bio: message})
return
};
if (msg.content.startsWith(`${prefix}mod`)){
if (msg.user.id != trusted) return
//let users = args[0]
//if (!users) return msg.user.sendWhisper('You did not supply a user to make mod!');
await msg.user.setAuthLevel(Constants.AuthLevel.MOD);
return
};
if (msg.content.startsWith(`${prefix}stats`)){
axios.get('https://api.dogegarden.net/v1/statistics')
.then(function (response) {
let stats = response.data
const statlist = bot.buildChatMessage((b) =>
b
.text("Here's some dogehouse stats:")
.text(`|| Rooms: ${stats.totalRooms}`)
.text(`|| Scheduled Rooms: ${stats.totalScheduledRooms}`)
.text(`|| Registered Users: ${stats.totalRegistered}`)
.text(`|| Online: ${stats.totalOnline}`)
.text(`|| Bots Online: ${stats.totalBotsOnline}`)
);
msg.user.sendWhisper(statlist);
}).catch(function (error) {
msg.user.sendWhisper(`Sorry, I had trouble finding the doges! \`${error}\``)
})
return
};
if (msg.content.startsWith(`${prefix}chat`)){
var searchString = args.join(" ");
if (!searchString)return await msg.room.sendChatMessage('You didnt provide anything to say!')
fetch(
`https://api.monkedev.com/fun/chat?msg=${encodeURIComponent(
searchString
)}&uid=0101`
)
.then((res) => res.json())
.then(async (json) => {
return await msg.room.sendChatMessage(json.response);
});
return
};
if (msg.content === (`${prefix}walk`)){
let url = 'https://www.youtube.com/watch?v=SXMhL_UoVWw';
await msg.room.sendChatMessage((b) =>
b.text("Playing Plug Walk").url(url).text("...")
);
playFromUrl(msg.room, url);
return
};
if (msg.content.startsWith(`${prefix}lofi`)){
if (args[0] === 'new'){
let url = 'https://www.youtube.com/watch?v=DWcJFNfaw9c';
await msg.room.sendChatMessage((b) =>
b.text("Playing Lofi").url(url).text("...")
);
playFromUrl(msg.room, url);
} else {
let url = 'https://www.youtube.com/watch?v=5qap5aO4i9A';
await msg.room.sendChatMessage((b) =>
b.text("Playing Lofi").url(url).text("...")
);
playFromUrl(msg.room, url);
}
return
};
if (msg.content.includes(`${prefix}play`)){
if (msg.user.id === trusted) return
const videoPattern = /^(https?:\/\/)?(www\.)?(m\.)?(youtube\.com|youtu\.?be)\/.+$/gi;
if (videoPattern.test(args[0])) {
var url = args[0];
await msg.room.sendChatMessage((b) =>
b.text("Playing").url(url).text("...")
);
playFromUrl(msg.room, url);
} else {
var searchString = args.join(" ");
if (!searchString)return await msg.room.sendChatMessage('You didnt provide a song to play!')
var searched = await yts.search(searchString)
//if(searched.videos.length === 0)return await msg.room.sendChatMessage('Looks like I wasnt able to find this video on youtube!')
var songInfo = searched.videos[0]
var url = songInfo.url
await msg.room.sendChatMessage((b) =>
b.text(`Playing ${songInfo.title}`).url(url).text("...")
);
playFromUrl(msg.room, url);
}
return
};
if (msg.content === (`${prefix}help`)){
return await msg.user.sendWhisper(commandList);
};
if (msg.content.includes(`${prefix}pause`)){
if (!isPlayingMusic(msg.room))
return msg.room.sendChatMessage("Not playing anything.");
if (msg.room.audioConnection.player.dispatcher.paused) return msg.room.sendChatMessage("Music is already paused!")
msg.room.audioConnection.player.dispatcher.pause();
return
};
if (msg.content.includes(`${prefix}resume`)){
if (!isPlayingMusic(msg.room))
return msg.room.sendChatMessage("Not playing anything.");
if (msg.room.audioConnection.player.dispatcher.paused){
msg.room.audioConnection.player.dispatcher.resume()
} else {
msg.room.sendChatMessage("The Music is not paused!");
}
return
};
if (msg.content.includes(`${prefix}volume`)){
if (!isPlayingMusic(msg.room))
return msg.room.sendChatMessage("Not playing anything.");
if (args.length < 1)
return await msg.room.sendChatMessage("Invalid volume");
const volume = parseInt(args[0] / 100);
if (volume > 2 * 100|| volume < 0)
return await msg.room.sendChatMessage("Invalid volume");
msg.room.audioConnection.player.dispatcher.setVolume(volume); // Set music volume
return
};
if (msg.content.includes(`${prefix}myid`)){
return msg.room.sendChatMessage(`Your id is ${msg.user.id}`);
};
if (msg.content.startsWith(`${prefix}`)){
return await msg.room.sendChatMessage("Unknown command.");
};
});
const playFromUrl = async (room, url) => {
if (!room.selfUser.isSpeaker) {
await room.sendChatMessage(
"I need to be a speaker in order to play music."
);
if (!room.selfUser.roomPermissions.askedToSpeak) await room.askToSpeak();
return;
}
let stream;
try {
stream = await ytdl(url);
} catch (e) {
await room.sendChatMessage("Failed to get video: " + e.message);
}
if (!stream) return;
const audioConnection = await room.connect(); // Connect to the room voice server (or grab it, if already connected.)
audioConnection.play(stream, { type: "opus" }); // Play opus stream from youtube.
};
bot.connect();