forked from Shuruhatik/quran-radio-bot-discord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
134 lines (127 loc) · 5.62 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
import inquirer from "inquirer";
import chalkAnimation from "chalk-animation";
import Discord from 'discord.js';
import { createAudioResource,createAudioPlayer, joinVoiceChannel} from '@discordjs/voice';
import { createSpinner } from "nanospinner";
import Database from "st.db";
import ms from 'ms';
import express from 'express';
import radio_choices from "./channels.js";
const app = express()
import replit from "quick.replit"
const config_db = new replit.Database(process.env["REPLIT_DB_URL"])
const config_delete_db = new Database({path:"./datas/config.yml"})
await getStarted()
async function getStarted(){ /*JANGAN DIRUBAH, MASUK KE /"DATA/CONFIG.YML" UNTUK MERESET CONFIGURASI ANDA = TRUE/FALSE*/
if(await config_delete_db.has("delete_this_value_if_you_want_delete_config") != true || await config_delete_db.get("delete_this_value_if_you_want_delete_config") == true){
await config_db.delete(`bot_config`)
}
if(await config_db.get(`bot_config`)) return await startBot()
const rainbow = chalkAnimation.pulse('LOADING JANGAN DI INPUT/CLICK');
setTimeout(async()=> {
rainbow.stop()
console.log(`\u001b[40;1m JANGAN LUPA BERSHOLAWAT KEPADA NABI MUHAMMAD SHALALLAHU ALAIHI WASSALAM\n\u001b[0m CODE DARI \u001b[47;1m\u001b[30;1mShuruhatik#2443\u001b[0m `)
const ask1 = await inquirer.prompt({
name:"token_bot",
type:'password',
message:`MASUKAN TOKEN DISINI`,
mask:"*"
})
const ask2 = await inquirer.prompt({
name:"status_bot",
type:'input',
message:`SET STATUS BOT KAMU`,
})
const ask3 = await inquirer.prompt({
name:"status_type",
type:'list',
message:`PILIH TYPE STATUS BOT KAMU`,
choices:[
"Playing","Competing","Listening","Watching"
]
})
const ask4 = await inquirer.prompt({
name:"voice_invitelink",
type:'input',
message:`BUAT DAN MASUKAN "VOICE" INVITE LINK DISINI`
})
const ask5 = await inquirer.prompt({
//HAPUS ATAU INPUT COMMENT UNTUK MENGGANTI CARA MEMLIHI CHANNEL
name:"radio_url",
//type:'url',
//message: `MASUKAN URL`,
type:'list',
message:`PILIH RADIO AL-QUR'AN`,
choices:radio_choices
})
await config_db.set(`bot_config`,{
token_bot:ask1.token_bot.replaceAll("\\","").replaceAll("~",""),
status_bot:ask2.status_bot.replaceAll("\\","").replaceAll("~",""),
status_type:ask3.status_type,
voice_invite_link:ask4.voice_invitelink.replaceAll("\\","").replaceAll("~","")
})
await config_delete_db.set(`radio_url`,ask5.radio_url)
return await startBot()
},6500)
}
async function startBot(){
console.clear()
const spinner = createSpinner(`Processing..`).start()
const client = new Discord.Client({
intents:[Discord.GatewayIntentBits.Guilds,Discord.GatewayIntentBits.GuildIntegrations,Discord.GatewayIntentBits.GuildVoiceStates],
partials: [Discord.Partials.GuildScheduledEvent,Discord.Partials.Channel, Discord.Partials.GuildPresences]
})
const config = await config_db.get(`bot_config`)
client.login(config.token_bot).then(()=>{
spinner.update({ text: 'Sedang Menjalankan Bot...' })
}).catch(()=>{
spinner.error({ text: 'Token Anda Salah...' })
})
// Event Ready
client.once("ready",async()=>{
client.user.setActivity(config.status_bot, { type:Discord.ActivityType[config.status_type] });
let bot_invite_link = `https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&permissions=8&scope=bot%20applications.commands`
spinner.success({ text: `Logged in as ${client.user.tag} (${client.user.id})`})
app.get('/',(r, s) => {
s.send({message:"Bot by Shuruhatik#2443",youtube_channel:"https://www.youtube.com/ShuruhatikYT"})
}).post('/',async(r, s) => {
s.send({
message:"Bot by Shuruhatik#2443", youtube_channel:"https://www.youtube.com/ShuruhatikYT"
})
if(await config_db.has(`uptime`) != true){
console.log("\u001b[32m✔ \u001b[0mﺡﺎيﺠﻨﺑ ﻉﻭﺮﺸﻤﻟ ﻢﻳﺎﺗ ﺏﺍ ﻞﻤﻋ ﻢﺗ")
await config_db.set(`uptime`,true)
}
})
.get("/invite", (req, res) => res.status(301).redirect(bot_invite_link))
.listen(3000)
console.log("\u001b[32m▣\u001b[0m \u001b[0mﺔﻄﺳﺍﻮﺑ ﺕﻮﺒﻟﺍ ﺔﺠﻣﺮﺑ ﻢﺗ \u001b[34;1mShuruhatik#2443\u001b[0m")
console.log("\u001b[32m▣ \u001b[0m\u001b[0m\u001b[40;1m\u001b[34;1mhttps://"+process.env.REPL_ID+".id.repl.co/invite\u001b[0m")
client.fetchInvite(config.voice_invite_link).then(async invite => {
let guild = await client.guilds.cache.get(invite.guild.id)
if(guild){
let voiceChannel = await guild.channels.cache.get(invite.channelId)
let connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
group:client.user.id
})
startPlayRadio(connection)
setInterval(() => startPlayRadio(connection),60000)
}
})
})
function startPlayRadio(connection) {
try{
let radio_url = config_delete_db.get(`radio_url`)
let player = createAudioPlayer()
let resource = createAudioResource(radio_url)
connection.subscribe(player)
player.play(resource)
} catch(e){
// jika terjadi kesalahan, hapus COMMENT di bawah ini untuk mengetahui kesalahanya
//console.error(e)
}
}
}