mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-02 03:03:37 +00:00
More typings to classes, commands, events, funcs
This commit is contained in:
@ -1,6 +1,32 @@
|
||||
import fs from 'fs';
|
||||
import { Guild } from 'discord.js';
|
||||
import fs, { NoParamCallback } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
interface entry {
|
||||
guild: {
|
||||
id: string,
|
||||
name?: string
|
||||
},
|
||||
statistics: {
|
||||
[key: string]: {
|
||||
"time": number,
|
||||
"used": number
|
||||
}
|
||||
} | {},
|
||||
state: {
|
||||
channels: {
|
||||
"text": string,
|
||||
"voice": string
|
||||
},
|
||||
date: string,
|
||||
station: {
|
||||
name: string,
|
||||
owner: string
|
||||
}
|
||||
} | {},
|
||||
updated?: string
|
||||
}
|
||||
|
||||
export default class {
|
||||
map: Map<string, any>;
|
||||
constructor() {
|
||||
@ -40,11 +66,13 @@ export default class {
|
||||
}
|
||||
|
||||
createEntry(id: string){
|
||||
let newData: any = {};
|
||||
newData.guild = {};
|
||||
newData.guild.id = id;
|
||||
newData.statistics = {};
|
||||
newData.state = {};
|
||||
let newData: entry = {
|
||||
guild: {
|
||||
id: id,
|
||||
},
|
||||
statistics: {},
|
||||
state: {}
|
||||
};
|
||||
this.map.set(id, newData);
|
||||
this.saveEntry(id, newData);
|
||||
}
|
||||
@ -61,7 +89,7 @@ export default class {
|
||||
return this.map.get(id);
|
||||
}
|
||||
|
||||
updateEntry(guild: any, newData: any) {
|
||||
updateEntry(guild: Guild | { id: string, name: string }, newData: entry) {
|
||||
newData.guild.name = guild.name;
|
||||
|
||||
let date = new Date();
|
||||
@ -72,7 +100,7 @@ export default class {
|
||||
//this.showEntry(this.getEntry(guild.id));
|
||||
}
|
||||
|
||||
showEntry(data : any){
|
||||
showEntry(data : entry){
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
@ -96,12 +124,10 @@ export default class {
|
||||
this.updateEntry(newData.guild, newData);
|
||||
}
|
||||
|
||||
saveEntry(file: string, data: any) {
|
||||
data = JSON.stringify(data, null, 4);
|
||||
|
||||
fs.writeFile(path.join(path.dirname(__dirname), '../../datastore') + "/" + file + ".json", data, 'utf8', function(err: any) {
|
||||
saveEntry(file: string, data: entry) {
|
||||
fs.writeFile(path.join(path.dirname(__dirname), '../../datastore') + "/" + file + ".json", JSON.stringify(data, null, 4), 'utf8', function(err: any) {
|
||||
if (err) {
|
||||
//console.log(err);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,19 @@
|
||||
import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice";
|
||||
import { Guild, GuildMember, VoiceChannel } from "discord.js";
|
||||
import { Guild, GuildMember, TextBasedChannel, VoiceBasedChannel, VoiceChannel } from "discord.js";
|
||||
import { getVoiceConnection, joinVoiceChannel, VoiceConnection } from "@discordjs/voice";
|
||||
import RadioClient from "../../Client";
|
||||
import { station } from "./Stations";
|
||||
|
||||
export interface radio {
|
||||
textChannel: TextBasedChannel | null,
|
||||
voiceChannel: VoiceBasedChannel,
|
||||
connection: VoiceConnection | null,
|
||||
message: null,
|
||||
station: station,
|
||||
datastore?: any,
|
||||
currentTime?: number,
|
||||
startTime: number,
|
||||
playTime?: number,
|
||||
}
|
||||
|
||||
export default class Radio extends Map {
|
||||
|
||||
|
@ -40,7 +40,7 @@ export default class Stations extends Array {
|
||||
});
|
||||
}
|
||||
|
||||
list.forEach(async (station: { stream: { [x: string]: any; default: string | number; }; }) => {
|
||||
list.forEach(async (station: station) => {
|
||||
try {
|
||||
let stationTest = await fetch(station.stream[station.stream.default]);
|
||||
if(stationTest.ok === true) return;
|
||||
@ -83,7 +83,7 @@ export default class Stations extends Array {
|
||||
return foundStation;
|
||||
} else {
|
||||
|
||||
let foundStations : any[] = [];
|
||||
let foundStations : { station: string, name: string, probability: number }[] = [];
|
||||
if (key == "radio") return false;
|
||||
|
||||
this
|
||||
@ -126,7 +126,7 @@ export default class Stations extends Array {
|
||||
}
|
||||
}
|
||||
}
|
||||
let highestProbabilityStation;
|
||||
let highestProbabilityStation : any | { station: string, name: string, probability: number } | string | null = null;
|
||||
for (let i = 0; i < foundStations.length; i++) {
|
||||
if (
|
||||
!highestProbabilityStation ||
|
||||
|
@ -1,14 +1,15 @@
|
||||
import { Guild } from "discord.js";
|
||||
import RadioClient from "../../Client";
|
||||
import { radio } from "./Radio";
|
||||
|
||||
export default class Statistics {
|
||||
map: any;
|
||||
map: Map<any, any>;
|
||||
|
||||
constructor() {
|
||||
this.map = new Map();
|
||||
}
|
||||
|
||||
update(client: RadioClient, guild: Guild | null, radio: any) {
|
||||
update(client: RadioClient, guild: Guild | null, radio: radio) {
|
||||
if(!guild) return;
|
||||
|
||||
client.datastore?.checkEntry(guild.id);
|
||||
@ -24,8 +25,8 @@ export default class Statistics {
|
||||
|
||||
let date = new Date();
|
||||
radio.currentTime = date.getTime();
|
||||
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
||||
radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time)+parseInt(radio.playTime);
|
||||
radio.playTime = radio.currentTime - radio.startTime;
|
||||
radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time) + radio.playTime;
|
||||
|
||||
radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1;
|
||||
client.datastore?.updateEntry(guild, radio.datastore);
|
||||
|
@ -5,12 +5,10 @@ import { station } from "./Stations";
|
||||
|
||||
export default class Streamer {
|
||||
map: any;
|
||||
mode: any | null;
|
||||
logger: any;
|
||||
mode: "auto" | "manual" = "manual";
|
||||
|
||||
constructor() {
|
||||
this.map = new Map();
|
||||
this.mode = null;
|
||||
}
|
||||
|
||||
init(client: RadioClient){
|
||||
|
Reference in New Issue
Block a user