-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
98 lines (83 loc) · 2.84 KB
/
main.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
const https = require('https');
const fetch = require('node-fetch');
const {Client, MessageAttachment, DMChannel} = require('discord.js');
const client = new Client();
const riotUrlEventData = "https://127.0.0.1:2999/liveclientdata/eventdata"
const riotUrlPlayerList = "https://127.0.0.1:2999/liveclientdata/playerlist"
const token = require("./token.js");
const { resolve } = require('path');
// setup an agent to make unsecure calls with locally
const unsecureAgent = new https.Agent({
rejectUnauthorized: false
})
let songDispatcher;
let voiceConnection;
// Global state
let eventNumber = 0;
client.on('ready', () => {
console.log('Starting...');
});
client.on('message', async msg => {
if(msg.content === '!oof') {
const attatchment = new MessageAttachment('./media/damage.gif');
msg.reply('OOF', attatchment);
} else if (msg.channel.name === 'fun-facts'){
// fun facts moderation
var message = msg.content.trim().toLowerCase();
if(!message.startsWith("fun fact:")){
msg.delete({'reason': 'Not a fun fact!'});
var dmChannel = new DMChannel(client, {'recipient': msg.author})
dmChannel.send("test");
}
} else if (msg.content === '!join') {
if(!msg.guild) return;
if (msg.member.voice.channel) {
voiceConnection = await msg.member.voice.channel.join();
WatchaSay();
}
else {
message.reply('You need to join a voice channel first!');
}
} else if(msg.content === "!leave") {
voiceConnection.disconnect();
}
})
function PlaySong(voiceConnection) {
}
function FindRespawnValue() {
try {
return new Promise((resolve, reject) => {
fetch(riotUrlPlayerList, {
agent: unsecureAgent
})
.then( res => {
if(!res.ok) {
throw new Error('League game not detected.')
}
return res.json()
} )
.then( players => {
for (var i = 0; i < players.length; i++ ) {
if (players[i].summonerName === "Via Dominus") {
resolve(players[i].respawnTimer.toString());
}
}
reject("Couldn't find respawn value");
})
.catch(error => {
console.log(error.code);
});
});
} catch (error) {
console.log(error);
}
}
client.login(token);
setInterval(function() {
try {
let promise = FindRespawnValue();
promise.then(value => console.log(value));
} catch (error) {
console.log(error);
}
}, 1000);